PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/libusbK/src/inf-wizard2/src/PageInstall.cpp

http://usb-travis.googlecode.com/
C++ | 714 lines | 554 code | 131 blank | 29 comment | 70 complexity | e4f952229d457ad1b5b3dce39559f8f2 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, LGPL-2.0
  1. // PageInstall.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. #include "stdafx.h"
  13. #include "InfWizardApp.h"
  14. #include "InfWizardDlg.h"
  15. #include "PageInstall.h"
  16. #include <shlwapi.h>
  17. #include "libwdimanager.h"
  18. #include "res\\packed_resources.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. typedef struct _PACKED_ITEM
  25. {
  26. WORD nID;
  27. LPCTSTR Filename;
  28. } PACKED_ITEM, *PPACKED_ITEM;
  29. PACKED_ITEM PackedItems[] =
  30. {
  31. { ID_DPINST_XML, _T("dpinst.xml") },
  32. { ID_7ZDP_SFX, _T("7ZDP_LZMA.sfx") },
  33. { ID_7ZDP_CFG, _T("7zDP_LZMA.cfg") },
  34. { ID_INSTRUCTIONS_TXT, _T("Instructions.txt") },
  35. { ID_REPACK_CMD, _T("re-pack-files.cmd") },
  36. { ID_7ZA_EXE, _T("7za.exe") },
  37. };
  38. const DWORD PackedItemsCount = sizeof(PackedItems) / sizeof(PackedItems[0]);
  39. extern InfWizardApp* g_App;
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CPageInstall property page
  42. IMPLEMENT_DYNCREATE(CPageInstall, CResizablePageEx)
  43. CPageInstall::CPageInstall() : CResizablePageEx(CPageInstall::IDD, IDS_INFWIZARD, IDS_PAGE_INSTALL_TITLE, IDS_PAGE_INSTALL_SUBTITLE)
  44. {
  45. m_psp.dwFlags &= ~(PSP_HASHELP);
  46. //{{AFX_DATA_INIT(CPageInstall)
  47. // NOTE: the ClassWizard will add member initialization here
  48. //}}AFX_DATA_INIT
  49. //m_strHeaderTitle = "Setup Page (Test)";
  50. //m_psp.dwFlags |= PSP_HIDEHEADER;
  51. }
  52. CPageInstall::~CPageInstall()
  53. {
  54. }
  55. void CPageInstall::DoDataExchange(CDataExchange* pDX)
  56. {
  57. CResizablePageEx::DoDataExchange(pDX);
  58. //{{AFX_DATA_MAP(CPageInstall)
  59. // NOTE: the ClassWizard will add DDX and DDV calls here
  60. //}}AFX_DATA_MAP
  61. DDX_Control(pDX, IDC_TXT_STATUS, m_TxtStatus);
  62. DDX_Control(pDX, IDC_BTN_SAVE_BASE_FOLDER, m_BtnSaveLocation);
  63. DDX_Control(pDX, IDC_TXT_SAVE_BASE_FOLDER, m_TxtSaveBaseFolder);
  64. DDX_Control(pDX, IDC_TXT_SAVE_NAME, m_TxtSaveName);
  65. }
  66. BEGIN_MESSAGE_MAP(CPageInstall, CResizablePageEx)
  67. //{{AFX_MSG_MAP(CPageInstall)
  68. ON_WM_SIZE()
  69. ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipNotify)
  70. //}}AFX_MSG_MAP
  71. ON_BN_CLICKED(IDC_BTN_CLIENT_INSTALLER, OnBnClickedBtnClientInstaller)
  72. ON_BN_CLICKED(IDC_BTN_LEGACY_PACKAGE, OnBnClickedBtnLegacyPackage)
  73. ON_BN_CLICKED(IDC_BTN_INSTALL_ONLY, OnBnClickedBtnInstallOnly)
  74. ON_BN_CLICKED(IDC_BTN_SAVE_BASE_FOLDER, OnBnClickedBtnSaveBaseFolder)
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CPageInstall message handlers
  78. BOOL CPageInstall::OnSetActive()
  79. {
  80. CPropertySheet* pSheet = (CPropertySheet*)GetParent();
  81. ASSERT_KINDOF(CPropertySheet, pSheet);
  82. pSheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
  83. if (!m_TxtSaveBaseFolder.GetWindowTextLength())
  84. m_TxtSaveBaseFolder.SetWindowText(g_App->Wdi.Session()->GetPackageBaseDir());
  85. m_TxtSaveName.SetWindowText(g_App->Wdi.Session()->GetPackageName());
  86. m_TxtStatus.SetSel(0, 0);
  87. return CResizablePageEx::OnSetActive();
  88. }
  89. LRESULT CPageInstall::OnWizardNext()
  90. {
  91. BOOL bClientInstaller = ((CButton*)GetDlgItem(IDC_BTN_CLIENT_INSTALLER))->GetCheck() == BST_CHECKED;
  92. BOOL bLegacyPackage = ((CButton*)GetDlgItem(IDC_BTN_LEGACY_PACKAGE))->GetCheck() == BST_CHECKED;
  93. BOOL bInstallOnly = ((CButton*)GetDlgItem(IDC_BTN_INSTALL_ONLY))->GetCheck() == BST_CHECKED;
  94. CString fmtRtf;
  95. CStringA infPathA;
  96. CStringA infNameA;
  97. int errorCode = ERROR_SUCCESS;
  98. if (!bClientInstaller && !bLegacyPackage && !bInstallOnly)
  99. {
  100. return CResizablePageEx::OnWizardNext();
  101. }
  102. CLibWdiDynamicAPI& API = g_App->Wdi;
  103. m_TxtStatus.SetWindowText(_T(""));
  104. m_TxtStatus.SetSel(0, -1);
  105. SetStatusFont(TRUE, RGB(0, 0, 0), _T("Tahoma"), TwipsPerPixelY() * 9);
  106. SetStatusFormat(PFA_LEFT, TRUE);
  107. HCURSOR hWaitCursor = AfxGetApp()->LoadStandardCursor(IDC_WAIT);
  108. HCURSOR hPrevCursor = SetCursor(hWaitCursor);
  109. Sleep(0);
  110. fmtRtf.Format(_T("%s..\n"), CInfWizardDisplay::GetTipString(IDS_STATUS_START_PACKAGER)->GetBuffer(0));
  111. this->AppendStatus(fmtRtf);
  112. WDI_DEVICE_INFO deviceInfo;
  113. g_App->Wdi.Session()->CopyTo(&deviceInfo);
  114. g_App->Wdi.Session()->RefreshSession();
  115. wdi_options_prepare_driver prepareOptions;
  116. memset(&prepareOptions, 0, sizeof(prepareOptions));
  117. prepareOptions.driver_type = g_App->Wdi.Session()->GetDriverType();
  118. if (g_App->Wdi.Session()->m_VendorName.GetLength() > 0)
  119. prepareOptions.vendor_name = g_App->Wdi.Session()->chVendorName;
  120. prepareOptions.device_guid = g_App->Wdi.Session()->chDeviceGuid;
  121. g_App->Wdi.Session()->m_InfClassName.Trim();
  122. g_App->Wdi.Session()->m_InfClassGuid.Trim();
  123. g_App->Wdi.Session()->m_InfProvider.Trim();
  124. if (g_App->Wdi.Session()->m_InfClassName.GetLength() > 0)
  125. prepareOptions.inf_class = g_App->Wdi.Session()->chInfClassName;
  126. if (g_App->Wdi.Session()->m_InfClassGuid.GetLength() > 0)
  127. prepareOptions.inf_class_guid = g_App->Wdi.Session()->chInfClassGuid;
  128. if (g_App->Wdi.Session()->m_InfProvider.GetLength() > 0)
  129. prepareOptions.inf_provider = g_App->Wdi.Session()->chInfProvider;
  130. prepareOptions.pwr_default_idle_state = g_App->Wdi.Session()->pwr_default_idle_state;
  131. prepareOptions.pwr_default_idle_timeout = g_App->Wdi.Session()->pwr_default_idle_timeout;
  132. prepareOptions.pwr_device_idle_enabled = g_App->Wdi.Session()->pwr_device_idle_enabled;
  133. prepareOptions.pwr_device_idle_ignore_wake_enable = g_App->Wdi.Session()->pwr_device_idle_ignore_wake_enable;
  134. prepareOptions.pwr_system_wake_enabled = g_App->Wdi.Session()->pwr_system_wake_enabled;
  135. prepareOptions.pwr_user_set_device_idle_enabled = g_App->Wdi.Session()->pwr_user_set_device_idle_enabled;
  136. wdi_options_install_driver installOptions;
  137. memset(&installOptions, 0, sizeof(installOptions));
  138. installOptions.hWnd = GetSafeHwnd();
  139. CString infPath, infName;
  140. m_TxtSaveName.GetWindowText(infName);
  141. m_TxtSaveBaseFolder.GetWindowText(infPath);
  142. if (bInstallOnly)
  143. {
  144. // Using a temp directory.
  145. CString tempPath;
  146. GetTempPath(256, tempPath.GetBufferSetLength(4096));
  147. tempPath.ReleaseBuffer();
  148. PathAppend(tempPath.GetBufferSetLength(4096), _T("InfWizard_Driver"));
  149. tempPath.ReleaseBuffer();
  150. infPath = tempPath;
  151. CreateDirectory(tempPath, NULL);
  152. CString infFullPath;
  153. GetTempFileName(tempPath, _T("Drv"), 0, infFullPath.GetBufferSetLength(4096));
  154. infFullPath.ReleaseBuffer();
  155. infName = PathFindFileName(infFullPath);
  156. PathRemoveExtension(infName.GetBuffer(0));
  157. infName.ReleaseBuffer();
  158. }
  159. else
  160. {
  161. PathAppend(infPath.GetBufferSetLength(4096), infName);
  162. infPath.ReleaseBuffer();
  163. }
  164. if (!PathIsDirectory(infPath))
  165. {
  166. if (SHCreateDirectoryEx(this->GetSafeHwnd(), infPath, NULL) != ERROR_SUCCESS)
  167. {
  168. errorCode = -ERROR_BAD_PATHNAME;
  169. CString* pTxtInvalidPath = CInfWizardDisplay::GetTipString(IDS_STATUS_INVALID_PATH);
  170. WriteStatusError(pTxtInvalidPath->GetBuffer(0), infPath);
  171. goto Done;
  172. }
  173. }
  174. CString* pTxtPackageFolder = CInfWizardDisplay::GetTipString(IDS_PACKAGE_DIR);
  175. fmtRtf.Format(_T("%s %s..\n"), pTxtPackageFolder->GetBuffer(0), infPath);
  176. this->AppendStatus(fmtRtf);
  177. CString* pTxtPackageName = CInfWizardDisplay::GetTipString(IDS_PACKAGE_NAME);
  178. fmtRtf.Format(_T("%s %s..\n"), pTxtPackageName->GetBuffer(0), infName);
  179. this->AppendStatus(fmtRtf);
  180. infName += _T(".inf");
  181. infPathA = infPath;
  182. infNameA = infName;
  183. fmtRtf.Format(_T("%s..\n"), CInfWizardDisplay::GetTipString(IDS_STATUS_PREPARE_DRIVER)->GetBuffer(0));
  184. this->AppendStatus(fmtRtf);
  185. if (bClientInstaller)
  186. {
  187. prepareOptions.driver_type |= WDI_PACKAGE_FLAG_CREATE_USER_INSTALLER;
  188. }
  189. else if (bLegacyPackage)
  190. {
  191. prepareOptions.driver_type |= WDI_PACKAGE_FLAG_CREATE_NORMAL;
  192. }
  193. prepareOptions.disable_signing = 1;
  194. prepareOptions.disable_cat = 1;
  195. errorCode = g_App->Wdi.PrepareDriver(&deviceInfo, infPathA.GetBuffer(0), infNameA.GetBuffer(0), &prepareOptions);
  196. if (errorCode != ERROR_SUCCESS)
  197. {
  198. CString* pTxtErrorPrepareDriver = CInfWizardDisplay::GetTipString(IDS_ERROR_PREPARE_DRIVER);
  199. CString wdiError;
  200. LPCSTR chWdiError = g_App->Wdi.StrError(errorCode);
  201. wdiError = chWdiError;
  202. WriteStatusError(pTxtErrorPrepareDriver->GetBuffer(0), wdiError);
  203. goto Done;
  204. }
  205. if (!FinalizePrepareDriver(&deviceInfo, infPathA.GetBuffer(0), infNameA.GetBuffer(0), &prepareOptions))
  206. {
  207. errorCode = GetLastError();
  208. goto Done;
  209. }
  210. if (bInstallOnly)
  211. {
  212. fmtRtf.Format(_T("%s..\n"), CInfWizardDisplay::GetTipString(IDS_STATUS_INSTALL_DRIVER)->GetBuffer(0));
  213. this->AppendStatus(fmtRtf);
  214. errorCode = g_App->Wdi.InstallDriver(&deviceInfo, infPathA.GetBuffer(0), infNameA.GetBuffer(0), &installOptions);
  215. if (errorCode != ERROR_SUCCESS)
  216. {
  217. CString* pTxtErrorInstallDriver = CInfWizardDisplay::GetTipString(IDS_ERROR_INSTALL_DRIVER);
  218. CString wdiError;
  219. LPCSTR chWdiError = g_App->Wdi.StrError(errorCode);
  220. wdiError = chWdiError;
  221. WriteStatusError(pTxtErrorInstallDriver->GetBuffer(0), wdiError);
  222. goto Done;
  223. }
  224. }
  225. Done:
  226. SetCursor(hPrevCursor);
  227. SetStatusFormat(PFA_LEFT, FALSE);
  228. g_App->Wdi.Session()->Destroy(&deviceInfo);
  229. if (errorCode == ERROR_SUCCESS)
  230. {
  231. g_App->Wdi.Session()->m_PackageStatus |= CLibWdiSession::PACKAGE_STATUS_SUCCESS;
  232. if (bLegacyPackage)
  233. {
  234. RemoveDirectory(infPath);
  235. }
  236. else
  237. {
  238. m_TxtSaveName.GetWindowText(infName);
  239. m_TxtSaveBaseFolder.GetWindowText(infPath);
  240. g_App->Wdi.Session()->m_PackageName = infName;
  241. g_App->Wdi.Session()->m_PackageBaseDir = infPath;
  242. }
  243. if (bClientInstaller)
  244. ((CButton*)GetDlgItem(IDC_BTN_CLIENT_INSTALLER))->SetCheck(BST_UNCHECKED);
  245. else if (bLegacyPackage)
  246. ((CButton*)GetDlgItem(IDC_BTN_LEGACY_PACKAGE))->SetCheck(BST_UNCHECKED);
  247. else if (bInstallOnly)
  248. ((CButton*)GetDlgItem(IDC_BTN_INSTALL_ONLY))->SetCheck(BST_UNCHECKED);
  249. CString* pTxtPackageSuccess = CInfWizardDisplay::GetTipString(IDS_STATUS_PACKAGE_SUCCESS);
  250. fmtRtf.Format(_T("%s\n"), pTxtPackageSuccess->GetBuffer(0));
  251. SetStatusFont(TRUE, CInfWizardDisplay::ColorGood, NULL, TwipsPerPixelY() * 11);
  252. this->AppendStatus(fmtRtf);
  253. InfWizardDlg* pDlg = (InfWizardDlg*)GetParent();
  254. ASSERT_KINDOF(InfWizardDlg, pDlg);
  255. m_TxtStatus.GetTextRange(0, m_TxtStatus.GetTextLength(), pDlg->m_InstallResults);
  256. return CResizablePageEx::OnWizardNext();
  257. }
  258. else
  259. {
  260. g_App->Wdi.Session()->m_PackageStatus |= CLibWdiSession::PACKAGE_STATUS_FAIL;
  261. CString* pTxtPackageError = CInfWizardDisplay::GetTipString(IDSE_STATUS_PACKAGE);
  262. fmtRtf.Format(_T("%s\n"), pTxtPackageError->GetBuffer(0));
  263. SetStatusFont(TRUE, CInfWizardDisplay::ColorError, NULL, TwipsPerPixelY() * 11);
  264. this->AppendStatus(fmtRtf);
  265. }
  266. return -1;
  267. }
  268. BOOL CPageInstall::OnInitDialog()
  269. {
  270. CResizablePageEx::OnInitDialog();
  271. m_BtnSaveLocation.SetIcon(IDI_ICON_OPEN_FOLDER);
  272. AddAnchor(IDC_BTN_CLIENT_INSTALLER, TOP_LEFT);
  273. AddAnchor(IDC_BTN_LEGACY_PACKAGE, TOP_LEFT);
  274. AddAnchor(IDC_BTN_INSTALL_ONLY, TOP_LEFT);
  275. AddAnchor(IDC_GRP_SAVE_INFORMATION, TOP_LEFT, TOP_RIGHT);
  276. AddAnchor(IDC_LBL_SAVE_BASE_FOLDER, TOP_LEFT, TOP_LEFT);
  277. AddAnchor(IDC_TXT_SAVE_BASE_FOLDER, TOP_LEFT, TOP_RIGHT);
  278. AddAnchor(IDC_BTN_SAVE_BASE_FOLDER, TOP_RIGHT);
  279. AddAnchor(IDC_LBL_SAVE_NAME, TOP_LEFT, TOP_LEFT);
  280. AddAnchor(IDC_TXT_SAVE_NAME, TOP_LEFT, TOP_RIGHT);
  281. AddAnchor(IDC_GRP_STATUS, TOP_LEFT, BOTTOM_RIGHT);
  282. AddAnchor(IDC_TXT_STATUS, TOP_LEFT, BOTTOM_RIGHT);
  283. COLORREF clrStatusBack = GetSysColor(COLOR_BTNFACE);
  284. m_TxtStatus.SetBackgroundColor(FALSE, clrStatusBack);
  285. if (g_App->Wdi.Session()->m_PackageBaseDir.IsEmpty())
  286. {
  287. CButton* wndInstallPackage = (CButton*)GetDlgItem(IDC_BTN_CLIENT_INSTALLER);
  288. wndInstallPackage->SetCheck(BST_CHECKED);
  289. OnBnClickedBtnClientInstaller();
  290. }
  291. if(!m_ToolTip.Create(this))
  292. {
  293. TRACE("Unable To create ToolTip\n");
  294. return FALSE;
  295. }
  296. CInfWizardDisplay::AddCallbackTool(&m_ToolTip, this, IDC_BTN_CLIENT_INSTALLER, IDS_TIP_CLIENT_INSTALLER);
  297. CInfWizardDisplay::AddCallbackTool(&m_ToolTip, this, IDC_BTN_LEGACY_PACKAGE, IDS_TIP_LEGACY_PACKAGE);
  298. CInfWizardDisplay::AddCallbackTool(&m_ToolTip, this, IDC_BTN_INSTALL_ONLY, IDS_TIP_INSTALL_ONLY);
  299. CInfWizardDisplay::AddCallbackTool(&m_ToolTip, this, IDC_TXT_SAVE_BASE_FOLDER, IDS_TIP_SAVE_BASE_FOLDER);
  300. CInfWizardDisplay::AddCallbackTool(&m_ToolTip, this, IDC_TXT_SAVE_NAME, IDS_TIP_PACKAGE_NAME);
  301. m_ToolTip.Activate(TRUE);
  302. m_ToolTip.SetMaxTipWidth(400);
  303. m_ToolTip.SetDelayTime(TTDT_AUTOPOP, 10000);
  304. return TRUE; // return TRUE unless you set the focus to a control
  305. // EXCEPTION: OCX Property Pages should return FALSE
  306. }
  307. void CPageInstall::OnSize(UINT nType, int cx, int cy)
  308. {
  309. CResizablePageEx::OnSize(nType, cx, cy);
  310. }
  311. void CPageInstall::SetStatusFont(BOOL isBold, COLORREF textColor, LPCTSTR pszFontName, LONG fontSize)
  312. {
  313. DWORD dwMask = 0;
  314. CHARFORMAT charFmt;
  315. memset(&charFmt, 0, sizeof(charFmt));
  316. charFmt.cbSize = sizeof(CHARFORMAT);
  317. charFmt.dwMask |= CFM_BOLD;
  318. if (isBold) charFmt.dwEffects |= CFE_BOLD;
  319. if ((int)textColor != -1)
  320. {
  321. charFmt.dwMask |= CFM_COLOR;
  322. charFmt.crTextColor = textColor;
  323. }
  324. if (pszFontName)
  325. {
  326. charFmt.dwMask |= CFM_FACE;
  327. _tcscpy_s(charFmt.szFaceName, 32, pszFontName);
  328. }
  329. if (fontSize > 0)
  330. {
  331. charFmt.dwMask |= CFM_SIZE;
  332. charFmt.yHeight = fontSize;
  333. }
  334. m_TxtStatus.SetSelectionCharFormat(charFmt);
  335. }
  336. void CPageInstall::AppendStatus(CString statusText)
  337. {
  338. m_TxtStatus.ReplaceSel(statusText, FALSE);
  339. m_TxtStatus.UpdateWindow();
  340. Sleep(0);
  341. }
  342. int CPageInstall::TwipsPerPixelY()
  343. {
  344. CClientDC dc = CClientDC(this);
  345. int logPixY = dc.GetDeviceCaps(LOGPIXELSY);
  346. return 1440 / logPixY;
  347. }
  348. void CPageInstall::WriteStatusError(LPCTSTR szCaption, LPCTSTR szText)
  349. {
  350. CString fmtRtf;
  351. SetStatusFont(TRUE, CInfWizardDisplay::ColorError, NULL, TwipsPerPixelY() * 10);
  352. fmtRtf.Format(_T("%s:\n"), szCaption);
  353. AppendStatus(fmtRtf);
  354. SetStatusFont(TRUE, RGB(0, 0, 0), NULL, TwipsPerPixelY() * 10);
  355. fmtRtf.Format(_T("%s\n"), szText);
  356. AppendStatus(fmtRtf);
  357. }
  358. void CPageInstall::WritePackageStatus()
  359. {
  360. BOOL bClientInstaller = ((CButton*)GetDlgItem(IDC_BTN_CLIENT_INSTALLER))->GetCheck() == BST_CHECKED;
  361. BOOL bLegacyPackage = ((CButton*)GetDlgItem(IDC_BTN_LEGACY_PACKAGE))->GetCheck() == BST_CHECKED;
  362. BOOL bInstallOnly = ((CButton*)GetDlgItem(IDC_BTN_INSTALL_ONLY))->GetCheck() == BST_CHECKED;
  363. CString* headerText;
  364. if (bClientInstaller)
  365. headerText = CInfWizardDisplay::GetTipString(IDS_TXT_CLIENT_INSTALLER);
  366. else if (bLegacyPackage)
  367. headerText = CInfWizardDisplay::GetTipString(IDS_TXT_LEGACY_PACKAGE);
  368. else if (bInstallOnly)
  369. headerText = CInfWizardDisplay::GetTipString(IDS_TXT_INSTALL_ONLY);
  370. else
  371. return;
  372. //m_TxtStatus.SetSel(0,-1);
  373. m_TxtStatus.SetWindowText(_T(""));
  374. SetStatus(PFA_CENTER, *headerText, _T("Tahoma"), TwipsPerPixelY() * 16, TRUE, CInfWizardDisplay::ColorGood);
  375. SetStatusFormat(PFA_CENTER, FALSE);
  376. }
  377. void CPageInstall::SetStatusFormat(DWORD pfaAlignment, BOOL bulletMode)
  378. {
  379. PARAFORMAT rtfParaFmt;
  380. memset(&rtfParaFmt, 0, sizeof(rtfParaFmt));
  381. rtfParaFmt.cbSize = sizeof(rtfParaFmt);
  382. rtfParaFmt.dwMask = PFM_ALIGNMENT | PFM_NUMBERING;
  383. rtfParaFmt.wAlignment = (WORD)pfaAlignment;
  384. rtfParaFmt.wNumbering = bulletMode ? PFN_BULLET : 0;
  385. m_TxtStatus.SetParaFormat(rtfParaFmt);
  386. }
  387. void CPageInstall::SetStatus(DWORD pfaAlignment, CString statusText, LPCTSTR fontName, LONG fontSize, BOOL fontBold, COLORREF textColor)
  388. {
  389. SetStatusFont(fontBold, textColor, fontName, fontSize);
  390. m_TxtStatus.ReplaceSel(statusText, FALSE);
  391. if (pfaAlignment)
  392. {
  393. PARAFORMAT rtfParaFmt;
  394. rtfParaFmt.cbSize = sizeof(rtfParaFmt);
  395. rtfParaFmt.dwMask = PFM_ALIGNMENT;
  396. rtfParaFmt.wAlignment = (WORD)pfaAlignment;
  397. m_TxtStatus.SetParaFormat(rtfParaFmt);
  398. }
  399. }
  400. void CPageInstall::EnableWindowGroup(WORD nID, BOOL bEnabled)
  401. {
  402. CWnd* wndGrp = GetDlgItem(nID);
  403. ASSERT(wndGrp);
  404. wndGrp->EnableWindow(bEnabled);
  405. wndGrp = wndGrp->GetNextWindow();
  406. while (wndGrp)
  407. {
  408. if (wndGrp->GetStyle() & WS_GROUP)
  409. break;
  410. wndGrp->EnableWindow(bEnabled);
  411. wndGrp = wndGrp->GetNextWindow();
  412. }
  413. }
  414. void CPageInstall::OnBnClickedBtnClientInstaller()
  415. {
  416. g_App->Wdi.Session()->m_PackageStatus = CLibWdiSession::PACKAGE_TYPE_CLIENT_INSTALLER;
  417. WritePackageStatus();
  418. EnableWindowGroup(IDC_GRP_SAVE_INFORMATION, TRUE);
  419. }
  420. void CPageInstall::OnBnClickedBtnLegacyPackage()
  421. {
  422. g_App->Wdi.Session()->m_PackageStatus = CLibWdiSession::PACKAGE_TYPE_LEGACY;
  423. WritePackageStatus();
  424. EnableWindowGroup(IDC_GRP_SAVE_INFORMATION, TRUE);
  425. }
  426. void CPageInstall::OnBnClickedBtnInstallOnly()
  427. {
  428. g_App->Wdi.Session()->m_PackageStatus = CLibWdiSession::PACKAGE_TYPE_INSTALL_ONLY;
  429. WritePackageStatus();
  430. EnableWindowGroup(IDC_GRP_SAVE_INFORMATION, FALSE);
  431. }
  432. BOOL CPageInstall::PreTranslateMessage(MSG* pMsg)
  433. {
  434. m_ToolTip.RelayEvent(pMsg);
  435. return CResizablePageEx::PreTranslateMessage(pMsg);
  436. }
  437. BOOL CPageInstall::OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
  438. {
  439. return CInfWizardDisplay::HandleToolTipNotify(id, pNMHDR, pResult);
  440. }
  441. VOID CPageInstall::OnBnClickedBtnSaveBaseFolder()
  442. {
  443. CString baseDir, name;
  444. m_TxtSaveBaseFolder.GetWindowText(baseDir);
  445. m_TxtSaveName.GetWindowText(name);
  446. if (g_App->Wdi.Session()->ShowSavePackageDialog(this->GetParent(), baseDir, name))
  447. {
  448. m_TxtSaveBaseFolder.SetWindowText(g_App->Wdi.Session()->GetPackageBaseDir());
  449. m_TxtSaveName.SetWindowText(g_App->Wdi.Session()->GetPackageName());
  450. }
  451. }
  452. BOOL CPageInstall::FinalizePrepareDriver(
  453. PWDI_DEVICE_INFO DeviceInfo,
  454. LPCSTR InfPathA,
  455. LPCSTR InfNameA,
  456. PWDI_OPTIONS_PREPARE_DRIVER Options)
  457. {
  458. CString infPath(InfPathA);
  459. CString infName(InfNameA);
  460. CString fileName;
  461. CFile extractFile;
  462. CString errorMessage;
  463. DWORD errorCode;
  464. BYTE* resourceData;
  465. DWORD resourceSize;
  466. BOOL success;
  467. PPACKED_ITEM packedItem = NULL;
  468. CString fmtRtf;
  469. if (Options->driver_type & WDI_PACKAGE_FLAG_CREATE_USER_INSTALLER)
  470. {
  471. fmtRtf.Format(_T("%s..\n"), CInfWizardDisplay::GetTipString(IDS_STATUS_EXPORT_INSTALLER_RESOURCES)->GetBuffer(0));
  472. this->AppendStatus(fmtRtf);
  473. WORD idPacked = ID_PACKED_BEGIN - 1;
  474. while (g_App->Wdi.GetDriverResource(++idPacked, ID_PACKED_RES, (LPVOID*)&resourceData, &resourceSize))
  475. {
  476. BOOL bTag = FALSE;
  477. BOOL bOverwrite = TRUE;
  478. LPCTSTR outFileName = NULL;
  479. int i;
  480. for(i = 0; i < ::PackedItemsCount; i++)
  481. {
  482. if (idPacked == PackedItems[i].nID)
  483. {
  484. packedItem = &PackedItems[i];
  485. break;
  486. }
  487. }
  488. if (!packedItem)
  489. {
  490. MessageBox(_T("You must compile from source to add resources."), _T("Missing file definitions"), MB_OK | MB_ICONEXCLAMATION);
  491. continue;
  492. }
  493. switch(idPacked)
  494. {
  495. case ID_7ZA_EXE:
  496. // Extract the 7za.exe tool.
  497. GetTempPath(MAX_PATH, fileName.GetBufferSetLength(MAX_PATH));
  498. PathAppend(fileName.GetBuffer(), _T("7za.exe"));
  499. fileName.ReleaseBuffer();
  500. outFileName = NULL;
  501. SetEnvironmentVariable(_T("7ZA_EXE"), fileName);
  502. SetEnvironmentVariable(_T("NO_REPACK_ERROR_WAIT"), _T("1"));
  503. bOverwrite = FALSE;
  504. break;
  505. default:
  506. fileName = infPath;
  507. outFileName = packedItem->Filename;
  508. break;
  509. }
  510. if (outFileName)
  511. {
  512. if (!PathAppend(fileName.GetBufferSetLength(MAX_PATH), outFileName))
  513. {
  514. errorCode = GetLastError();
  515. errorMessage.Format(IDSF_PATH_TO_LONG, MAX_PATH, fileName, errorCode);
  516. MessageBox(errorMessage, _T("Path is to long"), MB_OK | MB_ICONEXCLAMATION);
  517. SetLastError(errorCode);
  518. return FALSE;
  519. }
  520. fileName.ReleaseBuffer();
  521. }
  522. if (!bOverwrite && PathFileExists(fileName))
  523. continue;
  524. success = extractFile.Open(fileName, CFile::modeCreate | CFile::shareDenyNone | CFile::modeWrite);
  525. if (!success)
  526. {
  527. errorCode = GetLastError();
  528. errorMessage.Format(IDSF_CREATE_FILE_FAILED, fileName, errorCode);
  529. MessageBox(errorMessage, _T("Create file failed"), MB_OK | MB_ICONEXCLAMATION);
  530. SetLastError(errorCode);
  531. return FALSE;
  532. }
  533. extractFile.Write(resourceData, resourceSize);
  534. extractFile.Flush();
  535. extractFile.Close();
  536. }
  537. packedItem = NULL;
  538. for(int i = 0; i < PackedItemsCount; i++)
  539. {
  540. if (PackedItems[i].nID == ID_REPACK_CMD)
  541. {
  542. packedItem = &PackedItems[i];
  543. break;
  544. }
  545. }
  546. if (packedItem)
  547. {
  548. SHELLEXECUTEINFO execInfo;
  549. DWORD exitCode = 0;
  550. fmtRtf.Format(_T("%s..\n"), CInfWizardDisplay::GetTipString(IDS_STATUS_CREATE_USER_INSTALLER)->GetBuffer(0));
  551. this->AppendStatus(fmtRtf);
  552. memset(&execInfo, 0, sizeof(execInfo));
  553. execInfo.cbSize = sizeof(execInfo);
  554. execInfo.lpDirectory = infPath;
  555. execInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI | SEE_MASK_NO_CONSOLE;
  556. execInfo.nShow = SW_HIDE;
  557. execInfo.lpFile = packedItem->Filename;
  558. if(ShellExecuteEx(&execInfo) != FALSE)
  559. {
  560. WaitForSingleObject(execInfo.hProcess, INFINITE);
  561. GetExitCodeProcess(execInfo.hProcess, &exitCode);
  562. if (exitCode != 0)
  563. {
  564. LPCTSTR caption = CInfWizardDisplay::GetTipString(IDSE_CREATE_USER_INSTALLER)->GetBuffer(0);
  565. WriteStatusError(caption, execInfo.lpFile);
  566. MessageBox(execInfo.lpFile, caption, MB_OK | MB_ICONEXCLAMATION);
  567. SetLastError(exitCode);
  568. return FALSE;
  569. }
  570. }
  571. else
  572. {
  573. errorCode = GetLastError();
  574. LPCTSTR caption = CInfWizardDisplay::GetTipString(IDSE_UNKNOWN)->GetBuffer(0);
  575. WriteStatusError(caption, execInfo.lpFile);
  576. MessageBox(execInfo.lpFile, caption, MB_OK | MB_ICONEXCLAMATION);
  577. SetLastError(errorCode);
  578. return FALSE;
  579. }
  580. }
  581. }
  582. return TRUE;
  583. }