更新程序:覆盖文件?

2024-04-25 01:11:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个软件,出于几个原因,我想开发我自己的自动更新功能。该程序是一个完整的图形用户界面,用PyQt编写,使用图标、数据文件等。它将被cx_freeze或pyinstaller冻结。在

自动更新部分将在远程服务器上下载新版本(zip)。然后,事情变得复杂起来:

软件正在运行,并已下载新版本。它和新版本有什么关系?软件能否从压缩文件中提取文件,并覆盖运行版本的文件?在

或者我应该把新版本存储在一边,退出正在运行的版本,然后以某种方式使用新版本?如果是这样的话,我如何在新旧版本之间进行交换?在

编辑:

例如,下面是我的类QMainWindow的closeEvent方法:

def closeEvent(self, event):

    """Method to perform actions before exiting.
    Allows to save the prefs in a file"""

    ...Do some stuff...

    QtGui.qApp.quit()

    self.logger.info("Closing the program")

我可以用这个方法来交换吗?在


Tags: 文件theto方法self程序功能版本
1条回答
网友
1楼 · 发布于 2024-04-25 01:11:13

这和你的答案很相似,而且公认的答案是:

After downloading the installer for the newer version, you can use atexit.register() with os.exec*() to run the installer, e.g. atexit.register(os.execl, "installer.exe", "installer.exe"). This will make the installer start when the application is about to exit. The application will immediately exit after the os.exec*() call, so no race condition will occur.

看起来是一个很好的解决方案

相关问题 更多 >