home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 6 / 06.iso / b / b004 / 1.ddi / WM40.MS_ / WM40.bin
Encoding:
Text File  |  1994-04-12  |  12.7 KB  |  516 lines

  1. '**************************************************************************
  2. '*                       MSSetup Toolkit Sample 2
  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 APPHELP       = 900
  19. CONST CUSTINST       = 6200
  20. CONST TOOBIG       = 6300
  21. CONST BADPATH       = 6400
  22.  
  23. ''Bitmap ID
  24. CONST LOGO       = 1
  25.  
  26. ''File Types
  27. CONST APPFILES       = 1
  28. CONST OPTFILES1    = 2
  29. CONST OPTFILES2    = 3
  30.  
  31.  
  32. GLOBAL DEST$        ''Default destination directory.
  33. GLOBAL WINDRIVE$    ''Windows drive letter.
  34. GLOBAL OPT1OPT$     ''Option selection from OptFiles1 option dialog.
  35. GLOBAL OPT2OPT$     ''Option selection from OptFiles2 option dialog.
  36.  
  37. ''CustInst list symbol names
  38. GLOBAL APPNEEDS$    ''Option list costs per drive
  39. GLOBAL OPT1NEEDS$
  40. GLOBAL OPT2NEEDS$
  41. GLOBAL EXTRACOSTS$  ''List of extra costs to add per drive
  42. GLOBAL BIGLIST$     ''List of option files cost calc results (boolean)
  43.  
  44. ''Dialog list symbol names
  45. GLOBAL CHECKSTATES$
  46. GLOBAL STATUSTEXT$
  47. GLOBAL DRIVETEXT$
  48.  
  49.  
  50. DECLARE SUB AddOptFilesToCopyList (ftype%)
  51. DECLARE SUB RecalcOptFiles (ftype%)
  52. DECLARE SUB RecalcPath
  53. DECLARE SUB SetDriveStatus
  54. DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
  55.  
  56.  
  57.  
  58. INIT:
  59.     CUIDLL$ = "mscuistf.dll"            ''custom user interface dll
  60.     HELPPROC$ = "FHelpDlgProc"          ''Help dialog procedure
  61.  
  62.     SetBitmap CUIDLL$, LOGO
  63.     SetTitle "WinMate 4.0 Setup"
  64.  
  65.     szInf$ = GetSymbolValue("STF_SRCINFPATH")
  66.     IF szInf$ = "" THEN
  67.     szInf$ = GetSymbolValue("STF_CWDDIR") + "WM40.INF"
  68.     END IF
  69.     ReadInfFile szInf$
  70.  
  71.     WINDRIVE$ = MID$(GetWindowsDir, 1, 1)
  72.     DEST$ = WINDRIVE$ + ":\WINMATE"
  73.  
  74.     ''CustInst list symbols
  75.     CHECKSTATES$ = "CheckItemsState"
  76.     STATUSTEXT$  = "StatusItemsText"
  77.     DRIVETEXT$     = "DriveStatusText"
  78.     FOR i% = 1 TO 3 STEP 1
  79.     AddListItem CHECKSTATES$, "ON"
  80.     NEXT i%
  81.     FOR i% = 1 TO 3 STEP 1
  82.     AddListItem STATUSTEXT$, ""
  83.     NEXT i%
  84.     FOR i% = 1 TO 7 STEP 1
  85.     AddListItem DRIVETEXT$, ""
  86.     NEXT i%
  87.     ReplaceListItem DRIVETEXT$, 7, DEST$
  88.  
  89.     ''Disk cost list symbols
  90.     APPNEEDS$    = "AppNeeds"
  91.     OPT1NEEDS$    = "Opt1Needs"
  92.     OPT2NEEDS$    = "Opt2Needs"
  93.     EXTRACOSTS$ = "ExtraCosts"
  94.     BIGLIST$    = "BigList"
  95.     FOR i% = 1 TO 3 STEP 1
  96.     AddListItem BIGLIST$, ""
  97.     NEXT i%
  98.     FOR i% = 1 TO 26 STEP 1
  99.     AddListItem EXTRACOSTS$, "0"
  100.     NEXT i%
  101.  
  102.     ''File Option Variables
  103.     OPT1OPT$ = "1"
  104.     OPT2OPT$ = "1"
  105.  
  106.     RecalcPath
  107.     SetDriveStatus
  108.  
  109. '$IFDEF DEBUG
  110.     i% = SetSizeCheckMode(scmOnIgnore)      '' could use scmOff; def = scmOnFatal
  111. '$ENDIF ''DEBUG
  112.  
  113. WELCOME:
  114.     sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", APPHELP, HELPPROC$)
  115.     IF sz$ = "CONTINUE" THEN
  116.     UIPop 1
  117.     ELSE
  118.     GOSUB ASKQUIT
  119.     GOTO WELCOME
  120.     END IF
  121.  
  122.  
  123. CUSTINST:
  124.     sz$ = UIStartDlg(CUIDLL$, CUSTINST, "FCustInstDlgProc", APPHELP, HELPPROC$)
  125.  
  126.     IF sz$ = "CONTINUE" THEN
  127.     ''Install only if it will fit.
  128.     FOR i% = 1 TO 3 STEP 1
  129.         IF GetListItem(BIGLIST$, i%) <> "" THEN
  130.         GOSUB TOOBIG
  131.         GOTO CUSTINST
  132.         END IF
  133.     NEXT i%
  134.     UIPop 1
  135.     GOTO INSTALL
  136.     ELSEIF sz$ = "PATH" THEN
  137.     GOTO GETPATH
  138.     ELSEIF sz$ = "CHK1" THEN
  139.     RecalcOptFiles APPFILES
  140.     SetDriveStatus
  141.     GOTO CUSTINST
  142.     ELSEIF sz$ = "CHK2" THEN
  143.     RecalcOptFiles OPTFILES1
  144.     SetDriveStatus
  145.     GOTO CUSTINST
  146.     ELSEIF sz$ = "CHK3" THEN
  147.     RecalcOptFiles OPTFILES2
  148.     SetDriveStatus
  149.     GOTO CUSTINST
  150.     ELSEIF sz$ = "BTN2" THEN
  151.     GOTO OPTFILES1
  152.     ELSEIF sz$ = "BTN3" THEN
  153.     GOTO OPTFILES2
  154.     ELSEIF sz$ = "REACTIVATE" THEN
  155.     RecalcPath
  156.     SetDriveStatus
  157.     GOTO CUSTINST
  158.     ELSE
  159.     GOSUB ASKQUIT
  160.     GOTO CUSTINST
  161.     END IF
  162.  
  163.  
  164. INSTALL:
  165.     ClearCopyList
  166.     AddOptFilesToCopyList APPFILES
  167.     AddOptFilesToCopyList OPTFILES1
  168.     AddOptFilesToCopyList OPTFILES2
  169.     CreateDir DEST$, cmoNone
  170.     CopyFilesInCopyList
  171.  
  172.     IF GetListItem(CHECKSTATES$, OPTFILES1) = "ON" THEN
  173.     CreateIniKeyValue "Win.ini", "Desktop","Wallpaper",DEST$+"\WinMate.BMP",cmoOverwrite
  174.     CreateIniKeyValue "Win.ini", "Desktop","TileWallPaper","0",cmoOverwrite
  175.     CreateIniKeyValue "Win.ini", "Desktop","Pattern","(None)",cmoOverwrite
  176.     ini$ = ""
  177.     END IF
  178.  
  179.     IF GetListItem(CHECKSTATES$, APPFILES) = "ON" THEN
  180.     CreateProgmanGroup "WinMate 4.0", "", cmoNone
  181.     ShowProgmanGroup  "WinMate 4.0", 1, cmoNone
  182.     CreateProgmanItem "WinMate 4.0", "WinMate4.0", MakePath(DEST$,"winmate.exe"), "", cmoOverwrite
  183.     CreateProgmanItem "WinMate 4.0", "ReadMe", MakePath(DEST$,"readme.wri"), "", cmoOverwrite
  184.     CreateProgmanItem "WinMate 4.0", "Initial File",MakePath(DEST$,"winmate.ini"),"", cmoOverwrite
  185.     END IF
  186.  
  187.  
  188. QUIT:
  189.     ON ERROR GOTO ERRQUIT
  190.  
  191.     IF ERR = 0 THEN
  192.     dlg% = EXITSUCCESS
  193.     ELSEIF ERR = STFQUIT THEN
  194.     dlg% = EXITQUIT
  195.     ELSE
  196.     dlg% = EXITFAILURE
  197.     END IF
  198. QUITL1:
  199.     sz$ = UIStartDlg(CUIDLL$, dlg%, "FInfo0DlgProc", 0, "")
  200.     IF sz$ = "REACTIVATE" THEN
  201.     GOTO QUITL1
  202.     END IF
  203.     UIPop 1
  204.  
  205.     END
  206.  
  207. ERRQUIT:
  208.     i% = DoMsgBox("Setup sources were corrupted, call (01)-######!", "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
  209.     END
  210.  
  211.  
  212.  
  213. GETPATH:
  214.     SetSymbolValue "EditTextIn", DEST$
  215.     SetSymbolValue "EditFocus", "END"
  216. GETPATHL1:
  217.     sz$ = UIStartDlg(CUIDLL$, DESTPATH, "FEditDlgProc", APPHELP, HELPPROC$)
  218.  
  219.     IF sz$ = "CONTINUE" THEN
  220.     olddest$ = DEST$
  221.     DEST$ = GetSymbolValue("EditTextOut")
  222.  
  223.     ''Validate new path.
  224.     IF IsDirWritable(DEST$) = 0 THEN
  225.         GOSUB BADPATH
  226.         GOTO GETPATHL1
  227.     END IF
  228.     UIPop 1
  229.  
  230.     ''Truncate display if too long.
  231.     IF LEN(DEST$) > 23 THEN
  232.         ReplaceListItem DRIVETEXT$, 7, MID$(DEST$, 1, 23)+"..."
  233.     ELSE
  234.         ReplaceListItem DRIVETEXT$, 7, DEST$
  235.     END IF
  236.  
  237.     ''Recalc if path changed.
  238.     IF (olddest$ <> DEST$) AND (olddest$ <> DEST$+"\") AND (olddest$+"\" <> DEST$) THEN
  239.         RecalcPath
  240.         SetDriveStatus
  241.     END IF
  242.  
  243.     olddest$ = ""
  244.     GOTO CUSTINST
  245.     ELSEIF sz$ = "REACTIVATE" THEN
  246.     RecalcPath
  247.     SetDriveStatus
  248.     GOTO GETPATHL1
  249.     ELSEIF sz$ = "EXIT" THEN
  250.     GOSUB ASKQUIT
  251.     GOTO GETPATHL1
  252.     ELSE
  253.     UIPop 1
  254.     GOTO CUSTINST
  255.     END IF
  256.  
  257.  
  258.  
  259. OPTFILES1:
  260.     SetSymbolValue "RadioDefault", OPT1OPT$
  261. OPT1L1:
  262.     sz$ = UIStartDlg(CUIDLL$, OPTIONS, "FRadioDlgProc", APPHELP, HELPPROC$)
  263.     newopt$ = GetSymbolValue("ButtonChecked")
  264.  
  265.     IF sz$ = "CONTINUE" THEN
  266.     UIPop 1
  267.     IF newopt$ <> OPT1OPT$ THEN
  268.         OPT1OPT$ = newopt$
  269.         RecalcOptFiles OPTFILES1
  270.         SetDriveStatus
  271.     END IF
  272.     newopt$ = ""
  273.     GOTO CUSTINST
  274.     ELSEIF sz$ = "REACTIVATE" THEN
  275.     RecalcPath
  276.     SetDriveStatus
  277.     GOTO OPT1L1
  278.     ELSEIF sz$ = "EXIT" THEN
  279.     GOSUB ASKQUIT
  280.     GOTO OPT1L1
  281.     ELSE
  282.     UIPop 1
  283.     newopt$ = ""
  284.     GOTO CUSTINST
  285.     END IF
  286.  
  287.  
  288.  
  289. OPTFILES2:
  290.     SetSymbolValue "RadioDefault", OPT2OPT$
  291. OPT2L1:
  292.     sz$ = UIStartDlg(CUIDLL$, OPTIONS, "FRadioDlgProc", APPHELP, HELPPROC$)
  293.     newopt$ = GetSymbolValue("ButtonChecked")
  294.  
  295.     IF sz$ = "CONTINUE" THEN
  296.     UIPop 1
  297.     IF newopt$ <> OPT2OPT$ THEN
  298.         OPT2OPT$ = newopt$
  299.         RecalcOptFiles OPTFILES2
  300.         SetDriveStatus
  301.     END IF
  302.     newopt$ = ""
  303.     GOTO CUSTINST
  304.     ELSEIF sz$ = "REACTIVATE" THEN
  305.     RecalcPath
  306.     SetDriveStatus
  307.     GOTO OPT2L1
  308.     ELSEIF sz$ = "EXIT" THEN
  309.     GOSUB ASKQUIT
  310.     GOTO OPT2L1
  311.     ELSE
  312.     UIPop 1
  313.     newopt$ = ""
  314.     GOTO CUSTINST
  315.     END IF
  316.  
  317.  
  318.  
  319. TOOBIG:
  320.     sz$ = UIStartDlg(CUIDLL$, TOOBIG, "FInfo0DlgProc", 0, "")
  321.     IF sz$ = "REACTIVATE" THEN
  322.     RecalcPath
  323.     SetDriveStatus
  324.     GOTO TOOBIG
  325.     END IF
  326.     UIPop 1
  327.     RETURN
  328.  
  329.  
  330.  
  331. BADPATH:
  332.     sz$ = UIStartDlg(CUIDLL$, BADPATH, "FInfo0DlgProc", 0, "")
  333.     IF sz$ = "REACTIVATE" THEN
  334.     RecalcPath
  335.     SetDriveStatus
  336.     GOTO BADPATH
  337.     END IF
  338.     UIPop 1
  339.     RETURN
  340.  
  341.  
  342.  
  343. ASKQUIT:
  344.     sz1$ = UIStartDlg(CUIDLL$, ASKQUIT, "FQuitDlgProc", 0, "")
  345.  
  346.     IF sz1$ = "EXIT" THEN
  347.     UIPopAll
  348.     ERROR STFQUIT
  349.     ELSEIF sz1$ = "REACTIVATE" THEN
  350.     GOTO ASKQUIT
  351.     ELSE
  352.     UIPop 1
  353.     END IF
  354.     RETURN
  355.  
  356.  
  357.  
  358. '**
  359. '** Purpose:
  360. '**     Adds the specified option files to the copy list.
  361. '** Arguments:
  362. '**     ftype%  - type of files to add, one of the following:
  363. '**             APPFILES, OPTFILES1, OPTFILES2
  364. '** Returns:
  365. '**     none.
  366. '*************************************************************************
  367. SUB AddOptFilesToCopyList (ftype%) STATIC
  368.  
  369.     IF GetListItem(CHECKSTATES$, ftype%) = "ON" THEN
  370.     SrcDir$ = GetSymbolValue("STF_SRCDIR")
  371.     IF ftype% = APPFILES THEN
  372.         AddSectionFilesToCopyList "AppFiles", SrcDir$, DEST$
  373.     ELSEIF ftype% = OPTFILES1 THEN
  374.         AddSectionFilesToCopyList "Fonts", SrcDir$, MakePath(DEST$,"FONTS")
  375.     ELSEIF ftype% = OPTFILES2 THEN
  376.         AddSectionFilesToCopyList "hzbase", SrcDir$, MakePath(DEST$,"HZBASE")
  377.     END IF
  378.     SrcDir$ = ""
  379.     END IF
  380. END SUB
  381.  
  382.  
  383. '**
  384. '** Purpose:
  385. '**     Recalculates disk space for the given option files and sets
  386. '**     the status info symbol "StatusItemsText".
  387. '** Arguments:
  388. '**     ftype% - type of files to add, one of the following:
  389. '**             APPFILES, OPTFILES1, OPTFILES2
  390. '** Returns:
  391. '**     none.
  392. '*************************************************************************
  393. SUB RecalcOptFiles (ftype%) STATIC
  394.     CursorSave% = ShowWaitCursor()
  395.     ClearCopyList
  396.     AddOptFilesToCopyList ftype%
  397.  
  398.     fExtra% = 0
  399.     IF ftype% = APPFILES THEN
  400.     ListSym$ = APPNEEDS$
  401.     IF GetListItem(CHECKSTATES$, APPFILES) = "ON" THEN
  402.         ''Add extra cost to Windows drive for ini/progman, etc.
  403.         ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
  404.         ReplaceListItem EXTRACOSTS$, ndrive%, "10240"
  405.         fExtra% = 1
  406.     END IF
  407.     ELSEIF ftype% = OPTFILES1 THEN
  408.     ListSym$ = OPT1NEEDS$
  409.     ELSEIF ftype% = OPTFILES2 THEN
  410.     ListSym$ = OPT2NEEDS$
  411.     END IF
  412.  
  413.     StillNeed& = GetCopyListCost(EXTRACOSTS$, ListSym$, "")
  414.  
  415.     cost& = 0
  416.     FOR i% = 1 TO 26 STEP 1
  417.     cost&  = cost& + VAL(GetListItem(ListSym$, i%))
  418.     NEXT i%
  419.     ReplaceListItem STATUSTEXT$, ftype%, STR$(cost& / 1024) + " K"
  420.  
  421.     IF StillNeed& > 0 THEN
  422.     ReplaceListItem BIGLIST$, ftype%, "YES"
  423.     ELSE
  424.     ReplaceListItem BIGLIST$, ftype%, ""
  425.     END IF
  426.  
  427.     IF fExtra% THEN
  428.     ReplaceListItem EXTRACOSTS$, ndrive%, "0"
  429.     END IF
  430.     RestoreCursor CursorSave%
  431.     ListSym$ = ""
  432. END SUB
  433.  
  434.  
  435. '**
  436. '** Purpose:
  437. '**     Recalculates disk space and sets option status info according
  438. '**     to the current destination path.
  439. '** Arguments:
  440. '**     none.
  441. '** Returns:
  442. '**     none.
  443. '*************************************************************************
  444. SUB RecalcPath STATIC
  445.  
  446.     CursorSave% = ShowWaitCursor()
  447.  
  448.     RecalcOptFiles APPFILES
  449.     RecalcOptFiles OPTFILES1
  450.     RecalcOptFiles OPTFILES2
  451.  
  452.     RestoreCursor CursorSave%
  453. END SUB
  454.  
  455.  
  456. '**
  457. '** Purpose:
  458. '**     Sets drive status info according to latest disk space calcs.
  459. '** Arguments:
  460. '**     none.
  461. '** Returns:
  462. '**     none.
  463. '*************************************************************************
  464. SUB SetDriveStatus STATIC
  465.  
  466.     drive$ = MID$(DEST$, 1, 1)
  467.     ndrive% = ASC(ucase$(drive$)) - ASC("A") + 1
  468.     cost& = VAL(GetListItem(APPNEEDS$, ndrive%)) + VAL(GetListItem(OPT1NEEDS$, ndrive%)) + VAL(GetListItem(OPT2NEEDS$, ndrive%))
  469.     free& = GetFreeSpaceForDrive(drive$)
  470.     ReplaceListItem DRIVETEXT$, 1, drive$ + ":"
  471.     ReplaceListItem DRIVETEXT$, 2, STR$(cost& / 1024) + " K"
  472.     ReplaceListItem DRIVETEXT$, 3, STR$(free& / 1024) + " K"
  473.  
  474.     IF drive$ = WINDRIVE$ THEN
  475.     ReplaceListItem DRIVETEXT$, 4, ""
  476.     ReplaceListItem DRIVETEXT$, 5, ""
  477.     ReplaceListItem DRIVETEXT$, 6, ""
  478.     ELSE
  479.     ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
  480.     cost& = VAL(GetListItem(APPNEEDS$, ndrive%)) + VAL(GetListItem(OPT1NEEDS$, ndrive%)) + VAL(GetListItem(OPT2NEEDS$, ndrive%))
  481.     IF cost& = 0 THEN
  482.         ReplaceListItem DRIVETEXT$, 4, ""
  483.         ReplaceListItem DRIVETEXT$, 5, ""
  484.         ReplaceListItem DRIVETEXT$, 6, ""
  485.     ELSE
  486.         free& = GetFreeSpaceForDrive(WINDRIVE$)
  487.         ReplaceListItem DRIVETEXT$, 4, WINDRIVE$ + ":"
  488.         ReplaceListItem DRIVETEXT$, 5, STR$(cost& / 1024) + " K"
  489.         ReplaceListItem DRIVETEXT$, 6, STR$(free& / 1024) + " K"
  490.     END IF
  491.     END IF
  492. END SUB
  493.  
  494.  
  495. '**
  496. '** Purpose:
  497. '**     Appends a file name to the end of a directory path,
  498. '**     inserting a backslash character as needed.
  499. '** Arguments:
  500. '**     szDir$  - full directory path (with optional ending "\")
  501. '**     szFile$ - filename to append to directory
  502. '** Returns:
  503. '**     Resulting fully qualified path name.
  504. '*************************************************************************
  505. FUNCTION MakePath (szDir$, szFile$) STATIC AS STRING
  506.     IF szDir$ = "" THEN
  507.     MakePath = szFile$
  508.     ELSEIF szFile$ = "" THEN
  509.     MakePath = szDir$
  510.     ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
  511.     MakePath = szDir$ + szFile$
  512.     ELSE
  513.     MakePath = szDir$ + "\" + szFile$
  514.     END IF
  515. END FUNCTION
  516.