1
1
from os import path , remove
2
- import pathlib
3
2
from editor import HelperPath , LoadSetting , FullPath , currentSystem , ChooseFromOS , version , SavePath , GivePermission
4
3
from PyQt5 .QtWidgets import QDialog
5
4
from PyQt5 .QtCore import QThread , pyqtSignal , Qt
8
7
from requests import get , ConnectionError , Timeout
9
8
from zipfile import ZipFile
10
9
from sys import exit as sys_exit
11
- from shutil import copyfile , rmtree , move
10
+ from shutil import copyfile , rmtree
12
11
from subprocess import call
13
- from warning import ShowWarning
14
12
15
13
class Progress ():
16
14
def update (self , op_code , cur_count , max_count = None , message = '' ):
17
15
if (op_code > 10 ): UpdateThread .progress .emit (cur_count / max_count * 100 )
18
- legacymode = False
19
16
20
17
class Download (QThread ):
21
18
progress = pyqtSignal (int )
22
19
done = pyqtSignal ()
23
20
version = "null"
24
21
25
22
def run (self ):
26
- global legacymode
27
23
file = open (SavePath ()+ "/downloaded.zip" , "wb" )
28
24
with get ("https://github.com/BenjaminHalko/WiiMusicEditorPlus/releases/download/" + self .version + "/WiiMusicEditorPlus-" + currentSystem + ".zip" ,stream = True ) as response :
29
25
total = int (response .headers ['content-length' ])
@@ -35,22 +31,20 @@ def run(self):
35
31
36
32
file .close ()
37
33
38
- if (path .isfile (SavePath ()+ "/WiiMusicEditorPlus" + ChooseFromOS ([".exe" ,".app" ,"" ]))): remove (SavePath ()+ "/WiiMusicEditorPlus" + ChooseFromOS ([".exe" ,".app" ,"" ]))
39
- elif (path .isdir (SavePath ()+ "/WiiMusicEditorPlus" + ChooseFromOS ([".exe" ,".app" ,"" ]))): rmtree (SavePath ()+ "/WiiMusicEditorPlus" + ChooseFromOS ([".exe" ,".app" ,"" ]))
40
-
41
- if (currentSystem != "Mac" ):
34
+ if (currentSystem == "Linux" ):
35
+ if (path .isfile (SavePath ()+ "/WiiMusicEditorPlus" )): remove (SavePath ()+ "/WiiMusicEditorPlus" )
42
36
zip = ZipFile (SavePath ()+ "/downloaded.zip" )
43
37
zip .extractall (SavePath ())
44
- if (len (zip .infolist ()) > 5 ): legacymode = True
45
38
zip .close ()
46
- else :
39
+ elif (currentSystem == "Mac" ):
40
+ if (path .isdir (SavePath ()+ "/WiiMusicEditorPlus.app" )): rmtree (SavePath ()+ "/WiiMusicEditorPlus.app" )
47
41
zip = ZipFile (SavePath ()+ "/downloaded.zip" )
48
42
for file in zip .infolist ():
49
43
zip .extract (file , SavePath ())
50
44
call (["chmod" ,"u+x" ,path .join (SavePath (), file .filename )])
51
45
zip .close ()
52
-
53
- remove (SavePath ()+ "/downloaded.zip" )
46
+
47
+ if ( currentSystem != "Windows" ): remove (SavePath ()+ "/downloaded.zip" )
54
48
UpdateThread .done .emit ()
55
49
56
50
class UpdateWindow (QDialog ,Ui_Update ):
@@ -94,14 +88,7 @@ def restart(self):
94
88
copyfile (HelperPath ()+ "/Extra/update" + updateExt ,SavePath ()+ "/update" + updateExt )
95
89
96
90
if (currentSystem == "Windows" ):
97
- if (legacymode ):
98
- move (SavePath ()+ "/WiiMusicEditorPlus" ,pathlib .Path (FullPath ).parent )
99
- if (path .exists (SavePath ()+ "/update.bat" )): remove (SavePath ()+ "/update.bat" )
100
- copyfile (HelperPath ()+ "/Extra/update-legacy.bat" ,SavePath ()+ "/update.bat" )
101
- ShowWarning (f"Program format changed to folder\n New path of program: { pathlib .Path (FullPath ).parent } /WiiMusicEditorPlus/WiiMusicEditorPlus.exe" ,self )
102
- Popen ([SavePath ()+ "/update.bat" ,FullPath ])
103
- Popen (path .dirname (FullPath )+ "/WiiMusicEditorPlus/WiiMusicEditorPlus.exe" )
104
- else : Popen ([SavePath ()+ "/update.bat" ,FullPath ])
91
+ Popen ([SavePath ()+ "/update.bat" ,FullPath ])
105
92
else :
106
93
GivePermission (SavePath ()+ "/update.sh" )
107
94
if (currentSystem == "Linux" ): GivePermission (SavePath ()+ '/WiiMusicEditorPlus' )
@@ -117,7 +104,7 @@ def restart(self):
117
104
def CheckForUpdate ():
118
105
try :
119
106
tag = GetReleaseTag ()
120
- if (tag != version and tag != "test" ): return tag
107
+ if (tag != version ): return tag
121
108
else : return "null"
122
109
except (ConnectionError , Timeout ):
123
110
return "null"
@@ -137,6 +124,6 @@ def GetReleaseTag():
137
124
if (j ["name" ] == f"WiiMusicEditorPlus-{ currentSystem } .zip" ):
138
125
looking = False
139
126
break
140
- except Exception :
127
+ except :
141
128
i = 0
142
129
return data [i ]["tag_name" ]
0 commit comments