Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

927 lines
23 KiB

  1. /*---------------------------------------------------------------------------*\
  2. | MODULE: webptprn.cxx
  3. |
  4. | This is the main entry-point module for the application.
  5. |
  6. | Routines
  7. | --------
  8. | WinMain
  9. |
  10. |
  11. | Copyright (C) 1996-1998 Hewlett Packard Company
  12. | Copyright (C) 1996-1998 Microsoft Corporation
  13. |
  14. | history:
  15. | 15-Dec-1996 <chriswil> created.
  16. |
  17. \*---------------------------------------------------------------------------*/
  18. #include "webptprn.h"
  19. #define memAlloc(cbSize) (LPVOID)LocalAlloc(LPTR, cbSize)
  20. #define memFree(pvMem) LocalFree((LPVOID)pvMem)
  21. #define strFree(pszStr) {if (pszStr) GlobalFree((HANDLE)pszStr);}
  22. /*****************************************************************************\
  23. * strAlloc
  24. *
  25. * Allocates a string from the heap. This pointer must be freed with
  26. * a call to strFree().
  27. *
  28. \*****************************************************************************/
  29. LPTSTR strAlloc(
  30. LPCTSTR pszSrc)
  31. {
  32. DWORD cbSize;
  33. LPTSTR pszDst = NULL;
  34. cbSize = (pszSrc ? ((lstrlen(pszSrc) + 1) * sizeof(TCHAR)) : 0);
  35. if (cbSize) {
  36. if (pszDst = (LPTSTR)GlobalAlloc(GPTR, cbSize))
  37. CopyMemory(pszDst, pszSrc, cbSize);
  38. }
  39. return pszDst;
  40. }
  41. /*****************************************************************************\
  42. * strLoad
  43. *
  44. * Get string from resource based upon the ID passed in.
  45. *
  46. \*****************************************************************************/
  47. LPTSTR strLoad(
  48. UINT ids)
  49. {
  50. char szStr[MAX_RESBUF];
  51. if (LoadString(g_hInst, ids, szStr, sizeof(szStr)) == 0)
  52. szStr[0] = TEXT('\0');
  53. return strAlloc(szStr);
  54. }
  55. /*****************************************************************************\
  56. * InitStrings
  57. *
  58. *
  59. \*****************************************************************************/
  60. BOOL InitStrings(VOID)
  61. {
  62. g_szMsgAdd = strLoad(IDS_MSG_ADD);
  63. g_szMsgDel = strLoad(IDS_MSG_DEL);
  64. g_szMsgReboot = strLoad(IDS_MSG_REBOOT);
  65. g_szMsgUninstall = strLoad(IDS_MSG_UNINSTALL);
  66. g_szMsgFailCpy = strLoad(IDS_ERR_COPY);
  67. g_szMsgFailAdd = strLoad(IDS_ERR_ADD);
  68. g_szMsgFailAsc = strLoad(IDS_ERR_ASC);
  69. g_szRegDspVal = strLoad(IDS_REG_DISPLAY);
  70. g_szMsgOsVerHead = strLoad(IDS_ERR_OSVERHEAD);
  71. g_szMsgOsVerMsg = strLoad(IDS_ERR_OSVERMSG);
  72. return (g_szMsgAdd &&
  73. g_szMsgDel &&
  74. g_szMsgReboot &&
  75. g_szMsgUninstall &&
  76. g_szMsgFailCpy &&
  77. g_szMsgFailAdd &&
  78. g_szMsgFailAsc &&
  79. g_szRegDspVal &&
  80. g_szMsgOsVerHead &&
  81. g_szMsgOsVerMsg
  82. );
  83. }
  84. /*****************************************************************************\
  85. * FreeeStrings
  86. *
  87. *
  88. \*****************************************************************************/
  89. VOID FreeStrings(VOID)
  90. {
  91. strFree(g_szMsgAdd);
  92. strFree(g_szMsgDel);
  93. strFree(g_szMsgReboot);
  94. strFree(g_szMsgUninstall);
  95. strFree(g_szMsgFailCpy);
  96. strFree(g_szMsgFailAdd);
  97. strFree(g_szMsgFailAsc);
  98. strFree(g_szRegDspVal);
  99. strFree(g_szMsgOsVerHead);
  100. strFree(g_szMsgOsVerMsg);
  101. }
  102. /*---------------------------------------------------------------------------*\
  103. | pp_StrSize
  104. |
  105. | Returns the bytes occupied by the string.
  106. |
  107. \*---------------------------------------------------------------------------*/
  108. _inline DWORD pp_StrSize(
  109. LPCTSTR lpszStr)
  110. {
  111. return (lpszStr ? ((lstrlen(lpszStr) + 1) * sizeof(TCHAR)) : 0);
  112. }
  113. /*---------------------------------------------------------------------------*\
  114. | pp_AddFileAssociation
  115. |
  116. | Add the .webpnp to the file-associations.
  117. |
  118. \*---------------------------------------------------------------------------*/
  119. BOOL pp_AddFileAssociation(VOID)
  120. {
  121. LONG lRet;
  122. HKEY hkPath;
  123. BOOL bRet = FALSE;
  124. lRet = RegCreateKeyEx(HKEY_CLASSES_ROOT,
  125. g_szRegCabKey,
  126. 0,
  127. NULL,
  128. 0,
  129. KEY_WRITE,
  130. NULL,
  131. &hkPath,
  132. NULL);
  133. if (lRet == ERROR_SUCCESS) {
  134. lRet = RegSetValueEx(hkPath,
  135. NULL,
  136. 0,
  137. REG_SZ,
  138. (LPBYTE)g_szRegCabCmd,
  139. pp_StrSize(g_szRegCabCmd));
  140. bRet = (lRet == ERROR_SUCCESS ? TRUE : FALSE);
  141. RegCloseKey(hkPath);
  142. }
  143. return bRet;
  144. }
  145. /*---------------------------------------------------------------------------*\
  146. | pp_BuildName
  147. |
  148. | Return a fully-qualified path/name.
  149. |
  150. \*---------------------------------------------------------------------------*/
  151. LPTSTR pp_BuildName(
  152. LPCTSTR lpszPath,
  153. LPCTSTR lpszFile)
  154. {
  155. DWORD cbSize;
  156. LPTSTR lpszFull;
  157. static CONST TCHAR s_szFmt[] = TEXT("%s\\%s");
  158. // Calculate the size necessary to hold the full-path filename.
  159. //
  160. cbSize = pp_StrSize(lpszPath) + pp_StrSize(s_szFmt) + pp_StrSize(lpszFile);
  161. if (lpszFull = (LPTSTR)memAlloc(cbSize))
  162. wsprintf(lpszFull, s_szFmt, lpszPath, lpszFile);
  163. return lpszFull;
  164. }
  165. /*---------------------------------------------------------------------------*\
  166. | pp_CurDir
  167. |
  168. | Return CURRENT directory.
  169. |
  170. \*---------------------------------------------------------------------------*/
  171. LPTSTR pp_CurDir(VOID)
  172. {
  173. DWORD cbSize;
  174. DWORD cch;
  175. LPTSTR lpszDir = NULL;
  176. cbSize = GetCurrentDirectory(0, NULL);
  177. if (cbSize && (lpszDir = (LPTSTR)memAlloc(cbSize * sizeof(TCHAR)))) {
  178. GetCurrentDirectory(cbSize, lpszDir);
  179. if (cch = lstrlen(lpszDir)) {
  180. cch--;
  181. if (*(lpszDir + cch) == TEXT('\\'))
  182. *(lpszDir + cch) = TEXT('\0');
  183. }
  184. }
  185. return lpszDir;
  186. }
  187. /*---------------------------------------------------------------------------*\
  188. | pp_SysDir
  189. |
  190. | Return SYSTEM directory.
  191. |
  192. \*---------------------------------------------------------------------------*/
  193. LPTSTR pp_SysDir(VOID)
  194. {
  195. DWORD cbSize;
  196. LPTSTR lpszDir = NULL;
  197. cbSize = GetSystemDirectory(NULL, 0);
  198. if (cbSize && (lpszDir = (LPTSTR)memAlloc(cbSize * sizeof(TCHAR))))
  199. GetSystemDirectory(lpszDir, cbSize);
  200. return lpszDir;
  201. }
  202. /*---------------------------------------------------------------------------*\
  203. | pp_WinDir
  204. |
  205. | Return WINDOWS directory.
  206. |
  207. \*---------------------------------------------------------------------------*/
  208. LPTSTR pp_WinDir(VOID)
  209. {
  210. DWORD cbSize;
  211. LPTSTR lpszDir = NULL;
  212. cbSize = GetWindowsDirectory(NULL, 0);
  213. if (cbSize && (lpszDir = (LPTSTR)memAlloc(cbSize * sizeof(TCHAR))))
  214. GetWindowsDirectory(lpszDir, cbSize);
  215. return lpszDir;
  216. }
  217. /*---------------------------------------------------------------------------*\
  218. | pp_TmpDir
  219. |
  220. | Return TEMP directory.
  221. |
  222. \*---------------------------------------------------------------------------*/
  223. LPTSTR pp_TmpDir(VOID)
  224. {
  225. DWORD cbSize;
  226. DWORD cch;
  227. LPTSTR lpszDir = NULL;
  228. cbSize = GetTempPath(0, NULL);
  229. if (cbSize && (lpszDir = (LPTSTR)memAlloc(cbSize * sizeof(TCHAR)))) {
  230. GetTempPath(cbSize, lpszDir);
  231. if (cch = lstrlen(lpszDir)) {
  232. cch--;
  233. if (*(lpszDir + cch) == TEXT('\\'))
  234. *(lpszDir + cch) = TEXT('\0');
  235. }
  236. }
  237. return lpszDir;
  238. }
  239. /*---------------------------------------------------------------------------*\
  240. | pp_AddCOM
  241. |
  242. | This copies com-objects the destination directory.
  243. |
  244. \*---------------------------------------------------------------------------*/
  245. BOOL pp_AddCOM(
  246. LPCTSTR lpszSDir,
  247. LPCTSTR lpszDDir,
  248. LPCTSTR lpszFile)
  249. {
  250. LPTSTR lpszSrc;
  251. LPTSTR lpszDst;
  252. BOOL bRet = FALSE;
  253. if (lpszSrc = pp_BuildName(lpszSDir, lpszFile)) {
  254. if (lpszDst = pp_BuildName(lpszDDir, lpszFile)) {
  255. bRet = CopyFile(lpszSrc, lpszDst, FALSE);
  256. memFree(lpszDst);
  257. }
  258. memFree(lpszSrc);
  259. }
  260. return bRet;
  261. }
  262. /*---------------------------------------------------------------------------*\
  263. | pp_CopyFile
  264. |
  265. | Copy the file to the temporary directory, then set up the wininit.ini
  266. | for delayed-boot-copy.
  267. |
  268. \*---------------------------------------------------------------------------*/
  269. BOOL pp_CopyFile(
  270. LPCTSTR lpszCDir,
  271. LPCTSTR lpszSDir,
  272. LPCTSTR lpszTDir,
  273. LPCTSTR lpszFile)
  274. {
  275. LPTSTR lpszSrc;
  276. LPTSTR lpszDst;
  277. LPTSTR lpszTmp;
  278. BOOL bRet = FALSE;
  279. if (lpszSrc = pp_BuildName(lpszCDir, lpszFile)) {
  280. if (lpszDst = pp_BuildName(lpszSDir, lpszFile)) {
  281. if (lpszTmp = pp_BuildName(lpszTDir, lpszFile)) {
  282. if (CopyFile(lpszSrc, lpszTmp, FALSE)) {
  283. bRet = WritePrivateProfileString(g_szRename,
  284. lpszDst,
  285. lpszTmp,
  286. g_szFilInit);
  287. }
  288. memFree(lpszTmp);
  289. }
  290. memFree(lpszDst);
  291. }
  292. memFree(lpszSrc);
  293. }
  294. return bRet;
  295. }
  296. /*---------------------------------------------------------------------------*\
  297. | pp_CopyFiles
  298. |
  299. | This routine first copies the files to the temp-directory, then does
  300. | the necessary setup to have them copied upon boot.
  301. |
  302. \*---------------------------------------------------------------------------*/
  303. BOOL pp_CopyFiles(VOID)
  304. {
  305. LPTSTR lpszCDir;
  306. LPTSTR lpszSDir;
  307. LPTSTR lpszTDir;
  308. BOOL bRet = FALSE;
  309. if (lpszCDir = pp_CurDir()) {
  310. if (lpszSDir = pp_SysDir()) {
  311. if (lpszTDir = pp_TmpDir()) {
  312. // Copy the oleprn to the system-directory in case this
  313. // is the first time of install. This is necessary since
  314. // we do som COM-registration if called from WPNPINS.EXE.
  315. //
  316. pp_AddCOM(lpszCDir, lpszSDir, g_szFilOlePrn);
  317. // Copy the files to a temp-directory for installation
  318. // at boot-time.
  319. //
  320. if (pp_CopyFile(lpszCDir, lpszSDir, lpszTDir, g_szFilApp) &&
  321. pp_CopyFile(lpszCDir, lpszSDir, lpszTDir, g_szFilInetpp) &&
  322. pp_CopyFile(lpszCDir, lpszSDir, lpszTDir, g_szFilOlePrn) &&
  323. pp_CopyFile(lpszCDir, lpszSDir, lpszTDir, g_szFilInsEx) &&
  324. pp_CopyFile(lpszCDir, lpszSDir, lpszTDir, g_szFilIns16) &&
  325. pp_CopyFile(lpszCDir, lpszSDir, lpszTDir, g_szFilIns32)) {
  326. bRet = TRUE;
  327. }
  328. memFree(lpszTDir);
  329. }
  330. memFree(lpszSDir);
  331. }
  332. memFree(lpszCDir);
  333. }
  334. return bRet;
  335. }
  336. /*---------------------------------------------------------------------------*\
  337. | pp_AddProvidor
  338. |
  339. | Adds the print-provider to the registry.
  340. |
  341. \*---------------------------------------------------------------------------*/
  342. BOOL pp_AddProvidor(VOID)
  343. {
  344. PROVIDOR_INFO_1 pi1;
  345. pi1.pName = (LPTSTR)g_szPPName;
  346. pi1.pEnvironment = NULL;
  347. pi1.pDLLName = (LPTSTR)g_szFilInetpp;
  348. return AddPrintProvidor(NULL, 1, (LPBYTE)&pi1);
  349. }
  350. /*---------------------------------------------------------------------------*\
  351. | pp_AddRegistry
  352. |
  353. | Writes out the uninstall-section in the registry.
  354. |
  355. \*---------------------------------------------------------------------------*/
  356. BOOL pp_AddRegistry(VOID)
  357. {
  358. HKEY hKey;
  359. HKEY hUns;
  360. LONG lRet;
  361. lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  362. g_szRegUninstall,
  363. 0,
  364. KEY_READ | KEY_WRITE,
  365. &hKey);
  366. if (lRet == ERROR_SUCCESS) {
  367. lRet = RegOpenKeyEx(hKey,
  368. g_szRegUnsKey,
  369. 0,
  370. KEY_READ | KEY_WRITE,
  371. &hUns);
  372. if (lRet != ERROR_SUCCESS) {
  373. lRet = RegCreateKeyEx(hKey,
  374. g_szRegUnsKey,
  375. 0,
  376. NULL,
  377. 0,
  378. KEY_WRITE,
  379. NULL,
  380. &hUns,
  381. NULL);
  382. if (lRet == ERROR_SUCCESS) {
  383. RegSetValueEx(hUns,
  384. g_szRegDspNam,
  385. 0,
  386. REG_SZ,
  387. (LPBYTE)g_szRegDspVal,
  388. pp_StrSize(g_szRegDspVal));
  389. RegSetValueEx(hUns,
  390. g_szRegUnsNam,
  391. 0,
  392. REG_SZ,
  393. (LPBYTE)g_szRegUnsVal,
  394. pp_StrSize(g_szRegUnsVal));
  395. RegCloseKey(hUns);
  396. }
  397. }
  398. RegCloseKey(hKey);
  399. }
  400. return (lRet == ERROR_SUCCESS);
  401. }
  402. /*---------------------------------------------------------------------------*\
  403. | pp_DelProvidor
  404. |
  405. | Removes the print-provider from the registry.
  406. |
  407. \*---------------------------------------------------------------------------*/
  408. BOOL pp_DelProvidor(VOID)
  409. {
  410. return DeletePrintProvidor(NULL, NULL, (LPTSTR)g_szPPName);
  411. }
  412. /*---------------------------------------------------------------------------*\
  413. | pp_DelRegistry
  414. |
  415. | Removes the uninstall registry settings.
  416. |
  417. \*---------------------------------------------------------------------------*/
  418. BOOL pp_DelRegistry(VOID)
  419. {
  420. HKEY hKey;
  421. LONG lRet;
  422. lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  423. g_szRegUninstall,
  424. 0,
  425. KEY_READ | KEY_WRITE,
  426. &hKey);
  427. if (lRet == ERROR_SUCCESS) {
  428. lRet = RegDeleteKey(hKey, g_szRegUnsKey);
  429. RegCloseKey(hKey);
  430. }
  431. return (lRet == ERROR_SUCCESS);
  432. }
  433. /*---------------------------------------------------------------------------*\
  434. | pp_DelFile
  435. |
  436. | Remove the file from the system.
  437. |
  438. \*---------------------------------------------------------------------------*/
  439. BOOL pp_DelFile(
  440. HANDLE hFile,
  441. LPCTSTR lpszSDir,
  442. LPCTSTR lpszFile)
  443. {
  444. LPTSTR lpszSrc;
  445. DWORD cbWr;
  446. DWORD cch;
  447. TCHAR szBuf[MAX_BUFFER];
  448. BOOL bRet = FALSE;
  449. if (lpszSrc = pp_BuildName(lpszSDir, lpszFile)) {
  450. cch = wsprintf(szBuf, TEXT("NUL=%s\r\n"), lpszSrc);
  451. bRet = WriteFile(hFile, szBuf, cch, &cbWr, NULL);
  452. memFree(lpszSrc);
  453. }
  454. return bRet;
  455. }
  456. /*---------------------------------------------------------------------------*\
  457. | pp_DelFiles
  458. |
  459. | Deletes the files from the system (delayed delete).
  460. |
  461. \*---------------------------------------------------------------------------*/
  462. BOOL pp_DelFiles(VOID)
  463. {
  464. HANDLE hFile;
  465. LPTSTR lpszWDir;
  466. LPTSTR lpszSDir;
  467. LPTSTR lpszWFile;
  468. DWORD cch;
  469. DWORD cbWr;
  470. TCHAR szBuf[MAX_BUFFER];
  471. BOOL bRet = FALSE;
  472. if (lpszWDir = pp_WinDir()) {
  473. if (lpszSDir = pp_SysDir()) {
  474. if (lpszWFile = pp_BuildName(lpszWDir, g_szFilInit)) {
  475. hFile = CreateFile(lpszWFile,
  476. GENERIC_READ | GENERIC_WRITE,
  477. 0,
  478. NULL,
  479. CREATE_ALWAYS,
  480. FILE_ATTRIBUTE_NORMAL,
  481. NULL);
  482. if (hFile && (hFile != INVALID_HANDLE_VALUE)) {
  483. cch = wsprintf(szBuf, TEXT("[%s]\r\n"), g_szRename);
  484. WriteFile(hFile, szBuf, cch, &cbWr, NULL);
  485. pp_DelFile(hFile, lpszSDir, g_szFilApp);
  486. pp_DelFile(hFile, lpszSDir, g_szFilInetpp);
  487. pp_DelFile(hFile, lpszSDir, g_szFilOlePrn);
  488. pp_DelFile(hFile, lpszSDir, g_szFilInsEx);
  489. pp_DelFile(hFile, lpszSDir, g_szFilIns16);
  490. pp_DelFile(hFile, lpszSDir, g_szFilIns32);
  491. CloseHandle(hFile);
  492. bRet = TRUE;
  493. }
  494. memFree(lpszWFile);
  495. }
  496. memFree(lpszSDir);
  497. }
  498. memFree(lpszWDir);
  499. }
  500. return bRet;
  501. }
  502. /*---------------------------------------------------------------------------*\
  503. | pp_Sync
  504. |
  505. | Synchronize. This will not return until the process is terminated.
  506. |
  507. \*---------------------------------------------------------------------------*/
  508. BOOL pp_Sync(
  509. HANDLE hProcess)
  510. {
  511. DWORD dwObj;
  512. DWORD dwExitCode = 0;
  513. while (TRUE) {
  514. dwObj = WaitForSingleObject(hProcess, INFINITE);
  515. // Look for the exit type.
  516. //
  517. switch (dwObj) {
  518. // The process handle triggered the wait. Let's get the
  519. // exit-code and return whether the success. Otherwise,
  520. // drop through and return the failure.
  521. //
  522. case WAIT_OBJECT_0:
  523. GetExitCodeProcess(hProcess, &dwExitCode);
  524. if (dwExitCode == 0)
  525. return TRUE;
  526. // Something failed in the call. We failed.
  527. //
  528. case WAIT_FAILED:
  529. return FALSE;
  530. }
  531. }
  532. }
  533. /*---------------------------------------------------------------------------*\
  534. | pp_Exec
  535. |
  536. | Execute the process.
  537. |
  538. \*---------------------------------------------------------------------------*/
  539. BOOL pp_Exec(
  540. LPCTSTR lpszComFile)
  541. {
  542. PROCESS_INFORMATION pi;
  543. STARTUPINFO sti;
  544. LPTSTR lpszCmd;
  545. DWORD cbSize;
  546. BOOL bSuccess = FALSE;
  547. // Calculate enough space to hold the command-line arguments.
  548. //
  549. cbSize = (lstrlen(lpszComFile) + lstrlen(g_szExec) + 1) * sizeof(TCHAR);
  550. // Allocate the command-line for the create-process call.
  551. //
  552. if (lpszCmd = (LPTSTR)memAlloc(cbSize)) {
  553. // Initialize startup-info fields.
  554. //
  555. memset(&sti, 0, sizeof(STARTUPINFO));
  556. sti.cb = sizeof(STARTUPINFO);
  557. // Build the command-line string that exec's regsvr32.
  558. //
  559. wsprintf(lpszCmd, g_szExec, lpszComFile);
  560. // Exec the process.
  561. //
  562. if (EXEC_PROCESS(lpszCmd, &sti, &pi)) {
  563. CloseHandle(pi.hThread);
  564. // This will wait until the process if finished generating
  565. // the file. The return from this indicates whether the
  566. // generation succeeded or not.
  567. //
  568. pp_Sync(pi.hProcess);
  569. CloseHandle(pi.hProcess);
  570. }
  571. memFree(lpszCmd);
  572. }
  573. return bSuccess;
  574. }
  575. /*---------------------------------------------------------------------------*\
  576. | pp_DelCOM
  577. |
  578. | Unregisters the COM object.
  579. |
  580. \*---------------------------------------------------------------------------*/
  581. BOOL pp_DelCOM(VOID)
  582. {
  583. LPTSTR lpszSDir;
  584. LPTSTR lpszDst;
  585. BOOL bRet = FALSE;
  586. if (lpszSDir = pp_SysDir()) {
  587. if (lpszDst = pp_BuildName(lpszSDir, g_szFilOlePrn)) {
  588. pp_Exec(lpszDst);
  589. memFree(lpszDst);
  590. }
  591. memFree(lpszSDir);
  592. }
  593. return bRet;
  594. }
  595. /*---------------------------------------------------------------------------*\
  596. | pp_DelPrinters
  597. |
  598. | Deletes all the printers with URL-ports.
  599. |
  600. \*---------------------------------------------------------------------------*/
  601. BOOL pp_DelPrinters(VOID)
  602. {
  603. LPPRINTER_INFO_5 pi5;
  604. HANDLE hPrn;
  605. DWORD cbSize;
  606. DWORD cPrt;
  607. DWORD idx;
  608. DWORD cch;
  609. BOOL bRet = FALSE;
  610. // Get the size necessary to hold all enumerated printers.
  611. //
  612. cbSize = 0;
  613. EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, NULL, 0, &cbSize, &cPrt);
  614. if (cbSize && (pi5 = (LPPRINTER_INFO_5)memAlloc(cbSize))) {
  615. cPrt = 0;
  616. if (EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, (LPBYTE)pi5, cbSize, &cbSize, &cPrt)) {
  617. bRet = TRUE;
  618. for (idx = 0; idx < cPrt; idx++) {
  619. if ((_strnicmp((pi5+idx)->pPortName, g_szHttp , lstrlen(g_szHttp )) == 0) ||
  620. (_strnicmp((pi5+idx)->pPortName, g_szHttps, lstrlen(g_szHttps)) == 0)) {
  621. if (OpenPrinter((pi5+idx)->pPrinterName, &hPrn, NULL)) {
  622. DeletePrinter(hPrn);
  623. ClosePrinter(hPrn);
  624. }
  625. }
  626. }
  627. }
  628. memFree(pi5);
  629. }
  630. return bRet;
  631. }
  632. /*---------------------------------------------------------- entry routine --*\
  633. | WinMain
  634. |
  635. | This is the process entry-point routine. This is the basis for all
  636. | application events.
  637. |
  638. \*---------------------------------------------------------------------------*/
  639. int PASCAL WinMain(
  640. HINSTANCE hInst,
  641. HINSTANCE hPrevInst,
  642. LPSTR lpszCmd,
  643. int nShow)
  644. {
  645. OSVERSIONINFO OsVersion;
  646. int iRet = RC_WEXTRACT_AWARE;
  647. UNREFPARM(nShow);
  648. UNREFPARM(hPrevInst);
  649. g_hInst = hInst;
  650. if (InitStrings()) {
  651. OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  652. if (GetVersionEx(&OsVersion)) { // If we can't get the OSVersion, we assume it's alright
  653. // Check that we are on Win9X, then check that the version is not millenium
  654. // We assume that millenium is Version 5 or higher
  655. if (OsVersion.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS ||
  656. (OsVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
  657. OsVersion.dwMajorVersion > 4 )) {
  658. MessageBox( NULL, g_szMsgOsVerMsg, g_szMsgOsVerHead, MB_OK | MB_ICONINFORMATION);
  659. goto cleanup;
  660. }
  661. }
  662. if (lpszCmd && (lstrcmpi(lpszCmd, g_szCmdUns) == 0)) {
  663. // We were asked to uninstall, not from inside WEXTRACT, so return 0 if we return
  664. iRet = 0;
  665. if (MessageBox(NULL, g_szMsgUninstall, g_szMsgDel, MB_YESNO | MB_ICONQUESTION) == IDYES) {
  666. pp_DelPrinters();
  667. pp_DelProvidor();
  668. pp_DelRegistry();
  669. pp_DelCOM();
  670. pp_DelFiles();
  671. if (MessageBox(NULL, g_szMsgReboot, g_szMsgDel, MB_YESNO | MB_ICONINFORMATION) == IDYES)
  672. ExitWindowsEx(EWX_REBOOT, 0);
  673. }
  674. } else {
  675. if (pp_AddFileAssociation()) {
  676. if (pp_CopyFiles()) {
  677. pp_AddProvidor();
  678. pp_AddRegistry();
  679. iRet |= REBOOT_YES | REBOOT_ALWAYS;
  680. } else {
  681. MessageBox(NULL, g_szMsgFailCpy, g_szMsgAdd, MB_OK);
  682. }
  683. } else {
  684. MessageBox(NULL, g_szMsgFailAsc, g_szMsgAdd, MB_OK);
  685. }
  686. }
  687. cleanup:
  688. FreeStrings();
  689. }
  690. return iRet;
  691. }