33from tkinter import messagebox
44import os
55import requests
6- from Updater import changelogDiag , downloadDiag
6+ from Updater import changelogDiag , downloadDiag , legacy
77from vars import *
88from tokenString import *
99import json
1212root = Tk ()
1313root .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
4759def restartProgram (softwareName ):
4860 os .startfile (softwareName + ".exe" )
4961
5062def 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 + "\n Do 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
0 commit comments