1717from urllib .parse import urlencode
1818from .constants import *
1919from .translate import *
20-
21- try :
22- import addonHandler
23- addonHandler .initTranslation ()
24- except BaseException :
25- def _ (x ): return x
20+ from . import updaterStrings as strs
2621
2722try :
2823 import updateCheck
@@ -38,6 +33,22 @@ def _(x): return x
3833AUTO = 0
3934MANUAL = 1
4035
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+
4152class AutoUpdateChecker :
4253 def __init__ (self ):
4354 self .updater = None
@@ -74,13 +85,12 @@ def check_update(self):
7485 f = urlopen (req )
7586 except BaseException :
7687 if self .mode == MANUAL :
77- gui .messageBox (_ ("Unable to connect to update server.\n Check your internet connection." ),
78- _ ("Error" ), style = wx .CENTER | wx .ICON_WARNING )
88+ messageBox (strs .ERROR_UNABLE_TO_CONNECT , strs .ERROR )
7989 return False
8090
8191 if f .getcode () != 200 :
8292 if self .mode == MANUAL :
83- gui . messageBox (_ ( "Unable to connect to update server." ), _ ( "Error" ), style = wx . CENTER | wx . ICON_WARNING )
93+ messageBox (strs . ERROR_UNABLE_TO_CONNECT_SERVERSIDE , strs . ERROR )
8494 return False
8595
8696 try :
@@ -89,31 +99,25 @@ def check_update(self):
8999 update_dict = json .loads (update_dict )
90100 except BaseException :
91101 if self .mode == MANUAL :
92- gui .messageBox (
93- _ ("The update information is invalid.\n Please contact ACT Laboratory for further information." ),
94- _ ("Error" ),
95- style = wx .CENTER | wx .ICON_WARNING )
102+ messageBox (strs .ERROR_UPDATE_INFO_INVALID , strs .ERROR )
96103 return False
97104
98105 code = update_dict ["code" ]
99106 if code == UPDATER_LATEST :
100107 if self .mode == MANUAL :
101- gui . messageBox (_ ( "No updates found. \n You are using the latest version." ), _ ( "Update check" ), style = wx . CENTER | wx . ICON_INFORMATION )
108+ messageBox (strs . NO_UPDATES , strs . UPDATE_CHECK_TITLE )
102109 return False
103110 elif code == UPDATER_BAD_PARAM :
104111 if self .mode == MANUAL :
105- gui .messageBox (_ ("The request parameter is invalid. Please contact the developer." ),
106- _ ("Update check" ), style = wx .CENTER | wx .ICON_INFORMATION )
112+ messageBox (strs .ERROR_REQUEST_PARAMETERS_INVALID , strs .UPDATE_CHECK_TITLE )
107113 return False
108114 elif code == UPDATER_NOT_FOUND :
109115 if self .mode == MANUAL :
110- gui .messageBox (_ ("The updater is not registered. Please contact the developer." ),
111- _ ("Update check" ), style = wx .CENTER | wx .ICON_INFORMATION )
116+ messageBox (strs .UPDATER_NOT_REGISTERED , strs .UPDATE_CHECK_TITLE )
112117 return False
113118 elif code == UPDATER_VISIT_SITE :
114119 if self .mode == MANUAL :
115- gui .messageBox (_ ("An update was found, but updating from the current version is not possible. Please visit the software's website. " ),
116- _ ("Update check" ), style = wx .CENTER | wx .ICON_INFORMATION )
120+ messageBox (strs .UPDATE_NOT_POSSIBLE , strs .UPDATE_CHECK_TITLE )
117121 return False
118122
119123 new_version = update_dict ["update_version" ]
@@ -124,11 +128,11 @@ def check_update(self):
124128 hash = update_dict ["updater_hash" ]
125129 # end set hash
126130
127- caption = _ ( "Update confirmation" )
128- question = _ ( "{summary} Ver.{newVersion} is available. \n Would you like to update? \n Current version: {currentVersion} \n New version: {newVersion}" ) .format (
131+ caption = strs . UPDATE_CONFIRMATION_TITLE
132+ question = strs . UPDATE_CONFIRMATION_MESSAGE .format (
129133 summary = addonSummary , newVersion = new_version , currentVersion = addonVersion )
130- answer = gui . messageBox (question , caption , style = wx . CENTER | wx . OK | wx . CANCEL | wx . CANCEL_DEFAULT | wx . ICON_INFORMATION )
131- if answer == wx . OK :
134+ answer = confirm (question , caption )
135+ if answer == True :
132136 downloader = UpdateDownloader (addonName , [url ], hash )
133137 wx .CallAfter (downloader .start )
134138 return
@@ -151,8 +155,8 @@ def start(self):
151155 self ._shouldCancel = False
152156 self ._guiExecTimer = wx .PyTimer (self ._guiExecNotify )
153157 gui .mainFrame .prePopup ()
154- self ._progressDialog = wx .ProgressDialog (_ ( "Downloading add-on update" ) ,
155- _ ( "Connecting" ) ,
158+ self ._progressDialog = wx .ProgressDialog (strs . DOWNLOADING ,
159+ strs . CONNECTING ,
156160 style = wx .PD_CAN_ABORT | wx .PD_ELAPSED_TIME | wx .PD_REMAINING_TIME | wx .PD_AUTO_HIDE ,
157161 parent = gui .mainFrame )
158162 self ._progressDialog .Raise ()
@@ -163,10 +167,7 @@ def start(self):
163167 def _error (self ):
164168 self ._stopped ()
165169 self .cleanup_tempfile ()
166- gui .messageBox (
167- _ ("Error downloading add-on update." ),
168- translate ("Error" ),
169- wx .OK | wx .ICON_ERROR )
170+ messageBox (strs .ERROR_DOWNLOADING , strs .ERROR )
170171
171172 def _download (self , url ):
172173 headers = {}
@@ -221,27 +222,23 @@ def _downloadSuccess(self):
221222 bundle = addonHandler .AddonBundle (self .destPath )
222223 except BaseException :
223224 log .error ("Error opening addon bundle from %s" % self .destPath , exc_info = True )
224- gui .messageBox (translate ("Failed to open add-on package file at %s - missing file or invalid file format" ) % self .destPath ,
225- translate ("Error" ),
226- wx .OK | wx .ICON_ERROR )
225+ messageBox (strs .ERROR_OPENING % self .destPath , strs .ERROR )
227226 return
228227 bundleName = bundle .manifest ['name' ]
229228 for addon in addonHandler .getAvailableAddons ():
230229 if not addon .isPendingRemove and bundleName == addon .manifest ['name' ]:
231230 addon .requestRemove ()
232231 break
233232 progressDialog = gui .IndeterminateProgressDialog (gui .mainFrame ,
234- _ ( "Updating add-on" ) ,
235- _ ( "Please wait while the add-on is being updated." ) )
233+ strs . UPDATING ,
234+ strs . UPDATING_PLEASE_WAIT )
236235 try :
237236 gui .ExecAndPump (addonHandler .installAddonBundle , bundle )
238237 except BaseException :
239238 log .error ("Error installing addon bundle from %s" % self .destPath , exc_info = True )
240239 progressDialog .done ()
241240 del progressDialog
242- gui .messageBox (_ ("Failed to update add-on from %s." ) % self .destPath ,
243- translate ("Error" ),
244- wx .OK | wx .ICON_ERROR )
241+ messageBox (strs .ERROR_FAILED_TO_UPDATE % self .destPath , strs .ERROR )
245242 return
246243 else :
247244 progressDialog .done ()
0 commit comments