home *** CD-ROM | disk | FTP | other *** search
/ Hot Shareware 35 / hot35.iso / ficheros / LC / SIMPWN93.ZIP / SIMPWIN.ZIP / INSTAL92.C < prev    next >
C/C++ Source or Header  |  1997-05-04  |  5KB  |  225 lines

  1. /* simpwin9 copyright 1995 - 1997 by bruce r. o'banion */
  2.  
  3. # include <string.h>
  4. # include <stdarg.h>
  5. # include <conio.h>
  6. # include <stdlib.h>
  7. # include <dir.h>
  8. # include <dos.h>
  9. # include <bios.h>
  10. # include <stdio.h>
  11.  
  12. # include "simpwn92.h"
  13.  
  14. int deinstall(int install_drive,char *path);
  15. int install(int install_drive,char *path);
  16.  
  17. void main(int argc,char *argv[])
  18. {
  19.     char drive[2];
  20.     int install_drive;
  21.     int error = 0;
  22.     int done = 0;
  23.     char choice[3] = "1";
  24.     char path[256];
  25.     char *temp_point;
  26.  
  27.     system("CLS");
  28.     strcpy(path,argv[1]);
  29.     if((path[0] == 0x00) | (path[2] != '\\'))
  30.     {
  31.         cprintf("Comand instal92 [drive:\\path]");
  32.         exit(1);
  33.     }
  34.     temp_point = strrchr(path,'\\');
  35.     if(temp_point[1] == 0x00)
  36.     {
  37.         temp_point[0] = 0x00;
  38.     }
  39.     install_drive = getdisk();
  40.     if(init_window(3,1,drive) != 0)
  41.     {
  42.         cprintf("Can't init SIMPWIN92 !");
  43.         exit(1);
  44.     }
  45.     simp_window(1,1,80,25,1,0,14,1,0,0,0,0,0);
  46.     write_window((80 - strlen(" HIT ANY KEY ")) / 2,25," HIT ANY KEY ");
  47.     read_text("install.scr",2);
  48.     popup_window(1,31,8,49,13,2,1,15,1,1,8,0,0,0);
  49.     write_window(3,2,"1\) Install");
  50.     write_window(3,3,"2\) Deinstall");
  51.     write_window(3,5,"Choice ?");
  52.     save_screen(0);
  53.     while(done == 0)
  54.     {
  55.         show_cursor();
  56.         if(get_string(choice," ","9",12,5,1,1) != 0)
  57.         {
  58.             popup_window(2,25,10,55,12,2,1,14,4,1,8,0,0,0);
  59.             write_window(3,2,"Install/Deinstall Aborted!");
  60.             delay(1000);
  61.             unpopup_window(2);
  62.             error = 1;
  63.             done = 1;
  64.         }
  65.         else
  66.         {
  67.             switch(atoi(choice))
  68.             {
  69.                 case 1 : error = install(install_drive,argv[1]);
  70.                         done = 1;
  71.                         break;
  72.                 case 2 : error = deinstall(install_drive,argv[1]);
  73.                         done = 1;
  74.                         break;
  75.             }
  76.         }
  77.         hide_cursor();
  78.     }
  79.     load_screen(0);
  80.     unpopup_window(1);
  81.     if(error == 1)
  82.     {
  83.         popup_window(2,25,10,55,12,2,1,14,4,1,8,0,0,0);
  84.         write_window(3,2,"Install/Deinstall Error !");
  85.         delay(1000);
  86.     }
  87.     else
  88.     {
  89.         popup_window(2,20,10,60,13,2,1,15,1,1,8,0,0,0);
  90.         if(atoi(choice) == 1)
  91.         {
  92.             write_window((41 - strlen("Install complete !")) / 2,2,"Install complete !");
  93.         }
  94.         else
  95.         {
  96.             write_window((41 - strlen("Deinstall complete !")) / 2,2,"Denstall complete !");
  97.         }
  98.         write_window((41 - strlen(" HIT ANY KEY ")) / 2,4," HIT ANY KEY ");
  99.         bioskey(0);
  100.     }
  101.     unpopup_window(2);
  102.     uninit_window();
  103.     system("CLS");
  104.     show_cursor();
  105. }
  106.  
  107. int install(int install_drive,char *path)
  108. {
  109.     char drive[2];
  110.     char *temp_point;
  111.     char buff[256];
  112.     int error = 0,i = 0,count = 0;
  113.     unsigned long int start = 0L;
  114.     char make_direc[20][20];
  115.     char current_direc[256];
  116.  
  117.     getcwd(current_direc,255);
  118.     system("CLS");
  119.     drive[0] = path[0];
  120.     drive[1] = 0x00;
  121.     strupr(drive);
  122.     strcpy(buff,path);
  123.     temp_point = strtok(buff,"\\");
  124.     while(temp_point != NULL)
  125.     {
  126.         strcpy(make_direc[count],temp_point);
  127.         temp_point = strtok(NULL,"\\");
  128.         count++;
  129.     }
  130.     setdisk(drive[0] - 65);
  131.     chdir("\\");
  132.     for(i = 1;i < count;i++)
  133.     {
  134.         mkdir(make_direc[i]);
  135.         chdir(make_direc[i]);
  136.     }
  137.     setdisk(install_drive);
  138.     chdir(current_direc);
  139.     buff[0] = 0x00;
  140.     while((error = read_file(buff,"install.lst",256,start)) < 1)
  141.     {
  142.         if(buff[0] == 0x00)
  143.         {
  144.             break;
  145.         }
  146.         temp_point = strtok(buff,"\r\n");
  147.         start = strlen(temp_point) + 2 + start;
  148.         strcat(buff," ");
  149.         strcat(buff,path);
  150.         system(buff);
  151.         buff[0] = 0x00;
  152.     }
  153.     if(error > 0)
  154.     {
  155.         return(1);
  156.     }
  157.     return(0);
  158. }
  159.  
  160.  
  161. int deinstall(int install_drive,char *path)
  162. {
  163.     char drive[2];
  164.     char buff[256];
  165.     char *temp_point;
  166.     char remove_path[20][20];
  167.     int error = 0;
  168.     int count = 1;
  169.     int i;
  170.     unsigned long int start = 0L;
  171.     char current_direc[256];
  172.     char temp_path[256];
  173.  
  174.     strcpy(temp_path,path);
  175.     getcwd(current_direc,255);
  176.     drive[0] = path[0];
  177.     drive[1] = 0x00;
  178.     strupr(drive);
  179.     while((error = read_file(buff,"deinstall.lst",256,start)) < 1)
  180.     {
  181.         if(buff[0] == 0x00)
  182.         {
  183.             break;
  184.         }
  185.         setdisk(drive[0] - 65);
  186.         chdir(path);
  187.         temp_point = strtok(buff,"\r\n");
  188.         start = strlen(temp_point) + 2 + start;
  189.         if(remove(buff) != 0)
  190.         {
  191.             error = 1;
  192.             setdisk(install_drive);
  193.             break;
  194.         }
  195.         buff[0] = 0x00;
  196.         setdisk(install_drive);
  197.         chdir(current_direc);
  198.     }
  199.     if(error < 1)
  200.     {
  201.         temp_point = strtok(path,"\\");
  202.         while(temp_point != NULL)
  203.         {
  204.             strcpy(remove_path[count],temp_point);
  205.             temp_point = strtok(NULL,"\\");
  206.             count++;
  207.         }
  208.         setdisk(drive[0] - 65);
  209.         chdir(temp_path);
  210.         for(i = (count - 1);i > 0;i--)
  211.         {
  212.             chdir("..");
  213.             rmdir(remove_path[i]);
  214.         }
  215.         setdisk(install_drive);
  216.         chdir(current_direc);
  217.     }
  218.     else
  219.     {
  220.         return(1);
  221.     }
  222.     return(0);
  223. }
  224.  
  225.