home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / PLOT / SURFUTI3.ZIP / SURFINST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-10-09  |  13.9 KB  |  479 lines

  1. program SURFINST;
  2.  
  3. {$I DEFINES.INC}
  4. {$M 10000, 0, 20000}     { Leave memory for EXEC call }
  5.  
  6. uses crt,
  7.      dos,
  8. {$IFDEF EXTERNAL}
  9.   SURFbgi,
  10. {$ELSE}
  11.   Graph,
  12. {$ENDIF}
  13.  SurfGRAF,
  14.  SHAREDEC;
  15.  
  16. { SURFMODL automated installation program }
  17.  
  18. type  ModuleType = record
  19.         Modname: string[8];     { Module name }
  20.         Relpath: string[10];    { Default path relative to main directory }
  21.         Docopy:  boolean;       { User want to do the copy? }
  22.         Diskspace: integer;     { Approx size in Kbytes }
  23.         Descr:   string[80];    { Description of module contents }
  24.         Dirname: string[80];    { Directory to install to }
  25.       end;
  26.  
  27. const NMODULE = 8;
  28.  
  29. const modlist: array[1..NMODULE] of ModuleType = (
  30.   (Modname: 'SURFMAIN'; Relpath: ''; Docopy: TRUE; Diskspace: 555;
  31.     Descr: 'Main SURFMODL Program Files'),
  32.   (Modname: 'SURFDATA'; Relpath: ''; Docopy: TRUE; Diskspace: 373;
  33.     Descr: 'Example Data Files'),
  34.   (Modname: 'SURFDOC'; Relpath: '\DOC'; Docopy: TRUE; Diskspace: 155;
  35.     Descr: 'SURFMODL Documentation Files'),
  36.   (Modname: 'SURFSRC'; Relpath: '\SRC'; Docopy: FALSE; Diskspace: 258;
  37.     Descr: 'Source Code to SURFMODL'),
  38.   (Modname: 'SURFUTIL'; Relpath: '\SRC'; Docopy: FALSE; Diskspace: 280;
  39.     Descr: 'Source Code to SURFMODL Utilities'),
  40.   (Modname: 'SURFEMUL'; Relpath: '\EMULATT'; Docopy: FALSE; Diskspace: 22;
  41.     Descr: 'Code to Make a VaxMate Emulate an AT&T PC'),
  42.   (Modname: 'SURFIFF'; Relpath: ''; Docopy: FALSE; Diskspace: 102;
  43.     Descr: 'Executable for IFF version of SURFMODL'),
  44.   (Modname: 'SURFPRNT'; Relpath: '\PRNT'; Docopy: FALSE; Diskspace: 53;
  45.     Descr: 'Color Screen Dump Utility')
  46. );
  47.  
  48. procedure COPY_MODULE (Fromdir, Modname, Dirname: string);
  49. var Comspec: string[128]; { path to COMMAND.COM }
  50.     Cmmd: string[128];    { path to PKUNZIP }
  51.     Filename: string[128];
  52.     F: file;
  53.     ch: char;
  54.     Ready: boolean;
  55.  
  56. begin
  57.   { Check for existence of the ZIP file on the disk: }
  58.   Ready := FALSE;
  59.   Filename := Fromdir + Modname + '.ZIP';
  60.   assign (F, Filename);
  61.   repeat
  62.     {$I-}
  63.     reset (F);
  64.     {$I+}
  65.     if ioresult <> 0 then begin
  66.       writeln (chr(7), '***** Insert the ', Modname,
  67.           ' Installation Disk *****');
  68.       writeln ('Options:');
  69.       writeln ('  C - Continue');
  70.       writeln ('  S - Skip This Module');
  71.       writeln ('  A - Abort Installation');
  72.       repeat
  73.         write   ('Option: ');
  74.         ch := readkey;
  75.         ch := upcase (ch);
  76.         writeln(ch);
  77.         if (ch <> 'C') and (ch <> 'S') and (ch <> 'A') then
  78.           writeln ('Please type C, S or A.');
  79.       until (ch = 'C') or (ch = 'S') or (ch = 'A');
  80.       if (ch = 'S') then
  81.         exit
  82.       else if (ch = 'A') then begin
  83.         writeln ('Installation Aborted!');
  84.         halt(1);
  85.       end;
  86.     end else begin
  87.       Ready := TRUE;
  88.       close (F);
  89.     end;
  90.   until Ready;
  91.  
  92.   writeln ('Installing Module ', Modname, ' From ', Fromdir, ' To ', Dirname);
  93.  
  94.   { Build a command to unpack the module.  Note that we don't even have
  95.     to create the directory first, because PKUNZIP will do it with the
  96.     -d option (isn't that nice!)
  97.   }
  98.   Comspec := getenv ('COMSPEC');
  99.   Cmmd := '/C ' + Fromdir + 'PKUNZIP -o -d ' + Filename + ' ' + Dirname + '\';
  100.   writeln (Comspec, ' ', Cmmd);
  101.   exec (Comspec, Cmmd);
  102.   writeln;
  103.   writeln;
  104.  
  105. end; { COPY_MODULE }
  106.  
  107. procedure COPY_FILES;
  108. var Line: string[128];
  109.     Maindir: string[128];
  110.     Fromdir: string[128];
  111.     Modnum: integer;
  112.     ch: char;
  113.     Done: boolean;
  114.     i: integer;
  115.     F: file;
  116.     Comspec: string[128]; { path to COMMAND.COM }
  117.  
  118. begin
  119.   Maindir := 'C:\SURFMODL';
  120.   repeat
  121.     write ('What Drive is the Installation Disk in (A, B, etc.): ');
  122.     ch := readkey;
  123.     ch := upcase (ch);
  124.     writeln(ch);
  125.     if (ch < 'A') or (ch > 'Z') then
  126.       writeln ('Please enter a drive letter (A-Z).');
  127.   until (ch >= 'A') and (ch <= 'Z');
  128.  
  129.   Fromdir := ch + ':\';
  130.  
  131.   { Initialize the directory names }
  132.   for Modnum := 1 to NMODULE do
  133.     Modlist[Modnum].Dirname := Maindir + Modlist[Modnum].Relpath;
  134.  
  135.   { menu loop }
  136.   Done := FALSE;
  137.   repeat
  138.     writeln;
  139.     writeln ('              MODULE SELECTION MENU');
  140.     writeln;
  141.     writeln ('    MODULE    KBYTES  COPY?  DIRECTORY');
  142.     for Modnum := 1 to NMODULE do begin
  143.       with Modlist[Modnum] do begin
  144.         write (Modnum, ' - ', Modname);
  145.         { Pad blanks to 12 chars }
  146.         for i := 1 to (12 - length(Modname)) do
  147.           write (' ');
  148.         write (Diskspace:4, '      ');
  149.         if (Docopy) then
  150.           write ('Y')
  151.         else
  152.           write ('N');
  153.         writeln ('  ', Dirname);
  154.       end;
  155.     end;
  156.     writeln;
  157.     writeln ('Type a Module Number, or ''A'' to Abort,');
  158.     write ('  or ''S'' to Start Installation: ');
  159.     ch := readkey;
  160.     ch := upcase(ch);
  161.     writeln(ch);
  162.     if (ch = 'A') then begin
  163.       writeln ('Installation Aborted!');
  164.       halt(1);
  165.     end;
  166.     if (ch = 'S') then
  167.       Done := TRUE
  168.     else begin
  169.       Modnum := ord(ch) - 48;
  170.       if (Modnum < 1) or (Modnum > NMODULE) then
  171.         writeln ('You must type a number between 1 and ', NMODULE)
  172.       else begin
  173.         with Modlist[Modnum] do begin
  174.           writeln ('Module ', Modname, ': ', Descr);
  175.           writeln ('  Uses About ', Diskspace, ' Kbytes of Disk Space.');
  176.           repeat
  177.             write ('Do you want to install this module (Y/N)? ');
  178.             ch := readkey;
  179.             ch := upcase(ch);
  180.             writeln(ch);
  181.             if (ch <> 'Y') and (ch <> 'N') then
  182.               writeln ('Please press Y or N');
  183.           until (ch = 'Y') or (ch = 'N');
  184.           if (ch = 'Y') then begin
  185.             Docopy := TRUE;
  186.             writeln ('Destination for install is currently ', Dirname);
  187.             write ('Hit Enter to keep this destination, or type a new one: ');
  188.             readln (Line);
  189.             if (Line <> '') then
  190.               Dirname := Line;
  191.           end else
  192.             Docopy := FALSE;
  193.         end; { with }
  194.  
  195.         { If SURFMAIN is moved, everything goes with it. }
  196.         if (Modnum = 1) then begin
  197.           Maindir := Modlist[Modnum].Dirname;
  198.           for Modnum := 2 to NMODULE do
  199.             Modlist[Modnum].Dirname := Maindir + Modlist[Modnum].Relpath;
  200.         end;
  201.       end; { if Modnum }
  202.     end; { if ch }
  203.  
  204.   until Done;
  205.  
  206.   { Copy the selected modules }
  207.   for Modnum := 1 to NMODULE do begin
  208.     with Modlist[Modnum] do begin
  209.       if Docopy then
  210.         copy_module (Fromdir, Modname, Dirname);
  211.     end;
  212.   end;
  213.  
  214.   { Finally, copy the SURFINST.EXE file: }
  215.   Done := FALSE;
  216.   while not Done do begin
  217.     { Make sure the right floppy is in }
  218.     assign (F, Fromdir + 'SURFINST.EXE'); 
  219.     {$I-}
  220.     reset (F);
  221.     {$I+}
  222.     if ioresult = 0 then begin
  223.       close (F);
  224.       Done := TRUE;
  225.     end else begin
  226.       writeln ('Insert the floppy with SURFINST on it.');
  227.       write ('Press a key when ready...');
  228.       ch := readkey;
  229.     end;
  230.   end;
  231.  
  232.   { Change to the main directory before proceeding }
  233.   writeln ('CD ', Maindir);
  234.   chdir (Maindir);
  235.  
  236.   { Now make a DOS command to copy the file }
  237.   Comspec := getenv ('COMSPEC');
  238.   Line := '/C ' + 'COPY ' + Fromdir + 'SURFINST.EXE';
  239.   writeln (Comspec, ' ', Line);
  240.   exec (Comspec, Line);
  241.   writeln;
  242.   
  243.   writeln ('Files have been successfully copied.');
  244.  
  245. end; { COPY_FILES }
  246.  
  247. procedure CFG_STUFF;
  248. var Cfgfile: text;
  249.     Filename: string[80];
  250.     Filebad: boolean;
  251.     Errcode: integer;
  252.     i: integer;
  253.     ch: char;
  254.     success: boolean;
  255.  
  256. begin
  257.  
  258.   writeln ('Next we will auto-detect your graphics adapter type.');
  259.   write ('Hit ''A'' to Abort, or any other key to continue: ');
  260.   ch := readkey;
  261.   ch := upcase(ch);
  262.   writeln(ch);
  263.   if (ch = 'A') then begin
  264.     writeln ('Installation aborted.');
  265.     writeln ('You must manually create the SURFMODL.CFG file, or run');
  266.     writeln ('SURFINST again.  If you want to use SURFINST to create');
  267.     writeln ('SURFMODL.CFG but want to avoid the auto-detect, you may');
  268.     writeln ('specify the system number on the command line.');
  269.     halt(1);
  270.   end;
  271.  
  272.   { Graphics initialization: Make sure the .BGI files are already copied
  273.     over before this is done, and that we have chdir'd to that directory.
  274.   }
  275.   Grsys := -1;    { not initialized }
  276.   Textcol := 1;
  277.  
  278.   if (paramcount > 1) then begin
  279.     writeln ('usage: SURFINST [systype]');
  280.     halt(1);
  281.   end;
  282.   if (paramcount = 1) then begin
  283.     { System type specified on cmmd line, don't detect }
  284.     val (paramstr(1), Grsys, Errcode);
  285.     if (Errcode <> 0) then begin
  286.       writeln ('usage: SURFINST [systype]');
  287.       halt(1);
  288.     end;
  289.     if (Grsys < 1) or (Grsys > MAXSYS) then begin
  290.       writeln ('Illegal GRSYS: ', Grsys);
  291.       writeln ('Valid system numbers are: ');
  292.       for i := 1 to MAXSYS do
  293.         writeln (i:3, ' - ', Sys_name[i]);
  294.       halt(1);
  295.     end;
  296.   end;
  297.  
  298.   { Select the graphics adapter type }
  299.   select_sys;
  300.  
  301.   { Go into graphics mode, print a message to user }
  302.   success := true;
  303.   setgraphmode(grmode);
  304.   if (graphresult < 0) then
  305.     success := false
  306.   else begin
  307.     ngraphchar := GetMaxX div textwidth ('Z');
  308.     GXmin := 0;
  309.     GXMax := GetMaxX ;
  310.     Gymin := 0;
  311.     GYMax := GetMaxY;
  312.     Ncolors := GetMaxColor;
  313.  
  314.     { Select good default colors for system: }
  315.     if (Ncolors < 2) then begin
  316.       { Best text colors for a monochrome system }
  317.       Textcol := 1;
  318.       BGcol := 0;
  319.       Graphcol := 1;
  320.       RevVideo := TRUE;
  321.     end else if (Ncolors < 7) then begin
  322.       { Best text colors for a 4-color system }
  323.       Textcol := 2;
  324.       BGcol := 0;
  325.       Graphcol := 2;
  326.       RevVideo := FALSE;
  327.     end else begin
  328.       { Best text colors for a full-color system.  Sometimes Textcol 7
  329.         blinks in monochrome modes.
  330.       }
  331.       Textcol := 7;
  332.       BGcol := 0;
  333.       Graphcol := 2;
  334.       RevVideo := FALSE;
  335.     end;
  336.  
  337.     puttext (1, 10, 'Can You Read This (Y or N)?', Graphcol);
  338.     ch := readkey;
  339.     ch := upcase(ch);
  340.     writeln;
  341.     restorecrtmode;
  342.     if (ch <> 'Y') then
  343.       success := false;
  344.   end;
  345.  
  346.   if (not success) then begin
  347.     clrscr;
  348.     writeln ('Installation aborted due to problems with GRSYS=', Grsys,
  349.         ' GRMODE=', Grmode);
  350.     writeln ('Suggest you run SURFINST again and try a different GRSYS');
  351.     writeln ('or possibly GRMODE.');
  352.     halt(1);
  353.   end;
  354.  
  355.   { Write out the configuration file }
  356.   Filename := 'SURFMODL.CFG';
  357.   repeat
  358.     Filebad := FALSE;
  359.     assign (Cfgfile, Filename);
  360.     { Check to see if file already exists }
  361. {$I-}
  362.     reset (Cfgfile);
  363. {$I+}
  364.     if (ioresult = 0) then begin
  365.       close (Cfgfile);
  366.       write ('WARNING: ', Filename,
  367.           ' already exists.  OK to overwrite (Y/N)? ');
  368.       ch := readkey;
  369.       writeln (ch);
  370.       if (ch <> 'y') and (ch <> 'Y') then begin
  371.         writeln ('Installation aborted!');
  372.         halt(1);
  373.       end;
  374.     end;
  375.  
  376. {$I-}
  377.     rewrite (Cfgfile);
  378. {$I+}
  379.     if (ioresult <> 0) then begin
  380.       Filebad := TRUE;
  381.       writeln ('Error: Can''t create ', Filename);
  382.       writeln ('Enter alternative file name, or hit Enter to abort');
  383.       write (': ');
  384.       readln (Filename);
  385.       if (Filename = '') then
  386.         halt(1);
  387.     end;
  388.   until (not Filebad);
  389.  
  390.   writeln (Cfgfile, '* This is the SURFMODL configuration file.');
  391.   writeln (Cfgfile, 
  392.     '* It was created by SURFINST, but may be edited by the user with any');
  393.   writeln (Cfgfile, '* standard text editor.');
  394.   writeln (Cfgfile, '* The format is a command, followed by a colon, followed');
  395.   writeln (Cfgfile, '* by one or more values.');
  396.   writeln (Cfgfile, '* Any line starting with an asterisk is a comment.');
  397.   writeln (Cfgfile,
  398.       '* At the very least, it must contain entries for GRSYS and GRMODE');
  399.   writeln (Cfgfile, 'VERSION: 5');
  400.   writeln (Cfgfile, 'GRSYS: ', grsys);
  401.   writeln (Cfgfile, 'GRMODE: ', grmode);
  402.   writeln (Cfgfile, 'EYE: 100, -70, 75');
  403.   writeln (Cfgfile, 'FOCAL: 0, 0, 0');
  404.   writeln (Cfgfile, 'MAGNIFY: 1');
  405.   writeln (Cfgfile, 'VIEWTYPE: STD');
  406.   writeln (Cfgfile, 'LIGHT: 1');
  407.   writeln (Cfgfile, 'LTCOORD: 100, 30, 0');
  408.   writeln (Cfgfile, 'LTINTENS: 0.7');
  409.   writeln (Cfgfile, 'GOURAUD: 0.3');
  410.   writeln (Cfgfile, 'SHADOWING: OFF');
  411.   writeln (Cfgfile, 'AXISSHOW: OFF');
  412.   writeln (Cfgfile, 'AXISLEN: 0.2, 0.2, 0.2');
  413.   writeln (Cfgfile, 'AXISCOLOR: ', Graphcol);
  414.   writeln (Cfgfile, 'RANDOM: 0');
  415.   writeln (Cfgfile, 'BORDERS: OFF');
  416.   writeln (Cfgfile, 'TEXTCOL: ', Textcol);
  417.   writeln (Cfgfile, 'BGCOL: ', BGcol);
  418.   writeln (Cfgfile, 'GRAPHTEXT: ', Graphcol);
  419.   if RevVideo then
  420.     writeln (Cfgfile, 'REVVIDEO: ON')
  421.   else
  422.     writeln (Cfgfile, 'REVVIDEO: OFF');
  423.   writeln (Cfgfile, 'SHOWTITLE: ON');
  424.   writeln (Cfgfile, 'XYADJUST: 1.0');
  425.   close (Cfgfile);
  426.  
  427. end; { CFG_STUFF }
  428.  
  429. { Local variables for main }
  430. var Line: string[20];
  431.     Errcode: integer;
  432.     Select: integer;
  433.     Done: boolean;
  434.  
  435. begin { main }
  436.  
  437.   clrscr;
  438.   writeln ('       SURFINST: SURFMODL Automated Installation Utility');
  439.   writeln;
  440.   writeln ('       NOTE that in all prompts the value in brackets');
  441.   writeln ('       is the default, if you just hit Enter.');
  442.   writeln;
  443.   repeat
  444.     writeln ('       Options:');
  445.     writeln ('          1 - Full Installation');
  446.     writeln ('          2 - Just Update System Type in SURFMODL.CFG');
  447.     writeln ('          3 - Abort Installation');
  448.     writeln;
  449.     write ('       Selection [1]: ');
  450.     readln (Line);
  451.     Done := TRUE;
  452.     if Line = '' then
  453.       Select := 1
  454.     else begin
  455.       val (Line, Select, Errcode);
  456.       if (Errcode <> 0) or (Select < 1) or (Select > 3) then begin
  457.         writeln ('You must enter 1, 2 or 3.');
  458.         Done := FALSE;
  459.       end;
  460.     end;
  461.   until Done;
  462.  
  463.   if (Select = 3) then begin
  464.     writeln ('Installation Aborted!');
  465.     halt;
  466.   end;
  467.  
  468.   if (Select = 1) then
  469.     copy_files;
  470.  
  471.   cfg_stuff;
  472.  
  473.   if (Select = 1) then begin
  474.     writeln;
  475.     writeln ('Full installation completed.');
  476.     writeln ('For a demo of SURFMODL, type DEMO.');
  477.   end;
  478. end. { main }
  479.