19
19
versionchecktask = queue .Queue ()
20
20
21
21
22
- def getvesionmethod ():
22
+ def getvesionmethod_github ():
23
23
try :
24
24
headers = {
25
25
"Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ,
@@ -42,6 +42,22 @@ def getvesionmethod():
42
42
print_exc ()
43
43
return None
44
44
45
+ def getvesionmethod ():
46
+ try :
47
+ res = requests .get (
48
+ "https://lunatranslator.xyz/version" ,
49
+ verify = False ,
50
+ #proxies=getproxy(("github", "versioncheck")),
51
+ )
52
+ print (res .text )
53
+ res = res .json ()
54
+ # print(res)
55
+ _version = res ["version" ]
56
+ return _version , res
57
+ except :
58
+ print_exc ()
59
+ return None
60
+
45
61
46
62
def doupdate ():
47
63
if not gobject .baseobject .update_avalable :
@@ -69,7 +85,59 @@ def updatemethod_checkalready(size, savep):
69
85
70
86
71
87
@tryprint
72
- def updatemethod (_version , self ):
88
+ def updatemethod (info , self ):
89
+
90
+ check_interrupt = lambda : not (
91
+ globalconfig ["autoupdate" ] and versionchecktask .empty ()
92
+ )
93
+ if platform .architecture ()[0 ] == "64bit" :
94
+ bit = "64"
95
+ elif platform .architecture ()[0 ] == "32bit" :
96
+ bit = "32"
97
+ else :
98
+ raise Exception
99
+ url = info [bit ]
100
+
101
+ savep = gobject .getcachedir ("update/LunaTranslator{}.zip" .format (bit ))
102
+
103
+ r2 = requests .get (
104
+ url , stream = True , verify = False , proxies = getproxy (("github" , "download" ))
105
+ )
106
+ size = int (r2 .headers ["Content-Length" ])
107
+ if check_interrupt ():
108
+ return
109
+ if updatemethod_checkalready (size , savep ):
110
+ return savep
111
+ with open (savep , "wb" ) as file :
112
+ sess = requests .session ()
113
+ r = sess .get (
114
+ url , stream = True , verify = False , proxies = getproxy (("github" , "download" ))
115
+ )
116
+ file_size = 0
117
+ for i in r .iter_content (chunk_size = 1024 ):
118
+ if check_interrupt ():
119
+ return
120
+ if not i :
121
+ continue
122
+ file .write (i )
123
+ thislen = len (i )
124
+ file_size += thislen
125
+
126
+ prg = int (10000 * file_size / size )
127
+ prg100 = prg / 100
128
+ sz = int (1000 * (int (size / 1024 ) / 1024 )) / 1000
129
+ self .progresssignal .emit (
130
+ "总大小{} MB 进度 {:0.2f}% " .format (sz , prg100 ), prg
131
+ )
132
+
133
+ if check_interrupt ():
134
+ return
135
+ if updatemethod_checkalready (size , savep ):
136
+ return savep
137
+
138
+
139
+ @tryprint
140
+ def updatemethod_github (_version , self ):
73
141
74
142
check_interrupt = lambda : not (
75
143
globalconfig ["autoupdate" ] and versionchecktask .empty ()
@@ -121,7 +189,6 @@ def updatemethod(_version, self):
121
189
if updatemethod_checkalready (size , savep ):
122
190
return savep
123
191
124
-
125
192
def uncompress (self , savep ):
126
193
self .progresssignal .emit ("正在解压……" , 10000 )
127
194
shutil .rmtree (gobject .getcachedir ("update/LunaTranslator/" ))
@@ -144,7 +211,7 @@ def versioncheckthread(self):
144
211
if _version is None :
145
212
sversion = _TR ("获取失败" )
146
213
else :
147
- sversion = _version
214
+ sversion , info = _version
148
215
self .versiontextsignal .emit (sversion )
149
216
version = winsharedutils .queryversion (sys .argv [0 ])
150
217
need = (
@@ -154,7 +221,7 @@ def versioncheckthread(self):
154
221
)
155
222
if not (need and globalconfig ["autoupdate" ]):
156
223
continue
157
- savep = updatemethod (_version , self )
224
+ savep = updatemethod (info , self )
158
225
if not savep :
159
226
self .progresssignal .emit ("自动更新失败,请手动更新" , 0 )
160
227
continue
@@ -317,7 +384,7 @@ def setTab_update(self, basel):
317
384
]
318
385
319
386
shuominggrid = [
320
- ["Github" , makehtml ("https://github.com/HIllya51/LunaTranslator" )],
387
+ # ["Github", makehtml("https://github.com/HIllya51/LunaTranslator")],
321
388
["项目网站" , makehtml ("https://lunatranslator.xyz/" )],
322
389
[
323
390
"使用说明" ,
0 commit comments