Skip to content

Commit f3e8d55

Browse files
committed
[VEX-31]: Added legacy mode to updater
1 parent 70f045f commit f3e8d55

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

src/Updater/core.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from tkinter import messagebox
44
import os
55
import requests
6-
from Updater import changelogDiag, downloadDiag
6+
from Updater import changelogDiag, downloadDiag, legacy
77
from vars import *
88
from tokenString import *
99
import json
@@ -12,7 +12,7 @@
1212
root = Tk()
1313
root.withdraw()
1414

15-
def downloadNewVersion(versionString, softwareName):
15+
def downloadNewVersion(versionString, softwareName, legacyMode):
1616
os.system("taskkill /f /im " + softwareName + ".exe")
1717

1818
url = "https://github.com/" + GITHUB_USER + "/" + GITHUB_REPO + "/releases/download/" + versionString + "/" + softwareName + ".exe"
@@ -36,19 +36,32 @@ def downloadNewVersion(versionString, softwareName):
3636

3737
downDiag.destroy()
3838

39-
content = []
40-
with open(VERSION_PATH, 'r') as f:
41-
content = json.loads(f.read())
42-
43-
content[softwareName] = versionString
44-
with open(VERSION_PATH, 'w') as f:
45-
f.write(json.dumps(content, indent = 4, separators=(',', ': ')))
39+
if not legacyMode:
40+
content = []
41+
with open(VERSION_PATH, 'r') as f:
42+
content = json.loads(f.read())
43+
44+
content[softwareName] = versionString
45+
with open(VERSION_PATH, 'w') as f:
46+
f.write(json.dumps(content, indent = 4, separators=(',', ': ')))
47+
else:
48+
content = []
49+
with open(OLD_VERSION_PATH, 'r') as f:
50+
content = f.readlines()
51+
52+
content[LEGACY_VERSIONS.index(softwareName)] = versionString
53+
for i in range(0, len(content)):
54+
if i != len(content) - 1: content[i] += "\n"
55+
56+
with open(OLD_VERSION_PATH, 'w') as f:
57+
f.writelines(content)
4658

4759
def restartProgram(softwareName):
4860
os.startfile(softwareName + ".exe")
4961

5062
def checkNewVersion(softwareName):
5163
isNewVersion = False
64+
legacyMode = False
5265

5366
# Update old version file
5467
if not os.path.exists(VERSION_PATH):
@@ -58,17 +71,24 @@ def checkNewVersion(softwareName):
5871
version = f.readlines()
5972

6073
for i in range(0, len(version)): version[i] = version[i].strip()
74+
legacyMode = legacy.checkLegacy(version)
6175

62-
newVersion = {GITHUB_REPO: version[0], "Updater": version[1]}
63-
os.remove(OLD_VERSION_PATH)
76+
if not legacyMode:
77+
newVersion = {GITHUB_REPO: version[0], "Updater": version[1]}
78+
os.remove(OLD_VERSION_PATH)
6479
else:
6580
newVersion = {GITHUB_REPO: "v1.0", "Updater": "v1.0"}
6681

67-
with open(VERSION_PATH, 'w') as f:
68-
f.write(json.dumps(newVersion, indent = 4, separators=(',', ': ')))
82+
if not legacyMode:
83+
with open(VERSION_PATH, 'w') as f:
84+
f.write(json.dumps(newVersion, indent = 4, separators=(',', ': ')))
6985

70-
with open(VERSION_PATH, 'r') as f:
71-
versionString = json.loads(f.read())[softwareName]
86+
if legacyMode:
87+
with open(OLD_VERSION_PATH, 'r') as f:
88+
versionString = f.readlines()[LEGACY_VERSIONS.index(softwareName)]
89+
else:
90+
with open(VERSION_PATH, 'r') as f:
91+
versionString = json.loads(f.read())[softwareName]
7292

7393
versionNumber = versionString.split("v")[1]
7494

@@ -87,7 +107,7 @@ def checkNewVersion(softwareName):
87107
if versionNumber < latestVersionNumber:
88108
res = messagebox.askquestion("Updater", "A new version of " + softwareName + " is available: " + latestVersionString + "\nDo you want to update?")
89109
if res == "yes":
90-
downloadNewVersion(latestVersionString, softwareName)
110+
downloadNewVersion(latestVersionString, softwareName, legacyMode)
91111

92112
changelogRaw = r["body"].split("##")[1].split("\r\n")
93113
changelog = []
@@ -99,7 +119,7 @@ def checkNewVersion(softwareName):
99119
isNewVersion = True
100120

101121
restartProgram(softwareName)
102-
break
122+
break
103123

104124
root.destroy()
105125
return isNewVersion

src/Updater/legacy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from vars import *
2+
3+
def checkLegacy(version):
4+
if float(version[LEGACY_VERSIONS.index(APP_NAME)].split("v")[1]) <= LEGACY_LAST_APP or float(version[LEGACY_VERSIONS.index("Updater")].split("v")[1]) >= LEGACY_LAST_UPDATER:
5+
return True
6+
return False

src/vars.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@
1616
WINDOW_GEOMETRY = "700x640"
1717

1818
GITHUB_USER = "BitTim"
19-
GITHUB_REPO = "VexTrack"
20-
EXE_FILENAME = "VexTrack.exe"
19+
GITHUB_REPO = APP_NAME
20+
EXE_FILENAME = APP_NAME + ".exe"
21+
22+
LEGACY_VERSIONS = [APP_NAME, "Updater"]
23+
LEGACY_LAST_APP = 1.4
24+
LEGACY_LAST_UPDATER = 1.15

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"VexTrack": "v1.4",
2+
"VexTrack": "v1.5",
33
"Updater": "v1.2"
44
}

0 commit comments

Comments
 (0)