WndInstalling.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #include "CFrameWnd.h"
  2. #include"MixpanelScript.h"
  3. void CFrameWnd::InitInstallingControls()
  4. {
  5. thread installingThread(Thread_LoadedBanner, m_threadData);
  6. installingThread.detach();
  7. }
  8. /// <summary>
  9. /// 安装中界面控件绑定事件
  10. /// </summary>
  11. void CFrameWnd::NotifyInstalling(TNotifyUI& msg)
  12. {
  13. }
  14. LRESULT CFrameWnd::InstallingMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  15. {
  16. LRESULT lRes = 0;
  17. BOOL bHandled1 = TRUE;
  18. if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes;
  19. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  20. }
  21. //Todo:安装过程的逻辑还是会有些乱,还会有重复的代码,以后再进行优化
  22. void CFrameWnd::Thread_Installing(ThreadData threadData)
  23. {
  24. if (threadData.pFrame->banner->IsEmptyBanner == true)
  25. {
  26. thread installingThread(CFrameWnd::Thread_LoadedBanner, threadData);
  27. installingThread.detach();
  28. }
  29. //下载安装前,安装路径过长问题
  30. if (DiskCore::IsMeetInstallPathMaxLength(true) == false)
  31. {
  32. threadData.pFrame->KillAllTimer();
  33. if (MSGID_OK == MessageBoxWnd::Show(threadData.pFrame->m_hWnd, MessageContentType::LongInstallingPath))
  34. {
  35. DownloadProgress::Currentpercentage = 0;
  36. threadData.pFrame->SelectLayout(LayoutType::Home);
  37. return;//直接返回是为了避免IsExistFile判断无效;
  38. }
  39. else
  40. {
  41. wstring installPackgeAbePath = PathCore::smPath_Install + L"\\" + Product::smName_InstallPackage;
  42. PathCore::smPath_Install = PathCore::smPath_DefaultInstall;
  43. threadData.pFrame->StartTimer(Timer_Installing_ID);
  44. threadData.pFrame->StartTimer(Timer_Banner_ID);
  45. }
  46. }
  47. CDownLoadFile downLoadFile;
  48. bool isDownloadSuccess = false;
  49. CFrameWnd::m_SilenceInstallingType = SilenceInstallingType::DownLoading;
  50. //1.下载
  51. isDownloadSuccess = downLoadFile.GetInstallPackage(PathCore::smPath_Install.c_str());
  52. //2.下载失败
  53. if (isDownloadSuccess == false)
  54. {
  55. //TODO:检查是否是代理服务器问题,已确认初版隐藏掉该需求,不可删除以下这段代码
  56. //若要使用,可以恢复以下代码,修改弹窗提示内容便可;
  57. //2.1下载失败,代理服务器问题
  58. //if (NetWorkState::IsProxyNetError())
  59. //{
  60. // if (MSGID_OK == MessageBoxWnd::Show(threadData.pFrame->m_hWnd, MessageContentType::ProxyNetError))
  61. // {
  62. // //打开系统“Internet选项”-“连接”界面,引导用户,在“局域网设置”界面,取消勾选LAN代理,或者重新填写可用的代理服务器
  63. // ShellExecute(0, L"open", L"rundll32.exe", L"inetcpl.cpl,LaunchConnectionDialog", NULL, SW_SHOWDEFAULT);
  64. // }
  65. // threadData.pFrame->KillAllTimer();
  66. // DownloadProgress::Currentpercentage = 0;
  67. // threadData.pFrame->SelectLayout(LayoutType::Home);
  68. // return;
  69. //}
  70. //2.1下载失败,安装路径过长问题
  71. if (DiskCore::IsMeetInstallPathMaxLength(true) == false)
  72. {
  73. threadData.pFrame->KillAllTimer();
  74. if (MSGID_OK == MessageBoxWnd::Show(threadData.pFrame->m_hWnd, MessageContentType::LongInstallingPath))
  75. {
  76. DownloadProgress::Currentpercentage = 0;
  77. threadData.pFrame->SelectLayout(LayoutType::Home);
  78. return;//直接返回是为了避免IsExistFile判断无效;
  79. }
  80. else
  81. {
  82. wstring installPackgeAbePath = PathCore::smPath_Install + L"\\" + Product::smName_InstallPackage;
  83. PathCore::smPath_Install = PathCore::smPath_DefaultInstall;
  84. threadData.pFrame->StartTimer(Timer_Installing_ID);
  85. threadData.pFrame->StartTimer(Timer_Banner_ID);
  86. DownloadProgress::Currentpercentage = 0;
  87. isDownloadSuccess = downLoadFile.GetInstallPackage(PathCore::smPath_Install.c_str());
  88. }
  89. }
  90. }
  91. //2.3下载失败,网络断网问题
  92. if (isDownloadSuccess == false)
  93. {
  94. CFrameWnd::m_SilenceInstallingType = SilenceInstallingType::DownLoadNoNetWork;
  95. threadData.pFrame->m_InstallingPage->NetWorkUI(false);
  96. threadData.pFrame->WaitForNetwork();
  97. return;
  98. }
  99. CCmd cmd;
  100. bool IsNeedInstallNet = false;
  101. //3.若缺少NET Framework框架,则优先安装
  102. if (threadData.pFrame->m_State.m_NetFrameworkType == InstallNetFrameworkType::V40_46)
  103. {
  104. cmd.InstallNetcmd();
  105. IsNeedInstallNet = true;
  106. }
  107. //3.若缺少Vc++环境,则优先安装,目前以使用vcruntime140.dll来配置,配置环境逻辑注释掉
  108. /*if (threadData.pFrame->m_State.m_VcPlusPlusType != InstallVCPlusPlusType::V14_3)
  109. {
  110. cmd.InstallVcPlusPluscmd();
  111. }*/
  112. //4.静默安装产品
  113. threadData.pFrame->StartTimer(Timer_SilentInstall_ID);
  114. int error = cmd.Installcmd();
  115. if (error)
  116. {
  117. //如果安装失败,有可能是安装路径太长的问题,此处指令并不会返回失败的值;所以需要做个判断,是否需要返回安装前的页面
  118. //4.1 静默安装产品,若因为路径过长,安装失败
  119. if (DiskCore::IsMeetInstallPathMaxLength(false) == false)
  120. {
  121. threadData.pFrame->KillAllTimer();
  122. if (MSGID_OK == MessageBoxWnd::Show(threadData.pFrame->m_hWnd, MessageContentType::LongInstallingPath))
  123. {
  124. DownloadProgress::Currentpercentage = 0;
  125. threadData.pFrame->m_InstallingPage->SetProgressValue(0);
  126. threadData.pFrame->SelectLayout(LayoutType::Home);
  127. return;//直接返回是为了避免IsExistFile判断无效;
  128. }
  129. else
  130. {
  131. wstring installPackgeAbePath = PathCore::smPath_Install + L"\\" + Product::smName_InstallPackage;
  132. PathCore::smPath_Install = PathCore::smPath_DefaultInstall;
  133. FileCore::SourceFileMoveToDestionPath(installPackgeAbePath, PathCore::smPath_DefaultInstall);
  134. if (cmd.Installcmd() == false)
  135. {
  136. if (FileCore::IsExistProductAppPath() == false)
  137. {
  138. cmd.GetVBA_UTF8();
  139. }
  140. DownloadProgress::Currentpercentage = 0;
  141. threadData.pFrame->m_InstallingPage->SetProgressValue(0);
  142. threadData.pFrame->KillAllTimer();
  143. }
  144. }
  145. }
  146. else if (FileCore::IsExistProductAppPath() == false)
  147. {
  148. MixpanelScript* mix = new MixpanelScript();
  149. std::string GUID = mix->GetGUID();
  150. std::string CPUID = mix->GetCPUID();
  151. mix->PostData("InstallError_Trig_Reason", CPUID, GUID, error);
  152. //4.2 静默安装产品,若因为未知原因安装失败,则弹出安装路径,让用户进行手动安装
  153. if (MSGID_OK == MessageBoxWnd::Show(threadData.pFrame->m_hWnd, MessageContentType::InstallingFailed))
  154. {
  155. wstring folderPath = L"explorer.exe \"" + PathCore::smPath_Install + L"\"";
  156. char* ch = CharConvert::GetWstringToCharPtr(folderPath);
  157. mix->PostData("InstallError_Btn_Continue", CPUID, GUID, error);
  158. system(ch);
  159. }
  160. else
  161. {
  162. mix->PostData("InstallError_Btn_Close", CPUID, GUID, error);
  163. }
  164. }
  165. threadData.pFrame->SelectLayout(LayoutType::Installed);
  166. std::wstring path = L"";
  167. path = CLanguage::GetText(TextType::Btn_GoToFilesPath).c_str() + PathCore::smPath_Install;
  168. threadData.pFrame->m_InstalledPage->RefreshInstalledPath(path);
  169. }
  170. DownloadProgress::Currentpercentage = 0;
  171. threadData.pFrame->KillAllTimer();
  172. if (cmd.m_IsWin8InstallNet && IsNeedInstallNet)
  173. {
  174. threadData.pFrame->IsNeedReStartSystem = true;
  175. threadData.pFrame->ReStartSystem();
  176. }
  177. }
  178. void CFrameWnd::SetTimerSilen()
  179. {
  180. srand(time(0));
  181. auto randnum = rand() % (4 - 1 + 2) + 1;
  182. int dprogress = (int)(DownloadProgress::Currentpercentage + randnum) * 0.7;
  183. if (DownloadProgress::Currentpercentage < 143)
  184. DownloadProgress::Currentpercentage = DownloadProgress::Currentpercentage + randnum;
  185. if (dprogress > 99)
  186. {
  187. dprogress = 99;
  188. }
  189. m_InstallingPage->SetProgressValue(dprogress);
  190. }
  191. void CFrameWnd::SetTimerInstalling()
  192. {
  193. try
  194. {
  195. m_InstallingPage->NetWorkUI(NetWorkState::IsNetWorking());
  196. }
  197. catch (const std::exception&)
  198. {
  199. }
  200. if (CFrameWnd::m_SilenceInstallingType == SilenceInstallingType::DownLoading)
  201. {
  202. int dprogress = (int)DownloadProgress::Currentpercentage * 0.7;
  203. if (dprogress > 99)
  204. {
  205. dprogress = 99;
  206. }
  207. m_InstallingPage->SetProgressValue(dprogress);
  208. }
  209. else if (CFrameWnd::m_SilenceInstallingType == SilenceInstallingType::Installed)
  210. {
  211. m_InstallingPage->SetProgressValue(100);
  212. }
  213. else if (CFrameWnd::m_SilenceInstallingType == SilenceInstallingType::Installing || CFrameWnd::m_SilenceInstallingType == SilenceInstallingType::DownLoadSuccess)
  214. {
  215. }
  216. else if (CFrameWnd::m_SilenceInstallingType == SilenceInstallingType::DownLoadNoNetWork)
  217. {
  218. }
  219. }