home *** CD-ROM | disk | FTP | other *** search
/ Computer Life 1996 January / Computer Life January 1996.iso / slagoon / disk1 / lagoon.ms_ / lagoon.bin
Encoding:
Text File  |  1995-10-17  |  10.1 KB  |  403 lines

  1. '' ---------------------------------------------------------------------
  2. ''
  3. ''                    Sherman's Lagoon Setup
  4. ''
  5. '' ---------------------------------------------------------------------
  6.  
  7. '' '$define DEBUG  ''Define for script development/debugging
  8.  
  9. '' '$define LOGFILE
  10.  
  11. '' ---------------------------------------------------------------------
  12.  
  13. '$include 'setupapi.inc'
  14. '$include 'msdetect.inc'
  15.  
  16. '' ---------------------------------------------------------------------
  17.  
  18. '' Resource ID's
  19. CONST IDICN_SETUP         = 6000
  20. CONST IDBMP_LOGO          = 6100
  21.  
  22. '' Custom Dialog IDs
  23. CONST IDDLG_WELCOME       = 100
  24. CONST IDDLG_ASKQUIT       = 200
  25. CONST IDDLG_DESTPATH      = 300
  26. CONST IDDLG_EXITQUIT      = 400
  27. CONST IDDLG_EXITSUCCESS   = 500
  28. CONST IDDLG_NODISKSPACE   = 600
  29. CONST IDDLG_SELECTOPTIONS = 700
  30. CONST IDDLG_PLEASEWAIT    = 800
  31.  
  32. '' Custom user interface dll
  33. CONST CUIDLL$ = "cui.dll"
  34.  
  35. '' ---------------------------------------------------------------------
  36.  
  37. '' Default destination directory.
  38. GLOBAL DEST$
  39.  
  40. '' Windows version value.
  41. GLOBAL WinVer%
  42.  
  43. '' List of extra costs to add per drive
  44. CONST szExtraCosts$ = "ExtraCosts"
  45. CONST szCosts$ = "Costs"
  46.  
  47. '' Options
  48. GLOBAL OptMakeDefault%
  49.  
  50. '' Section names, case sensitive: any files without a section go under "Files"
  51. CONST ProgramKey$ = "lagoon"
  52.  
  53. '' ---------------------------------------------------------------------
  54.  
  55. '' Return values from GetWindowsVersion()
  56. CONST WINVER_WIN31  =  1
  57. CONST WINVER_WIN40  =  2
  58. CONST WINVER_WFW    =  3
  59. CONST WINVER_WOW    =  4
  60. CONST WINVER_NT     =  5
  61. CONST WINVER_32S    =  6
  62. CONST WINVER_ERROR  = -1
  63.  
  64. '$ifdef WIN_FILE_FUNCTIONS
  65. '' _lopen modes and flags.
  66. CONST READ                 = 0
  67. CONST WRITE                = 1
  68. CONST READ_WRITE           = 2
  69. CONST OF_SHARE_COMPAT       = 0
  70. CONST OF_SHARE_DENY_NONE   = 64
  71. CONST OF_SHARE_DENY_READ   = 48
  72. CONST OF_SHARE_DENY_WRITE  = 32
  73. CONST OF_SHARE_EXCLUSIVE   = 16
  74.  
  75. '' _llseek origin values.
  76. CONST SEEK_SET = 0
  77. CONST SEEK_CUR = 1
  78. CONST SEEK_END = 2
  79.  
  80. '' Windows functions
  81. DECLARE FUNCTION _lopen  LIB "kernel" (szFile$, iOpenMode%) AS INTEGER
  82. DECLARE FUNCTION _lcreat LIB "kernel" (szFile$, iCreateMode)  AS INTEGER
  83. DECLARE FUNCTION _lclose LIB "kernel" (handle%) AS INTEGER
  84. DECLARE FUNCTION _llseek LIB "kernel" (handle%, LONG, int) AS LONG
  85. DECLARE FUNCTION _lread  LIB "kernel" (handle%, void _huge*, UINT) AS INTEGER
  86. DECLARE FUNCTION _lwrite LIB "kernel" (handle%, const void _huge*, UINT) AS INTEGER
  87. '$endif
  88.  
  89. '' My DLL functions
  90. DECLARE FUNCTION CountSectionCost LIB "cui.dll" (uDestDisk%, section$, keylistname$) AS LONG
  91. DECLARE FUNCTION IsStringInFile LIB "cui.dll" (lpszFilename$, lpszString$) AS INTEGER
  92. DECLARE FUNCTION GetGroupList LIB "cui.dll" (lpszSymName$) AS INTEGER
  93. DECLARE FUNCTION GetWindowsVersion LIB "cui.dll" AS INTEGER
  94. ''DECLARE FUNCTION MoveFile LIB "cui.dll" (pszSrc$, pszDst$) AS INTEGER
  95.  
  96. '' Local function declarations
  97. DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
  98. DECLARE SUB BuildCopyList (_Option%)
  99. DECLARE SUB DoInstall
  100. DECLARE SUB AskQuit
  101. DECLARE FUNCTION BytesPerOption (_Opttion%) AS LONG
  102.  
  103. '' ---------------------------------------------------------------------
  104.  
  105. '' Lets do an installation ...
  106. INIT:
  107.     ON ERROR GOTO QUIT
  108.  
  109.     '' Some standard setup stuff
  110.     SetBitmap CUIDLL$, IDBMP_LOGO
  111.     SetTitle ""  ''Already displayed as a bmp in the window --> "Sherman's Lagoon Setup"
  112.  
  113.     '' Make a complete path to the INF file
  114.     szInf$ = GetSymbolValue("STF_SRCINFPATH")
  115.     IF szInf$ = "" THEN
  116.        szInf$ = GetSymbolValue("STF_CWDDIR") + "LAGOON.INF"
  117.     END IF
  118.  
  119.     '' Read in the INF file
  120.     ReadInfFile szInf$
  121.  
  122.     '' Screen savers go in either the "windows" or "windows\system" directory.
  123.     WinVer% = GetWindowsVersion()
  124.     if WinVer% = WINVER_WIN31 OR WinVer% = WINVER_WFW OR WinVer% = WINVER_32S THEN
  125.         DEST$ = GetWindowsDir()            '' Windows 3.1
  126.     ELSE
  127.         DEST$ = GetWindowsSysDir()         '' Windows 95, Windows NT
  128.     END IF
  129.  
  130.     '' Default: select all options
  131.     OptMakeDefault% = 1
  132.  
  133. '$ifdef DEBUG
  134.     i% = SetSizeCheckMode(scmOnIgnore)
  135. '$else
  136.     i% = SetSizeCheckMode(scmOnFatal)
  137. '$endif
  138.  
  139. '$ifdef LOGFILE
  140.     OpenLogFile MakePath$(DEST$, "lagoon.log"), 0
  141. '$endif
  142.  
  143. WELCOME:
  144.     sz$ = UIStartDlg(CUIDLL$, IDDLG_WELCOME, "FDlgProc", 0, "")
  145.     IF sz$ = "CONTINUE" THEN
  146.         UIPop 1
  147.     ELSEIF sz$ = "REACTIVATE" THEN
  148.         GOTO WELCOME
  149.     ELSE
  150.         ASKQUIT
  151.         GOTO WELCOME
  152.     END IF
  153.  
  154.  
  155. SELECTOPTIONS:
  156.     sz$ = UIStartDlg(CUIDLL$, IDDLG_PLEASEWAIT, "FModelessDlgProc", 0, "")
  157.  
  158.     '' Screen savers
  159.     Bytes& = BytesPerOption&(1)
  160.     SetSymbolValue "Text1", STR$(Bytes& / 1024) + "K"
  161.  
  162.     '' Check the options
  163.     SetSymbolValue "CheckItemsIn", ""
  164.     IF OptMakeDefault% = 1 THEN
  165.         AddListItem "CheckItemsIn", "ON"
  166.     ELSE
  167.         AddListItem "CheckItemsIn", "OFF"
  168.     END IF
  169.  
  170.     UIPop 1
  171.  
  172. SELECTOPTIONS1:
  173.     '' Run the dialog
  174.     sz$ = UIStartDlg(CUIDLL$, IDDLG_SELECTOPTIONS, "FDlgProc", 0, "")
  175.     IF sz$ = "CONTINUE" OR sz$ = "BACK" THEN
  176.  
  177.         '' Retrieve the options
  178.         IF GetListItem("CheckItemsOut", 1) = "ON" THEN
  179.             OptMakeDefault% = 1
  180.         ELSE
  181.             OptMakeDefault% = 0
  182.         END IF
  183.  
  184.         UIPop 1
  185.  
  186.         IF sz$ = "BACK" THEN
  187.             GOTO WELCOME
  188.         END IF
  189.  
  190.     ELSEIF sz$ = "REACTIVATE" THEN
  191.         GOTO SELECTOPTIONS        '' Recalc sizes
  192.     ELSE
  193.         ASKQUIT
  194.         GOTO SELECTOPTIONS
  195.     END IF
  196.  
  197.     '' Like it says
  198.     BuildCopyList 1
  199.  
  200. RECALC:
  201.     '' Check the amount of space needed
  202.     StillNeed& = GetCopyListCost("ExtraCostsList", "CostCostsList", "NeededCostsList")
  203.     IF StillNeed& <> 0 THEN
  204. SPACE_CHECK_DLG:
  205.         '' Space required
  206.         SetSymbolValue "Text1", STR$(StillNeed& / 1024) + "K"
  207.  
  208.         '' Space available
  209.         Bytes& = GetFreeSpaceForDrive(Mid$(DEST$, 1, 1))
  210.         SetSymbolValue "Text2", STR$(Bytes& / 1024) + "K"
  211.  
  212. SPACE_CHECK_DLG1:
  213.         sz$ = UIStartDlg(CUIDLL$, IDDLG_NODISKSPACE, "FDlgProc", 0, "")
  214.         IF sz$ = "CONTINUE" THEN
  215.             UIPop 1
  216.             GOTO SELECTOPTIONS
  217.         ELSEIF sz$ = "REACTIVATE" THEN
  218.             GOTO RECALC
  219.         ELSE
  220.             ASKQUIT
  221.             GOTO SPACE_CHECK_DLG
  222.         END IF
  223.     ENDIF
  224.  
  225.     '' Perform the installation
  226.     DoInstall
  227.  
  228.  
  229. QUIT:
  230.     IF ERR = 0 THEN
  231.         dlg% = IDDLG_EXITSUCCESS
  232.     ELSEIF ERR = STFQUIT THEN
  233.         dlg% = IDDLG_EXITQUIT
  234.     ELSE
  235.         dlg% = IDDLG_EXITQUIT
  236.     END IF
  237.  
  238. QUITL1:
  239.     sz$ = UIStartDlg(CUIDLL$, dlg%, "FDlgProc", 0, "")
  240.     IF sz$ = "REACTIVATE" THEN
  241.         GOTO QUITL1
  242.     END IF
  243.     UIPop 1
  244.  
  245.  
  246. '$ifdef LOGFILE
  247.     CloseLogFile
  248. '$endif
  249.  
  250.     END
  251.  
  252. '' ---------------------------------------------------------------------
  253.  
  254. SUB BuildCopyList (_Option%) STATIC
  255.  
  256.     SrcDir$ = GetSymbolValue("STF_SRCDIR")
  257.     ClearCopyList
  258.  
  259.     '' Add everything that has the given key string.
  260.     AddSectionFilesToCopyList ProgramKey$, SrcDir$, DEST$
  261.  
  262. END SUB
  263.  
  264. '' ---------------------------------------------------------------------
  265.  
  266. '**
  267. '** Count the number of bytes needed to copy the given
  268. '** section(s) to the users disk.
  269. '**
  270.  
  271. FUNCTION BytesPerOption (_Option%) STATIC AS LONG
  272.  
  273.     BuildCopyList 1
  274.  
  275.     '' Zero out the variables.
  276.     SetSymbolValue szExtraCosts$, ""
  277.     FOR i% = 1 TO 26 STEP 1
  278.         AddListItem szExtraCosts$, "0"
  279.     NEXT i%
  280.  
  281.     '' Add extra cost to Windows drive for ini additions.
  282.     ''szWinDrive$ = MID$(GetWindowsDir, 1, 1)
  283.     ''ndrive% = ASC(ucase$(szWinDrive$)) - ASC("A") + 1
  284.     ''ReplaceListItem szExtraCosts$, ndrive%, "1024"
  285.  
  286.     '' Compute the space
  287.     StillNeed& = GetCopyListCost(szExtraCosts$, szCosts$, "")
  288.  
  289.     '' Add up the space required
  290.     cost& = 0
  291.     FOR i% = 1 TO 26 STEP 1
  292.         TheCost& = VAL(GetListItem(szCosts$, i%))
  293.         IF TheCost& > 0 THEN
  294.             cost& = cost& + TheCost&
  295.         END IF
  296.     NEXT i%
  297.  
  298.     BytesPerOption = cost&
  299.  
  300. END FUNCTION
  301.  
  302. '' ---------------------------------------------------------------------
  303.  
  304. '**
  305. '** Purpose:
  306. '**     Builds the copy list and performs all installation operations.
  307. '** Arguments:
  308. '**     none.
  309. '** Returns:
  310. '**     none.
  311.  
  312. SUB DoInstall STATIC
  313.  
  314.     SrcDir$ = GetSymbolValue("STF_SRCDIR")
  315.     CreateDir DEST$, cmoNone
  316.  
  317.     ClearBillboardList
  318.     CopyFilesInCopyList
  319.  
  320.     sz$ = UIStartDlg(CUIDLL$, IDDLG_PLEASEWAIT, "FModelessDlgProc", 0, "")
  321.  
  322.     '' The default disk file name.
  323.     szSaverName$ = "Lagoon.scr"
  324.  
  325.     '' If under windows 95 change disk file name of the screen saver to
  326.     '' it's descriptive name.
  327.     IF WinVer% = WINVER_WIN40 THEN
  328.         szSaverName$ = "Sherman's Lagoon.scr"
  329.         szSrc$ = MakePath$(DEST$, "lagoon.scr")
  330.         szDst$ = """" + szSaverName$ + """"
  331.  
  332.         '' Rename to it's descriptive name.
  333.         SHELL "del " + """" + MakePath$(DEST$, szSaverName$) + """"
  334.         SHELL "ren " + szSrc$ + " " + szDst$
  335.  
  336.         '' Change to the 8.3 format so it appears as default screen saver.
  337.         szSaverName$ = "SHERMA~1.SCR"
  338.     END IF
  339.  
  340.     '' Make the screen saver current.
  341.     IF OptMakeDefault% <> 0 THEN
  342.         inifile$ = MakePath$(GetWindowsDir(), "system.ini")
  343.         scrsaver$ = MakePath$(DEST$, szSaverName$)
  344.         CreateIniKeyValue inifile$, "boot", "SCRNSAVE.EXE", scrsaver$, cmoOverwrite
  345.     END IF
  346.  
  347.     UIPop 1
  348.  
  349. END SUB
  350.  
  351. '' ---------------------------------------------------------------------
  352.  
  353. '**
  354. '** Purpose:
  355. '**     Appends a file name to the end of a directory path,
  356. '**     inserting a backslash character as needed.
  357. '**
  358. '** Arguments:
  359. '**     szDir$  - full directory path (with optional ending "\")
  360. '**     szFile$ - filename to append to directory
  361. '**
  362. '** Returns:
  363. '**     Resulting fully qualified path name.
  364. '**
  365.  
  366. FUNCTION MakePath (szDir$, szFile$) STATIC AS STRING
  367.  
  368.     IF szDir$ = "" THEN
  369.         MakePath = szFile$
  370.     ELSEIF szFile$ = "" THEN
  371.         MakePath = szDir$
  372.     ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
  373.         MakePath = szDir$ + szFile$
  374.     ELSE
  375.         MakePath = szDir$ + "\" + szFile$
  376.     END IF
  377.  
  378. END FUNCTION
  379.  
  380. '' ---------------------------------------------------------------------
  381.  
  382. '**
  383. '** Ask the user if they want to quit.
  384. '**
  385.  
  386. SUB AskQuit STATIC
  387.  
  388. _ASKQUIT:
  389.     sz$ = UIStartDlg(CUIDLL$, IDDLG_ASKQUIT, "FDlgProc", 0, "")
  390.  
  391.     IF sz$ = "EXIT" THEN
  392.         UIPopAll
  393.         ERROR STFQUIT
  394.     ELSEIF sz$ = "REACTIVATE" THEN
  395.         GOTO _ASKQUIT
  396.     ELSE
  397.         UIPop 1
  398.     END IF
  399.  
  400. END SUB
  401.  
  402. '' ---------------------------------------------------------------------
  403.