home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / utils / install / install.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-24  |  3.6 KB  |  150 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <errno.h>
  5. #include <dos.h>
  6. #include <dir.h>
  7. #include <fcntl.h>
  8. #include <sys/stat.h>
  9. #include <process.h>
  10.  
  11. #include "structs.h"
  12.  
  13. char default_dir[80], *default_fptr;
  14. char install_dir[80], *install_fptr;
  15. int disk_number = -1;
  16. FileEntry *file_entries = 0;
  17.  
  18. FileEntry unzip_fe = {
  19.   1, 1, 1,
  20.   "unzip-dj.exe",
  21.   0, "Unzip",
  22.   0
  23. };
  24.  
  25. #include "ansi.h"
  26. #include "query.h"
  27. #include "select.h"
  28. #include "diskutil.h"
  29. #include "loaddat.h"
  30. #include "yesno.h"
  31. #include "unzip.h"
  32.  
  33. main(int argc, char **argv)
  34. {
  35.   long free_space;
  36.   char *cp, *cp2;
  37.   char buffer[100];
  38.   FileEntry *fe;
  39.   int i;
  40.   int auto_desire = 0;
  41.  
  42.   setbuf(stdout, 0);
  43.   ansidetect();
  44.   ansi("\033[0m");
  45.  
  46.   if (argc < 1)
  47.     exit(1);
  48.   printf("Executing %s\n", argv[0]);
  49.  
  50.   strcpy(default_dir, argv[0]);
  51.   cp = default_dir;
  52.   for(cp2 = default_dir; *cp2; cp2++)
  53.     if (*cp2 == '/' || *cp2 == '\\' || *cp2 == ':')
  54.       cp = cp2+1;
  55.   default_fptr = cp;
  56.  
  57.   load_data_file();
  58.   sort_data_file(1);
  59.   show_data_file();
  60.  
  61.   do {
  62.     query("Directory to install in : ", install_dir, "c:/djgpp");
  63.     free_space = show_free_space();
  64.     
  65.     if (yesno("Use this disk/directory") == 'n')
  66.       continue;
  67.   
  68.     if (mmkdir(install_dir))
  69.       printf("Cannot create that directory.  Please specify another.\n");
  70.     else
  71.       break;
  72.   } while (1);
  73.  
  74.   while (1)
  75.   {
  76.     long space_used = 0;
  77.     for (fe=file_entries; fe; fe=fe->next)
  78.     {
  79.       printf("\nModule: %s%s%s   size: %s%s   ",
  80.              ansibold, fe->file_name, ansinorm,
  81.              ansibold, kb(fe->size_uncompressed), ansibold);
  82.       ansi("\033[32m");
  83.       printf("%s%s\n", fe->description, ansinorm);
  84.       if (fe->mandatory)
  85.       {
  86.         ansi("\033[1;33m");
  87.         printf("This module is mandatory.%s\n", ansinorm);
  88.         fe->desired = 1;
  89.       }
  90.       else if (space_used + fe->size_uncompressed > free_space)
  91.       {
  92.         ansi("\033[1;34m");
  93.         printf("There is not enough space for this module.%s\n", ansinorm);
  94.         fe->desired = 2;
  95.       }
  96.       else
  97.       {
  98.         if (auto_desire)
  99.           fe->desired = auto_desire;
  100.         else
  101.           fe->desired = select(fe->desired, "", "Install", "Skip", "Install remainder", "Skip remainder", 0);
  102.         if (fe->desired == 3)
  103.         {
  104.           fe->desired = 1;
  105.           auto_desire = 1;
  106.         }
  107.         if (fe->desired == 4)
  108.         {
  109.           fe->desired = 2;
  110.           auto_desire = 2;
  111.         }
  112.       }
  113.       if (fe->desired == 1)
  114.         space_used += fe->size_uncompressed;
  115.       if (space_used > free_space)
  116.       {
  117.         printf("\n%sThere is not enough disk space on this drive to install\n", ansibold);
  118.         printf("The mandatory parts of djgpp.  Please free up space or\n");
  119.         printf("install on a different drive.%s\n", ansinorm);
  120.         exit(1);
  121.       }
  122.       printf("You have used %s%s%s of space. ", ansibold, kb(space_used), ansinorm);
  123.       printf("There is %s%s%s of space remaining.\n", ansibold, kb(free_space - space_used), ansinorm);
  124.     }
  125.     show_data_file();
  126.     if (yesno("Would you like to change anything") == 'n')
  127.       break;
  128.     auto_desire = 0;
  129.   }
  130.  
  131.   sort_data_file(0);
  132.  
  133.   *install_fptr = 0;
  134.   if (install_dir[1] == ':')
  135.     setdisk((install_dir[0]& 0x1f) - 1);
  136.   if (chdir(install_dir))
  137.   {
  138.     printf("can't change directories to %s\n", install_dir);
  139.     exit(1);
  140.   }
  141.  
  142.   unzip(&unzip_fe, 0);
  143.  
  144.   for (fe=file_entries; fe; fe=fe->next)
  145.     if (fe->desired == 1)
  146.       unzip(fe, 1);
  147.   remove("unzip-dj.exe");
  148.   return 0;
  149. }
  150.