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)
|
2023-06-12 09:11:25 +00:00
|
|
|
#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
|
2023-06-12 09:11:25 +00:00
|
|
|
|
|
|
|
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)
|
2023-06-12 09:11:25 +00:00
|
|
|
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
|
2023-06-12 09:11:25 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-02-27 07:07:42 +00:00
|
|
|
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;
|
2023-02-27 07:07:42 +00:00
|
|
|
if (translator_qt.load(":translation/qt_zh_CN.qm"))
|
2022-11-10 02:22:58 +00:00
|
|
|
a.installTranslator(&translator_qt);
|
|
|
|
|
2022-11-10 09:23:16 +00:00
|
|
|
HGChar cfgPath[256]= {0};
|
2023-06-12 09:11:25 +00:00
|
|
|
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);
|
2023-06-12 09:11:25 +00:00
|
|
|
QString password = (0 == *str) ? "huagoscan" : MainWindow::passwordDecrypt(str);
|
2022-11-10 09:23:16 +00:00
|
|
|
|
2023-06-15 02:58:30 +00:00
|
|
|
LoginDialog login("admin", password, nullptr);
|
2022-11-10 09:23:16 +00:00
|
|
|
if (login.exec())
|
|
|
|
{
|
2023-06-15 02:58:30 +00:00
|
|
|
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
|
|
|
w.show();
|
|
|
|
a.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2022-11-10 02:22:58 +00:00
|
|
|
}
|