home *** CD-ROM | disk | FTP | other *** search
/ Games for Windows / GAMOS.iso / eng / lines / setup.ms_ / setup.bin
Text File  |  1994-10-24  |  18KB  |  542 lines

  1. '*****************************************************************************
  2. '*                       Color Lines Setup Program
  3. '*****************************************************************************
  4.  
  5. '**'$DEFINE DEBUG
  6. '** '$DEFINE SETUP_3M   ''Define for the 3M version of the setup script
  7.  
  8.  
  9. '$INCLUDE 'setupapi.inc'
  10. '$INCLUDE 'msdetect.inc'
  11.  
  12. '** Dialog ID's
  13. '*****************************************************************************
  14. CONST WELCOME           = 100
  15. CONST ASKQUIT           = 200
  16. CONST DESTPATH          = 300
  17. CONST EXITFAILURE       = 400
  18. CONST EXITQUIT          = 600
  19. CONST EXITSUCCESS       = 700
  20. CONST OPTIONS           = 800
  21. CONST APPHELP           = 900
  22. CONST TOOBIG            = 6300
  23. CONST BADPATH           = 6400
  24. CONST CDALREADYUSED     = 7100
  25. CONST CDCONFIRMINFO     = 7300
  26. CONST CDGETNAMEORG      = 7500
  27.  
  28. CONST DESTPATHHELP      = 10000
  29. CONST WRONGVER          = 10400
  30.  
  31.  
  32. '** Symbol table identifiers and other goodies
  33. '*****************************************************************************
  34. CONST SW_SHOWNORMAL   = 1
  35. CONST RT_STRING       = 6
  36. CONST SEM_NOOPENFILEERRORBOX = &H8000   '** 0x8000
  37.  
  38. CONST ID_USERNAME     = 200
  39. CONST ID_USERORG      = 201
  40. CONST ID_NUMBER          = 202
  41.  
  42. CONST DEFAULTDEST$    = "C:\LINESWIN"
  43. CONST FRAMETITLE$     = "Color Lines Installation Program"
  44.  
  45. CONST APPEXE$         = "AppEXE"
  46. CONST APPDLL$         = "AppDLL"
  47. CONST INIFILE$          = "INI"
  48. CONST SYSFILES$       = "SystemFiles"
  49.  
  50. CONST README$         = "ReadMe"
  51. CONST VIEWAPP$        = "write.exe"
  52.  
  53. CONST PROGMANGRPNAME$ = "Gamos"
  54. CONST APPLICATION$    = "Application"
  55. CONST APPITEMNAME$    = "Color Lines"
  56.  
  57.  
  58.    '** This string also exists in the dialog box code.  If you change it
  59.    '** here, change it there too.
  60.    '*************************************************************************
  61. CONST DESTDIRNAME$    = "destdirname"
  62.  
  63.  
  64. '** Bitmap IDs
  65. '*****************************************************************************
  66. CONST LOGO    = 1
  67. CONST APPLOGO = 2
  68.  
  69.  
  70. '** Global variable declarations
  71. '*****************************************************************************
  72. GLOBAL dest$        '' Default destination directory.
  73. GLOBAL username$    '' User name (required)
  74. GLOBAL userorg$     '' User organization (optional)
  75. GLOBAL definst$     '' "1" iff default installation
  76. GLOBAL stamped%     '' has username/org been stamped ?
  77. GLOBAL srcdir$      '' directory where setup is run from
  78. GLOBAL serialno$    '' serial number    
  79.  
  80.  
  81. '** Function/subroutine declarations.
  82. '*****************************************************************************
  83. DECLARE SUB      LibInitialize     LIB "mscuistf.dll" (hwnd%, id%)
  84. DECLARE SUB      LibTerminate      LIB "mscuistf.dll"
  85. DECLARE FUNCTION DWListInit        LIB "mscuistf.dll" (listlen%) AS INTEGER
  86. DECLARE SUB      DWListTerm        LIB "mscuistf.dll"
  87. DECLARE SUB      DWListAddItem     LIB "mscuistf.dll" (item%, itemval&)
  88. DECLARE SUB      DWListSetBase     LIB "mscuistf.dll" (baseval&)
  89. DECLARE FUNCTION IsALConflict      LIB "mscuistf.dll" (thestr$) AS INTEGER
  90. DECLARE SUB      FixALConflict     LIB "mscuistf.dll" (thestr$)
  91. DECLARE SUB      DeleteExeName     LIB "mscuistf.dll" (thestr$, exename$)
  92. DECLARE FUNCTION GetNameOrg        LIB "mscuistf.dll" AS INTEGER
  93. DECLARE SUB      PrependToAutoExec LIB "mscuistf.dll" (filename$, strdata$, datalen%)
  94.  
  95. DECLARE SUB      ReplaceResString LIB "mscuistf.dll" (filename$, id%, new$)
  96.  
  97. DECLARE FUNCTION SetErrorMode LIB "kernel" (newmode%) AS INTEGER
  98. DECLARE SUB      WinExec LIB "kernel" (cmdline$, cmdshow%)
  99.  
  100. DECLARE FUNCTION GetSizeofSectionFiles (szSect$) AS LONG
  101. DECLARE FUNCTION GetAutoExecName () AS STRING
  102. DECLARE FUNCTION DoesInfSectionExist (szsect$) AS INTEGER
  103. DECLARE SUB      Install
  104. DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
  105.  
  106.  
  107. INIT:
  108.     CUIDLL$   = "mscuistf.dll"          ''Custom user interface dll
  109.     HELPPROC$ = "FHelpDlgProc"          ''Help dialog procedure
  110.  
  111.     '** Set the frame window bitmap and title.
  112.     '*************************************************************************
  113.     LibInitialize HwndFrame(), APPLOGO
  114.     SetBitmap CUIDLL$, LOGO
  115.     SetTitle FRAMETITLE$
  116.  
  117.     '** Get the full path spec for the .INF file.
  118.     '*************************************************************************
  119.     szInf$ = GetSymbolValue("STF_SRCINFPATH")
  120.     IF srcdir$ = "" THEN
  121.         szInf$ = GetSymbolValue("STF_CWDDIR") + "SETUP.INF"
  122.     END IF
  123.     ReadInfFile szInf$
  124.  
  125.     '** Initialize global variables
  126.     '*************************************************************************
  127.     dest$     = DEFAULTDEST
  128.     username$ = ""
  129.     userorg$  = ""
  130.     fix_al%   = 0
  131.     definst$  = "1"
  132.     stamped%  = 0
  133.     srcdir$   = GetSymbolValue("STF_SRCDIR")
  134.     serialno$ = "beta 031895"
  135.  
  136. '$IFDEF DEBUG
  137.     i% = SetSizeCheckMode(scmOnIgnore)    '' could use scmOff; def = scmOnFatal
  138.     WinDrive$ = MID$(GetWindowsDir, 1, 1)
  139.     IF IsDriveValid(WinDrive$) = 0 THEN
  140.         i% = DoMsgBox("Windows drive ('"+WinDrive$+"') is not a valid drive.", "DEBUG", MB_TASKMODAL+MB_ICONHAND+MB_OK)
  141.         GOTO QUIT
  142.     END IF
  143. '$ENDIF ''DEBUG
  144.  
  145.     '** Verify that we are installing in at least Windows 3.1.  This puppy
  146.     '** doesn't support 3.0.
  147.     '*************************************************************************
  148.     IF (GetWindowsMajorVersion() = 3) AND (GetWindowsMinorVersion() < 10) THEN
  149.     WRONGVERSION:
  150.         sz$ = UIStartDlg(CUIDLL$, WRONGVER, "FInfoDlgProc", 0, "")
  151.  
  152.         IF sz$ = "REACTIVATE" THEN
  153.             GOTO WRONGVERSION
  154.         END IF
  155.  
  156.         UIPopAll
  157.         ERROR STFQUIT
  158.     END IF
  159.  
  160.  
  161.     '** Show the Welcome dialog box.  The ASKQUIT subroutine will query the
  162.     '** user if they want to quit.  If they really do quit, run-time error
  163.     '** STF_QUIT occurs and execution resumes at the "QUIT:" label.
  164.     '**
  165.     '** The 3M version of the script does not include the custom/default
  166.     '** installation option.  Since definst$ = "1" initially, and never gets
  167.     '** changed, the 3M version always uses the default installation.
  168.     '*************************************************************************
  169.     SetSymbolValue "RadioDefault", "1"
  170.  
  171. WELCOME:
  172.     sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", 0, "")
  173.  
  174.     IF sz$ = "CONTINUE" THEN
  175.         UIPop 1
  176.     ELSEIF sz$ = "REACTIVATE" THEN
  177.         GOTO WELCOME
  178.     ELSE
  179.         GOSUB ASKQUIT
  180.         GOTO WELCOME
  181.     END IF
  182.  
  183.  
  184.     '** Get the User name and User organization strings.
  185.     '*************************************************************************
  186.     sz$ = MakePath(srcdir$, "SETUP.INI")
  187.  
  188.     IF DoesIniKeyExist(sz$, "UserInfo", "UserName") > 0 THEN
  189.         '** Product has already been installed once.  Give the "you're a
  190.         '** potentially baaaad user message" and retrieve the strings.
  191.         '*********************************************************************
  192.         username$ = GetIniKeyString(sz$, "UserInfo", "UserName")
  193.         userorg$  = GetIniKeyString(sz$, "UserInfo", "UserOrg")
  194.         stamped%  = 1
  195.  
  196.         SetSymbolValue "ConfirmTextIn", ""
  197.         AddListItem "ConfirmTextIn", username$
  198.         AddListItem "ConfirmTextIn", userorg$
  199.  
  200.     ALREADYUSED:
  201.         sz$ = UIStartDlg(CUIDLL$, CDALREADYUSED, "FConfirmDlgProc", 0, "")
  202.  
  203.         IF sz$ = "CONTINUE" THEN
  204.             UIPop 1
  205.         ELSEIF sz$ = "REACTIVATE" THEN
  206.             GOTO ALREADYUSED
  207.         ELSE
  208.             UIPopAll
  209.             GOTO EXITSCRIPT
  210.         END IF
  211.     ELSE
  212.         '** Get the user Name/Organization.  Returned symbols are:
  213.         '**     "NameOut" - the user's name.
  214.         '**     "OrgOut"  - the user's organization (if any).
  215.         '*********************************************************************
  216.     GETNAMEORG:
  217.         sz$ = UIStartDlg(CUIDLL$, CDGETNAMEORG, "FNameOrgDlgProc", 0, "")
  218.         username$ = GetSymbolValue("NameOut")
  219.         userorg$  = GetSymbolValue("OrgOut")
  220.         stamped%  = 0
  221.  
  222.         IF sz$ = "CONTINUE" THEN
  223.             '** Confirm what they told us.  Empty the list before inserting the
  224.             '** names into it.
  225.             '*****************************************************************
  226.             SetSymbolValue "ConfirmTextIn", ""
  227.             AddListItem "ConfirmTextIn", username$
  228.             AddListItem "ConfirmTextIn", userorg$
  229.             sz$ = UIStartDlg(CUIDLL$, CDCONFIRMINFO, "FConfirmDlgProc", 0, "")
  230.  
  231.             if sz$ = "CONTINUE" THEN
  232.                 UIPop(2)
  233.             ELSE
  234.                 UIPop(1)
  235.                 GOTO GETNAMEORG
  236.             END IF
  237.         ELSEIF sz$ = "REACTIVATE" THEN
  238.             GOTO GETNAMEORG
  239.         ELSE
  240.             GOSUB ASKQUIT
  241.             GOTO GETNAMEORG
  242.         END IF
  243.     END IF
  244.  
  245.     SetSymbolValue "ConfirmTextIn", ""
  246.     SetSymbolValue "NameOut", ""
  247.     SetSymbolValue "OrgOut", ""
  248.  
  249.  
  250.     '** Get the destination pathname.
  251.     '*************************************************************************
  252. GETPATH:
  253.     SetSymbolValue "EditTextIn", dest$
  254.     SetSymbolValue "EditFocus", "ALL"
  255.  
  256. GETPATHL1:
  257.     sz$   = UIStartDlg(CUIDLL$, DESTPATH, "FEditDlgProc", DESTPATHHELP, HELPPROC$)
  258.     dest$ = GetSymbolValue("EditTextOut")
  259.  
  260.     IF sz$ = "CONTINUE" THEN
  261.         IF IsDirWritable(dest$) = 0 THEN
  262.             GOSUB BADPATH
  263.             GOTO GETPATHL1
  264.         END IF
  265.         UIPop 1
  266.     ELSEIF sz$ = "REACTIVATE" THEN
  267.         GOTO GETPATHL1
  268.     ELSE
  269.         GOSUB ASKQUIT
  270.         GOTO GETPATH
  271.     END IF
  272.  
  273.  
  274.     '** Finally - do the install.
  275.     '*************************************************************************
  276.     Install
  277.  
  278.  
  279. QUIT:
  280.     ON ERROR GOTO ERRQUIT
  281.  
  282.     IF ERR = 0 THEN
  283.     EXIT_SUCCESS:
  284.         '** Successfull install.  At exit allow the user the chance to
  285.         '** run the program.
  286.         '*********************************************************************
  287.         sz$     = UIStartDlg(CUIDLL$, EXITSUCCESS, "FInfo0DlgProc", 0, "")
  288.         runapp$ = GetSymbolValue("DLGEVENT")
  289.  
  290.         IF sz$ = "REACTIVATE" THEN
  291.             GOTO EXIT_SUCCESS
  292.         END IF
  293.         UIPop 1
  294.  
  295.         IF runapp$ = "RUN" THEN
  296.             runapp$  = VIEWAPP$ + " " + MakePath(dest$, GetSectionKeyFilename(APPDLL$, README$))
  297.  
  298. '$IFDEF DEBUG
  299.             OpenLogFile MakePath(dest$, "LOGFILE.TXT"), 1
  300.             WriteToLogFile "Running: " + runapp$ + "."
  301.             CloseLogFile
  302. '$ENDIF ''DEBUG
  303.  
  304.             errmode% = SetErrorMode(SEM_NOOPENFILEERRORBOX)
  305.             WinExec runapp$, SW_SHOWNORMAL
  306.             errmode% = SetErrorMode(errmode%)
  307.         END IF
  308.     ELSEIF (ERR = STFQUIT) OR (ERR = STFERR) THEN
  309.         dlg% = 0
  310.     ELSE
  311.     EXIT_FAIL:
  312.         '** Unsuccessfull installation.
  313.         '*********************************************************************
  314.         sz$ = UIStartDlg(CUIDLL$, EXITFAILURE, "FInfo0DlgProc", 0, "")
  315.  
  316.         IF sz$ = "REACTIVATE" THEN
  317.             GOTO EXIT_FAIL
  318.         END IF
  319.         UIPop 1
  320.     END IF
  321.  
  322. EXITSCRIPT:
  323.     LibTerminate
  324.     END
  325.  
  326. ERRQUIT:
  327.     LibTerminate
  328.  
  329. '$IFDEF DEBUG
  330.     OpenLogFile MakePath(dest$, "LOGFILE.TXT"), 1
  331.     WriteToLogFile "ERRQUIT: error = " + STR$(ERR) + "."
  332.     CloseLogFile
  333. '$ENDIF ''DEBUG
  334.  
  335.     i% = DoMsgBox("An unknown error has occurred.\nPlease contact Alex Software.", "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
  336.     END
  337.  
  338.  
  339.  
  340. '** Subroutine BADPATH
  341. '**
  342. '** Simply notifies the user that the path they specified is bogus, and
  343. '** then returns.
  344. '**
  345. '*****************************************************************************
  346. BADPATH:
  347.     DIM MSGTEXT1$
  348.     DIM MSGTEXT2$
  349.  
  350.     MSGTEXT1$ = "The path you specified is invalid.  Please re-enter the path for "
  351.     MSGTEXT2$ = "installation, or cancel Setup and check your computer's configuration."
  352.     i% = DoMsgBox(MSGTEXT1$ + MSGTEXT2$, "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
  353.     RETURN
  354.  
  355.  
  356.  
  357. '** Subroutine ASKQUIT
  358. '**
  359. '** Querys the user in a "do you really, really want to quit ?" fashion.
  360. '** If they do, ERROR STFQUIT occurs.  Otherwise, the subroutine returns.
  361. '**
  362. '*****************************************************************************
  363. ASKQUIT:
  364.     sz$ = UIStartDlg(CUIDLL$, ASKQUIT, "FQuitDlgProc", 0, "")
  365.  
  366.     IF sz$ = "EXIT" THEN
  367.         UIPopAll
  368.         ERROR STFQUIT
  369.     ELSEIF sz$ = "REACTIVATE" THEN
  370.         GOTO ASKQUIT
  371.     ELSE
  372.         UIPop 1
  373.     END IF
  374.     RETURN
  375.  
  376.  
  377. '** Function GetSizeofSectionFiles
  378. '**
  379. '** Determines the size of all files contained in a given section.
  380. '**
  381. '*****************************************************************************
  382. FUNCTION GetSizeofSectionFiles (szSect$) STATIC AS LONG
  383.     MakeListFromSectionKeys "__get_list", szSect$
  384.     listlen%  = GetListLength("__get_list")
  385.     sectsize& = 0
  386.  
  387.     FOR i% = 1 TO listlen% STEP 1
  388.         sz$ = GetListItem("__get_list", i%)
  389.         sectsize& = sectsize& + GetSectionKeySize(szSect$, sz$)
  390.     NEXT
  391.  
  392.     SetSymbolValue "__get_list", ""
  393.     GetSizeofSectionFiles = sectsize&
  394. END FUNCTION
  395.  
  396.  
  397.  
  398. '** Function DoesInfSectionExist
  399. '**
  400. '** Determines if the specified INF file section exists.  This is necessary
  401. '** since some of setup functions die if the section does not exist.
  402. '**
  403. '*****************************************************************************
  404. FUNCTION DoesInfSectionExist (szsect$) STATIC AS INTEGER
  405.     MakeListFromSectionKeys "__test_list", szsect$
  406.     listlen% = GetListLength("__test_list")
  407.     SetSymbolValue "__test_list", ""
  408.  
  409.     DoesInfSectionExist = listlen%
  410. END FUNCTION
  411.  
  412.  
  413. '**
  414. '** Purpose:
  415. '**     Builds the copy list and performs all installation operations.
  416. '** Arguments:
  417. '**     none.
  418. '** Returns:
  419. '**     none.
  420. '*****************************************************************************
  421. SUB Install STATIC
  422.     '** Stamp SETUP.INI with the user name and organization.
  423.     '*************************************************************************
  424.     IF stamped% = 0 THEN
  425.         sz$ = MakePath(srcdir$, "SETUP.INI")
  426.  
  427.         IF IsFileWritable(sz$) = 1 THEN
  428.             CreateIniKeyValue sz$, "UserInfo", "UserName", username$, cmoNone
  429.             CreateIniKeyValue sz$, "UserInfo", "UserOrg", userorg, cmoNone
  430.         END IF
  431.     END IF
  432.  
  433.  
  434.     '** Create the destination directory.
  435.     '*************************************************************************
  436.     CreateDir dest$, cmoNone
  437.  
  438. '$IFDEF DEBUG
  439.     OpenLogFile MakePath(dest$, "LOGFILE.TXT"), 0
  440.     WriteToLogFile ""
  441.     WriteToLogFile "  User chose as destination directory: '" + dest$ + "'"
  442.     WriteToLogFile "  Source directory: '" + srcdir$ + "'"
  443.     WriteToLogFile ""
  444.     WriteToLogFile "May have had to create the directory: " + dest$
  445.     WriteToLogFile ""
  446. '$ENDIF ''DEBUG
  447.  
  448.  
  449.     '** Build the copy list and copy the files.
  450.     '*************************************************************************
  451.     AddSectionFilesToCopyList APPEXE$, srcdir$, dest$
  452.     AddSectionFilesToCopyList APPDLL$, srcdir$, dest$
  453.  
  454.  
  455.     '** Add the screen saver SCR file to the copylist only in Windows
  456.     '** version 3.1 and newer, and -not- for the 3M version.
  457.     '*************************************************************************
  458. '$IFNDEF    SETUP_3M
  459.     IF (GetWindowsMajorVersion() > 3) OR (GetWindowsMinorVersion() >= 10) THEN
  460.         sz$ = GetSectionKeyFilename(SYSFILES$, "CTL3D")
  461.         sz$ = MakePath(GetWindowsSysDir(), sz$)
  462.         AddSpecialFileToCopyList SYSFILES$, "CTL3D", srcdir$, sz$
  463.     END IF
  464. '$ENDIF ''SETUP_3M
  465.  
  466. '$IFDEF DEBUG
  467.     '** mode% = SetCopyMode(0)  '** disables actual copy
  468.     DumpCopyList MakePath(dest$, "copylist.txt")
  469. '$ENDIF ''DEBUG
  470.  
  471.     '** Verify that the user has enough space to copy all files in the copy
  472.     '** list.  If not, just let them know and terminate the installation.
  473.     '*************************************************************************
  474.     needed& = GetCopyListCost("", "", "")
  475.  
  476.     IF needed& > 0 THEN
  477.     NEEDSPACE:
  478.         sz$ = UIStartDlg(CUIDLL$, TOOBIG, "FInfo0DlgProc", 0, "")
  479.  
  480.         IF sz$ = "REACTIVATE" THEN
  481.             GOTO NEEDSPACE
  482.         ELSE
  483.             UIPopAll
  484.             ERROR STFQUIT
  485.         END IF
  486.     END IF
  487.  
  488.  
  489.     '** OK, now really copy the files.
  490.     '*************************************************************************
  491.     CopyFilesInCopyList
  492.  
  493.  
  494.     '** Stamp the EXE with the username and org.
  495.     '*************************************************************************
  496.     sz$ = MakePath(dest$, GetSectionKeyFilename(APPEXE$, APPLICATION$))
  497.     ReplaceResString sz$, ID_USERNAME, username$
  498.     ReplaceResString sz$, ID_USERORG,  userorg$
  499.     ReplaceResString sz$, ID_NUMBER, serialno$
  500.  
  501.  
  502.     '** Stamp INIFILE with the user name and organization.
  503.     '*************************************************************************
  504.     sz$ = MakePath(dest$, GetSectionKeyFilename(APPDLL$, INIFILE$))
  505.     CreateIniKeyValue sz$, "User", "User", username$, cmoNone
  506.     CreateIniKeyValue sz$, "User", "Organization", userorg, cmoNone
  507.  
  508.  
  509.     CreateProgmanGroup PROGMANGRPNAME$, "", cmoNone
  510.     ShowProgmanGroup   PROGMANGRPNAME$,  1, cmoNone
  511.     CreateProgmanItem  PROGMANGRPNAME$, APPITEMNAME$, MakePath(dest$, GetSectionKeyFilename(APPEXE$, APPLICATION$)), "", cmoOverwrite
  512.  
  513. '$IFDEF DEBUG
  514.     CloseLogFile
  515. '$ENDIF ''DEBUG
  516.  
  517. END SUB
  518.  
  519.  
  520.  
  521. '**
  522. '** Purpose:
  523. '**     Appends a file name to the end of a directory path,
  524. '**     inserting a backslash character as needed.
  525. '** Arguments:
  526. '**     szDir$  - full directory path (with optional ending "\")
  527. '**     szFile$ - filename to append to directory
  528. '** Returns:
  529. '**     Resulting fully qualified path name.
  530. '*****************************************************************************
  531. FUNCTION MakePath (szDir$, szFile$) STATIC AS STRING
  532.     IF szDir$ = "" THEN
  533.         MakePath = szFile$
  534.     ELSEIF szFile$ = "" THEN
  535.         MakePath = szDir$
  536.     ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
  537.         MakePath = szDir$ + szFile$
  538.     ELSE
  539.         MakePath = szDir$ + "\" + szFile$
  540.     END IF
  541. END FUNCTION
  542.