code_app/app/upgrade/main.cpp

92 lines
2.6 KiB
C++

#include "mainwindow.h"
#include <QApplication>
#include <QThread>
#include <QScreen>
#include <QTranslator>
#include <QMessageBox>
#include "version/HGVersion.h"
#include "HGUpgrade.h"
int main(int argc, char *argv[])
{
std::string type;
std::string appName;
std::string desc;
std::string pkgPath;
for (int i = 1; i < argc; i++)
{
char* z = argv[i];
if (z == strstr(z, "-type="))
type = z + strlen("-type=");
else if (z == strstr(z, "-appName="))
appName = z + strlen("-appName=");
else if (z == strstr(z, "-desc="))
desc = z + strlen("-desc=");
else if (z == strstr(z, "-pkgpath="))
pkgPath = z + strlen("-pkgpath=");
}
if ("postinstallinfo" == type && !appName.empty())
{
HGVersionMgr mgr = nullptr;
HGVersion_CreateMgr(&mgr);
if (nullptr != mgr)
{
HGVersion_PostInstallInfo(mgr, appName.c_str(), desc.c_str());
HGVersion_DestroyMgr(mgr);
}
}
else if ("postuninstallinfo" == type && !appName.empty())
{
HGVersionMgr mgr = nullptr;
HGVersion_CreateMgr(&mgr);
if (nullptr != mgr)
{
HGVersion_PostUninstallInfo(mgr, appName.c_str(), desc.c_str());
HGVersion_DestroyMgr(mgr);
}
}
else if ("upgrade" == type && !appName.empty() && !pkgPath.empty())
{
QApplication a(argc, argv);
while (AppIsRun(appName))
QThread::msleep(20);
QTranslator translator_upgrade_;
if (translator_upgrade_.load(":translation/Upgrade_zh_CN.qm"))
a.installTranslator(&translator_upgrade_);
MainWindow w(appName, pkgPath);
QScreen *screen = QGuiApplication::primaryScreen();
w.move((screen->size().width() - w.width()) / 2, (screen->size().height() - w.height()) / 2);
w.show();
a.exec();
if (w.isInstallSuccess())
{
QMessageBox msg(QMessageBox::Information, QObject::tr("tip"),
QObject::tr("install succeed!"),
QMessageBox::Ok);
msg.setButtonText(QMessageBox::Ok, QObject::tr("yes"));
msg.exec();
if (!AppIsRun(appName))
RunApp(appName);
}
else
{
QMessageBox msg(QMessageBox::Critical, QObject::tr("error"),
QObject::tr("install failed!"),
QMessageBox::Ok);
msg.setButtonText(QMessageBox::Ok, QObject::tr("yes"));
msg.exec();
}
}
return 0;
}