linux下实现获取版本号和升级安装的功能

This commit is contained in:
luoliangyi 2022-07-01 13:57:27 +08:00
parent 0ca78dc96f
commit 4b46f54448
3 changed files with 72 additions and 6 deletions

View File

@ -164,8 +164,16 @@ static std::string GetCurrVersion()
std::string version = "0.0.0.0";
#if defined(HG_CMP_MSC)
#if defined(OEM_HANWANG)
std::string regName = "SOFTWARE\\HanvonScan";
#elif defined(OEM_LISICHENG)
std::string regName = "SOFTWARE\\LanxumScan";
#else
std::string regName = "SOFTWARE\\HuaGoScan";
#endif
HKEY hKey = nullptr;
RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\HuaGoScan", 0, KEY_QUERY_VALUE, &hKey);
RegOpenKeyExA(HKEY_LOCAL_MACHINE, regName.c_str(), 0, KEY_QUERY_VALUE, &hKey);
if (nullptr != hKey)
{
CHAR szData[MAX_PATH] = { 0 };
@ -178,7 +186,43 @@ static std::string GetCurrVersion()
RegCloseKey(hKey);
}
#else
// TODO
#if defined(OEM_HANWANG)
std::string appName = "com.hanvonchina.hanvonscan";
#elif defined(OEM_LISICHENG)
std::string appName = "com.lanxumchina.lanxumscan";
#else
std::string appName = "com.huagaochina.huagoscan";
#endif
std::string cmd = "dpkg -l " + appName;
FILE *fp = popen(cmd.c_str(), "r");
if (nullptr != fp)
{
char buff[2048] = {0};
fread(buff, 2048, 1, fp);
char *p = strstr(buff, appName.c_str());
if (nullptr != p)
{
char *p2 = p + appName.size();
while (!isdigit(*p2) && '.' != *p2)
++p2;
int len = (int)strlen(p2);
for (int i = 0; i < len; ++i)
{
if (!isdigit(p2[i]) && '.' != p2[i])
{
p2[i] = '\0';
break;
}
}
version = p2;
}
pclose(fp);
}
#endif
return version;
@ -254,20 +298,36 @@ static bool PostInfo(int type, const std::string &desc)
osName = "Linux";
archName = "unknown";
FILE *fp = popen("system("cat /etc/issue | cut -d\' \' -f1")", "r");
FILE *fp = popen("cat /etc/issue | cut -d\' \' -f1", "r");
if (nullptr != fp)
{
char buff[1024] = {0};
fread(buff, 1024, 1, fp);
int len = (int)strlen(buff);
for (int i = 0; i < len; ++i)
{
if (buff[i] == '\n')
buff[i] = '\0';
}
osName = buff;
pclose(fp);
}
fp = popen("system("arch")", "r");
fp = popen("arch", "r");
if (nullptr != fp)
{
char buff[1024] = {0};
fread(buff, 1024, 1, fp);
int len = (int)strlen(buff);
for (int i = 0; i < len; ++i)
{
if (buff[i] == '\n')
buff[i] = '\0';
}
archName = buff;
pclose(fp);
}
@ -330,6 +390,7 @@ bool PostUninstallInfo(const std::string &desc)
static bool Setup(const std::string& pkgPath)
{
bool ret = false;
#if defined(HG_CMP_MSC)
PROCESS_INFORMATION ProcessInfo;
@ -348,7 +409,9 @@ static bool Setup(const std::string& pkgPath)
}
#else
// TODO
std::string cmd = "dpkg -i \"" + pkgPath + "\"";
if (0 == system(cmd.c_str()))
ret = true;
#endif
return ret;

View File

@ -1,6 +1,7 @@
#include "mainwindow.h"
#include <QApplication>
#include <QScreen>
#include "HGUpgrade.h"
int main(int argc, char *argv[])
@ -32,7 +33,10 @@ int main(int argc, char *argv[])
else if (3 == type && !pkgPath.empty())
{
QApplication a(argc, argv);
MainWindow w(pkgPath, desc);
QScreen *screen = QGuiApplication::primaryScreen();
w.move((screen->size().width() - w.width()) / 2, (screen->size().height() - w.height()) / 2);
w.show();
a.exec();
}

View File

@ -23,7 +23,6 @@
<Depends filename="HGBase/HGBase.cbp" />
<Depends filename="HGImgFmt/HGImgFmt.cbp" />
<Depends filename="HGImgProc/HGImgProc.cbp" />
<Depends filename="HGSaneUser/HGSaneUser.cbp" />
</Project>
</Workspace>
</CodeBlocks_workspace_file>