Last active
December 17, 2020 01:37
-
-
Save Podshot/f415300561d43d203158ce786d95e0a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from amulet_map_editor.programs.edit.plugins.api.simple_operation_panel import ( | |
SimpleOperationPanel, | |
) | |
import subprocess | |
import os | |
import sys | |
import threading | |
import glob | |
import urllib.request | |
import zipfile | |
import shutil | |
import wx | |
import amulet_map_editor | |
UPDATER_DOWNLOAD_URL = "https://github.com/Amulet-Team/AmuletUpdater/releases/download/latest/AmuletUpdater.zip" | |
JAVA_DOWNLOAD_URL = "https://download.java.net/java/GA/jdk14.0.2/205943a0976c4ed48cb16f1043c5c647/12/GPL/openjdk-14.0.2_windows-x64_bin.zip" | |
class DownloadFileThread(threading.Thread): | |
def __init__(self, url, filepath, unpack_path): | |
threading.Thread.__init__(self) | |
self._url = url | |
self._filepath = filepath | |
self._unpack_path = unpack_path | |
def run(self) -> None: | |
urllib.request.urlretrieve(self._url, self._filepath) | |
with zipfile.ZipFile(self._filepath, "r") as z_ref: | |
z_ref.extractall(self._unpack_path) | |
class Update(SimpleOperationPanel): | |
def __init__(self, parent, canvas, world, options_path): | |
SimpleOperationPanel.__init__(self, parent, canvas, world, options_path) | |
self.Freeze() | |
self._sizer = wx.BoxSizer(wx.VERTICAL) | |
self._update_to_beta = wx.CheckBox(self, label="Update to beta version?") | |
self._sizer.Add(self._update_to_beta, 0, wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND, 5) | |
self.SetSizer(self._sizer) | |
self._add_run_button() | |
self.Thaw() | |
def _operation( | |
self, world: "World", dimension: "Dimension", selection: "SelectionGroup" | |
) -> "OperationReturnType": | |
print(os.path.dirname(sys.executable)) | |
temp_dir = os.path.join(os.path.dirname(sys.executable), "updater-tmp") | |
os.mkdir(temp_dir) | |
print(temp_dir) | |
print(os.listdir(temp_dir)) | |
updater_zip_path = os.path.join(temp_dir, "AmuletUpdater.zip") | |
java_zip_path = os.path.join(temp_dir, "openjdk_14.0.2.zip") | |
updater_download_thread = DownloadFileThread(UPDATER_DOWNLOAD_URL, updater_zip_path, temp_dir) | |
java_download_thread = DownloadFileThread(JAVA_DOWNLOAD_URL, java_zip_path, temp_dir) | |
java_download_thread.start() | |
updater_download_thread.start() | |
java_download_thread.join() | |
updater_download_thread.join() | |
try: | |
version = amulet_map_editor.__version__ | |
except AttributeError as ae: | |
version = amulet_map_editor.version | |
pass | |
jars = glob.glob(os.path.join(temp_dir, "*.jar")) | |
updater_jar = jars[0] | |
args = [ | |
os.path.join(temp_dir, "jdk-14.0.2", "bin", "java.exe"), | |
"-jar", | |
updater_jar, | |
"-current_version", | |
version, | |
"-wd", | |
os.path.dirname(sys.executable), | |
"-pid", | |
str(os.getpid()), | |
] | |
if self._update_to_beta.GetValue(): | |
args.append("-install_beta") | |
p = subprocess.Popen(args, shell=True, cwd=temp_dir) | |
export = {"name": "Updater", "operation": Update} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment