home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / INSTALL.C < prev    next >
C/C++ Source or Header  |  1998-05-17  |  11KB  |  351 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <conio.h>
  21. #include <stdlib.h>
  22. #include <dir.h>
  23. #include <io.h>
  24. #include <fcntl.h>
  25. #include <alloc.h>
  26. #include <dos.h>
  27. #include <string.h>
  28. #include <sys\stat.h>
  29.  
  30. #include <cxl\cxlvid.h>
  31.  
  32. #include "lsetup.h"
  33. #include "version.h"
  34.  
  35. #define OLD_SIZEOF_FILEAREA   256
  36.  
  37. int fdin, fdout = -1;
  38.  
  39. #define UNPACK    1
  40. #define MKDIR     2
  41. #define TARGET    3
  42. #define OVERWRITE 4
  43. #define UPGRADE   5
  44. #define ERASE     6
  45. #define STORED    7
  46. #define EXECUTE   8
  47. #define STAMPDATE 9
  48.  
  49. typedef struct {
  50.    short action;
  51.    short fid;
  52.    char  filename[14];
  53.    unsigned short ftime;
  54.    unsigned short fdate;
  55.    long complen;
  56. } COMPREC;
  57.  
  58. long fsize;
  59.  
  60. void proportional (void)
  61. {
  62.    unsigned m;
  63.    char filename[80];
  64.  
  65.    memset (filename, '█', 77);
  66.    m = (int)(tell (fdin) * 77L / filelength (fdin));
  67.    filename[m] = '\0';
  68.    gotoxy (3, 14);
  69.    cprintf (filename);
  70. }
  71.  
  72. #ifdef __OS2__
  73. unsigned ReadBuff (char *buff, unsigned short int *size)
  74. {
  75.    unsigned rs, m;
  76.  
  77.    rs = *size;
  78.    if (rs > fsize)
  79.       rs = (unsigned )fsize;
  80.    fsize -= rs;
  81.  
  82.    m = read (fdin, buff, rs);
  83.    proportional ();
  84.  
  85.    return (m);
  86. }
  87.  
  88. unsigned WriteBuff (char *buff, unsigned short int *size)
  89. {
  90.    return (write (fdout, buff, *size));
  91. }
  92. #else
  93. unsigned far pascal ReadBuff (char far *buff, unsigned short int far *size)
  94. {
  95.    unsigned rs, m;
  96.  
  97.    rs = *size;
  98.    if (rs > fsize)
  99.       rs = (unsigned )fsize;
  100.    fsize -= rs;
  101.  
  102.    m = read (fdin, buff, rs);
  103.    proportional ();
  104.  
  105.    return (m);
  106. }
  107.  
  108. unsigned far pascal WriteBuff (char far *buff, unsigned short int far *size)
  109. {
  110.    return (write (fdout, buff, *size));
  111. }
  112. #endif
  113.  
  114. void store_file (char *work_buff)
  115. {
  116.    unsigned short int i;
  117.    unsigned short int size = 12574;
  118.  
  119.    do {
  120.       i = ReadBuff (work_buff, &size);
  121.       WriteBuff (work_buff, &i);
  122.    } while (i == size);
  123. }
  124.  
  125. struct _configuration config;
  126.  
  127. void main (int argc, char *argv[])
  128. {
  129.    int overwrite = 1, skipupgrade = 0;
  130.    char filename[80], tdir[14];
  131.    char *WorkBuff;
  132.    long stublen = -1L;
  133.    COMPREC cr;
  134.  
  135.    if (argc);
  136.    WorkBuff = (char *)malloc(12574);
  137.  
  138.    fdin = open ("CONFIG.DAT", O_RDONLY|O_BINARY);
  139.    if (fdin != -1) {
  140.       skipupgrade = 1;
  141.       close (fdin);
  142.    }
  143.  
  144.    if ((fdin = open (argv[0], O_RDONLY|O_BINARY)) == -1)
  145.       return;
  146.  
  147.    hidecur ();
  148.    clrscr ();
  149.  
  150. //#ifdef __OS2__
  151. //   cprintf ("          LoraBBS-OS/2 v%s - The Computer-Based Information System\r\n", INSTALL_VERSION);
  152. //#else
  153. //   cprintf ("          LoraBBS-DOS v%s - The Computer-Based Information System\r\n", INSTALL_VERSION);
  154. //#endif
  155. #ifdef __OS2__
  156.    cprintf ("          LoraBBS-OS/2 v%s - The Computer-Based Information System\r\n", "2.99.41");
  157. #else
  158.    cprintf ("          LoraBBS-DOS v%s - The Computer-Based Information System\r\n", "2.99.41");
  159. #endif
  160.    cprintf ("        CopyRight (c) 1997-97 by Marco Maccaferri. All Rights Reserved\r\n");
  161.    cprintf ("────────────────────────────────────────────────────────────────────────────────");
  162.    gotoxy (1, 24);
  163.    cprintf ("────────────────────────────────────────────────────────────────────────────────");
  164.    gotoxy (30, 9);
  165.    cprintf ("SOFTWARE INSTALLATION");
  166.    gotoxy (1, 12);
  167.    cprintf ("┌──────────────────────────────────────────────────────────────────────────────┐");
  168.    cprintf ("│ 0%                                  50%                                 100% │");
  169.    cprintf ("│                                                                              │");
  170.    cprintf ("│                                                                              │");
  171.    cprintf ("└──────────────────────────────────────────────────────────────────────────────┘");
  172.  
  173.    gotoxy (3, 14);
  174.    cprintf ("▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
  175.  
  176.    lseek (fdin, filelength (fdin) - 4L, SEEK_SET);
  177.    read (fdin, &stublen, 4);
  178.  
  179.    lseek (fdin, stublen, SEEK_SET);
  180.  
  181.    for (;;) {
  182.       if (read (fdin, &cr, sizeof (COMPREC)) < sizeof (COMPREC))
  183.         break;
  184.  
  185.       if (cr.action == MKDIR) {
  186.          if (!overwrite && skipupgrade)
  187.             proportional ();
  188.          else {
  189.             gotoxy (1, 25);
  190.             sprintf (filename, "Creating directory: %s", cr.filename);
  191.             cprintf ("%-78.78s", filename);
  192.  
  193.             mkdir (cr.filename);
  194.             strcpy (tdir, cr.filename);
  195.          }
  196.       }
  197.  
  198.       else if (cr.action == EXECUTE) {
  199.          gotoxy (1, 25);
  200.          sprintf (filename, "Executing: %s", cr.filename);
  201.          cprintf ("%-78.78s", filename);
  202.  
  203.          gotoxy (1, 16);
  204.          sprintf (filename, "%s", cr.filename);
  205.          system (filename);
  206.  
  207.          gotoxy (1, 17);
  208.          cprintf ("                                                                                ");
  209.          cprintf ("                                                                                ");
  210.          cprintf ("                                                                                ");
  211.          cprintf ("                                                                                ");
  212.          cprintf ("                                                                                ");
  213.          cprintf ("                                                                                ");
  214.          cprintf ("                                                                                ");
  215.       }
  216.  
  217.       else if (cr.action == ERASE) {
  218.          _chmod (filename, 1, (_chmod (filename, 0) & ~(FA_HIDDEN|FA_RDONLY)));
  219.          unlink (cr.filename);
  220.       }
  221.  
  222.       else if (cr.action == UPGRADE)
  223.          overwrite = 1;
  224.  
  225.       else if (cr.action == OVERWRITE)
  226.          overwrite = 0;
  227.  
  228.       else if (cr.action == STORED) {
  229.          if (!overwrite && skipupgrade) {
  230.             lseek (fdin, cr.complen, SEEK_CUR);
  231.             proportional ();
  232.          }
  233.          else {
  234.             gotoxy (1, 25);
  235.             sprintf (filename, "Unpacking: %s", cr.filename);
  236.             cprintf ("%-78.78s", filename);
  237.  
  238.             sprintf (filename, "%s\\%s", tdir, cr.filename);
  239.             _chmod (filename, 1, (_chmod (filename, 0) & ~(FA_HIDDEN|FA_RDONLY)));
  240.             if (overwrite)
  241.                fdout = open (filename, O_WRONLY|O_BINARY|O_TRUNC|O_CREAT, S_IREAD|S_IWRITE);
  242.             else
  243.                fdout = open (filename, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  244.             if (!overwrite && filelength (fdout) > 0L) {
  245.                close (fdout);
  246.                lseek (fdin, cr.complen, SEEK_CUR);
  247.                proportional ();
  248.                continue;
  249.             }
  250.             fsize = cr.complen;
  251.             store_file (WorkBuff);
  252.  
  253.             _dos_setftime (fdout, cr.fdate, cr.ftime);
  254.             close (fdout);
  255.          }
  256.       }
  257.  
  258. /*
  259.       else if (cr.action == UNPACK) {
  260. #ifndef __OS2__
  261.          if (!overwrite && skipupgrade) {
  262.             lseek (fdin, cr.complen, SEEK_CUR);
  263.             proportional ();
  264.          }
  265.          else {
  266.             sprintf (filename, "%s\\%s", tdir, cr.filename);
  267.             _chmod (filename, 1, _chmod (filename, 0, 0) & ~(FA_HIDDEN|FA_RDONLY));
  268.             if (overwrite)
  269.                fdout = open (filename, O_WRONLY|O_BINARY|O_TRUNC|O_CREAT, S_IREAD|S_IWRITE);
  270.             else
  271.                fdout = open (filename, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  272.             if (!overwrite && filelength (fdout) > 0L) {
  273.                lseek (fdin, cr.complen, SEEK_CUR);
  274.                proportional ();
  275.                continue;
  276.             }
  277.             fsize = cr.complen;
  278.             explode (ReadBuff, WriteBuff, WorkBuff);
  279.  
  280.             _dos_setftime (fdout, cr.fdate, cr.ftime);
  281.             close (fdout);
  282.          }
  283. #endif
  284.       }
  285. */
  286.  
  287.       else if (cr.action == STAMPDATE) {
  288.          if (overwrite || !skipupgrade) {
  289.             sprintf (filename, "%s\\%s", tdir, cr.filename);
  290.             _chmod (filename, 1, (_chmod (filename, 0) & ~(FA_HIDDEN|FA_RDONLY)));
  291.             fdout = open (filename, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  292.             _dos_setftime (fdout, cr.fdate, cr.ftime);
  293.             close (fdout);
  294.          }
  295.       }
  296.    }
  297.  
  298.    close (fdin);
  299.    _chmod (argv[0], 1, _chmod (argv[0], 0, 0) & ~(FA_HIDDEN|FA_RDONLY));
  300.    unlink (argv[0]);
  301.  
  302. /*
  303.    i = open ("KEYFILE.DAT", O_RDONLY|O_BINARY);
  304.    if (i != -1) {
  305.       newkey = (struct _newkey *)malloc ((int)filelength (i));
  306.       read (i, newkey, (int)filelength (i));
  307.       sk = (int)filelength (i);
  308.       nk = sk  / sizeof (struct _newkey);
  309.       close (i);
  310.    }
  311.    else
  312.       sk = nk = 0;
  313.  
  314.    p = (char *)newkey;
  315.    for (i = 0; i < sk; i++) {
  316.       *p ^= 0xAA;
  317.       p++;
  318.    }
  319.  
  320.    if ((fdin = open ("CONFIG.DAT", O_RDWR|O_BINARY)) != -1) {
  321.       read (fdin, &config, sizeof (struct _configuration));
  322.       lseek (fdin, 0L, SEEK_SET);
  323.       if (config.keycode && !config.newkey_code[0]) {
  324.          for (i = 0; i < nk; i++) {
  325.             if (newkey[i].oldkey == config.keycode && !stricmp (config.sysop, newkey[i].name))
  326.                break;
  327.          }
  328.          if (i < nk) {
  329.             config.keycode = 0;
  330.             strcpy (config.newkey_code, newkey[i].newkey);
  331.             write (fdin, &config, sizeof (struct _configuration));
  332.          }
  333.       }
  334.       close (fdin);
  335.    }
  336.  
  337.    i = open ("KEYFILE.DAT", O_WRONLY|O_BINARY|O_TRUNC);
  338.    if (i != -1)
  339.       close (i);
  340.    unlink ("KEYFILE.DAT");
  341. */
  342.  
  343.    clrscr ();
  344.    gotoxy (1, 12);
  345.    printf ("Installation complete. Type LORA <─┘ to start.");
  346.  
  347.    gotoxy (1, 24);
  348.    showcur ();
  349. }
  350.  
  351.