我目前正在使用 Qt 安装程序框架并设法建立一个在线存储库。我想知道的是:
框架是否提供某种“自动更新”机制,例如每次程序/系统启动时检查更新的插件/服务?
检查更新就足够了,因为安装本身可以使用维护工具完成。
我能找到的关于这个话题的只有这个小句子:
http://doc.qt.io/qtinstallerframework/ifw-overview.html#choosing-installer-type 编辑:最终用户可以在初始安装后使用维护工具从服务器安装其他组件,以及在服务器上发布更新后立即“接收内容的自动更新”。
从这里:
建议
根据这个问题的接受答案,我创建了一个小型库来使用安装程序框架自动检查更新 - https://github.com/Skycoder42/QtAutoUpdater
请注意,我在应用程序启动时将工作目录设置为应用程序的路径,这样我就可以运行maintenancetool。
QProcess process;
process.start("maintenancetool --checkupdates");
// Wait until the update tool is finished
process.waitForFinished();
if(process.error() != QProcess::UnknownError)
{
qDebug() << "Error checking for updates";
return false;
}
// Read the output
QByteArray data = process.readAllStandardOutput();
// No output means no updates available
// Note that the exit code will also be 1, but we don't use that
// Also note that we should parse the output instead of just checking if it is empty if we want specific update info
if(data.isEmpty())
{
qDebug() << "No updates available";
return false;
}
// Call the maintenance tool binary
// Note: we start it detached because this application need to close for the update
QStringList args("--updater");
bool success = QProcess::startDetached("maintenancetool", args);
// Close the application
qApp->closeAllWindows();
--checkupdates
不返回任何内容,请使用
ch
或 check-updates
代替。Commands:
in, install - install default or selected packages - <pkg ...>
ch, check-updates - show available updates information on maintenance tool
up, update - update all or selected packages - <pkg ...>
rm, remove - uninstall packages and their child components - <pkg ...>
li, list - list currently installed packages - <regexp>
se, search - search available packages - <regexp>
co, create-offline - create offline installer from selected packages - <pkg ...>
pr, purge - uninstall all packages and remove entire program directory
from AnyQt.QtCore import QProcess
from AnyQt.QtWidgets import QApplication
from AnyQt.QtXml import QDomDocument
def extract_xml(self, data):
xml_string = str(data, encoding='utf-8')
# Find the start and end positions of the XML content
start_pos = xml_string.find('<?xml')
end_pos = xml_string.find('</updates>') + len('</updates>')
xml_content = xml_string[start_pos:end_pos]
return xml_content
def parse_xml(self, xml_content):
doc = QDomDocument()
doc.setContent(xml_content)
# Access and process the XML data as needed
root = doc.documentElement()
updates = root.elementsByTagName('update')
package_names = []
for i in range(updates.count()):
update = updates.item(i)
if update.isElement():
element = update.toElement()
name = element.attribute('name')
version = element.attribute('version')
# size = element.attribute('size')
# _id = element.attribute('id')
package_names.append( (name, version) )
return package_names
# ...
updates_list = []
updater_tool_path = "maintenancetool.exe"
if updater_tool_path:
process = QProcess()
params = ["ch"]
process.start(updater_tool_path, params)
process.waitForFinished()
if process.error() != QProcess.UnknownError:
print("Error checking for updates")
# Handle error
data = process.readAllStandardOutput()
xml_content = extract_xml(data)
updates_list = parse_xml(xml_content)
else:
print("Couldn't found maintenancetool.exe for checking updates")
# Handle error
# If there are updates let's start maintenancetool with "Update components" radiobutton selected:
if len(updates_list) > 0:
args = ["--updater"]
success = QProcess.startDetached(update_tool_path, args)