1- # coding: UTF-8
2-
31from __future__ import unicode_literals
42import addonHandler
53import globalVars
1917from urllib .parse import urlencode
2018from .constants import *
2119from .translate import *
22-
23- try :
24- import addonHandler
25- addonHandler .initTranslation ()
26- except BaseException :
27- def _ (x ): return x
20+ from . import updaterStrings as strs
2821
2922try :
3023 import updateCheck
@@ -40,6 +33,22 @@ def _(x): return x
4033AUTO = 0
4134MANUAL = 1
4235
36+ def isCompatibleWith2025 ():
37+ return versionInfo .version_year >= 2025
38+
39+ def messageBox (message , title ):
40+ if isCompatibleWith2025 ():
41+ gui .message .MessageDialog .alert (message , title )
42+ else :
43+ gui .messageBox (message , title , style = wx .CENTER )
44+
45+ def confirm (message , title ):
46+ if isCompatibleWith2025 ():
47+ return gui .message .MessageDialog .confirm (message , title ) == gui .message .ReturnCode .OK
48+ else :
49+ return gui .messageBox (message , title , style = wx .CENTER | wx .OK | wx .CANCEL | wx .ICON_INFORMATION ) == wx .OK
50+
51+
4352class AutoUpdateChecker :
4453 def __init__ (self ):
4554 self .updater = None
@@ -51,7 +60,6 @@ def autoUpdateCheck(self, mode=AUTO):
5160 Call this method to check for updates. mode=AUTO means automatic update check, and MANUAL means manual triggering like "check for updates" menu invocation.
5261 When set to AUTO mode, some dialogs are not displayed (latest and error).
5362 """
54-
5563 if not updatable :
5664 return
5765 self .updater = NVDAAddOnUpdater (mode )
@@ -66,6 +74,7 @@ def __init__(self, mode, version=addonVersion):
6674 t .start ()
6775
6876 def check_update (self ):
77+ """Called as the thread entry point."""
6978 post_params = {
7079 "name" : addonKeyword ,
7180 "version" : addonVersion ,
@@ -76,13 +85,12 @@ def check_update(self):
7685 f = urlopen (req )
7786 except BaseException :
7887 if self .mode == MANUAL :
79- gui .messageBox (_ ("アップデートサーバに接続できません。\n インターネット接続を確認してください。" ),
80- _ ("エラー" ), style = wx .CENTER | wx .ICON_WARNING )
88+ messageBox (strs .ERROR_UNABLE_TO_CONNECT , strs .ERROR )
8189 return False
8290
8391 if f .getcode () != 200 :
8492 if self .mode == MANUAL :
85- gui . messageBox (_ ( "アップデートサーバに接続できません。" ), _ ( "エラー" ), style = wx . CENTER | wx . ICON_WARNING )
93+ messageBox (strs . ERROR_UNABLE_TO_CONNECT_SERVERSIDE , strs . ERROR )
8694 return False
8795
8896 try :
@@ -91,31 +99,25 @@ def check_update(self):
9199 update_dict = json .loads (update_dict )
92100 except BaseException :
93101 if self .mode == MANUAL :
94- gui .messageBox (
95- _ ("不正なデータが送信されました。\n この問題が継続する場合、ACT Laboratoryにお問い合わせください。" ),
96- _ ("エラー" ),
97- style = wx .CENTER | wx .ICON_WARNING )
102+ messageBox (strs .ERROR_UPDATE_INFO_INVALID , strs .ERROR )
98103 return False
99104
100105 code = update_dict ["code" ]
101106 if code == UPDATER_LATEST :
102107 if self .mode == MANUAL :
103- gui . messageBox (_ ( "お使いのアドオンは最新です。" ), _ ( "アップデート確認" ), style = wx . CENTER | wx . ICON_INFORMATION )
108+ messageBox (strs . NO_UPDATES , strs . UPDATE_CHECK_TITLE )
104109 return False
105110 elif code == UPDATER_BAD_PARAM :
106111 if self .mode == MANUAL :
107- gui .messageBox (_ ("不正なデータが送信されました。\n この問題が継続する場合、ACT Laboratoryにお問い合わせください。" ),
108- _ ("アップデート確認" ), style = wx .CENTER | wx .ICON_INFORMATION )
112+ messageBox (strs .ERROR_REQUEST_PARAMETERS_INVALID , strs .UPDATE_CHECK_TITLE )
109113 return False
110114 elif code == UPDATER_NOT_FOUND :
111115 if self .mode == MANUAL :
112- gui .messageBox (_ ("このアドオンのアップデータは登録されていません。\n この問題が継続する場合、ACT Laboratoryまでお問い合わせください。" ),
113- _ ("アップデート確認" ), style = wx .CENTER | wx .ICON_INFORMATION )
116+ messageBox (strs .UPDATER_NOT_REGISTERED , strs .UPDATE_CHECK_TITLE )
114117 return False
115118 elif code == UPDATER_VISIT_SITE :
116119 if self .mode == MANUAL :
117- gui .messageBox (_ ("アップデートが見つかりましたが、このままアップデートを継続することができません。\n アドオンのウェブサイトを確認してください。" ),
118- _ ("アップデート確認" ), style = wx .CENTER | wx .ICON_INFORMATION )
120+ messageBox (strs .UPDATE_NOT_POSSIBLE , strs .UPDATE_CHECK_TITLE )
119121 return False
120122
121123 new_version = update_dict ["update_version" ]
@@ -126,11 +128,11 @@ def check_update(self):
126128 hash = update_dict ["updater_hash" ]
127129 # end set hash
128130
129- caption = _ ( "アップデート確認" )
130- question = _ ( "{summary} Ver.{newVersion}が利用できます。 \n アップデートしますか? \n 現在のバージョン: {currentVersion} \n 最新バージョン: {newVersion}" ) .format (
131+ caption = strs . UPDATE_CONFIRMATION_TITLE
132+ question = strs . UPDATE_CONFIRMATION_MESSAGE .format (
131133 summary = addonSummary , newVersion = new_version , currentVersion = addonVersion )
132- answer = gui . messageBox (question , caption , style = wx . CENTER | wx . OK | wx . CANCEL | wx . CANCEL_DEFAULT | wx . ICON_INFORMATION )
133- if answer == wx . OK :
134+ answer = confirm (question , caption )
135+ if answer == True :
134136 downloader = UpdateDownloader (addonName , [url ], hash )
135137 wx .CallAfter (downloader .start )
136138 return
@@ -153,8 +155,8 @@ def start(self):
153155 self ._shouldCancel = False
154156 self ._guiExecTimer = wx .PyTimer (self ._guiExecNotify )
155157 gui .mainFrame .prePopup ()
156- self ._progressDialog = wx .ProgressDialog (_ ( "アップデートをダウンロード中" ) ,
157- _ ( "接続中..." ) ,
158+ self ._progressDialog = wx .ProgressDialog (strs . DOWNLOADING ,
159+ strs . CONNECTING ,
158160 style = wx .PD_CAN_ABORT | wx .PD_ELAPSED_TIME | wx .PD_REMAINING_TIME | wx .PD_AUTO_HIDE ,
159161 parent = gui .mainFrame )
160162 self ._progressDialog .Raise ()
@@ -165,10 +167,7 @@ def start(self):
165167 def _error (self ):
166168 self ._stopped ()
167169 self .cleanup_tempfile ()
168- gui .messageBox (
169- _ ("アップデートのダウンロードに失敗しました。" ),
170- _ ("エラー" ),
171- wx .OK | wx .ICON_ERROR )
170+ messageBox (strs .ERROR_DOWNLOADING , strs .ERROR )
172171
173172 def _download (self , url ):
174173 headers = {}
@@ -216,42 +215,38 @@ def _download(self, url):
216215
217216 def _downloadSuccess (self ):
218217 self ._stopped ()
219- from gui import addonGui
220- addonGui .promptUserForRestart ()
221218 try :
222219 try :
223220 bundle = addonHandler .AddonBundle (self .destPath .decode ("mbcs" ))
224221 except AttributeError :
225222 bundle = addonHandler .AddonBundle (self .destPath )
226223 except BaseException :
227224 log .error ("Error opening addon bundle from %s" % self .destPath , exc_info = True )
228- gui .messageBox (translate ("Failed to open add-on package file at %s - missing file or invalid file format" ) % self .destPath ,
229- translate ("Error" ),
230- wx .OK | wx .ICON_ERROR )
225+ messageBox (strs .ERROR_OPENING % self .destPath , strs .ERROR )
231226 return
232227 bundleName = bundle .manifest ['name' ]
233228 for addon in addonHandler .getAvailableAddons ():
234229 if not addon .isPendingRemove and bundleName == addon .manifest ['name' ]:
235230 addon .requestRemove ()
236231 break
237232 progressDialog = gui .IndeterminateProgressDialog (gui .mainFrame ,
238- _ ( "アップデートをダウンロード中" ) ,
239- _ ( "アドオンがアップデートされるまでお待ちください。" ) )
233+ strs . UPDATING ,
234+ strs . UPDATING_PLEASE_WAIT )
240235 try :
241236 gui .ExecAndPump (addonHandler .installAddonBundle , bundle )
242237 except BaseException :
243238 log .error ("Error installing addon bundle from %s" % self .destPath , exc_info = True )
244239 progressDialog .done ()
245240 del progressDialog
246- gui .messageBox (_ ("アドオンのアップデートに失敗しました。" ),
247- _ ("エラー" ),
248- wx .OK | wx .ICON_ERROR )
241+ messageBox (strs .ERROR_FAILED_TO_UPDATE % self .destPath , strs .ERROR )
249242 return
250243 else :
251244 progressDialog .done ()
252245 del progressDialog
253246 finally :
254247 self .cleanup_tempfile ()
248+ from gui import addonGui
249+ addonGui .promptUserForRestart ()
255250
256251 def cleanup_tempfile (self ):
257252 if not os .path .isfile (self .destPath ):
0 commit comments