lyfzUpgrade.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*************************************************************
  2. /* Copyright (C), 2014-2020, lyfz. Co., Ltd.
  3. /* 文件名: 当前控制台
  4. /* 作者: Jeff.w
  5. /* 创建日期: 2014-08-22
  6. /* 版本号: V1.0
  7. /* 描述: 统一升级包
  8. /* 其它:
  9. /* 主要类模块:
  10. /* 历史修改记录:
  11. /* 作者 时间 版本 描述
  12. /* Jeff.w 14/08/18 1.0 创建这个模块
  13. /*
  14. /* 已实现:
  15. /* 1.根据加密狗信息自动判断是否Enterprise版本来升级相应的资源;
  16. /* 2.需要添加加密狗的支持功能;
  17. ***************************************************************/
  18. // lyfzUpgrade.cpp : 定义控制台应用程序的入口点。
  19. //
  20. #include "stdafx.h"
  21. #include "lyfzUpgrade.h"
  22. #include "Executor.h"
  23. #include "my32.h"
  24. #include "SQLStatementImpl.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #endif
  28. typedef struct __STVERSION__
  29. {
  30. int nVersion;
  31. CString strVersion;
  32. }STVersion, *pSTVersion;
  33. STVersion g_stVersion[6] =
  34. {
  35. { 0, _T("儿童座席版") },
  36. { 1, _T("婚纱座席版") },
  37. { 2, _T("儿童企业版") },
  38. { 3, _T("婚纱企业版") },
  39. { 4, _T("儿童全能版") },
  40. { 5, _T("婚纱全能版") }
  41. };
  42. // 唯一的应用程序对象
  43. CWinApp theApp;
  44. using namespace std;
  45. int MyTest()
  46. {
  47. FindAndCloseProcess(_T("E:\\lyfzbin\\Services\\lyfzServices.exe"));
  48. return 0;
  49. CSQLStatementImpl::GetInstancePtr()->ReSetKind(_T("dindan"), _T("where id='120456465465'"), KIND_UPDATE, 10);
  50. CSQLStatementImpl::GetInstancePtr()->AddElement(_T("satisfaction1"),1);
  51. CSQLStatementImpl::GetInstancePtr()->AddElement(_T("satisfaction2"),2);
  52. CSQLStatementImpl::GetInstancePtr()->AddElement(_T("satisfaction3"),3);
  53. CSQLStatementImpl::GetInstancePtr()->AddElement(_T("satisfaction4"),4);
  54. CSQLStatementImpl::GetInstancePtr()->AddElement(_T("satisfaction5"), 5);
  55. CSQLStatementImpl::GetInstancePtr()->AddElement(_T("satisfaction6"), 6);
  56. CSQLStatementImpl::GetInstancePtr()->AddElement(_T("satisfaction7"), 7);
  57. CSQLStatementImpl::GetInstancePtr()->AddElement(_T("satisfaction8"), 8);
  58. CSQLStatementImpl::GetInstancePtr()->AddElement(_T("bz5"), _T("22333"));
  59. CString sql = CSQLStatementImpl::GetInstancePtr()->ReturnSQL();
  60. return 0;
  61. }
  62. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  63. {
  64. int nRetCode = 0;
  65. //return MyTest();
  66. // 获取升级的文件版本;
  67. //GetFileVersion(NULL, g_arrFileVersion);
  68. GetProductVersion((HMODULE)NULL, g_arrFileVersion);
  69. // 对进程提权;
  70. GetDebugPriv();
  71. // 初始化 MFC 并在失败时显示错误
  72. if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
  73. {
  74. _tprintf(_T("错误: MFC 初始化失败\n"));
  75. nRetCode = 1;
  76. }
  77. else
  78. {
  79. HANDLE hObject = CreateMutex(NULL, FALSE, _T("lyfzUpgradeRuning"));
  80. if (GetLastError() == ERROR_ALREADY_EXISTS)
  81. {
  82. #ifdef USE_CONSOLE
  83. AfxMessageBox(_T("升级程序已启动!"));
  84. #else
  85. _tprintf(_T("升级程序已启动\n"));
  86. #endif
  87. return false;
  88. }
  89. // 1.加载配置文件;
  90. if (GetIniInfo() == -1)
  91. {
  92. #ifdef USE_CONSOLE
  93. AfxMessageBox(_T("没有找到ServiceInof.ini文件,请修改默认生成的ServiceInof.ini后重新更新!"));
  94. #else
  95. _tprintf(_T("没有找到ServiceInof.ini文件,请修改默认生成的ServiceInof.ini后重新更新\n"));
  96. #endif
  97. TCHAR szExecuteFile[MAX_PATH] = _T("");
  98. _stprintf_s(szExecuteFile, _T("%sServiceInfo.ini"), g_ModulePath);
  99. CExecutor::UpdateFile(ServiceInfo, _T("INI"), szExecuteFile);
  100. return -1;
  101. }
  102. // 2.预留第二步:获取加密狗信息,以判断是否升级为相信的版本;
  103. /*
  104. int nVersion = GetSoftWareVersion();
  105. if (nVersion == -1)
  106. {
  107. #ifdef USE_CONSOLE
  108. AfxMessageBox(_T("未找到加密狗,程序退出……!"));
  109. #else
  110. _tprintf(_T("未找到加密狗,程序退出……\n"));
  111. #endif
  112. return -1;
  113. }
  114. else
  115. {
  116. #ifdef USE_CONSOLE
  117. AfxMessageBox(g_stVersion[g_nVersion].strVersion);
  118. #else
  119. _tprintf(_T("当前版:%s\n"), g_stVersion[g_nVersion].strVersion);
  120. #endif
  121. }*/
  122. #ifdef USE_CONSOLE
  123. //AfxMessageBox(_T("升级完成后会提示 '升级成功' 如没有提示,请重启电脑后再次安装!"));
  124. #else
  125. _tprintf(_T("升级完成后会提示 '升级成功' 如没有提示,请重启电脑后再次安装!\n"));
  126. #endif
  127. TCHAR szDealFile[MAX_PATH] = _T("");
  128. _stprintf_s(szDealFile, _T("%s\\日志.txt"), g_ModulePath);
  129. lyfzCopyFileEx(szDealFile,szDealFile,TRUE);
  130. ::DeleteFile(szDealFile);
  131. _stprintf_s(szDealFile, _T("%s\\升级包日志.txt"), g_ModulePath);
  132. ::DeleteFile(szDealFile);
  133. // 3.执行更新;
  134. CExecutor tagExecutor;
  135. #if 1
  136. if (tagExecutor.ConnectDatabase() == -1)
  137. return 0;
  138. // if (tagExecutor.UpgradeSQL() == -1)
  139. // return AfxMessageBox(_T("数据库升级失败"));
  140. // else
  141. // AfxMessageBox(_T("数据库升级成功"));
  142. #endif
  143. tagExecutor.InitMaster();
  144. //AfxMessageBox(_T("查看有无订单相片记录张数不符情况"));
  145. //tagExecutor.VerifyCurrentNoQuestion();
  146. //AfxMessageBox(_T("结束查看订单相片记录张数不符情况"));
  147. if (tagExecutor.UpgradeExe(FALSE) == -1)
  148. return 0;
  149. //AfxMessageBox(_T("更新文件成功"));
  150. //AfxMessageBox(_T("结束数据库连接"));
  151. tagExecutor.DisConnectDatabase();
  152. }
  153. return nRetCode;
  154. }