home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / drawcli / setup.rul < prev    next >
Encoding:
Text File  |  1998-03-27  |  17.5 KB  |  516 lines

  1. /*----------------------------------------------------------------------------*\
  2.  *
  3.  *  IIIIIII SSSSSS
  4.  *    II    SS                          InstallSHIELD (R)
  5.  *    II    SSSSSS          (c) 1990-1995, Stirling Technologies, Inc.
  6.  *    II        SS                     All Rights Reserved.
  7.  *  IIIIIII SSSSSS
  8.  *
  9.  *
  10.  *  This source code is intended as a supplement to Stirling Technologies,
  11.  *  Inc., product documentation.  Refer to your Stirling Technologies, Inc.,
  12.  *  product documentation for more detailed information.
  13.  *
  14.  *
  15.  *    File Name:  SETUP.RUL
  16.  *
  17.  *  Description:  InstallSHIELD SDK Edition MFC Sample script.
  18.  *
  19.  *
  20.  *
  21.  *
  22.  *       Author:  Stirling Technologies, Inc.       Date:  2-4-95
  23.  *
  24.  *     Comments:  This sample script installs a simple MFC application
  25.  *                to a Windows 95 or Windows NT platform.  The installation
  26.  *                includes application program files, sample files,
  27.  *                and help files. For information on using this script,
  28.  *                see the file README.TXT.
  29.  *                With minor modifications, this script can be
  30.  *                adapted to create new, customized installations.
  31.  *
  32.  *
  33.  *
  34. \*----------------------------------------------------------------------------*/
  35.  
  36.  
  37.  
  38. // Size of components.
  39. #define SIZE_REQ_SAMPLES          12000
  40. #define SIZE_REQ_HELP              32000
  41. #define SIZE_REQ_PROGRAM        1300000
  42.  
  43. #define APP_NAME                "Drawing Client"
  44. #define PROGRAM_GROUP_NAME      "YourCompany Applications"
  45. #define APPBASE_PATH            "YourCompany\\DrawCli\\"
  46. #define COMPANY_NAME            "YourCompany"
  47. #define PRODUCT_NAME            "Drawing Client"
  48. #define PRODUCT_VERSION         "2.0"
  49. #define PRODUCT_KEY             "drawcli.exe"
  50. #define UNINSTALL_KEY           "DrawCliV3"
  51. #define APPBASE_DIR95           "Program Files"
  52. #define BASE_REGISTRYNT         "Software\\Microsoft\\Windows NT\\CurrentVersion\\App Paths\\"
  53. #define BASE_REGISTRY95         "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"
  54.  
  55. #define STR_COMPLETE95 "by selecting the program icon in the Programs menu.\n\n"
  56. #define STR_COMPLETENT "by selecting the program icon in the program group.\n\n"
  57.  
  58. declare
  59.  
  60.         // Global variable declarations.
  61.         STRING  svGrp, szMsg, szFileSet, szTitle, szAppPath, szAppSharedDir;
  62.         STRING  szProgram, szTemp, svUninstLogFile, szRegKey;
  63.         STRING  svMainDirectory[ _MAX_STRING ];
  64.         BOOL    bSpaceOk, bReshowSetupType;
  65.         NUMBER  nResult, nStatusId, nType;
  66.  
  67.         BOOL    bIncludeProgram, bIncludeSamples, bIncludeHelp;
  68.         BOOL    bWinNT;
  69.  
  70.         // Function declarations.
  71.         prototype SetupScreen();
  72.         prototype CheckRequirements();
  73.         prototype CheckSpaceRequirements( number, number, number, string );
  74.         prototype CreateRegDBEntries();
  75.  
  76. program
  77.  
  78. StartHere:
  79.         Disable( BACKGROUND );
  80.  
  81.         // Set up the installation screen.
  82.         SetupScreen();
  83.  
  84.         // Set installation info., which is required for registry entries.
  85.         InstallationInfo( COMPANY_NAME, PRODUCT_NAME, PRODUCT_VERSION, PRODUCT_KEY );
  86.  
  87. // Create a Welcome dialog.
  88. WelcomeDlg:
  89.         Disable( BACKBUTTON );
  90.         Welcome( "Welcome", 0 );
  91.         Enable( BACKBUTTON );
  92.  
  93.         // Test target system proper configuration.
  94.         CheckRequirements();
  95.  
  96.         // Ask user for a destination location for the installation.
  97. GetTargetDirectory:
  98.  
  99.         svMainDirectory = TARGETDISK ^ APPBASE_DIR95 ^ APPBASE_PATH;
  100.  
  101.         szMsg = "Please enter the destination path\n"+
  102.                 "To accept the default, select > (Next)";
  103.         if ( AskDestPath( "Choose Destination Location", szMsg,
  104.                           svMainDirectory, 0 ) = BACK ) then
  105.            goto WelcomeDlg;
  106.         endif;
  107.  
  108.         szAppSharedDir = svMainDirectory ^ "System";
  109.  
  110.         nType = TYPICAL;
  111. DetermineUserSelection:
  112.  
  113.         nType = SetupType( "Selection of Installation Type", "", svMainDirectory, nType, 0 );
  114.         if ( nType = BACK ) then goto GetTargetDirectory; endif;
  115.  
  116.         bReshowSetupType = FALSE;
  117.  
  118.         switch (nType)
  119.         case TYPICAL:
  120.              bIncludeSamples  = TRUE;
  121.              bIncludeProgram  = TRUE;
  122.              bIncludeHelp = TRUE;
  123.         case COMPACT:
  124.              bIncludeProgram  = TRUE;
  125.         case CUSTOM:
  126.              SetDialogTitle( DLG_ASK_OPTIONS, "Select Components" );
  127.              bIncludeSamples  = TRUE;
  128.              bIncludeProgram  = TRUE;
  129.              bIncludeHelp     = TRUE;
  130.              szMsg = "Select the components that you wish to install.\n"+
  131.                      "If the check box is unchecked, that component will not be "+
  132.                      "installed. Click Next to continue with the installation.";
  133.  
  134.              nResult = AskOptions( NONEXCLUSIVE, szMsg,
  135.                                    "Application Program Files", bIncludeProgram,
  136.                                    "Sample Files", bIncludeSamples,
  137.                                    "On-Line Help Files", bIncludeHelp );
  138.  
  139.              if ( nResult = BACK ) then goto DetermineUserSelection; endif;
  140.  
  141.              // Handle user clicking Cancel button.
  142.              if (nResult = CANCEL) then
  143.                 if (AskYesNo( "Are you sure you would like to exit setup?", NO ) = YES) then
  144.                    abort;
  145.                 else
  146.                    bReshowSetupType = TRUE;
  147.                 endif;
  148.              endif;
  149.         endswitch;
  150.  
  151.         if (bReshowSetupType = TRUE) then goto DetermineUserSelection; endif;
  152.  
  153.         // Check to see if target system meets space requirements.
  154.         bSpaceOk = CheckSpaceRequirements( bIncludeSamples,
  155.                                            bIncludeProgram,
  156.                                            bIncludeHelp,
  157.                                            svMainDirectory );
  158.  
  159.         // Ask user to try again if not enough space available.
  160.         if (bSpaceOk = FALSE) then goto DetermineUserSelection; endif;
  161.  
  162. FolderSelection:
  163.         if ( bWinNT ) then
  164.            svGrp = PROGRAM_GROUP_NAME;
  165.  
  166.            // Allow user to modify folder name.
  167.            if ( SelectFolder( "Folder Selection", svGrp, svGrp ) = BACK ) then
  168.               goto DetermineUserSelection;
  169.            endif;
  170.         endif;
  171.  
  172. FileTransferSetup:
  173.  
  174.         // Prepare InstallSHIELD to record deinstallation information.
  175.         DeinstallStart( svMainDirectory, svUninstLogFile, UNINSTALL_KEY, 0 );
  176.         RegDBSetItem( REGDB_UNINSTALL_NAME, APP_NAME );
  177.  
  178.         // Set registry App Paths key information for the main application.
  179.         szAppPath = svMainDirectory ^ "PROGRAM" + ";" + szAppSharedDir;
  180.         RegDBSetItem( REGDB_APPPATH, szAppPath );
  181.         szProgram = svMainDirectory ^ "PROGRAM\\drawcli.exe";
  182.         RegDBSetItem( REGDB_APPPATH_DEFAULT, szProgram );
  183.  
  184.         // Define the "General" file set.
  185.         szFileSet = "General";
  186.         TARGETDIR = svMainDirectory;
  187.  
  188.         FileSetBeginDefine( szFileSet );
  189.  
  190.           SetStatusWindow( -1, "Copying program files..." );
  191.  
  192.           // Always copy README & related files, located at
  193.           // the root level in the DATA.Z library file.
  194.           CompressGet( "data.z", "*.*", COMP_NORMAL );
  195.  
  196.           if (bIncludeProgram) then
  197.              TARGETDIR = svMainDirectory ^ "PROGRAM";
  198.              CompressGet( "data.z", "program\\*.*", INCLUDE_SUBDIR );
  199.              if ( bWinNT ) then
  200.                 TARGETDIR = TARGETDISK ^ "\\WINNT35\\SYSTEM32";
  201.              else
  202.                 TARGETDIR = TARGETDISK ^ "\\WINDOWS\\SYSTEM";
  203.              endif;
  204.              CompressGet( "data.z", "shared\\*.*",
  205.                          SHAREDFILE | COMP_UPDATE_VERSION );
  206. //           CompressGet( "data.z", "shared\\*.*", COMP_NORMAL );
  207. //           TARGETDIR = szAppSharedDir;
  208. //           CompressGet( "data.z", "shared\\*.*", SHAREDFILE | COMP_NORMAL );
  209.           endif;
  210.  
  211.           if (bIncludeSamples) then
  212.              TARGETDIR = svMainDirectory ^ "SAMPLES";
  213.              CompressGet( "data.z", "samples\\*.*", INCLUDE_SUBDIR );
  214.           endif;
  215.  
  216.           if (bIncludeHelp) then
  217.              TARGETDIR = svMainDirectory ^ "HELP";
  218.              CompressGet( "data.z", "help\\*.*", INCLUDE_SUBDIR );
  219.           endif;
  220.  
  221.         FileSetEndDefine( szFileSet );
  222.  
  223. DoFileTransfer:
  224.         // Set up progress indicator and information gauge.
  225.         Enable( STATUSDLG );
  226.         StatusUpdate( ON, 50 );
  227.  
  228.         // Perform the file set.
  229.         nResult = FileSetPerformEz( szFileSet, 0 );
  230.  
  231.         switch (nResult)
  232.  
  233.         case FS_DONE: // Successful completion.
  234.  
  235.         case FS_CREATEDIR: // Create directory error.
  236.              MessageBox( "Unable to create a directory under " + TARGETDIR + "."+
  237.                          "Please check write access to this directory.", SEVERE );
  238.              abort;
  239.  
  240.         default: // Group all other errors under default label.
  241.              NumToStr( szTemp, nResult );
  242.              MessageBox( "General file transfer error."+
  243.                           "Please check your target location and try again."+
  244.                           "\n\n Error Number:"+szTemp, SEVERE );
  245.  
  246.              abort;
  247.         endswitch;
  248.  
  249. SetRegistryEntries:
  250.  
  251.         CreateRegDBEntries( );
  252.  
  253.         Delay(2);
  254.         Disable( FEEDBACK_FULL );
  255.         Disable( STATUSDLG );
  256.  
  257.         // Create program groups (folders) and icons.
  258.  
  259. CreateFolderIcons:
  260.         SetStatusWindow( 99, "Installing program icon to the Start Menu...." );
  261.  
  262.         if ( bWinNT ) then
  263.            CreateProgramFolder( svGrp );
  264.            ShowProgramFolder( svGrp, SW_SHOW );
  265.            LongPathToShortPath( svMainDirectory );
  266.            Delay(1);
  267.         endif;
  268.  
  269.         TARGETDIR = svMainDirectory;
  270.  
  271.         if (bIncludeProgram) then
  272.            szProgram = TARGETDIR ^ "PROGRAM\\DRAWCLI.EXE";
  273.            if ( bWinNT ) then
  274.               AddFolderIcon( svGrp, APP_NAME, szProgram,
  275.                              TARGETDIR ^ "PROGRAM",
  276.                              "", 0, "", REPLACE );
  277.            else
  278.               LongPathToQuote( szProgram, TRUE );
  279.               AddFolderIcon( "", APP_NAME, szProgram,
  280.                              TARGETDIR ^ "PROGRAM",
  281.                              "", 0, "", REPLACE );
  282.            endif;
  283.            Delay( 1 );
  284.         endif;
  285.  
  286.         if ( bWinNT ) then
  287.            if (bIncludeSamples) then
  288.               szProgram = TARGETDIR ^ "PROGRAM\\DRAWCLI.EXE ";
  289.               AddFolderIcon( svGrp, "Example1",
  290.                              szProgram + TARGETDIR ^ "SAMPLES\\DRAWCLI1.DRW",
  291.                              TARGETDIR ^ "SAMPLES",
  292.                              szProgram, 1, "", REPLACE );
  293.               Delay( 1 );
  294.            endif;
  295.  
  296.            if (bIncludeSamples) then
  297.               AddFolderIcon( svGrp, "Example2",
  298.                              szProgram + TARGETDIR ^ "SAMPLES\\HMM.DRW",
  299.                              TARGETDIR ^ "SAMPLES",
  300.                              szProgram, 1, "", REPLACE );
  301.               Delay( 1 );
  302.            endif;
  303.  
  304.            AddFolderIcon( svGrp, "ReadmeFile",
  305.                           "NOTEPAD.EXE " + TARGETDIR ^ "README.TXT",
  306.                           TARGETDIR,
  307.                           "", 0, "", REPLACE );
  308.            Delay( 1 );
  309.  
  310.            szProgram = WINDIR ^ "UNINST.EXE";
  311.            LongPathToShortPath( szProgram );
  312.            LongPathToShortPath( svUninstLogFile );
  313.            AddFolderIcon( svGrp, "Uninstaller",
  314.                           szProgram + " -f" + svUninstLogFile,
  315.                           WINDIR,
  316.                           "", 0, "", REPLACE );
  317.            Delay( 1 );
  318.         endif;
  319.  
  320.         // Announce setup complete.
  321.  
  322.         SetStatusWindow( 100, "Installation complete." );
  323.  
  324.         // If shared files could not be installed, then users must restart system.
  325.         if (BATCH_INSTALL = TRUE) then
  326.            szMsg = "Some files could not be installed because they are "+
  327.                    "currently in use by other programs in the system.  "+
  328.                    "To allow for proper operation of the new program you should restart"+
  329.                    "your system at this time.";
  330.           if (RebootDialog( "Restart Windows", szMsg, SYS_BOOTMACHINE ) = 0) then
  331.               // Set up shared files to be installed after system is next rebooted.
  332.               CommitSharedFiles(0);
  333.           endif;
  334.         else
  335.  
  336.            szMsg = "Setup is complete.  You may run the installed program ";
  337.            if ( bWinNT ) then
  338.               szMsg = szMsg + STR_COMPLETENT;
  339.            else
  340.               szMsg = szMsg + STR_COMPLETE95;
  341.            endif;
  342.  
  343.            MessageBeep( 0 );
  344.            MessageBox( szMsg, INFORMATION );
  345.         endif;
  346.  
  347.         exit;
  348.  
  349.  
  350. /*---------------------------------------------------------------------------*\
  351.  *
  352.  * Function:  SetupScreen
  353.  *
  354.  *  Purpose:  This function will set up the screen look.  This includes
  355.  *            colors, fonts, text to be displayed, etc.
  356.  *
  357.  *
  358.  *    Input:
  359.  *
  360.  *  Returns:
  361.  *
  362.  * Comments:
  363. \*---------------------------------------------------------------------------*/
  364.  
  365. function SetupScreen()
  366.         begin
  367.  
  368.           Enable( DEFWINDOWMODE );
  369.           Enable( INDVFILESTATUS );
  370.  
  371.           SetTitle( APP_NAME + " Setup", 36, WHITE );
  372.  
  373.           SetTitle( "Setup", 0, BACKGROUNDCAPTION ); // Caption bar text.
  374.  
  375.           Enable( BACKGROUND );
  376.  
  377.         end;
  378.  
  379.  
  380. /*---------------------------------------------------------------------------*\
  381.  *
  382.  * Function:  CheckRequirements
  383.  *
  384.  *  Purpose:  This function will check all minimum requirements for the
  385.  *            application being installed.  If any fail, then the user
  386.  *            is informed and the installation is terminated.
  387.  *
  388.  *
  389.  *    Input:
  390.  *
  391.  *  Returns:
  392.  *
  393.  * Comments:
  394. \*---------------------------------------------------------------------------*/
  395.  
  396. function CheckRequirements()
  397.           number  nvDx, nvDy;
  398.           number nvResult;
  399.           STRING szResult;
  400.         begin
  401.  
  402.           // Determine if target system uses NT or Windows 95.
  403.           GetSystemInfo( WINMAJOR, nvResult, szResult );
  404.           bWinNT = TRUE;
  405.           if (nvResult = 4) then
  406.              bWinNT = FALSE; // Running Windows 95.
  407.           endif;
  408.  
  409.           // Check screen resolution.
  410.           GetExtents( nvDx, nvDy );
  411.           if (nvDy < 480) then
  412.              MessageBox( "This program requires VGA or better resolution.", WARNING );
  413.              exit;
  414.           endif;
  415.  
  416.         end;
  417.  
  418. /*---------------------------------------------------------------------------*\
  419.  *
  420.  * Function:  CheckSpaceRequirements
  421.  *
  422.  *  Purpose:  This function will check space requirements based on the
  423.  *            elements being installed.
  424.  *
  425.  *    Input:
  426.  *
  427.  *  Returns:
  428.  *
  429.  * Comments:
  430. \*---------------------------------------------------------------------------*/
  431.  
  432. function CheckSpaceRequirements( bIncludeSamples,
  433.                                  bIncludeProgram,
  434.                                  bIncludeHelp,
  435.                                  szDir )
  436.           number  nSizeRequired;
  437.         begin
  438.  
  439.           nSizeRequired = 0;
  440.  
  441.           // Determine total size.
  442.           if (bIncludeSamples) then
  443.             nSizeRequired = nSizeRequired + SIZE_REQ_SAMPLES;
  444.           endif;
  445.  
  446.           if (bIncludeHelp) then
  447.             nSizeRequired = nSizeRequired + SIZE_REQ_HELP;
  448.           endif;
  449.  
  450.           if (bIncludeProgram) then
  451.             nSizeRequired = nSizeRequired + SIZE_REQ_PROGRAM;
  452.           endif;
  453.  
  454.           // Check space on target drive.
  455.           bSpaceOk = TRUE;
  456.           if (GetDiskSpace( szDir ) < nSizeRequired) then
  457.              szMsg = "There is not enough space available on the disk\n" +
  458.                      "'" + svMainDirectory + "' \n" +
  459.                      "Please free up some space or change the target location\n" +
  460.                      "to a different disk";
  461.              MessageBeep(0);
  462.              MessageBox( szMsg, WARNING );
  463.              bSpaceOk = FALSE;
  464.           endif;
  465.  
  466.           return bSpaceOk;
  467.         end;
  468.  
  469.  
  470. /*---------------------------------------------------------------------------*\
  471.  *
  472.  * Function:  CreateRegDBEntries
  473.  *
  474.  *  Purpose:  This function will create necessary keys and values for
  475.  *            the sample program.
  476.  *
  477.  *    Input:
  478.  *
  479.  *  Returns:
  480.  *
  481.  * Comments:
  482. \*---------------------------------------------------------------------------*/
  483.  
  484. function CreateRegDBEntries()
  485.         string szKey[255], szValue, szDemo, szProgram;
  486. begin
  487.  
  488.         RegDBSetDefaultRoot( HKEY_LOCAL_MACHINE );
  489.  
  490.         // Create PRODUCT_KEY key.
  491.         szKey = "SOFTWARE\\" + COMPANY_NAME + "\\" + PRODUCT_NAME + "\\" +
  492.                 PRODUCT_VERSION + "\\" + "DRAWCLI";
  493.         RegDBCreateKeyEx( szKey, "" );
  494.  
  495.         // The following keys are duplicates of ones that the MFC library
  496.         // will create. They're included so that they'll be registered
  497.         // in the log used by InstallSHIELD's uninstall program, causing
  498.         // them to be removed upon uninstall.
  499.  
  500.         // create key used by CWinApp::SetRegisterKey
  501.         RegDBSetDefaultRoot( HKEY_CURRENT_USER );
  502.         RegDBCreateKeyEx( "Software\\" + COMPANY_NAME, "" );
  503.  
  504.         // create keys used by CWinApp::EnableShellFileTypes
  505.         RegDBSetDefaultRoot( HKEY_CLASSES_ROOT );
  506.         RegDBCreateKeyEx( ".DRW", "" );
  507.         RegDBCreateKeyEx( "DrawCl.Document", "" );
  508.  
  509.         // register filetype icon
  510.         RegDBCreateKeyEx( "DrawCl.Document\\DefaultIcon", "" );
  511.         RegDBSetKeyValueEx( "DrawCl.Document\\DefaultIcon", 
  512.                             "", REGDB_STRING, APPBASE_DIR95 + "\\" +
  513.                             APPBASE_PATH + "\\PROGRAM\\" + PRODUCT_KEY + ",1", -1 );
  514. end;
  515.  
  516.