Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addon-updaterの更新 #9

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 35 additions & 38 deletions addon/globalPlugins/ERE/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
from urllib.parse import urlencode
from .constants import *
from .translate import *

try:
import addonHandler
addonHandler.initTranslation()
except BaseException:
def _(x): return x
from . import updaterStrings as strs

try:
import updateCheck
Expand All @@ -38,6 +33,22 @@ def _(x): return x
AUTO=0
MANUAL=1

def isCompatibleWith2025():
return versionInfo.version_year >= 2025

def messageBox(message, title):
if isCompatibleWith2025():
gui.message.MessageDialog.alert(message, title)
else:
gui.messageBox(message, title, style=wx.CENTER)

def confirm(message, title):
if isCompatibleWith2025():
return gui.message.MessageDialog.confirm(message, title) == gui.message.ReturnCode.OK
else:
return gui.messageBox(message, title, style=wx.CENTER | wx.OK | wx.CANCEL | wx.ICON_INFORMATION) == wx.ID_OK
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gui.messageBox()の戻り値は、wx.ID_OKではなくwx.OKのようです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value is one of: YES , NO , CANCEL , OK or HELP (notice that this return value is different from the return value of wx.MessageDialog.ShowModal ).

ほんまや



class AutoUpdateChecker:
def __init__(self):
self.updater = None
Expand Down Expand Up @@ -74,13 +85,12 @@ def check_update(self):
f = urlopen(req)
except BaseException:
if self.mode == MANUAL:
gui.messageBox(_("Unable to connect to update server.\nCheck your internet connection."),
_("Error"), style=wx.CENTER | wx.ICON_WARNING)
messageBox(strs.ERROR_UNABLE_TO_CONNECT, strs.ERROR)
return False

if f.getcode() != 200:
if self.mode == MANUAL:
gui.messageBox(_("Unable to connect to update server."), _("Error"), style=wx.CENTER | wx.ICON_WARNING)
messageBox(strs.ERROR_UNABLE_TO_CONNECT_SERVERSIDE, strs.ERROR)
return False

try:
Expand All @@ -89,31 +99,25 @@ def check_update(self):
update_dict = json.loads(update_dict)
except BaseException:
if self.mode == MANUAL:
gui.messageBox(
_("The update information is invalid.\nPlease contact ACT Laboratory for further information."),
_("Error"),
style=wx.CENTER | wx.ICON_WARNING)
gui.messageBox(strs.ERROR_UPDATE_INFO_INVALID, strs.ERROR)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

messageBox(strs.ERROR_UPDATE_INFO_INVALID, strs.ERROR)

ではないでしょうか。

return False

code = update_dict["code"]
if code == UPDATER_LATEST:
if self.mode == MANUAL:
gui.messageBox(_("No updates found.\nYou are using the latest version."), _("Update check"), style=wx.CENTER | wx.ICON_INFORMATION)
messageBox(strs.NO_UPDATES, strs.UPDATE_CHECK_TITLE)
return False
elif code == UPDATER_BAD_PARAM:
if self.mode == MANUAL:
gui.messageBox(_("The request parameter is invalid. Please contact the developer."),
_("Update check"), style=wx.CENTER | wx.ICON_INFORMATION)
messageBox(strs.ERROR_REQUEST_PARAMETERS_INVALID, strs.UPDATE_CHECK_TITLE)
return False
elif code == UPDATER_NOT_FOUND:
if self.mode == MANUAL:
gui.messageBox(_("The updater is not registered. Please contact the developer."),
_("Update check"), style=wx.CENTER | wx.ICON_INFORMATION)
messageBox(strs.UPDATER_NOT_REGISTERED, strs.UPDATE_CHECK_TITLE)
return False
elif code == UPDATER_VISIT_SITE:
if self.mode == MANUAL:
gui.messageBox(_("An update was found, but updating from the current version is not possible. Please visit the software's website. "),
_("Update check"), style=wx.CENTER | wx.ICON_INFORMATION)
messageBox(strs.UPDATE_NOT_POSSIBLE, strs.UPDATE_CHECK_TITLE)
return False

new_version = update_dict["update_version"]
Expand All @@ -124,11 +128,11 @@ def check_update(self):
hash = update_dict["updater_hash"]
# end set hash

caption = _("Update confirmation")
question = _("{summary} Ver.{newVersion} is available.\nWould you like to update?\nCurrent version: {currentVersion}\nNew version: {newVersion}").format(
caption = strs.UPDATE_CONFIRMATION_TITLE
question = strs.UPDATE_CONFIRMATION_MESSAGE.format(
summary=addonSummary, newVersion=new_version, currentVersion=addonVersion)
answer = gui.messageBox(question, caption, style=wx.CENTER | wx.OK | wx.CANCEL | wx.CANCEL_DEFAULT | wx.ICON_INFORMATION)
if answer == wx.OK:
answer = confirm(question, caption)
if answer == True:
downloader = UpdateDownloader(addonName, [url], hash)
wx.CallAfter(downloader.start)
return
Expand All @@ -151,8 +155,8 @@ def start(self):
self._shouldCancel = False
self._guiExecTimer = wx.PyTimer(self._guiExecNotify)
gui.mainFrame.prePopup()
self._progressDialog = wx.ProgressDialog(_("Downloading add-on update"),
_("Connecting"),
self._progressDialog = wx.ProgressDialog(strs.DOWNLOADING,
strs.CONNECTING,
style=wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME | wx.PD_AUTO_HIDE,
parent=gui.mainFrame)
self._progressDialog.Raise()
Expand All @@ -163,10 +167,7 @@ def start(self):
def _error(self):
self._stopped()
self.cleanup_tempfile()
gui.messageBox(
_("Error downloading add-on update."),
translate("Error"),
wx.OK | wx.ICON_ERROR)
messageBox(strs.ERROR_DOWNLOADING, strs.ERROR)

def _download(self, url):
headers = {}
Expand Down Expand Up @@ -221,27 +222,23 @@ def _downloadSuccess(self):
bundle = addonHandler.AddonBundle(self.destPath)
except BaseException:
log.error("Error opening addon bundle from %s" % self.destPath, exc_info=True)
gui.messageBox(translate("Failed to open add-on package file at %s - missing file or invalid file format") % self.destPath,
translate("Error"),
wx.OK | wx.ICON_ERROR)
messageBox(strs.ERROR_OPENING % self.destPath, strs.ERROR)
return
bundleName = bundle.manifest['name']
for addon in addonHandler.getAvailableAddons():
if not addon.isPendingRemove and bundleName == addon.manifest['name']:
addon.requestRemove()
break
progressDialog = gui.IndeterminateProgressDialog(gui.mainFrame,
_("Updating add-on"),
_("Please wait while the add-on is being updated."))
strs.UPDATING,
strs.UPDATING_PLEASE_WAIT)
try:
gui.ExecAndPump(addonHandler.installAddonBundle, bundle)
except BaseException:
log.error("Error installing addon bundle from %s" % self.destPath, exc_info=True)
progressDialog.done()
del progressDialog
gui.messageBox(_("Failed to update add-on from %s.") % self.destPath,
translate("Error"),
wx.OK | wx.ICON_ERROR)
messageBox(strs.ERROR_FAILED_TO_UPDATE % self.destPath, strs.ERROR)
return
else:
progressDialog.done()
Expand Down
24 changes: 24 additions & 0 deletions addon/globalPlugins/ERE/updaterStrings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
try:
import addonHandler
addonHandler.initTranslation()
except BaseException:
def _(x): return x

ERROR = _("Error")
ERROR_UNABLE_TO_CONNECT = _("Unable to connect to update server.\nCheck your internet connection.")
ERROR_UNABLE_TO_CONNECT_SERVERSIDE = _("Unable to connect to update server.")
ERROR_UPDATE_INFO_INVALID = _("The update information is invalid.\nPlease contact ACT Laboratory for further information.")
ERROR_REQUEST_PARAMETERS_INVALID = _("The request parameter is invalid. Please contact the developer.")
ERROR_DOWNLOADING = _("Error downloading add-on update.")
ERROR_OPENING = _("Failed to open add-on package file at %s - missing file or invalid file format")
ERROR_FAILED_TO_UPDATE = _("Failed to update add-on from %s.")
NO_UPDATES = _("No updates found.\nYou are using the latest version.")
UPDATER_NOT_REGISTERED = _("The updater is not registered. Please contact the developer.")
UPDATE_NOT_POSSIBLE = _("An update was found, but updating from the current version is not possible. Please visit the software's website. ")
UPDATE_CHECK_TITLE = _("Update check")
UPDATE_CONFIRMATION_TITLE = _("Update confirmation")
UPDATE_CONFIRMATION_MESSAGE = _("{summary} Ver.{newVersion} is available.\nWould you like to update?\nCurrent version: {currentVersion}\nNew version: {newVersion}")
DOWNLOADING = _("Downloading add-on update")
CONNECTING = _("Connecting")
UPDATING = _("Updating add-on")
UPDATING_PLEASE_WAIT = _("Please wait while the add-on is being updated.")
Loading