forked from RatPoison-dev/RatInstaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.py
68 lines (62 loc) · 2.94 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import glob, requests, settingsTools, locales, os, subprocess, shutil, utils, __main__
settings = settingsTools.loadSettings()
locales = locales.Locales()
executing = os.path.splitext(os.path.basename(__main__.__file__))[0]
YES = locales.YES
repository = settings["github_repo"]
def download_repo(origin_branch):
locales.advPrint("DOWNLOADING_NEW_VERSION")
new_path = f"{settings.repository_name}-{origin_branch}"
if (os.path.exists(new_path)):
if (locales.advInput("FOLDER_ALREADY_EXIST_INPUT", {"new_path": new_path}) in YES):
utils.rmtree(new_path)
locales.advPrint("FOLDER_DELETED")
utils.downloadFileAndExtract(f"https://github.com/{settings['github_repo']}/archive/{origin_branch}.zip", f"{origin_branch}.zip")
locales.advPrint("DOWNLOADING_FINISHED")
return new_path
def continue_actions(new_path):
utils.killJDKs()
if (os.path.exists("jdk-14.0.2")):
shutil.move("jdk-14.0.2", new_path)
locales.advPrint("MOVING_CFGS")
folder_name = utils.getSettingsPath()
utils.migrateFolder(f"{folder_name}/CFGS", f"{new_path}/settings/CFGS")
locales.advPrint("MOVING_HITSOUNDS")
utils.migrateFolder(f"{folder_name}/hitsounds", f"{new_path}/settings/hitsounds")
locales.advPrint("MOVING_NADEHELPERS")
utils.migrateFolder(f"{folder_name}/NadeHelper", f"{new_path}/settings/NadeHelper")
locales.advPrint("MOVING_DEFAULT_SETTINGS")
utils.migrateDefaultSettings(f"{folder_name}/", f"{new_path}/settings/CFGS/default_migration.cfg")
os.chdir(new_path)
return new_path
def delete_folder(new_path):
for file in os.listdir("../"):
filePath = os.path.join("..", file)
if (not new_path in file and not executing in file):
if (os.path.isdir(filePath)):
utils.rmtree(filePath)
else:
os.remove(filePath)
for file in os.listdir(os.getcwd()):
if (not ".git" in file and not executing in file):
shutil.move(file, "../")
os.chdir("../")
utils.rmtree(new_path)
def shouldUpdate():
for file in glob.glob("version.txt"):
with open(file) as f:
c = f.readlines()
origin_version = c[0].replace("\n", "")
origin_branch = c[1].replace("\n", "")
r = requests.get(f"https://raw.githubusercontent.com/{repository}/{origin_branch}/version.txt")
if (r.status_code == 404):
return False, 0, 0, 0
remote_text = r.text.split("\n")
remote_version = remote_text[0]
if (remote_version == origin_version):
return False, 0, 0, 0
shouldUpdate = settings["force_cheat_update"] or (locales.advInput("NEW_VERSION_AVAILABLE_INPUT", globals={"origin_version": origin_version, "remote_version": remote_version}) in YES)
if (not shouldUpdate):
return False, 0, 0, 0
return True, origin_version, remote_version, origin_branch
return False, 0, 0, 0