|
@@ -5,6 +5,7 @@
|
|
|
#include "VTM_IL.h"
|
|
|
|
|
|
#include<string>
|
|
|
+#include<regex>
|
|
|
#include <windows.h>
|
|
|
#include <shellapi.h>
|
|
|
#include <fstream>
|
|
@@ -13,6 +14,7 @@
|
|
|
using namespace std;
|
|
|
|
|
|
#define MAX_LOADSTRING 100
|
|
|
+#define ERROR_TITILE "可视柜台终端应用程序"
|
|
|
|
|
|
const int HOTKEY_ID = 1;
|
|
|
|
|
@@ -106,6 +108,39 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
|
|
|
return RegisterClassEx(&wcex);
|
|
|
}
|
|
|
|
|
|
+BOOL ExistsFileA(LPCSTR lpFilePath)
|
|
|
+{
|
|
|
+ DWORD dwRet = GetFileAttributesA(lpFilePath);
|
|
|
+ return (dwRet != INVALID_FILE_ATTRIBUTES) && !(dwRet & FILE_ATTRIBUTE_DIRECTORY);
|
|
|
+}
|
|
|
+
|
|
|
+UINT GetErrorMessage(CString& retMessage, LPCTSTR lpDefault, DWORD error = GetLastError())
|
|
|
+{
|
|
|
+ if (error == 0) {
|
|
|
+ retMessage = lpDefault;
|
|
|
+ return strlen(lpDefault);
|
|
|
+ }
|
|
|
+ LPVOID lpMsgBuf;
|
|
|
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
|
|
+ | FORMAT_MESSAGE_FROM_SYSTEM
|
|
|
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
+ NULL,
|
|
|
+ error,
|
|
|
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
+ (LPTSTR)&lpMsgBuf,
|
|
|
+ 0,
|
|
|
+ NULL);
|
|
|
+ if (lpMsgBuf == NULL) {
|
|
|
+ retMessage = lpDefault;
|
|
|
+ return strlen(lpDefault);
|
|
|
+ }
|
|
|
+ CString strTemp;
|
|
|
+ strTemp.Format("错误描述:%s", (LPCTSTR)lpMsgBuf);
|
|
|
+ retMessage = strTemp;
|
|
|
+ LocalFree((LPVOID)lpMsgBuf);
|
|
|
+ return retMessage.GetLength();
|
|
|
+}
|
|
|
+
|
|
|
int GetVersion(char** pVersion)
|
|
|
{
|
|
|
char szFileName[MAX_PATH] = {0};
|
|
@@ -115,6 +150,11 @@ int GetVersion(char** pVersion)
|
|
|
int nPos = strFileName.find_last_of("\\");
|
|
|
string strDir = strFileName.substr(0, nPos);
|
|
|
sprintf_s(szFilePath, MAX_PATH,"%s\\active.txt", strDir.c_str());
|
|
|
+ if (!ExistsFileA(szFilePath)) {
|
|
|
+ CString strText;
|
|
|
+ strText.Format("[RTAXXXX] 版本文件active.txt不存在,请检查应用程序的完整性!版本文件路径:%s", szFilePath);
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
+ }
|
|
|
|
|
|
char cVer[MAX_PATH] = {0};
|
|
|
ifstream infile(szFilePath);
|
|
@@ -122,25 +162,51 @@ int GetVersion(char** pVersion)
|
|
|
{
|
|
|
if(infile.getline(cVer, MAX_PATH))
|
|
|
{
|
|
|
- memcpy_s(*pVersion, MAX_PATH, cVer, MAX_PATH);
|
|
|
- infile.close();
|
|
|
-
|
|
|
- return 1;
|
|
|
+ CString strVersionTxt(cVer);
|
|
|
+ strVersionTxt.Trim();
|
|
|
+ if (strVersionTxt.IsEmpty()) {
|
|
|
+ CString strText;
|
|
|
+ strText.Format("[RTAXXXX] 版本文件active.txt内容为空,请检查应用程序的完整性!版本文件路径:%s", szFilePath);
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
+ infile.close();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ std::regex reg("^\\d+\\.\\d+\\.\\d+\\.\\d+$");
|
|
|
+ std::string strVerion(cVer);
|
|
|
+ /** 要不要加正则表达式校验待定,目前没有加 [Gifur@2025516]*/
|
|
|
+ if (TRUE || std::regex_match(strVerion, reg))
|
|
|
+ {
|
|
|
+ memcpy_s(*pVersion, MAX_PATH, cVer, MAX_PATH);
|
|
|
+ infile.close();
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CString strText;
|
|
|
+ strText.Format("[RTAXXXX] 版本文件active.txt内容不符合X.Y.Z.W格式,请检查应用程序的完整性!\r\n版本文件路径:%s\r\n当前内容为:%s"
|
|
|
+ , szFilePath, cVer);
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
+ infile.close();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- MessageBoxA(NULL,"获取版本信息失败:文件内容为空",NULL,0);
|
|
|
+ CString strText;
|
|
|
+ strText.Format("[RTAXXXX] 版本文件active.txt内容为空,请检查应用程序的完整性!版本文件路径:%s", szFilePath);
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
+ infile.close();
|
|
|
return 0;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- MessageBoxA(NULL,"获取版本信息失败:文件打开失败",NULL,0);
|
|
|
+ else {
|
|
|
+ CString strText;
|
|
|
+ strText.Format("[RTAXXXX] 版本文件active.txt打开失败,请联系分行IT或厂商排查!版本文件路径:%s", szFilePath);
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
infile.close();
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -156,16 +222,12 @@ BOOL GetSpShellPath(char** pPath)
|
|
|
int nPos = strFileName.find_last_of("\\");
|
|
|
string strDir = strFileName.substr(0, nPos);
|
|
|
|
|
|
- if(GetVersion(&pVer))
|
|
|
- {
|
|
|
- sprintf_s(szFilePath, MAX_PATH, "%s\\%s\\bin\\SpShell.exe", strDir.c_str(), pVer);
|
|
|
- }
|
|
|
- else
|
|
|
+ if(!GetVersion(&pVer))
|
|
|
{
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ sprintf_s(szFilePath, MAX_PATH, "%s\\%s\\bin\\SpShell.exe", strDir.c_str(), pVer);
|
|
|
memcpy_s(*pPath, MAX_PATH, szFilePath, MAX_PATH);
|
|
|
|
|
|
if (NULL != pVer)
|
|
@@ -174,6 +236,13 @@ BOOL GetSpShellPath(char** pPath)
|
|
|
pVer = NULL;
|
|
|
}
|
|
|
|
|
|
+ if (!ExistsFileA(*pPath)) {
|
|
|
+ CString strText;
|
|
|
+ strText.Format("[RTAXXXX] 应用程序执行文件SpShell.exe不存在,请检查应用程序的完整性!执行文件路径:%s", *pPath);
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
ifstream shellFile(*pPath);
|
|
|
if(shellFile)
|
|
|
{
|
|
@@ -181,7 +250,9 @@ BOOL GetSpShellPath(char** pPath)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- MessageBoxA(NULL,"获取执行文件失败:文件无效或文件不存在",NULL,0);
|
|
|
+ CString strText;
|
|
|
+ strText.Format("[RTAXXXX] 应用程序执行文件SpShell.exe不存在,请检查应用程序的完整性!执行文件路径:%s", *pPath);
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
return FALSE;
|
|
|
}
|
|
|
}
|
|
@@ -195,11 +266,14 @@ BOOL Execute(const char* cExeName)
|
|
|
|
|
|
if (!ShellExecuteExA(&sei))
|
|
|
{
|
|
|
- DWORD dwError = GetLastError();
|
|
|
- char szError[128];
|
|
|
- memset(szError, '\0', 128);
|
|
|
- sprintf_s(szError, 128, "执行应用程序失败:%u", dwError);
|
|
|
- MessageBoxA(NULL, szError,NULL,0);
|
|
|
+ const DWORD dwError = GetLastError();
|
|
|
+ CString strText;
|
|
|
+ CString strError;
|
|
|
+ char szDefault[128];
|
|
|
+ sprintf_s(szDefault, "错误描述:%u", dwError);
|
|
|
+ GetErrorMessage(strError, szDefault, dwError);
|
|
|
+ strText.Format("[RTAXXXX] 运行应用程序执行文件SpShell.exe失败,请联系分行IT或厂商排查!\r\n%s\r\n执行文件路径:%s", strError.GetBuffer(), cExeName);
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
@@ -208,41 +282,46 @@ BOOL Execute(const char* cExeName)
|
|
|
|
|
|
BOOL RunSpshell()
|
|
|
{
|
|
|
+ BOOL ret = FALSE;
|
|
|
+
|
|
|
char* pSpPath = new char[MAX_PATH];
|
|
|
memset(pSpPath, 0, MAX_PATH);
|
|
|
|
|
|
- if (!GetSpShellPath(&pSpPath))
|
|
|
+ do
|
|
|
{
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
+ if (!GetSpShellPath(&pSpPath))
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (!Execute(pSpPath))
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ ret = TRUE;
|
|
|
|
|
|
- if (!Execute(pSpPath))
|
|
|
- {
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
+ } while (false);
|
|
|
|
|
|
if (NULL != pSpPath)
|
|
|
{
|
|
|
- free(pSpPath);
|
|
|
+ delete[] pSpPath;
|
|
|
pSpPath = NULL;
|
|
|
}
|
|
|
-
|
|
|
- return TRUE;
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
//校正
|
|
|
-void checkActiveTxtAttr()
|
|
|
+int checkActiveTxtAttr()
|
|
|
{
|
|
|
char vtmexePath[MAX_PATH] = {0};
|
|
|
GetModuleFileNameA(NULL, vtmexePath, sizeof(vtmexePath));
|
|
|
string strRunVtmPath = vtmexePath;
|
|
|
- int nPosVtm = strRunVtmPath.find_first_of("\\version\\VTM.exe");
|
|
|
- if(nPosVtm<0)
|
|
|
+ const auto nPosVtm = strRunVtmPath.find("\\version\\VTM.exe");
|
|
|
+ if(nPosVtm == -1)
|
|
|
{
|
|
|
- MessageBoxA(NULL,"VTM.exe 不在X:\\version\\VTM.exe下",NULL,0);
|
|
|
- return ;
|
|
|
+ MessageBoxA(NULL,"[RTAXXXX] VTM.exe 不在规定路径下运行,请按规范安装版本!", ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
+ return -1;
|
|
|
}
|
|
|
- int nPos = strRunVtmPath.find_last_of("\\");
|
|
|
+ const int nPos = strRunVtmPath.find_last_of("\\");
|
|
|
string strVersionDir = strRunVtmPath.substr(0, nPos);
|
|
|
CString strActiveTxtPath=strVersionDir.c_str();//+"active.txt";
|
|
|
strActiveTxtPath +="\\";
|
|
@@ -255,6 +334,7 @@ void checkActiveTxtAttr()
|
|
|
rStatus.m_attribute=rStatus.m_attribute & 0x3E ;
|
|
|
CFile::SetStatus(strActiveTxtPath, rStatus );//更改文件的属性设置
|
|
|
}
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
void RegistHotkey()
|
|
@@ -378,7 +458,8 @@ void GetDisplayScale()
|
|
|
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
|
|
{
|
|
|
// 校正active.txt的属性
|
|
|
- checkActiveTxtAttr();
|
|
|
+ if (0 != checkActiveTxtAttr())
|
|
|
+ return FALSE;
|
|
|
|
|
|
//启动框架
|
|
|
if (RunSpshell()) {
|