home *** CD-ROM | disk | FTP | other *** search
/ On Hand / On_Hand_From_Softbank_1994_Release_2_Disc_2_1994.iso / 00049 / s / disk1 / fonts001.ms_ / fonts001.ms
Text File  |  1992-03-11  |  15KB  |  477 lines

  1. '**************************************************************************
  2. '*         MSSetup Script -- TrueType FontPack for Windows
  3. '**************************************************************************
  4.  
  5. '''$DEFINE DEBUG  ''Define for script development/debugging
  6.  
  7. '$INCLUDE 'setupapi.inc'
  8. '$INCLUDE 'msdetect.inc'
  9. '$INCLUDE 'mscpydis.inc'    ''System
  10. '$INCLUDE 'msttfont.inc'    
  11.  
  12. ''Boolean values
  13. CONST FALSE = 0
  14. CONST TRUE  = 1
  15.  
  16. ''Dialog ID's
  17. CONST WELCOME       = 100
  18. CONST ASKQUIT       = 200
  19. CONST DESTPATH      = 300
  20. CONST EXITFAILURE   = 400
  21. CONST EXITQUIT      = 600
  22. CONST EXITSUCCESS   = 700
  23. CONST OPTIONS       = 800
  24. CONST APPHELP       = 900
  25. CONST BADPATH       = 6400
  26. CONST FNTSLIDER     = 10000
  27.  
  28. ''SendMessage() IDs
  29. CONST WM_WININICHANGE = &H001A
  30. CONST WM_FONTCHANGE   = &H001D
  31.  
  32. ''ExitWindows() parameter
  33. CONST EW_RESTARTWINDOWS = &H42
  34.  
  35. ''Bitmap ID
  36. CONST LOGO = 1
  37.  
  38. ''Miscellaneous constants
  39. CONST REQUIREDFREESPACE  = 3145728      '' 3 Mb required hard drive free space
  40. CONST REQUIREDWINVERSION = &H030A       '' Hex value for Windows Version 3.10
  41.  
  42. CONST MAXPATH = 256                     '' Max characters in pathname
  43. CONST REQUIREMENTSTITLE$ = "Setup Failed"
  44. CONST WININI$ = "WIN.INI"
  45.  
  46. GLOBAL DEST$                            ''Default destination directory.
  47. GLOBAL CUIDLL$                          ''Dialog box resources and code
  48. GLOBAL TEMPDIR$                ''Restart directory
  49.  
  50. ''External functions
  51. DECLARE FUNCTION GetTempFileName LIB "kernel" (a%,b$,c%,d$) AS INTEGER
  52. DECLARE FUNCTION GetProfileInt LIB "kernel" (a$,b$,c%) AS INTEGER
  53. DECLARE FUNCTION SendMessage LIB "user" (a%,b%,c%,d$) AS INTEGER
  54. DECLARE FUNCTION AddFontResource LIB "gdi" (a$) AS INTEGER
  55. DECLARE FUNCTION ExitWindows LIB "user" (a&, b%) AS INTEGER
  56. DECLARE SUB DoSortList LIB "mscuistf.dll" (a$) 
  57.  
  58. ''Internal functions and subroutines
  59. DECLARE SUB CheckRequirements
  60. DECLARE SUB Install
  61. DECLARE SUB ConfirmQuit
  62. DECLARE SUB RestartWindows 
  63. DECLARE FUNCTION InstallFontIsNew (ttfName$) AS INTEGER
  64. DECLARE FUNCTION itoa (x&) AS STRING
  65. DECLARE FUNCTION VersionString (v%) AS STRING
  66. DECLARE FUNCTION GetTempDirName AS STRING
  67. DECLARE FUNCTION InstallFontsNeedsReboot AS INTEGER
  68. DECLARE FUNCTION EnableTTNeedsReboot AS INTEGER
  69.  
  70. '*************************************************************************
  71. INIT:
  72.     ''**OpenLogFile "C:\LogFile.out", 0
  73.     ''**WriteToLogFile "C:\LogFile.out: Away we go......."
  74.  
  75.     CUIDLL$ = "mscuistf.dll"            ''Custom user interface dll
  76.     HELPPROC$ = "FHelpDlgProc"          ''Help dialog procedure
  77.     DEST$ = GetWindowsSysDir()          ''Windows system directory
  78.  
  79.     SetBitmap CUIDLL$, LOGO
  80.     SetTitle "Microsoft TrueType Font Pack for Windows Setup"
  81.  
  82.     szInf$ = GetSymbolValue("STF_SRCINFPATH")
  83.     IF szInf$ = "" THEN
  84.         szInf$ = GetSymbolValue("STF_CWDDIR") + "FONTS001.INF"
  85.     END IF
  86.     ReadInfFile szInf$
  87.  
  88. WELCOME:
  89.     sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", APPHELP, HELPPROC$)
  90.     IF sz$ = "CONTINUE" THEN
  91.         UIPop 1
  92.         CheckRequirements
  93.     ELSE
  94.         ConfirmQuit
  95.         GOTO WELCOME
  96.     END IF
  97.  
  98.     Install
  99.  
  100. QUIT:
  101.     ON ERROR GOTO ERRQUIT
  102.  
  103.     IF ERR = 0 THEN
  104.         dlg% = EXITSUCCESS
  105.     ELSEIF ERR = STFQUIT THEN
  106.         dlg% = EXITQUIT
  107.     ELSE
  108.         dlg% = EXITFAILURE
  109.     END IF
  110. QUITL1:
  111.     sz$ = UIStartDlg(CUIDLL$, dlg%, "FInfo0DlgProc", 0, "")
  112.     IF sz$ = "REACTIVATE" THEN
  113.         GOTO QUITL1
  114.     END IF
  115.     UIPop 1
  116.  
  117.     END
  118.  
  119. ERRQUIT:
  120.     msg$ = "Setup sources were corrupted. "
  121.     msg$ = msg + "For assistance, contact Microsoft product support."
  122.     i% = DoMsgBox(msg$, "Setup Failed", MB_OK+MB_TASKMODAL+MB_ICONHAND)
  123.     END
  124. '*************************************************************************
  125.  
  126.  
  127. '**
  128. '** Purpose:
  129. '**     Builds the copy list and performs all installation operations.
  130. '** Arguments:
  131. '**     none.
  132. '** Returns:
  133. '**     none.
  134. '*************************************************************************
  135. SUB Install STATIC
  136.  
  137.     IF  EnableTTNeedsReboot() <> FALSE THEN
  138.     '' CreateScalableFontResource() fails work when TrueType is disabled.
  139.     '' We have changed TTEnabled in WIN.INI, but this will have no
  140.     '' effect until Windows is booted.  There is no way for us
  141.     '' to automatically restart Windows and start SETUP.EXE again, 
  142.     '' so we will have to ask the user to do it "by hand".
  143.  
  144.     caption$ = "Setup"
  145.     body$ = "Your TrueType system was disabled.  You will need to "
  146.     body$ = body$ + "quit and restart Windows to enable TrueType "
  147.     body$ = body$ + "and then run SETUP to install the TrueType "
  148.     body$ = body$ + "Font Pack."
  149.  
  150.     mbFlags% = MB_OK + MB_TASKMODAL + MB_ICONHAND
  151.     ignore% = DoMsgBox (body$, caption$, mbFlags%)
  152.     STOP
  153.     END IF
  154.  
  155. WELCOMEL1:
  156.     WHILE InitSystem(1, "", 0) = 0 
  157.         ConfirmQuit
  158.     WEND
  159.  
  160.     SrcDir$ = GetSymbolValue("STF_SRCDIR")
  161. ''''    AddSectionFilesToCopyList "Files", SrcDir$, DEST$
  162.     AddSectionFilesToCopyList "Fonts", SrcDir$, DEST$
  163.  
  164.     TEMPDIR$ = GetTempDirName()
  165.     SetRestartDir TEMPDIR$
  166.     CopyFilesInCopyList
  167.  
  168.     ignore% = InstallFontsNeedsReboot()
  169.     '' We now ignore the return code from InstallFontsNeedsReboot()
  170.     '' because SETUP properly inserts .TTF files into the restart
  171.     '' list as of version 2.018.
  172.  
  173.     IF  RestartListEmpty() <> FALSE THEN
  174.         ''**WriteToLogFile "Broadcasting msgs"
  175.         ignore% = SendMessage (-1, WM_WININICHANGED, 0, "fonts")
  176.         ignore% = SendMessage (-1, WM_FONTCHANGE, 0, "")
  177.     ELSE
  178.         RestartWindows
  179.     END IF
  180.  
  181.     ''**CloseLogFile
  182. END SUB
  183.  
  184.  
  185. '**
  186. '** Purpose:
  187. '**     Checks system for minimum requirements.
  188. '**     Aborts if minimum system requirements are not met.
  189. '*************************************************************************
  190. SUB CheckRequirements STATIC
  191.  
  192.     '' Check free space on destination (Windows) drive
  193.     freeSpace& = GetFreeSpaceForDrive (DEST$)
  194.     IF  freeSpace& < REQUIREDFREESPACE THEN
  195.         msg$ =        itoa(REQUIREDFREESPACE)
  196.         msg$ = msg$ + " bytes free space required on drive "
  197.         msg$ = msg$ + MID$(DEST$,1,1) + ":.  "
  198.         msg$ = msg$ + itoa(freeSpace&) + " bytes free."
  199.         res% = DoMsgBox (msg$, REQUIREMENTSTITLE, MB_OK)
  200.         ERROR STFQUIT
  201.     END IF
  202.  
  203.     '' Check windows Version
  204.     winVersion% = GetWindowsMajorVersion()*256 + GetWindowsMinorVersion()
  205.     IF  winVersion% < REQUIREDWINVERSION THEN
  206.         msg$ = "Windows version "
  207.         msg$ = msg$ + VersionString(REQUIREDWINVERSION)
  208.         msg$ = msg$ + " or later required. "
  209.         msg$ = msg$ + "(v" + VersionString(winVersion%) + " detected.)"
  210.         res% = DoMsgBox (msg$, REQUIREMENTSTITLE, MB_OK)
  211.         ERROR STFQUIT
  212.     END IF
  213.  
  214.     msg$ = ""
  215. END SUB
  216.  
  217. '**
  218. '** Purpose:
  219. '**     Creates a new ".FOT" TrueType font resource file,
  220. '**     and logs the file in the WIN.INI file.  
  221. '**     If there is no existing font with the same name, 
  222. '**     calls AddFontResource() to add it to GDI's font table.
  223. '**     
  224. '** Argument:
  225. '**     Name of TTF file
  226. '**     (NOT a full pathname, but relative to Windows System directory).
  227. '**
  228. '** Returns:
  229. '**     TRUE to indicate that font was not already present in the system
  230. '**     FALSE otherwise.
  231. '*************************************************************************
  232. FUNCTION InstallFontIsNew (ttfNameArg$) STATIC AS INTEGER
  233.     newFont% = FALSE
  234.  
  235.     ttfName$ = UCASE$(ttfNameArg$)
  236.     ttfPath$ = DEST$ + ttfName$
  237.     faceName$ = GetFaceName (ttfPath$)
  238.     ''**WriteToLogFile "InstallFont: " + ttfPath$ + " is " + faceName$
  239.  
  240.     IF  faceName$ <> "" THEN
  241.         SetSymbolValue "CREATING_FONT", faceName$
  242.         sz$ = UIStartDlg(CUIDLL$,FNTSLIDER,"SliderDlgProc",APPHELP,HELPPROC$)
  243.         IF sz$ <> "CONTINUE" THEN
  244.             ConfirmQuit
  245.         END IF
  246.  
  247.         section$ = "fonts"
  248.         key$ = faceName$ + " (TrueType)"
  249.  
  250.         s$ = STRING$(32,64)
  251.         if  GetProfileString (section$, key$, "", s$, 64) = 0 THEN
  252.         ''**WriteToLogFile "In WIN.INI, " + key$ + "=" + s$
  253.             newFont% = TRUE
  254.         ''**WriteToLogFile "newFont% = " + STR$(newFont%)
  255.         END IF
  256.         
  257.     ''**WriteToLogFile "CreateFOT ( " + ttfName$ + " ) = "
  258.         fotName$ = CreateFOT (ttfName$)
  259.     ''**WriteToLogFile ttfName$ + " -> " + fotName
  260.     ''**WriteToLogFile "newFont% = " + STR$(newFont%)
  261.  
  262.         IF  fotName$ <> "" THEN  
  263.             CreateIniKeyValue WININI$,section$,key$,fotName$,cmoOverwrite
  264.         ''**WriteToLogFile "Test newFont% <> FALSE ... " + STR$(newFont%)
  265.  
  266.             IF  newFont% <> FALSE  THEN
  267.             fotName$ = DEST$ + fotName$
  268.  
  269.                 ''**WriteToLogFile "AddFontResource ( " + fotName$ + " ) "
  270.                 IF  AddFontResource (fotName$) = 0  THEN
  271.             ''**WriteToLogFile "AddFontResource () = 0."
  272.                     newFont% = FALSE
  273.                 END IF
  274.             END IF 
  275.  
  276.         END IF
  277.     END IF
  278.     
  279.     
  280.     ''**WriteToLogFile ttfPath$+","+faceName$+"new="+STR$(newFont%)
  281.     ttfPath$ = ""
  282.     faceName$ = ""
  283.     key$ = ""
  284.     section$ = ""
  285.     s$ = ""
  286.     fotName$ = ""
  287.     ttfName$ = ""
  288.     InstallFontIsNew = newFont%
  289. END FUNCTION
  290.  
  291.  
  292. '**
  293. '** Purpose:
  294. '**     Generates an ASCII representation of an integer, 
  295. '**     WITHOUT leading space as prepended by STRING$().
  296. '** Argument:
  297. '**     A signed integer.
  298. '** Returns:
  299. '**     The string.
  300. '*************************************************************************
  301. FUNCTION itoa (x&) STATIC AS STRING
  302.     s$ = STR$(x&)
  303.     if  x& >= 0  THEN
  304.         s$ = MID$(s$,2,LEN(s$)-1)
  305.     END IF
  306.     itoa = s$
  307. END FUNCTION
  308.  
  309.  
  310. '**
  311. '** Purpose:
  312. '**     Generates an ASCII representation of a Windows version code.
  313. '** Argument:
  314. '**     2-byte Windows version code with major version in high order byte.
  315. '** Returns:
  316. '**     Resulting human-readble ASCII version string.
  317. '*************************************************************************
  318. FUNCTION VersionString (v%) STATIC AS STRING
  319.     VersionString = itoa(v/256) + "." + itoa(v MOD 256)
  320. END FUNCTION
  321.  
  322.  
  323. '**
  324. '** Purpose:
  325. '**     Locate the preferred temp directory (in case reboot is required.)
  326. '** Arguments:
  327. '**     none
  328. '** Returns:
  329. '**     Resulting fully qualified directory path name.
  330. '*************************************************************************
  331. FUNCTION GetTempDirName STATIC AS STRING
  332.     tmpPath$ = STRING$(32,MAXPATH)
  333.     tmpCode% = GetTempFileName (0, "zzz", 0, tmpPath$)
  334.     KILL tmpPath$
  335.  
  336.     SPLITPATH tmpPath$,tmpDrv$,tmpDir$,tmpName$,tmpExt$
  337.     if  LEN(tmpDir$) > 1 THEN
  338.         tmpDir$ = MID$(tmpDir$,1,LEN(tmpDir$)-1)
  339.     END IF 
  340.  
  341.     GetTempDirName = tmpDrv$ + tmpDir$
  342.     tmpPath$ = ""
  343.     tmpDrv$ = ""
  344.     tmpDir$ = ""
  345.     tmpName$ = ""
  346.     tmpExt$ = ""
  347. END FUNCTION
  348.  
  349.  
  350.  
  351. '**
  352. '** Purpose:
  353. '**     Asks the user if he is certain he wants to quit Setup.
  354. '**     Returns only if the user decides not to quit, otherwise esacpes
  355. '**     using ERROR handling.
  356. '*************************************************************************
  357. SUB ConfirmQuit STATIC
  358. ASKQUIT_TOP:
  359.     sz$ = UIStartDlg(CUIDLL$, ASKQUIT, "FQuitDlgProc", 0, "")
  360.  
  361.     IF sz$ = "EXIT" THEN
  362.         UIPopAll
  363.         ERROR STFQUIT
  364.     ELSEIF sz$ = "REACTIVATE" THEN
  365.         GOTO ASKQUIT_TOP
  366.     ELSE
  367.         UIPop 1
  368.     END IF
  369.  
  370.     sz$ = ""
  371. END SUB
  372.  
  373.  
  374. '**
  375. '** Purpose:
  376. '**     Sets the "TrueType enabled" flag in WIN.INI
  377. '** Arguments:
  378. '**     none
  379. '** Returns:
  380. '**     TRUE if reboot is required for the change to take effect,
  381. '**     FALSE if no change was required.
  382. '*************************************************************************
  383. FUNCTION EnableTTNeedsReboot STATIC AS INTEGER
  384.     section$ = "TrueType"
  385.     key$ = "TTEnable"
  386.  
  387.     profileValue% = GetProfileInt (section$, key$, 1)
  388.     ''**WriteToLogFile "TTEnabled = " + STR$(profileValue%)
  389.     
  390.     IF  profileValue% = 1 THEN
  391.         EnableTTNeedsReboot = FALSE
  392.     ELSE
  393.         CreateIniKeyValue WININI$,section$,key$,"1",cmoOverwrite
  394.         EnableTTNeedsReboot = TRUE
  395.     END IF
  396.  
  397.     key$ = ""
  398.     section$ = ""
  399. END FUNCTION
  400.  
  401.  
  402. '**
  403. '** Purpose:
  404. '**     Installs all fonts listed in the "[Fonts]" section of the .INF file
  405. '** Arguments:
  406. '**     none
  407. '** Returns:
  408. '**     TRUE if reboot is required (some font replaces an existing font).
  409. '**     FALSE if no reboot is required.
  410. '*************************************************************************
  411.  
  412. FUNCTION InstallFontsNeedsReboot STATIC AS INTEGER
  413.  
  414.     needRestart% = FALSE
  415.     MakeListFromSectionFilename "FONTS_LIST", "Fonts"
  416.     DoSortList "FONTS_LIST"
  417.  
  418.     listLength% = GetListLength ("FONTS_LIST")
  419.     if  listLength% > 0 THEN
  420.         FOR item% = 1 TO listLength%
  421.             fontFile$ = GetListItem("FONTS_LIST", item%)
  422.         IF  InstallFontIsNew (fontFile$) = FALSE THEN
  423.         needRestart% = TRUE
  424.         ''**WriteToLogFile "InstallFontsNeedsReboot " + fontFile$
  425.         END IF
  426.         NEXT
  427.  
  428.         SetSymbolValue "CREATING_FONT", ""
  429.         sz$ = UIStartDlg(CUIDLL$,FNTSLIDER,"SliderDlgProc",APPHELP,HELPPROC$)
  430.         UIPop 1
  431.     END IF
  432.  
  433.     ''**WriteToLogFile "InstallFontsNeedsReboot => " + STR$(needRestart%)
  434.  
  435.     InstallFontsNeedsReboot = needRestart%
  436.     fontFile$ = ""
  437.     sz$ = ""
  438. END FUNCTION
  439.  
  440.  
  441. '**
  442. '** Purpose:
  443. '**     Restarts Windows using ExitExecRestart() if there are files in
  444. '**     the GUI Setup Toolkit's Restart List, or using the ExitWindows()
  445. '**     kernel API call if the restart is necessary for other reasons.
  446. '** Arguments:
  447. '**     none
  448. '** Never returns, it either restarts windows or causes a 
  449. '**     TRUE if reboot is required (some font replaces an existing font).
  450. '**     FALSE if no reboot is required.
  451. '*************************************************************************
  452.  
  453. SUB RestartWindows STATIC
  454.     body$ = "Setup must restart Windows to complete this installation.  "
  455.  
  456.     caption$ = "Setup Complete"
  457.     complete$ = ""
  458.  
  459.     FOR i% = 1 TO 1    '' No need for "TO 2"; ExitExecRestart() has a loop.
  460.         body$ = body$ + "Press OK to restart Windows and proceed."
  461.  
  462.     ignore% = DoMsgBox (body$, caption$, MB_OK+MB_TASKMODAL+MB_ICONHAND)
  463.     ignore% = ExitExecRestart()
  464.  
  465.         body$ = "Setup cannot restart Windows.  "
  466.         body$ = body$ + "Please close all active applications. " 
  467.     NEXT
  468.  
  469.     caption$ = "Setup"
  470.     failmsg$ = "You must exit Windows and type the command _MSRSTRT"
  471.     failmsg$ = failmsg$ + " from " + TEMPDIR$
  472.     failmsg$ = failmsg$ + " to finish the installation."
  473.     ignore% = DoMsgBox (failmsg$, caption$, MB_OK+MB_TASKMODAL+MB_ICONHAND)
  474.     
  475.     END    ''Was ERROR STFQUIT, but that is too verbose.
  476. END SUB
  477.