home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 November / VPR9711A.ISO / WINTEX / W32S130C / DISK1 / 32SINST.MS_ / 32SINST.MS
Text File  |  1996-01-26  |  28KB  |  775 lines

  1. '**************************************************************************
  2. '*                  MS Test script for Win32s setup program
  3. '**************************************************************************
  4.  
  5. '' $DEFINE DEBUG  ''Define for script development/debugging
  6.  
  7. '$INCLUDE 'setupapi.inc'
  8. '$INCLUDE 'msdetect.inc'
  9.  
  10. ''Dialog ID's
  11. CONST WELCOME                  = 100
  12. CONST ASKQUIT                  = 200
  13. CONST DESTPATH                 = 300
  14. CONST EXITFAILURE              = 400
  15. CONST EXITQUIT                 = 600
  16. CONST EXITSUCCESS              = 700
  17. CONST OPTIONS                  = 800
  18. CONST BADPATH                  = 6400
  19.  
  20. CONST HELPWELCOME              = 1000
  21. CONST VERPATH                  = 1100
  22. CONST EXITFAILNOTWIN31         = 1200
  23. CONST EXITFAILNOTENH           = 1300
  24. CONST EXITFAILNOTPAGING        = 1325
  25. CONST EXITFAILNOTINTEL         = 1350
  26. CONST EXITFAILRUNAPP           = 1360
  27. CONST FREECELLINST             = 1400
  28. CONST FREECELLINSTNOWIN32S     = 1450
  29. CONST FREECELLPATH             = 1500
  30. CONST HELPFREECELL             = 1600
  31.  
  32.  
  33. ''Bitmap ID
  34. CONST LOGO = 1
  35.  
  36. ''GetTempFileName flags
  37. CONST TF_FORCEDRIVE            = 128
  38.  
  39. GLOBAL DESTWIN$      ''Windows directory.
  40. GLOBAL DESTSYS$      ''Windows\System directory.
  41. GLOBAL DEST32S$      ''Windows\System\Win32s directory
  42. GLOBAL DESTFREE$     ''Freecell directory
  43. GLOBAL OLE_PROTECT%  ''Indicates whether ole2 dlls were protected from being
  44.                      '' copied.
  45. GLOBAL OLE_OLEBOOT%
  46. GLOBAL VERNUM$       '' Win32s Version Number (i.e., for v1.25 VERNUM$="125"
  47.  
  48. DECLARE SUB Install(OLEINCLUDED%, OLEONLY%, OLE2_32%, OLE2_16%, OLE2AUTO_16%, OLE16RUNAPP%)
  49. DECLARE SUB RecoverFromCopy(szFileName$)
  50. DECLARE FUNCTION UpdateSystemIni AS INTEGER
  51. DECLARE FUNCTION RebootSystem(OLEONLY%) AS INTEGER
  52. DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
  53. DECLARE FUNCTION MakeSystemIni LIB "INIUPD.DLL" (arg1$, arg2$) AS INTEGER
  54. DECLARE FUNCTION RestartWindows LIB "INIUPD.DLL" AS INTEGER
  55. DECLARE FUNCTION OnWindowsNT LIB "INIUPD.DLL" AS INTEGER
  56. DECLARE FUNCTION PagingEnabled LIB "INIUPD.DLL" AS INTEGER
  57. DECLARE FUNCTION ShareEnabled LIB "INIUPD.DLL" AS INTEGER
  58. DECLARE FUNCTION IsWin32sLoaded LIB "INIUPD.DLL" (arg1$) AS INTEGER
  59. DECLARE FUNCTION IsRunningApp LIB "INIUPD.DLL" AS INTEGER
  60. DECLARE FUNCTION SetCuiFlags LIB "MSCUISTF.DLL" (arg1%, arg2%) AS INTEGER
  61. DECLARE FUNCTION ExitWindowsExec LIB "USER.EXE" (arg1$, arg2$) AS INTEGER
  62. DECLARE FUNCTION GetModuleHandle LIB "KRNL386.EXE" (arg1$) AS INTEGER
  63. DECLARE FUNCTION LoadLibrary LIB "KRNL386.EXE" (arg1$) AS INTEGER
  64. DECLARE SUB FreeLibrary LIB "KRNL386.EXE" (arg1%)
  65. DECLARE FUNCTION SetErrorMode LIB "KRNL386.EXE" (arg1%) AS INTEGER
  66.  
  67. DECLARE FUNCTION GetTempFileName LIB "KRNL386.EXE" (drive%, prefix$, u%, filename$) AS INTEGER
  68. DECLARE SUB WriteLine LIB "INIUPD.DLL" (filename$, text$)
  69. DECLARE FUNCTION GetTempFileAt(szDir$, szPrefix$) as string
  70. DECLARE FUNCTION GetSystemCodePage LIB "INIUPD.DLL" AS INTEGER
  71. INIT:
  72.     CUIDLL$ = "mscuistf.dll"            '' Custom user interface dll
  73.     HELPPROC$ = "FHelpDlgProc"          '' Help dialog procedure
  74.     szOldVer$ ="1.00.000     "          '' Reserve space in string for version
  75.     WIN32ENABLED% = 0
  76.     OLEONLY% = 0
  77.     OLE2_16% = 0
  78.     OLE2AUTO_16% = 0
  79.     OLE16RUNAPP% = 0
  80.     OLE_PROTECT% = 0
  81.     OLE_OLEBOOT% = 0
  82.  
  83.     ON ERROR GOTO ERRNORMAL
  84.  
  85.     SrcDir$ = GetSymbolValue("STF_SRCDIR")
  86.  
  87.     szInf$ = GetSymbolValue("STF_SRCINFPATH")
  88.     IF szInf$ = "" THEN
  89.         szInf$ = GetSymbolValue("STF_CWDDIR") + "32sinst.inf"
  90.     END IF
  91.     ReadInfFile szInf$
  92.  
  93.     SetBitmap CUIDLL$, LOGO
  94.  
  95.     WIN32SVER$ = MID$(GetSectionKeyVersion("WindowsSystem", "win32s16"), 1, 4)
  96.     SetTitle "Microsoft Win32s version " + WIN32SVER$ + " Setup Program"
  97.     VERNUM$ = MID$(WIN32SVER$, 1, 1) + MID$(WIN32SVER$, 3 , 2)
  98.  
  99.     DESTWIN$ = GetWindowsDir()
  100.     DESTSYS$ = GetWindowsSysDir()
  101.     DEST32S$ = DESTSYS + "WIN32S\"
  102.  
  103. '$IFDEF DEBUG
  104.     i% = SetSizeCheckMode(scmOnIgnore)    '' could use scmOff; def = scmOnFatal
  105.     WinDrive$ = MID$(GetWindowsDir, 1, 1)
  106.     IF IsDriveValid(WinDrive$) = 0 THEN
  107.         i% = DoMsgBox("Windows drive ('"+WinDrive$+"') is not a valid drive.", "DEBUG", MB_TASKMODAL+MB_ICONHAND+MB_OK)
  108.         GOTO QUIT
  109.     END IF
  110. '$ENDIF ''DEBUG
  111.  
  112. CHECK:
  113.     '' Can not run on versions less than 3.10.
  114.     IF GetWindowsMajorVersion < 3 THEN
  115.         ExitCode% = EXITFAILNOTWIN31
  116.         GOTO QUIT
  117.     END IF
  118.     IF GetWindowsMajorVersion = 3 AND GetWindowsMinorVersion < 10 THEN
  119.         ExitCode% = EXITFAILNOTWIN31
  120.         GOTO QUIT
  121.     END IF
  122.     '' Check that we are not runnig on Chicago, including pre-released
  123.     '' Chicago versions.
  124.     IF GetWindowsMajorVersion * 100 + GetWindowsMinorVersion > 350 THEN
  125.         ExitCode% = EXITSUCCESS
  126.         WIN32ENABLED% = 1
  127.         GOTO FREECELL
  128.     END IF
  129.     IF GetWindowsMode < 2  THEN
  130.         IF OnWindowsNT() THEN
  131.             ExitCode% = EXITFAILNOTINTEL '' Running on Windows NT (on RISC)
  132.         ELSE
  133.             ExitCode% = EXITFAILNOTENH   '' Standard Mode Windows
  134.         END IF
  135.         GOTO QUIT
  136.     END IF
  137.     IF OnWindowsNT() THEN
  138.         ExitCode% = EXITSUCCESS
  139.         WIN32ENABLED% = 1
  140.         GOTO FREECELL
  141.     END IF
  142.     ExitCode% = EXITSUCCESS
  143.  
  144.     if IsRunningApp() <> 0 THEN
  145.         ExitCode% = EXITFAILRUNAPP
  146.         GOTO QUIT
  147.     END IF
  148.  
  149.     '' Get version of Win32s to be installed from version info in INF file
  150.     szNewVer$ = GetSectionKeyVersion("WindowsSystem", "win32s16")
  151.  
  152.     '' See if OLE is included.
  153.  
  154.     OLEINCLUDED% = DoesFileExist( GetSymbolValue("STF_SRCDIR") + "OLE2THK.DL_", femExists )
  155.     '' Do the same for ole2thk.dll, if it is not compressed
  156.     OLEINCLUDED% = OLEINCLUDED% OR DoesFileExist( GetSymbolValue("STF_SRCDIR") + "OLE2THK.DLL", femExists )
  157.  
  158.     IF OLEINCLUDED% = 1 THEN
  159.         '' See whether one of the OLE 16 bit components is loaded.
  160.         IF GetModulehandle("compobj") <> 0 THEN
  161.             OLE16RUNAPP% = 1
  162.             GOTO GetOleVersion
  163.         END IF
  164.         IF GetModuleHandle("ole2") <> 0 THEN
  165.             OLE16RUNAPP% = 1
  166.             GOTO GetOleVersion
  167.         END IF
  168.         IF GetModuleHandle("ole2prox") <> 0 THEN
  169.             OLE16RUNAPP% = 1
  170.             GOTO GetOleVersion
  171.         END IF
  172.         IF GetModuleHandle("ole2conv") <> 0 THEN
  173.             OLE16RUNAPP% = 1
  174.             GOTO GetOleVersion
  175.         END IF
  176.         IF GetModuleHandle("storage") <> 0 THEN
  177.             OLE16RUNAPP% = 1
  178.             GOTO GetOleVersion
  179.         END IF
  180.         IF GetModuleHandle("ole2nls") <> 0 THEN
  181.             OLE16RUNAPP% = 1
  182.             GOTO GetOleVersion
  183.         END IF
  184.         IF GetModuleHandle("ole2disp") <> 0 THEN
  185.             OLE16RUNAPP% = 1
  186.             GOTO GetOleVersion
  187.         END IF
  188.         IF GetModuleHandle("typelib") <> 0 THEN
  189.             OLE16RUNAPP% = 1
  190.             GOTO GetOleVersion
  191.         END IF
  192.  
  193. GetOleVersion:
  194.         szOleNewVer$ = GetSectionKeyVersion("OleWindowsSystemWin32s", "ole2thk")
  195.  
  196.         '' Get version of currently installed OLE32 from version info of
  197.         '' ole2thk file
  198.         szOleOldVer$ = GetVersionOfFile( DESTSYS$ + "WIN32S\OLE2THK.DLL" )
  199.  
  200.         szOle16OldVer$ = GetVersionOfFile( DESTSYS$ + "COMPOBJ.DLL" )
  201.         szOle16NewVer$ = GetSectionKeyVersion("OleWindowsSystem", "compobj")
  202.         IF (szOle16NewVer$ > szOle16OldVer$) THEN
  203.             OLE2_16% = 1
  204.         END IF
  205.  
  206.         szOle16OldVer$ = GetVersionOfFile( DESTSYS$ + "OLE2.DLL" )
  207.         szOle16NewVer$ = GetSectionKeyVersion("OleWindowsSystem", "ole2")
  208.         IF (szOle16NewVer$ > szOle16OldVer$) THEN
  209.             OLE2_16% = 1
  210.         END IF
  211.  
  212.         szOle16OldVer$ = GetVersionOfFile( DESTSYS$ + "OLE2PROX.DLL" )
  213.         szOle16NewVer$ = GetSectionKeyVersion("OleWindowsSystem", "ole2prox")
  214.         IF (szOle16NewVer$ > szOle16OldVer$) THEN
  215.             OLE2_16% = 1
  216.         END IF
  217.  
  218.         szOle16OldVer$ = GetVersionOfFile( DESTSYS$ + "STORAGE.DLL" )
  219.         szOle16NewVer$ = GetSectionKeyVersion("OleWindowsSystem", "storage")
  220.         IF (szOle16NewVer$ > szOle16OldVer$) THEN
  221.             OLE2_16% = 1
  222.         END IF
  223.  
  224.         szOle16OldVer$ = GetVersionOfFile( DESTSYS$ + "OLE2CONV.DLL" )
  225.         szOle16NewVer$ = GetSectionKeyVersion("OleWindowsSystem", "ole2conv")
  226.         IF (szOle16NewVer$ > szOle16OldVer$) THEN
  227.             OLE2_16% = 1
  228.         END IF
  229.  
  230.         szOle16OldVer$ = GetVersionOfFile( DESTSYS$ + "OLE2NLS.DLL" )
  231.         szOle16NewVer$ = GetSectionKeyVersion("OleWindowsSystem", "ole2nls")
  232.         IF (szOle16NewVer$ > szOle16OldVer$) THEN
  233.             OLE2AUTO_16% = 1
  234.         END IF
  235.  
  236.         szOle16OldVer$ = GetVersionOfFile( DESTSYS$ + "OLE2DISP.DLL" )
  237.         szOle16NewVer$ = GetSectionKeyVersion("OleWindowsSystem", "ole2disp")
  238.         IF (szOle16NewVer$ > szOle16OldVer$) THEN
  239.             OLE2AUTO_16% = 1
  240.         END IF
  241.  
  242.         szOle16OldVer$ = GetVersionOfFile( DESTSYS$ + "TYPELIB.DLL" )
  243.         szOle16NewVer$ = GetSectionKeyVersion("OleWindowsSystem", "typelib")
  244.         IF (szOle16NewVer$ > szOle16OldVer$) THEN
  245.             OLE2AUTO_16% = 1
  246.         END IF
  247.  
  248.     END IF
  249.  
  250.     OLE2_32% = OLEINCLUDED%
  251.  
  252.     '' Check if Win32s is partially installed
  253.     sz$ = GetIniKeyString (DESTSYS$ + "WIN32S.INI", "Win32s", "Setup")
  254.     '' If WIN32S.INI specifies Win32s Setup=0, then force complete Win32s file overwrite
  255.     IF sz$ = "0" THEN
  256.         GOTO WELCOME
  257.     END IF
  258.     '' If WIN32S.INI is missing, try and reinstall Win32s files/recreate WIN32S.INI
  259.     IF sz$ <> "1" THEN
  260.         GOTO WELCOME
  261.     END IF
  262.  
  263.     '' If Win32s is already installed, get running version number
  264.     i% = DoesFileExist( DESTSYS$ + "W32SYS.DLL", femExists )
  265.     IF i% = 1 THEN
  266.         i% = IsWin32sLoaded( szOldVer$ )
  267.     ENDIF
  268.  
  269.     IF i% = 0 THEN
  270.         GOTO WELCOME
  271.     END IF
  272.  
  273.     IF szNewVer$ > szOldVer$ THEN
  274.         GOTO WELCOME
  275.     END IF
  276.  
  277.     IF szNewVer$ = szOldVer$ THEN
  278.         SystemCP% = GetSystemCodePage()
  279.         Win32sCP% = VAL ( GetIniKeyString (DESTSYS$ + "WIN32S.INI", "Nls", "AnsiCP") )
  280.         IF SystemCP% <> Win32sCP% THEN
  281.             GOTO WELCOME
  282.         END IF
  283.     END IF
  284.  
  285.     IF OLEINCLUDED% = 1 THEN
  286.  
  287.         OLE2_32% = 0
  288.  
  289.         IF (szNewVer$ = szOldVer$) OR (szNewVer$ < szOldVer$) THEN
  290.             '' Compare OLE32 version and versions of each of OLE16 libraries.
  291.             sz$ = GetIniKeyString (DESTSYS$ + "WIN32S.INI", "OLE", "Setup")
  292.             '' If WIN32S.INI specifies OLE2 Setup=0, then force OLE2 file overwrite
  293.             IF ((sz$ <> "1") OR (szOleNewVer$ > szOleOldVer$)) THEN
  294.                 OLEONLY% = 1
  295.                 OLE2_32% = 1
  296.                 GOTO WELCOME
  297.             END IF
  298.  
  299.             IF OLE2_16% OR OLE2AUTO_16 THEN
  300.                 OLEONLY% = 1
  301.                 GOTO WELCOME
  302.             END IF
  303.  
  304.         END IF
  305.  
  306.     END IF
  307.  
  308.     WIN32ENABLED% = 1
  309.     GOTO FREECELL
  310.  
  311. WELCOME:
  312.     i% = SetCuiFlags(OLEONLY%, OLE16RUNAPP%)
  313.     sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", HELPWELCOME, HELPPROC$)
  314.     IF sz$ = "CONTINUE" THEN
  315.         UIPop 1
  316.     ELSE
  317.         UIPop 1
  318.         GOSUB ASKQUIT
  319.         GOTO WELCOME
  320.     END IF
  321.  
  322.  
  323. GETWIN32SPATH:
  324.     IF PagingEnabled() = 0 THEN
  325.         i% = DoMsgBox("Use the Control Panel 386 Enhanced icon and configure Windows using the Virtual Memory option.", "Win32s requires Virtual Memory", MB_TASKMODAL+MB_ICONHAND+MB_OK)
  326.         ExitCode% = EXITFAILURE '' Enhanced mode but not paging
  327.         GOTO QUIT
  328.     END IF
  329.  
  330.     IF ShareEnabled() = 0 THEN
  331.         i% = DoMsgBox( "File-sharing must be enabled. Run SHARE.EXE before starting Windows or add SHARE.EXE to your AUTOEXEC.BAT file.", "Win32s Setup: SHARE.EXE is not loaded", MB_TASKMODAL+MB_ICONEXCLAMATION+MB_OK)
  332.     END IF
  333.  
  334.     SetSymbolValue "EditTextIn", DESTSYS$
  335.     SetSymbolValue "EditFocus", "END"
  336.  
  337. GETPATHL1:
  338.     sz$ = UIStartDlg(CUIDLL$, VERPATH, "FDispDlgProc", HELPWELCOME, HELPPROC$)
  339.  
  340.     IF sz$ = "CONTINUE" THEN
  341.         IF IsDirWritable(DESTSYS$) = 0 THEN
  342.             GOSUB BADPATH
  343.             GOTO GETPATHL1
  344.         END IF
  345.         UIPop 1
  346.     ELSEIF sz$ = "REACTIVATE" THEN
  347.         UIPop 1
  348.         GOTO GETPATHL1
  349.     ELSEIF sz$ = "BACK" THEN
  350.         UIPop 1
  351.         GOTO WELCOME
  352.     ELSE
  353.         UIPop 1
  354.         GOSUB ASKQUIT
  355.         GOTO GETPATHL1
  356.     END IF
  357.  
  358. COPYFILES:
  359.     IF OLEONLY% = 0 THEN
  360.         CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Win32s", "Setup", "0", cmoOverwrite
  361.     END IF
  362.     IF OLE2_32% = 1 THEN
  363.         CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "OLE", "Setup", "0", cmoOverwrite
  364.     END IF
  365.  
  366.     '' Indicate Win32s install failure until all files known to be copied.
  367.     ExitCode% = EXITFAILURE
  368.     ERR = 0
  369.     CreateDir DEST32S$, cmoNone
  370.     Install OLEINCLUDED%, OLEONLY%, OLE2_32%, OLE2_16%, OLE2AUTO_16%, OLE16RUNAPP%
  371.     i% = UpdateSystemIni
  372.     '' Terminate if unhandled fatal error
  373.     IF (ERR <> 0) OR (i% = 0) THEN
  374.     GOTO QUIT
  375.     END IF
  376.  
  377.     IF OLEONLY% = 0 THEN
  378.         CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Win32s", "Setup", "1", cmoOverwrite
  379.         CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Win32s", "Version", szNewVer$, cmoOverwrite
  380.         CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Nls", "AnsiCP", STR$(GetSystemCodePage()), cmoOverwrite
  381.     END IF
  382.     IF OLE2_32% = 1 THEN
  383.         CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "OLE", "Setup", "1", cmoOverwrite
  384.         CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "OLE", "Version", szOleNewVer, cmoOverwrite
  385.     END IF
  386.  
  387.     i% = DoMsgBox("Win32s files successfully installed.", "Microsoft Win32s Setup", MB_OK+MB_TASKMODAL)
  388.     '' Indicate Win32s correctly copied and installed.
  389.     ExitCode% = EXITSUCCESS
  390.  
  391. FREECELL:
  392.     IF OLEONLY% = 1 THEN
  393.         GOTO QUIT
  394.     ENDIF
  395.     IF WIN32ENABLED% = 1 THEN
  396.         sz$ = UIStartDlg(CUIDLL$, FREECELLINSTNOWIN32S, "FInfoDlgProc",0, "")
  397.     ELSE
  398.         sz$ = UIStartDlg(CUIDLL$, FREECELLINST, "FInfoDlgProc",0, "")
  399.     END IF
  400.     UIPop 1
  401.     IF sz$ <> "CONTINUE" THEN
  402.         GOTO QUIT
  403.     END IF
  404.  
  405. GETFREEPATH:
  406.     DESTFREE$ = MID$(DESTSYS$,1,3) + "WIN32APP\FREECELL\"
  407.     SetSymbolValue "EditTextIn", DESTFREE$
  408.     SetSymbolValue "EditFocus", "END"
  409.  
  410. GETFREEPATHL1:
  411.     sz$ = UIStartDlg(CUIDLL$, FREECELLPATH, "FEditDlgProc", HELPFREECELL, HELPPROC$)
  412.  
  413.     IF sz$ = "CONTINUE" THEN
  414.         DESTFREE$ = GetSymbolValue("EditTextOut")
  415.  
  416.         IF MID$(DESTFREE$, LEN(DESTFREE$), 1) <> "\" THEN
  417.             DESTFREE$ = DESTFREE$ + "\"
  418.         END IF
  419.         ''Validate new path.
  420.         IF IsDirWritable(DESTFREE$) = 0 THEN
  421.             GOSUB BADPATH
  422.             GOTO GETFREEPATHL1
  423.         END IF
  424.         UIPop 1
  425.  
  426.         GOTO COPYFREECELL
  427.     ELSEIF sz$ = "REACTIVATE" THEN
  428.         GOTO GETFREEPATHL1
  429.     ELSEIF sz$ = "EXIT" THEN
  430.         UIPop 1
  431.         GOTO QUIT
  432.     END IF
  433.  
  434. COPYFREECELL:
  435.     ClearCopyList
  436.     CreateDir DESTFREE$, cmoNone
  437.  
  438.     SrcDir$ = GetSymbolValue("STF_SRCDIR")
  439.  
  440.     ERR = 0
  441.     AddSectionFilesToCopyList "Win32appFreecell", SrcDir$, DESTFREE$
  442.     CopyFilesInCopyList
  443.     '' If error copying FreeCell, not a fatal error. Win32s is already installed.
  444.     IF ERR <> 0 THEN
  445.     ERR = 0
  446.     GOTO QUIT
  447.     END IF
  448.     ERR = 0
  449.  
  450.     IF DoesFileExist( DESTSYS$ + "WIN32S.INI", femExists ) THEN
  451.     CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Freecell", "Setup", "1", cmoOverwrite
  452.     CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Freecell", "Version", szNewVer$, cmoOverwrite
  453.     END IF
  454.  
  455.     ERR = 0
  456.     CreateProgmanGroup "Win32 Applications", "", cmoNone
  457.     ShowProgmanGroup   "Win32 Applications", 1, cmoNone
  458.     CreateProgmanItem  "Win32 Applications", "Freecell", DESTFREE$ + "FREECELL.EXE", "", cmoOverwrite
  459.     '' Only put up success dialog if icon added to group
  460.     IF ERR = 0 THEN
  461.     i% = DoMsgBox("Freecell was successfully installed.", "Freecell Setup", MB_OK+MB_TASKMODAL)
  462.     END IF
  463.     ERR = 0
  464.  
  465. QUIT:
  466.     '' Install error handler for final message box routines
  467.     ON ERROR GOTO ERRQUIT
  468.     IF ERR = 0 THEN
  469.         dlg% = ExitCode%
  470.     ELSEIF ERR = STFQUIT THEN
  471.         IF (OLE_PROTECT% = 1) THEN
  472.             '' Free all previously loaded libraries
  473.             FreeLibrary GetModuleHandle("compobj")
  474.             FreeLibrary GetModuleHandle("ole2")
  475.             FreeLibrary GetModuleHandle("ole2prox")
  476.             FreeLibrary GetModuleHandle("ole2conv")
  477.             FreeLibrary GetModuleHandle("storage")
  478.             FreeLibrary GetModuleHandle("ole2nls")
  479.             FreeLibrary GetModuleHandle("ole2disp")
  480.             FreeLibrary GetModuleHandle("typelib")
  481.         END IF
  482.         dlg% = EXITQUIT
  483.         ExitCode% = EXITQUIT
  484.     ELSE
  485.         dlg% = EXITFAILURE
  486.         ExitCode% = EXITQUIT
  487.     END IF
  488.  
  489. QUITL1:
  490.     IF WIN32ENABLED% = 1 THEN
  491.         UIPop 1
  492.         END
  493.     END IF
  494.  
  495.     sz$ = UIStartDlg(CUIDLL$, dlg%, "FInfo0DlgProc", 0, "")
  496.     IF sz$ = "REACTIVATE" THEN
  497.         GOTO QUITL1
  498.     END IF
  499.     UIPop 1
  500.  
  501.     IF ExitCode% = EXITSUCCESS THEN
  502.         IF RebootSystem(OLEONLY% and not OLE_OLEBOOT%) = 0 THEN
  503.             CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Win32s", "Setup", "0", cmoOverwrite
  504.             IF OLE2_32% = 1 THEN
  505.                 CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "OLE", "Setup", "0", cmoOverwrite
  506.             END IF
  507.             i% = DoMsgBox("Win32s is not properly configured and Win32s Setup must be run again.", "Unable to Restart Windows", MB_ICONEXCLAMATION+MB_OK+MB_TASKMODAL)
  508.         END IF
  509.     ENDIF
  510.  
  511.     END
  512.  
  513. '' Fatal error handler for error message routine
  514. ERRQUIT:
  515.     i% = DoMsgBox("Setup sources were corrupted!", "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
  516.     END
  517.  
  518. '' Bypass run-time errors. Let final dialog box display fatal error message.
  519. ERRNORMAL:
  520.     '' Check if user cancelled setup
  521.     IF ERR = STFQUIT THEN
  522.     GOTO QUIT
  523.     END IF
  524.     RESUME NEXT
  525.  
  526.  
  527. BADPATH:
  528.     sz$ = UIStartDlg(CUIDLL$, BADPATH, "FInfo0DlgProc", 0, "")
  529.     IF sz$ = "REACTIVATE" THEN
  530.         GOTO BADPATH
  531.     END IF
  532.         UIPop 1
  533.     RETURN
  534.  
  535.   ASKQUIT:
  536.     sz$ = UIStartDlg(CUIDLL$, ASKQUIT, "FQuitDlgProc", 0, "")
  537.  
  538.     IF sz$ = "EXIT" THEN
  539.         UIPop 1
  540.         UIPopAll
  541.         ERROR STFQUIT
  542.     ELSEIF sz$ = "REACTIVATE" THEN
  543.         GOTO ASKQUIT
  544.     ELSE
  545.         UIPop 1
  546.     END IF
  547.     RETURN
  548.  
  549.  
  550.  
  551. '**
  552. '** Purpose:
  553. '**     Builds the copy list and performs all installation operations.
  554. '** Arguments:
  555. '**     none.
  556. '** Returns:
  557. '**     none.
  558. '*************************************************************************
  559. SUB Install(OLEINCLUDED%, OLEONLY%, OLE2_32%, OLE2_16%, OLE2AUTO_16%, OLE16RUNAPP%) STATIC
  560.  
  561.     SrcDir$ = GetSymbolValue("STF_SRCDIR")
  562.  
  563.     '' Use file layout sections that specify OLDER file version/time check
  564.     IF OLEONLY% = 0 THEN
  565.         AddSectionFilesToCopyList "WindowsSystem", SrcDir$, DESTSYS$
  566.         AddSectionFilesToCopyList "WindowsSystemWin32s", SrcDir$, DESTSYS$ + "WIN32S\"
  567.         i% = GetSystemCodePage()
  568.         IF i% = 932 THEN
  569.             AddSectionFilesToCopyList "WindowsSystem_932", SrcDir$, DESTSYS$
  570.             AddSectionFilesToCopyList "WindowsSystemWin32s_932", SrcDir$, DESTSYS$ + "WIN32S\"
  571.         ELSEIF i% = 949 THEN
  572.             AddSectionFilesToCopyList "WindowsSystem_949", SrcDir$, DESTSYS$
  573.             AddSectionFilesToCopyList "WindowsSystemWin32s_949", SrcDir$, DESTSYS$ + "WIN32S\"
  574.         ELSEIF i% = 936 THEN
  575.             AddSectionFilesToCopyList "WindowsSystem_936", SrcDir$, DESTSYS$
  576.             AddSectionFilesToCopyList "WindowsSystemWin32s_936", SrcDir$, DESTSYS$ + "WIN32S\"
  577.         ELSEIF i% = 950 THEN
  578.             AddSectionFilesToCopyList "WindowsSystem_950", SrcDir$, DESTSYS$
  579.             AddSectionFilesToCopyList "WindowsSystemWin32s_950", SrcDir$, DESTSYS$ + "WIN32S\"
  580.         ELSE
  581.             AddSectionFilesToCopyList "WindowsSystem_1252", SrcDir$, DESTSYS$
  582.             AddSectionFilesToCopyList "WindowsSystemWin32s_1252", SrcDir$, DESTSYS$ + "WIN32S\"
  583.         END IF
  584.         '' Add obsolete files to be removed
  585.         AddSectionFilesToCopyList "Win32sSystemObsoleteFiles", SrcDir$, DESTSYS$ + "WIN32S\"
  586.     END IF
  587.  
  588.     OLE_PROTECT% = 0
  589.     if OLEINCLUDED% = 1 THEN
  590.         IF (OLE2_16% = 1) OR (OLE2AUTO_16% = 1) THEN
  591.             IF OLE16RUNAPP% = 1 THEN
  592.                 '' Force all OLE2 DLLS to be copied during reboot.
  593.                 i% = SetErrorMode(-32768)
  594.                 i% = LoadLibrary(DESTSYS$ + "compobj.dll")
  595.                 i% = LoadLibrary(DESTSYS$ + "ole2.dll")
  596.                 i% = LoadLibrary(DESTSYS$ + "ole2prox.dll")
  597.                 i% = LoadLibrary(DESTSYS$ + "ole2conv.dll")
  598.                 i% = LoadLibrary(DESTSYS$ + "storage.dll")
  599.                 i% = LoadLibrary(DESTSYS$ + "ole2nls.dll")
  600.                 i% = LoadLibrary(DESTSYS$ + "ole2disp.dll")
  601.                 i% = LoadLibrary(DESTSYS$ + "typelib.dll")
  602.                 OLE_PROTECT% = 1
  603.             END IF
  604.             AddSectionFilesToCopyList "OleWindowsSystem", SrcDir$, DESTSYS$
  605.         END IF
  606.         IF OLE2_32% = 1 THEN
  607.             AddSectionFilesToCopyList "OleWindowsSystemWin32s", SrcDir$, DESTSYS$ + "WIN32S\"
  608.             i% = GetSystemCodePage()
  609.             IF i% = 932 THEN
  610.                 AddSectionFilesToCopyList "OleWindowsSystemWin32s_932", SrcDir$, DESTSYS$ + "WIN32S\"
  611.             ELSEIF i% = 949 THEN
  612.                 AddSectionFilesToCopyList "OleWindowsSystemWin32s_949", SrcDir$, DESTSYS$ + "WIN32S\"
  613.             ELSEIF i% = 936 THEN
  614.                 AddSectionFilesToCopyList "OleWindowsSystemWin32s_936", SrcDir$, DESTSYS$ + "WIN32S\"
  615.             ELSEIF i% = 950 THEN
  616.                 AddSectionFilesToCopyList "OleWindowsSystemWin32s_950", SrcDir$, DESTSYS$ + "WIN32S\"
  617.             ELSE
  618.                 AddSectionFilesToCopyList "OleWindowsSystemWin32s_1252", SrcDir$, DESTSYS$ + "WIN32S\"
  619.             END IF
  620.         END IF
  621.         IF (OLE2_16% = 1) OR (OLE2_32% = 1) OR (OLE2AUTO_16% = 1) THEN
  622.             AddSectionFilesToCopyList "Ole2RegWindowsSystem", SrcDir$, DESTSYS$
  623.         END IF
  624.         IF (OLE2AUTO_16% = 1) THEN
  625.             AddSectionFilesToCopyList "StdoleWindowsSystem", SrcDir$, DESTSYS$
  626.             IF (OLE16RUNAPP and DoesFileExist(DESTSYS$ + "stdole.tlb", femExists) ) THEN
  627.                 ' copy stdole.tlb -> tempfile1
  628.                 stdole1$ = DESTSYS$ + GetTempFileAt(DESTSYS$, "STD")
  629.                 CopyFile DESTSYS$+"STDOLE.TLB", stdole1$, cmoOverwrit, 0
  630.                 OLE_OLEBOOT% = 1
  631.             ENDIF
  632.         END IF
  633.     END IF
  634.  
  635.     SetRestartDir GetWindowsDir()
  636.  
  637.     CopyFilesInCopyList
  638.  
  639.     IF (OLEINCLUDED% = 1) THEN
  640.         RecoverFromCopy DESTSYS$ + "compobj.dll"
  641.         RecoverFromCopy DESTSYS$ + "ole2.dll"
  642.         RecoverFromCopy DESTSYS$ + "ole2prox.dll"
  643.         RecoverFromCopy DESTSYS$ + "ole2conv.dll"
  644.         RecoverFromCopy DESTSYS$ + "storage.dll"
  645.         RecoverFromCopy DESTSYS$ + "ole2nls.dll"
  646.         RecoverFromCopy DESTSYS$ + "ole2disp.dll"
  647.         RecoverFromCopy DESTSYS$ + "typelib.dll"
  648.     END IF
  649.  
  650.     IF (OLE_PROTECT% = 1) THEN
  651.         '' Free all previously loaded libraries
  652.         FreeLibrary GetModuleHandle("compobj")
  653.         FreeLibrary GetModuleHandle("ole2")
  654.         FreeLibrary GetModuleHandle("ole2prox")
  655.         FreeLibrary GetModuleHandle("ole2conv")
  656.         FreeLibrary GetModuleHandle("storage")
  657.         FreeLibrary GetModuleHandle("ole2nls")
  658.         FreeLibrary GetModuleHandle("ole2disp")
  659.         FreeLibrary GetModuleHandle("typelib")
  660.         OLE_PROTECT% = 0
  661.     END IF
  662.     IF (OLE_OLEBOOT% = 1) THEN
  663.             'rename new stdole.tlb -> tempfile2
  664.             stdole2$ = GetTempFileAt(DESTSYS$, "STD")
  665.             RemoveFile DESTSYS$+stdole2$, cmoForce
  666.             RenameFile DESTSYS$+"STDOLE.TLB" , stdole2$
  667.             'rename tempfile1 -> stdole.tlb
  668.             RenameFile stdole1$, "STDOLE.TLB"
  669.             'write to _mssetup.bat: rename tempfile2 to stdole.tlb
  670.             WriteLine DESTWIN$+"_MSSETUP.BAT", ""
  671.             WriteLine DESTWIN$+"_MSSETUP.BAT", "DEL "+DESTSYS$+"STDOLE.TLB"
  672.             WriteLine DESTWIN$+"_MSSETUP.BAT", "REN "+DESTSYS$+stdole2$+" STDOLE.TLB"
  673.     ENDIF
  674.     IF OLEINCLUDED% AND (OLE2_16% OR OLE2_32% OR OLE2AUTO_16%) THEN
  675.         IF OLE16RUNAPP% THEN
  676.             reg1$ = DESTWIN$ + GetTempFileAt(DESTWIN$, "REG")
  677.             CopyFile DESTWIN$+"REG.DAT", reg1$, cmoOverwrit, 0
  678.         ENDIF
  679.  
  680.         RUN "regedit /s " + DESTSYS$ + "ole2.reg"
  681.  
  682.         IF OLE16RUNAPP% THEN
  683.             reg2$ = GetTempFileAt(DESTWIN$, "REG")
  684.             RemoveFile DESTWIN$ + reg2$, cmoForce
  685.             RenameFile DESTWIN$ + "REG.DAT" , reg2$
  686.             'rename tempfile1 -> reg.dat
  687.             RenameFile reg1$, "REG.DAT"
  688.             'write to _mssetup.bat: rename tempfile2 to reg.dat
  689.             WriteLine DESTWIN$+"_MSSETUP.BAT", ""
  690.             WriteLine DESTWIN$+"_MSSETUP.BAT", "DEL "+DESTWIN$+"REG.DAT"
  691.             WriteLine DESTWIN$+"_MSSETUP.BAT", "REN "+DESTWIN$ + reg2$+" REG.DAT"
  692.             OLE_OLEBOOT% = 1
  693.         ENDIF
  694.     END IF
  695. END SUB
  696.  
  697. FUNCTION UpdateSystemIni STATIC AS INTEGER
  698.  
  699.     VxDPath$ = DEST32S$ + "W32S.386"
  700.     SystemIniPath$ = GetWindowsDir()
  701.  
  702.     UpdateSystemIni% = MakeSystemIni(SystemIniPath$, VxdPath$)
  703.  
  704. END FUNCTION
  705.  
  706. FUNCTION RebootSystem(OLEONLY%) STATIC AS INTEGER
  707.  
  708. '   Check if any files were locked during install.  If the RestartList
  709. '   is not empty, ExitExecRestart() will restart Windows, cleanup setup
  710. '   files, and copy over locked files before Windows restarts.
  711.     i% = RestartListEmpty()
  712.     IF i% = 0 THEN
  713. '      ExitExecRestart() only returns if applications refuse to be shutdown.
  714. '      Win32s is installed but will not operate until Windows is restarted
  715. '      and the Win32s VxD is loaded.
  716.        i% = ExitExecRestart()
  717.        RebootSystem = 0
  718.     ELSE
  719. '      If the RestartList list is empty, it is necessary to restart windows
  720. '      directly.  The MSSETUP program creates _MSRSTRT.EXE and _MSSETUP.BAT
  721. '      in the restart directory.  This program should be exec'd to handle
  722. '      proper MSSETUP cleanup (temp files) and restart Windows.
  723.        IF (OLEONLY% = 1) THEN
  724.            RebootSystem = 1
  725.        ELSE
  726.            i% = ExitWindowsExec( GetWindowsDir() + "_MSRSTRT.EXE", "_MSSETUP.BAT" )
  727.            RebootSystem = 0
  728.        END IF
  729.     ENDIF
  730.  
  731. END FUNCTION
  732.  
  733.  
  734. '**
  735. '** Purpose:
  736. '**     Appends a file name to the end of a directory path,
  737. '**     inserting a backslash character as needed.
  738. '** Arguments:
  739. '**     szDir$  - full directory path (with optional ending "\")
  740. '**     szFile$ - filename to append to directory
  741. '** Returns:
  742. '**     Resulting fully qualified path name.
  743. '*************************************************************************
  744. FUNCTION MakePath (szDir$, szFile$) STATIC AS STRING
  745.     IF szDir$ = "" THEN
  746.     MakePath = szFile$
  747.     ELSEIF szFile$ = "" THEN
  748.     MakePath = szDir$
  749.     ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
  750.     MakePath = szDir$ + szFile$
  751.     ELSE
  752.     MakePath = szDir$ + "\" + szFile$
  753.     END IF
  754. END FUNCTION
  755.  
  756. FUNCTION GetTempFileAt(szDir$, szPrefix$) STATIC AS STRING
  757.     szCurDir$ = CURDIR$
  758.     CHDIR szDir$ + "."
  759.     szTempFile$ = STRING$(144, "E")
  760.     i% = GetTempFileName(TF_FORCEDRIVE, szPrefix$,0, szTempFile$)
  761.     CHDIR szCurDir$
  762.     GetTempFileAt = MID$(szTempFile$,3)
  763. END FUNCTION
  764.  
  765. SUB RecoverFromCopy(szFileName$) STATIC
  766.     IF DoesFileExist(szFileName$, femExist) = 0 THEN
  767.         szBackFile$ = MID$(szFileName$, 1, LEN(szFileName$)-3) + VERNUM$
  768.         IF DoesfileExist(szBackFile$, femExist) = 0 THEN
  769.             i% = DoMsgBox("ERROR: Could not find backup file "+szBackfile$, "Setup Error", MB_ICONEXLAMATION + MB_OK)
  770.         ELSE
  771.             CopyFile szBackFile$, szFileName$, cmoTimeStamp, 0
  772.         END IF
  773.     END IF
  774. END SUB
  775.