GrpcPrint/PrintS/HBDSystem.cpp

103 lines
2.6 KiB
C++

#include "HBDSystem.h"
UserType g_Admin;
string g_AppPath;
//string g_AppDisk;
Logger* g_log;
LanguageManager* g_LngManager;
Toast* g_Toast;
bool g_isDebug;
uint32_t g_ScanSerial;
string g_gno;
SystemInfo* g_SystemInfo;
//char* g_Lang;
HBDSystem::HBDSystem()
: m_dataHandle(new DataHandle()){
}
HBDSystem::~HBDSystem() {
DELP(g_log);
DELP(g_SystemInfo);
DELP(g_Toast);
DELP(g_LngManager);
DELP(m_dataHandle);
}
void HBDSystem::Init() {
char szFilePath[MAX_PATH + 1] = { 0 };
GetModuleFileName(NULL, szFilePath, MAX_PATH);
(strrchr(szFilePath, '\\'))[1] = 0;
g_AppPath = szFilePath;
//g_AppDisk = g_AppPath.substr(0, 2);
g_Lang = (char*)"zh_CN";
g_Admin = ADMIN;
g_log = new Logger();
#ifdef _DEBUG
g_isDebug = true;
#else
g_isDebug = false;
#endif
g_LngManager = new LanguageManager();
g_LngManager->Init();
ConfigManager::GetInstance()->Init();
g_SystemInfo = new SystemInfo();
g_LngManager->Translation(HbdLanguage::Language(ConfigManager::GetInstance()->GetMachineCfg()->m_language->GetValue()));
g_Toast = new Toast();
m_dataHandle->Init();
GetVersion();
}
void HBDSystem::GetVersion()
{
char cPath[MAX_PATH];
DWORD dwHandle, InfoSize;
string strVersion;
::GetModuleFileName(NULL, cPath, sizeof(cPath));
InfoSize = GetFileVersionInfoSize(cPath, &dwHandle);
if (InfoSize == 0L) return;
unsigned char* InfoBuf = new unsigned char[InfoSize];
GetFileVersionInfo(cPath, 0, InfoSize, InfoBuf); //获得生成文件使用的代码页及文件版本
unsigned int cbTranslate = 0;
struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;
VerQueryValue(InfoBuf, TEXT("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate);
// Read the file description for each language and code page.
for (unsigned int i = 0; i < (cbTranslate / sizeof(struct LANGANDCODEPAGE)); i++)
{
char SubBlock[200];
wsprintf(SubBlock,
TEXT("\\StringFileInfo\\%04x%04x\\ProductVersion"),
lpTranslate[i].wLanguage,
lpTranslate[i].wCodePage);
void* lpBuffer = NULL;
unsigned int dwBytes = 0;
VerQueryValue(InfoBuf,SubBlock,&lpBuffer,&dwBytes);
string strTemp = (char*)lpBuffer;
strVersion += strTemp;
}
delete[] InfoBuf;
g_SystemInfo->m_ProductVersion = strVersion;
}
void HBDSystem::Usage() {
printf(COLOR_GREEN "print service usage:\n" COLOR_RESET);
printf(" r(run): " COLOR_YELLOW "start run...\n" COLOR_RESET);
printf(" s(stop): " COLOR_YELLOW "stop run...\n" COLOR_RESET);
printf(" e(exit): " COLOR_YELLOW "exit program...\n" COLOR_RESET);
printf(" h(help): " COLOR_YELLOW "print help information...\n" COLOR_RESET);
}