|
@@ -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;
|
|
|
|
|
@@ -40,15 +42,14 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
|
|
|
UNREFERENCED_PARAMETER(hPrevInstance);
|
|
|
UNREFERENCED_PARAMETER(lpCmdLine);
|
|
|
|
|
|
- // TODO: 在此放置代码。
|
|
|
MSG msg;
|
|
|
HACCEL hAccelTable;
|
|
|
|
|
|
- // 初始化全局字符串
|
|
|
+ // 初始化全局字符串
|
|
|
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
|
|
LoadString(hInstance, IDC_TEST, szWindowClass, MAX_LOADSTRING);
|
|
|
MyRegisterClass(hInstance);
|
|
|
-
|
|
|
+ Sleep(200);
|
|
|
// 执行应用程序初始化:
|
|
|
if (!InitInstance (hInstance, nCmdShow))
|
|
|
{
|
|
@@ -106,6 +107,45 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
|
|
|
return RegisterClassEx(&wcex);
|
|
|
}
|
|
|
|
|
|
+BOOL ExistsFileA(LPCSTR lpFilePath)
|
|
|
+{
|
|
|
+ DWORD dwRet = GetFileAttributesA(lpFilePath);
|
|
|
+ return (dwRet != INVALID_FILE_ATTRIBUTES) && !(dwRet & FILE_ATTRIBUTE_DIRECTORY);
|
|
|
+}
|
|
|
+
|
|
|
+BOOL ExistsDirA(LPCSTR lpDirPath)
|
|
|
+{
|
|
|
+ DWORD dwRet = GetFileAttributesA(lpDirPath);
|
|
|
+ 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,32 +155,45 @@ 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("[RTA0031] 版本文件不存在,请重新安装程序版本!");
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- char cVer[MAX_PATH] = {0};
|
|
|
ifstream infile(szFilePath);
|
|
|
- if(infile) // 有该文件
|
|
|
+ if(infile.is_open())
|
|
|
{
|
|
|
- if(infile.getline(cVer, MAX_PATH))
|
|
|
- {
|
|
|
- memcpy_s(*pVersion, MAX_PATH, cVer, MAX_PATH);
|
|
|
+ std::string line;
|
|
|
+ if(std::getline(infile, line)){
|
|
|
+ CString strVersionTxt(line.c_str());
|
|
|
+ memcpy_s(*pVersion, MAX_PATH, strVersionTxt.GetString(), MAX_PATH);
|
|
|
infile.close();
|
|
|
-
|
|
|
return 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- MessageBoxA(NULL,"获取版本信息失败:文件内容为空",NULL,0);
|
|
|
+ CString strText;
|
|
|
+ strText.Format("[RTA0032] 版本文件内容为空,请重新安装程序版本!");
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
+ infile.close();
|
|
|
return 0;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- MessageBoxA(NULL,"获取版本信息失败:文件打开失败",NULL,0);
|
|
|
+ else {
|
|
|
+ const DWORD dwError = GetLastError();
|
|
|
+ CString strText;
|
|
|
+ CString strError;
|
|
|
+ char szDefault[128];
|
|
|
+ sprintf_s(szDefault, "错误描述:%u", dwError);
|
|
|
+ GetErrorMessage(strError, szDefault, dwError);
|
|
|
+ strText.Format("[RTA0033] 版本文件打开失败,请联系分行IT或厂商排查!\r\n\r\n%s", strError.GetBuffer());
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
infile.close();
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -156,34 +209,46 @@ BOOL GetSpShellPath(char** pPath)
|
|
|
int nPos = strFileName.find_last_of("\\");
|
|
|
string strDir = strFileName.substr(0, nPos);
|
|
|
|
|
|
- if(GetVersion(&pVer))
|
|
|
+ if(!GetVersion(&pVer))
|
|
|
{
|
|
|
- sprintf_s(szFilePath, MAX_PATH, "%s\\%s\\bin\\SpShell.exe", strDir.c_str(), pVer);
|
|
|
+ if (NULL != pVer)
|
|
|
+ {
|
|
|
+ delete [] pVer;
|
|
|
+ pVer = NULL;
|
|
|
+ }
|
|
|
+ return FALSE;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
+ memset(szFileName, 0, sizeof(szFileName));
|
|
|
+ sprintf_s(szFileName, MAX_PATH, "%s\\%s", strDir.c_str(), pVer);
|
|
|
+ if (!ExistsDirA(szFileName)) {
|
|
|
+ CString strText;
|
|
|
+ strText.Format("[RTA0034] 版本文件夹 [%s] 不存在,请重新安装程序版本!",pVer);
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
+ if (NULL != pVer)
|
|
|
+ {
|
|
|
+ delete[] pVer;
|
|
|
+ pVer = NULL;
|
|
|
+ }
|
|
|
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)
|
|
|
{
|
|
|
- free(pVer);
|
|
|
+ delete[] pVer;
|
|
|
pVer = NULL;
|
|
|
}
|
|
|
|
|
|
- ifstream shellFile(*pPath);
|
|
|
- if(shellFile)
|
|
|
- {
|
|
|
- return TRUE;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- MessageBoxA(NULL,"获取执行文件失败:文件无效或文件不存在",NULL,0);
|
|
|
+ if (!ExistsFileA(*pPath)) {
|
|
|
+ CString strText;
|
|
|
+ strText.Format("[RTA0035] 程序执行文件不存在,请重新安装程序版本!(文件路径:%s)", *pPath);
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
return FALSE;
|
|
|
}
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
}
|
|
|
|
|
|
BOOL Execute(const char* cExeName)
|
|
@@ -195,11 +260,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("[RTA0036] 执行应用程序文件失败,请联系分行IT或厂商排查!\r\n\r\n%s", strError.GetBuffer());
|
|
|
+ MessageBoxA(NULL, strText, ERROR_TITILE, MB_OK | MB_ICONERROR);
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
@@ -208,53 +276,60 @@ 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,"[RTA0030] 可视柜台应用程序不在规定路径下执行,请重新安装程序版本!", 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 +="\\";
|
|
|
strActiveTxtPath +="active.txt";
|
|
|
-
|
|
|
- CFileStatus rStatus;
|
|
|
- CFile::GetStatus(strActiveTxtPath,rStatus);//获得文件的属性设置
|
|
|
- //如果文件为只读的,将只读属性去掉
|
|
|
- if(rStatus.m_attribute&CFile::readOnly){
|
|
|
- rStatus.m_attribute=rStatus.m_attribute & 0x3E ;
|
|
|
- CFile::SetStatus(strActiveTxtPath, rStatus );//更改文件的属性设置
|
|
|
+ if (ExistsFileA(strActiveTxtPath)) {
|
|
|
+ CFileStatus rStatus;
|
|
|
+ CFile::GetStatus(strActiveTxtPath, rStatus);//获得文件的属性设置
|
|
|
+ //如果文件为只读的,将只读属性去掉
|
|
|
+ if (rStatus.m_attribute & CFile::readOnly) {
|
|
|
+ rStatus.m_attribute = rStatus.m_attribute & 0x3E;
|
|
|
+ CFile::SetStatus(strActiveTxtPath, rStatus);//更改文件的属性设置
|
|
|
+ }
|
|
|
}
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
void RegistHotkey()
|
|
@@ -378,27 +453,22 @@ void GetDisplayScale()
|
|
|
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
|
|
{
|
|
|
// 校正active.txt的属性
|
|
|
- checkActiveTxtAttr();
|
|
|
-
|
|
|
- //启动框架
|
|
|
- if (RunSpshell()) {
|
|
|
+ if (0 == checkActiveTxtAttr() && RunSpshell()) {
|
|
|
HideTaskBar(TRUE);
|
|
|
}
|
|
|
|
|
|
hInst = hInstance; // 将实例句柄存储在全局变量中
|
|
|
|
|
|
- /*hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
|
|
|
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
|
|
|
-
|
|
|
- if (!hWnd)
|
|
|
- {
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
+ //HWND hWnd = CreateWindowA(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
|
|
|
+ //CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
|
|
|
|
|
|
- ShowWindow(hWnd, nCmdShow);
|
|
|
- UpdateWindow(hWnd);*/
|
|
|
- //MessageBoxA(NULL,"Hello",NULL,0);
|
|
|
+ //if (!hWnd)
|
|
|
+ //{
|
|
|
+ //return FALSE;
|
|
|
+ //}
|
|
|
|
|
|
+ //ShowWindow(hWnd, nCmdShow);
|
|
|
+ //UpdateWindow(hWnd);
|
|
|
return FALSE;
|
|
|
}
|
|
|
|