code_app/app/fwupgrade/main.cpp

88 lines
2.1 KiB
C++
Raw Normal View History

2022-11-10 09:23:16 +00:00
#include "logindialog.h"
2022-11-10 02:22:58 +00:00
#include "mainwindow.h"
#include <QApplication>
#include <QThread>
#include <QScreen>
#include <QTranslator>
#include <QMessageBox>
2022-11-10 09:23:16 +00:00
#include "base/HGBase.h"
2023-06-13 07:24:58 +00:00
#if defined(HG_CMP_MSC)
#include <shlobj.h>
2023-06-13 07:24:58 +00:00
#else
#include <grp.h>
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#endif
HGResult GetConfigPath(HGChar* configPath, HGUInt maxLen)
{
if (NULL == configPath || 0 == maxLen)
{
return HGBASE_ERR_INVALIDARG;
}
const char *appName = "HuaGoScan";
2023-06-13 07:24:58 +00:00
#if defined(HG_CMP_MSC)
CHAR cfgPath[MAX_PATH] = { 0 };
BOOL ret = SHGetSpecialFolderPathA(NULL, cfgPath, CSIDL_APPDATA, FALSE);
if (!ret)
return HGBASE_ERR_FAIL;
if (cfgPath[strlen(cfgPath) - 1] != '\\')
strcat(cfgPath, "\\");
strcat(cfgPath, appName);
strcat(cfgPath, "\\Cfg\\");
2023-06-13 07:24:58 +00:00
#else
char cfgPath[512] = { 0 };
struct passwd* pw = getpwuid(getuid());
strcpy(cfgPath, pw->pw_dir);
if (cfgPath[strlen(cfgPath) - 1] != '/')
strcat(cfgPath, "/");
strcat(cfgPath, ".");
strcat(cfgPath, appName);
strcat(cfgPath, "/Cfg/");
#endif
if (maxLen < strlen(cfgPath) + 1)
return HGBASE_ERR_FAIL;
strcpy(configPath, cfgPath);
return HGBASE_ERR_OK;
}
2022-11-10 02:22:58 +00:00
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTranslator translator_app;
if (translator_app.load(":translation/FWUpgrade_zh_CN.qm"))
a.installTranslator(&translator_app);
2022-11-10 02:22:58 +00:00
QTranslator translator_qt;
if (translator_qt.load(":translation/qt_zh_CN.qm"))
2022-11-10 02:22:58 +00:00
a.installTranslator(&translator_qt);
MainWindow w;
QScreen *screen = QGuiApplication::primaryScreen();
w.move((screen->size().width() - w.width()) / 2, (screen->size().height() - w.height()) / 2);
2022-11-10 09:23:16 +00:00
HGChar cfgPath[256]= {0};
GetConfigPath(cfgPath, 256);
2022-11-10 09:23:16 +00:00
strcat(cfgPath, "config.ini");
HGChar str[256] = {0};
HGBase_GetProfileString(cfgPath, "login", "password", "", str, 256);
QString password = (0 == *str) ? "huagoscan" : MainWindow::passwordDecrypt(str);
2022-11-10 09:23:16 +00:00
LoginDialog login("admin", password, &w);
if (login.exec())
{
w.show();
a.exec();
}
return 0;
2022-11-10 02:22:58 +00:00
}