
//////////////////// installation declarations ///////////////////

  // ----- DLL prototypes -----


     // your DLL prototypes


  // ---- script prototypes -----

     // generated
     prototype ShowDialogs();
     prototype MoveFileData();
     prototype HandleMoveDataError( NUMBER );
     prototype ProcessBeforeDataMove();
     prototype ProcessAfterDataMove();
     prototype SetupRegistry();
     prototype SetupFolders();
     prototype CleanUpInstall();
     prototype SetupInstall();
     prototype SetupScreen();
     prototype CheckRequirements();
     prototype DialogShowSdWelcome();
     prototype DialogShowSdLicense();
     prototype DialogShowSdShowInfoList();
     prototype DialogShowSdAskDestPath();
     prototype DialogShowSdFinishReboot();
#ifndef DO_NOT_DO_NTCDENABLE
     prototype DialogCheckAdminNT();
#endif //DO_NOT_DO_NTCDENABLE

#ifdef WRITE_GODATA
prototype godata_prefix_from_target (BYREF STRING, STRING);
prototype Str (NUMBER, STRING);
prototype write_godata_sav (STRING);
#endif

     // your prototypes
#ifdef ADD_HOTBAND_TO_START
    prototype add_to_start_menu(STRING, STRING, STRING, NUMBER);
#endif //ADD_HOTBAND_TO_START



  // ----- global variables ------

     // generated
     BOOL        bWinNT, bIsShellExplorer, bInstallAborted, bIs32BitSetup;
     STRING      svDir;
     STRING      svName, svCompany, svSerial;
     STRING      svDefGroup;
     STRING      szAppPath;
     STRING      svSetupType;
     STRING      g_cd_enable_name;


     // your global variables


///////////////////////////////////////////////////////////////////////////////
//
//   MAIN PROGRAM
//
//      The setup begins here by hiding the visible setup
//      window.  This is done to allow all the titles, images, etc. to
//      be established before showing the main window.  The following
//      logic then performs the setup in a series of steps.
//
///////////////////////////////////////////////////////////////////////////////
program

    Disable( BACKGROUND );

    CheckRequirements();

    SetupInstall();

    SetupScreen();

    if (ShowDialogs()<0) goto end_install;

    if (ProcessBeforeDataMove()<0) goto end_install;

    if (MoveFileData()<0) goto end_install;

    if (ProcessAfterDataMove()<0) goto end_install;

    if (SetupRegistry()<0) goto end_install;

    if (SetupFolders()<0) goto end_install;


  end_install:

    CleanUpInstall();

     // If an unrecoverable error occurred, clean up the partial installation.
     // Otherwise, exit normally.

    if (bInstallAborted) then
        abort;
    endif;

endprogram

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function:  ShowDialogs                                                    //
//                                                                           //
//  Purpose:  This function manages the display and navigation               //
//            the standard dialogs that exist in a setup.                    //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function ShowDialogs()
    NUMBER  nResult;
 begin

    Dlg_Start:
        // beginning of dialogs label

    Dlg_CheckAdmin:
#if 0
#ifndef DO_NOT_DO_NTCDENABLE
        nResult = DialogCheckAdminNT();
        if (nResult = BACK) goto Dlg_Start;
#endif //DO_NOT_DO_NTCDENABLE
#endif

    Dlg_SdWelcome:
        nResult = DialogShowSdWelcome();
        if (nResult = BACK) goto Dlg_CheckAdmin;

    Dlg_SdLicense:
        nResult = DialogShowSdLicense();
        if (nResult = BACK) goto Dlg_SdWelcome;

//    Dlg_SdShowInfoList:
//        nResult = DialogShowSdShowInfoList();
//        if (nResult = BACK) goto Dlg_SdLicense;

    Dlg_SdAskDestPath:
        nResult = DialogShowSdAskDestPath();
        if (nResult = BACK) goto Dlg_SdLicense;

    return 0;

 end;

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: ProcessBeforeDataMove                                           //
//                                                                           //
//  Purpose: This function performs any necessary operations prior to the    //
//           actual data move operation.                                     //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function ProcessBeforeDataMove()
    STRING svLogFile;
    NUMBER nResult;
 begin

  InstallationInfo( @COMPANY_NAME, @PRODUCT_NAME, @PRODUCT_VERSION, @PRODUCT_KEY );

#if 0
  if (bIsShellExplorer && bIs32BitSetup && !bWinNT) then
     ComponentSelectItem(MEDIA, CDENABLE_COMPONENT_NAME, TRUE);
     g_cd_enable_name = CDENABLE_NAME;
  else
     ComponentSelectItem(MEDIA, CDENABLE_COMPONENT_NAME, FALSE);
  endif;

#ifndef DO_NOT_DO_NTCDENABLE
  if (bWinNT) then
     ComponentSelectItem(MEDIA, NT_CD_COMPONENT_NAME, TRUE);
     g_cd_enable_name = NT_CDENABLE_NAME;
  else
     ComponentSelectItem(MEDIA, NT_CD_COMPONENT_NAME, FALSE);
  endif;
#endif //DO_NOT_DO_NTCDENABLE
#endif

  svLogFile = UNINST_LOGFILE_NAME;

  nResult = DeinstallStart( svDir, svLogFile, @UNINST_KEY, 0 );
  if (nResult < 0) then
      MessageBox( @ERROR_UNINSTSETUP, WARNING );
  endif;

  szAppPath = TARGETDIR;

  if ((bIs32BitSetup) && (bIsShellExplorer)) then
      RegDBSetItem( REGDB_APPPATH, szAppPath );
      RegDBSetItem( REGDB_APPPATH_DEFAULT, szAppPath ^ @PRODUCT_KEY );
      RegDBSetItem( REGDB_UNINSTALL_NAME, @UNINST_DISPLAY_NAME );
  endif;


  return 0;
 end;

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function:  MoveFileData                                                   //
//                                                                           //
//  Purpose:  This function handles the data movement for                    //
//            the setup.                                                     //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function MoveFileData()
    NUMBER nResult, nDisk;
 begin

  nDisk = 1;
  SetStatusWindow( 0, "" );
  Disable( DIALOGCACHE );
  Enable( STATUS );
  StatusUpdate( ON, 100 );
  nResult = ComponentMoveData( MEDIA, nDisk, 0 );

  HandleMoveDataError( nResult );

  Disable( STATUS );

  return nResult;

 end;


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: HandleMoveDataError                                             //
//                                                                           //
//  Purpose: This function handles the error (if any) during the move data   //
//           operation.                                                      //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function HandleMoveDataError( nResult )
 begin

  switch (nResult)
  case 0:
       return 0;
  default:
       SprintfBox( SEVERE, @TITLE_CAPTIONBAR, @ERROR_MOVEDATA, nResult );
       bInstallAborted = TRUE;
       return nResult;
  endswitch;

 end;

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: ProcessAfterDataMove                                            //
//                                                                           //
//  Purpose: This function performs any necessary operations needed after    //
//           all data has been moved.                                        //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function ProcessAfterDataMove()
    STRING szReferenceFile, szCmdLine, szCommand;
    STRING szFileName, svFilesLine, svNumFiles, szSavePath;
    NUMBER nvNumFiles, nvLocation, error;

 begin

  // DeinstallSetReference specifies a file to be checked before
  // uninstallation. If the file is in use, uninstallation will not proceed.

  szReferenceFile = svDir ^ @PRODUCT_KEY;
  DeinstallSetReference( szReferenceFile );

#if 0
  if (bIsShellExplorer && bIs32BitSetup
#ifdef DO_NOT_DO_NTCDENABLE
      && !bWinNT
#endif //DO_NOT_DO_NTCDENABLE
      ) then
    szCommand = TARGETDIR ^ g_cd_enable_name;
    szCmdLine = "/ON";
    LaunchApp (szCommand, szCmdLine);
  endif;
#endif

  if (bWinNT) then
    szSavePath = SRCDIR;
    SRCDIR = WINSYSDIR;
    szFileName = "config.nt";
    error = FileGrep(szFileName, "FILES=", svFilesLine, nvLocation, CONTINUE);
    error = StrSub(svNumFiles, svFilesLine, 6, 5);
    error = StrToNum(nvNumFiles, svNumFiles);
    if (nvNumFiles < 40) then
      error = FileInsertLine(szFileName, "FILES=40", nvLocation, REPLACE);
    endif;
    SRCDIR = szSavePath;
  endif;

#ifdef WRITE_GODATA
  write_godata_sav (TARGETDIR);
#endif

  return 0;
 end;

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: SetupRegistry                                                   //
//                                                                           //
//  Purpose: This function makes the registry entries for this setup.        //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function SetupRegistry()

STRING szKey, szCommand, svUninstallKey, svValue;
NUMBER error, nvSize, nvType;

 begin

  // TODO : Add all your registry entry keys here
  //
  //
  //    RegDBCreateKeyEx, RegDBSetKeyValueEx....
  //

#if 0
  if (bIsShellExplorer && bIs32BitSetup && !bWinNT) then
    szKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
    szCommand = TARGETDIR ^ CDENABLE_NAME +  " /ON";
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
    Disable(LOGGING);
    error = RegDBCreateKeyEx(szKey, "");
    Enable(LOGGING);
    error = RegDBSetKeyValueEx(szKey, CDENABLE_KEYVALUE, REGDB_STRING, szCommand, -1);
  endif;
#endif

#if 0
#ifndef DO_NOT_DO_NTCDENABLE
  if (bWinNT) then
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
    error = RegDBGetItem(REGDB_UNINSTALL_NAME, svUninstallKey);
    szKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
            + svUninstallKey;
    error = RegDBGetKeyValueEx (szKey, "UninstallString", nvType, svValue, nvSize);
    error = RegDBSetKeyValueEx (szKey, "UninstallString", REGDB_STRING,
             svDir + "\\" + NT_CDENABLE_NAME + " /OFF " + svValue, -1);
  endif;
#endif //DO_NOT_DO_NTCDENABLE
#endif
  return 0;
 end;

///////////////////////////////////////////////////////////////////////////////
//
// Function: SetupFolders
//
//  Purpose: This function creates all the folders and shortcuts for the
//           setup.  This includes program groups and items for Windows 3.1.
//
///////////////////////////////////////////////////////////////////////////////
function SetupFolders()

STRING iconline, szCommandLine;
STRING newcommandline, folder_programs;

 begin
  if (bIsShellExplorer) then
#ifndef ADD_HOTBAND_TO_START
      szCommandLine = TARGETDIR ^ EXECUTOR_NAME;
      LongPathToQuote (szCommandLine, TRUE);

      folder_programs = FOLDER_PROGRAMS;

#ifdef START_SUBDIR
      folder_programs = folder_programs ^ "\\" ^ START_SUBDIR;
#endif

      iconline = ICON_LOCATION;
// Don't use LongPathToQuote on variable that is going to be used in
// AddFolderIcon
//      LongPathToQuote (iconline, TRUE);
      AddFolderIcon(folder_programs, START_MENU_NAME, szCommandLine,
                    TARGETDIR, iconline, ICON_NUMBER, "", REPLACE);
#ifdef START_MENU_NAME_FS
      newcommandline = szCommandLine ^ " -fullscreen";
      AddFolderIcon(folder_programs, START_MENU_NAME_FS, newcommandline,
                    TARGETDIR, iconline, ICON_NUMBER, "", REPLACE);
#endif
      ShowProgramFolder (folder_programs, SW_SHOW);
#else //ADD_HOTBAND_TO_START
      add_to_start_menu("", "executor 2.0t", ICON_LOCATION, ICON_NUMBER);
      add_to_start_menu("System:Shareware:Tex-Edit:Tex-Edit", "Tex-Edit",
                         ICON_LOCATION, ICON_NUMBER - 1);
#endif //ADD_HOTBAND_TO_START
  endif;
  return 0;
 end;

#ifdef ADD_HOTBAND_TO_START
function add_to_start_menu( szArguments, svProgname,
         szIconLocation, nvIconNumber)

STRING iconline, szCommandLine;

begin
  szCommandLine = TARGETDIR ^ EXECUTOR_NAME;
  LongPathToQuote (szCommandLine, TRUE);
  if (szArguments != "") then
    szCommandLine = szCommandLine + " \"" + szArguments + "\"";
  endif;
  iconline = szIconLocation;
// Don't use LongPathToQuote on variable that is going to be used in
// AddFolderIcon
//  LongPathToQuote (iconline, TRUE);
  AddFolderIcon(FOLDER_PROGRAMS + "\\" + "Executor", svProgname, szCommandLine,
                TARGETDIR, iconline, nvIconNumber, "", REPLACE);
end;
#endif //ADD_HOTBAND_TO_START


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: CleanUpInstall                                                  //
//                                                                           //
//  Purpose: This cleans up the setup.  Anything that should                 //
//           be released or deleted at the end of the setup should           //
//           be done here.                                                   //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function CleanUpInstall()
 begin


  if (bInstallAborted) then
      return 0;
  endif;

  DialogShowSdFinishReboot();

  if (BATCH_INSTALL) then // ensure locked files are properly written
      CommitSharedFiles(0);
  endif;

  return 0;
 end;

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: SetupInstall                                                    //
//                                                                           //
//  Purpose: This will setup the installation.  Any general initialization   //
//           needed for the installation should be performed here.           //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function SetupInstall()
 begin

  Enable( CORECOMPONENTHANDLING );

  bInstallAborted = FALSE;

  svDir = DEFAULT_TARGET_DIR;

  SdProductName( @PRODUCT_NAME );

  SdInit();

  Enable( DIALOGCACHE );

  return 0;
 end;

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function:  SetupScreen                                                    //
//                                                                           //
//  Purpose:  This function establishes  the screen look.  This includes     //
//            colors, fonts, and text to be displayed.                       //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function SetupScreen()
 begin

  Enable( FULLWINDOWMODE );
  SetTitle( @TITLE_MAIN, 24, WHITE );

  SetTitle( @TITLE_CAPTIONBAR, 0, BACKGROUNDCAPTION ); // Caption bar text.

  Enable( BACKGROUND );

  Delay( 1 );
 end;

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function:  CheckRequirements                                              //
//                                                                           //
//  Purpose:  This function checks all minimum requirements for the          //
//            application being installed.  If any fail, then the user       //
//            is informed and the setup is terminated.                       //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function CheckRequirements()
    NUMBER  nvDx, nvDy, nvResult;
    STRING  svResult;

 begin

  bWinNT           = FALSE;
  bIsShellExplorer = FALSE;

  // Check screen resolution.
  GetExtents( nvDx, nvDy );

  if (nvDy < 480) then
      MessageBox( @ERROR_VGARESOLUTION, WARNING );
      abort;
  endif;

  // set 'setup' operation mode
  bIs32BitSetup = TRUE;
  GetSystemInfo( ISTYPE, nvResult, svResult );
  if (nvResult = 16) then
      bIs32BitSetup = FALSE; // running 16-bit setup
      return 0; // no additional information required
  endif;

  // --- 32-bit testing after this point ---

  // Determine the target system's operating system.
  GetSystemInfo( OS, nvResult, svResult );

  if (nvResult =  IS_WINDOWSNT) then
      // Running Windows NT.
      bWinNT = TRUE;

      // Check to see if the shell being used is EXPLORER shell.
      if (GetSystemInfo( OSMAJOR, nvResult, svResult ) = 0) then
          if (nvResult >= 4) then
              bIsShellExplorer = TRUE;
          endif;
      endif;

  elseif (nvResult = IS_WINDOWS95 ) then
      bIsShellExplorer = TRUE;

  endif;

 end;


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: DialogShowSdWelcome                                             //
//                                                                           //
//  Purpose: This function handles the standard welcome dialog.              //
//                                                                           //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function DialogShowSdWelcome()
    NUMBER nResult;
    STRING szTitle, szMsg;
 begin

  szTitle = "";
  szMsg   = "";
  nResult = SdWelcome( szTitle, szMsg );

  return nResult;
 end;


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: DialogShowSdLicense                                             //
//                                                                           //
//  Purpose: This function displays the license agreement dialog.            //
//                                                                           //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function DialogShowSdLicense()
    NUMBER nResult;
    STRING szTitle, szMsg, szQuestion, szLicenseFile;
 begin

  szLicenseFile = SUPPORTDIR ^ "license.txt";
  szTitle    = "";
  szMsg      = "";
  szQuestion = "";
  nResult    = SdLicense( szTitle, szMsg, szQuestion, szLicenseFile );

  return nResult;
 end;


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: DialogShowSdShowInfoList                                        //
//                                                                           //
//  Purpose: This function displays the general information list dialog.     //
//                                                                           //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function DialogShowSdShowInfoList()
    NUMBER nResult;
    LIST   list;
    STRING szTitle, szMsg, szFile;
 begin

  szFile = SUPPORTDIR ^ "infolist.txt";

  list = ListCreate( STRINGLIST );
  ListReadFromFile( list, szFile );
  szTitle  = "";
  szMsg    = " ";
  nResult  = SdShowInfoList( szTitle, szMsg, list );

  ListDestroy( list );

  return nResult;
 end;


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: DialogShowSdAskDestPath                                         //
//                                                                           //
//  Purpose: This function asks the user for the destination directory.      //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function DialogShowSdAskDestPath()
    NUMBER nResult;
    STRING szTitle, szMsg;
 begin

  szTitle = "";
  szMsg   = "";
  nResult = SdAskDestPath( szTitle, szMsg, svDir, 0 );

  TARGETDIR = svDir;

  return nResult;
 end;


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Function: DialogShowSdFinishReboot                                        //
//                                                                           //
//  Purpose: This function will show the last dialog of the product.         //
//           It will allow the user to reboot and/or show some readme text.  //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
function DialogShowSdFinishReboot()
    NUMBER nResult, nDefOptions;
    STRING szTitle, szMsg1, szMsg2, szOption1, szOption2;
    NUMBER bOpt1, bOpt2;
 begin

  if (!BATCH_INSTALL) then
      bOpt1 = FALSE;
      bOpt2 = FALSE;
      szMsg1 = ENDING_TEXT;
      szMsg2 = "";
      szOption1 = "";
      szOption2 = "";
      nResult = SdFinish( szTitle, szMsg1, szMsg2, szOption1, szOption2, bOpt1, bOpt2 );
      return 0;
  endif;

  nDefOptions = SYS_BOOTMACHINE;
  szTitle     = "";
  szMsg1      = "";
  szMsg2      = "";
  nResult     = SdFinishReboot( szTitle, szMsg1, nDefOptions, szMsg2, 0 );

  return nResult;
 end;

#if 0
#ifndef DO_NOT_DO_NTCDENABLE
function DialogCheckAdminNT()
STRING szMsg;
number nResult;
begin
  if (bWinNT && !Is(USER_ADMINISTRATOR, "")) then
    szMsg = "Executor should be installed by someone in the Administrator group.\n"
        + "You don't belong to that group.  If you choose to install anyway,\n"
        + "Executor won't be able to read Macintosh CD-ROMs until it has\n"
        + "been run once by someone in the Administrator group.\n"
        + "\n"
        + "You are now encouraged to leave Setup without installing Executor, so\n"
        + "that you can log out and have an Administrator log in to install\n"
        + "Executor.  Would you like to leave Setup now without installing\n"
        + "Executor?";
    nResult = AskYesNo(szMsg, YES);
    if (nResult = YES) then
      abort;
    endif;
  endif;
  return 0;
end;
#endif //DO_NOT_DO_NTCDENABLE
#endif

#ifdef WRITE_GODATA
function godata_prefix_from_target (prefix, target)
  string disk, dir, temp;
  LIST pathlist;
  NUMBER success;
begin
  GetDisk (target, disk);
  GetDir (target, dir);
  StrSub (prefix, disk, 0, 1);
  prefix = prefix + "/:";
  pathlist = ListCreate (STRINGLIST);
  StrGetTokens (pathlist, dir, "\\");
  ListGetFirstString (pathlist, temp); // ignore first component (null)
loop:
  success = ListGetNextString (pathlist, temp);
  if (success == 0) then
    prefix = prefix + ":" + temp;
    goto loop;
  endif;
  ListDestroy (pathlist);
  prefix = prefix + ":Apps";
end;

function Str (fd, str)
  string temp;
begin
  WriteBytes (fd, str, 0, StrLength (str));
  temp = "\015";
  WriteBytes (fd, temp, 0, 1);
end;

function write_godata_sav (target)
  string godata_folder;
  string p;
  NUMBER fd;
begin
  godata_folder = target ^ "Apps\\System Folder";
  OpenFileMode(FILE_MODE_BINARY);
  OpenFile(fd, godata_folder, "godata.sav");
  godata_prefix_from_target (p, target);
  Str (fd, p + ":Demoware:StuffIt Expander\252 4.0.1 Folder:StuffIt Expander\252");
  Str (fd, p + ":Freeware:Risk!");
  Str (fd, p + ":Demoware:Ultimate Solitaire Demo");
  Str (fd, p + ":Shareware:Tex-Edit:Tex-Edit");
  Str (fd, p + "Demoware:MacBreadboard\304:MacBreadboard DEMO 1.1");
  Str (fd, p + "");
  Str (fd, p + ":Shareware:About Shareware");
  Str (fd, "");
  Str (fd, p + ":Shareware");
  Str (fd, "27 349 361 442");
  Str (fd, p + "");
  Str (fd, "36 100 418 191");
  Str (fd, p + ":Freeware");
  Str (fd, "451 97 621 193");
  Str (fd, p + ":Demoware");
  Str (fd, "40 219 494 314");
  CloseFile (fd);
end;

#endif

 // --- include script file section ---

#include "sddialog.rul"



















