home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / internet / tcpip / src205 / TCPIP_Src / Main / c / upgrade < prev    next >
Encoding:
Text File  |  1995-03-08  |  5.1 KB  |  223 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include "wimpt.h"
  6. #include "event.h"
  7. #include "werr.h"
  8. #include "wimp.h"
  9. #include "win.h"
  10. #include "dbox.h"
  11. #include "visdelay.h"
  12. #include "bbc.h"
  13.  
  14. #include "global.h"
  15. #include "misc.h"
  16. #include "arc.h"
  17.  
  18. #include "vterm.h"
  19.  
  20. static int upgrade_203_204(int version);
  21. static int upgrade_204_205(int version);
  22.  
  23. /*
  24.  * The idea of this lot is to take care of upgrades as automatically as
  25.  * possible.
  26.  *
  27.  * Basically any file formats changes that occure, or files that get
  28.  * moved will be processed here.
  29.  *
  30.  * The last version known to the user is kept in a file called
  31.  * !TCPIPUser.Version.
  32.  *
  33.  * At startup, this file is read and compared to the actual version
  34.  * number of the sofware in use.
  35.  *
  36.  * If they are different, then a sequence of upgrades is performed until files
  37.  * match the latest version.
  38.  *
  39.  * Each of these upgrades is performed one at a time, something that has
  40.  * changed more than once will end up getting changed more than once.
  41.  *
  42.  * This will hopefully put a end to the problems that occure evrytime
  43.  * something is re-arranged/added between one version and the next.
  44.  *
  45.  * Of course version prior to 2.05 (the first to have this facility)
  46.  * dont have the version control file, so thing are a little more
  47.  * complicated because we dont actually know what version the user might
  48.  * have, so for this, we assume they have version 2.03 or 2.04 as by now
  49.  * most should have one or the other of these, and doubtless those who
  50.  * dont will probably do a new instalation.
  51.  */
  52.  
  53. /*
  54.  * Calls event process a few times until
  55.  * some indication that the wimp is likely to have 
  56.  * opened the main window. Once this window is open
  57.  * then a user can see the upgrade progressing.
  58.  *
  59.  * Also called to wait for completeion dbox to close.
  60.  */ 
  61. static void wait_for_wimp(void)
  62. {
  63.   wimp_eventstr *e;
  64.  
  65.   do
  66.   {
  67.     event_process();
  68.     e = wimpt_last_event();
  69.   }
  70.   while (e->e!=wimp_EREDRAW && e->e!=wimp_EOPEN && e->e!=wimp_ECLOSE);
  71. }
  72.  
  73. static void wait_for_user(int from, int to)
  74. {
  75.   dbox d;
  76.  
  77.   char buf[8];
  78.  
  79.   if (d = dbox_new("upgraded"), d!=NULL)
  80.   {
  81.     sprintf(buf, "%d.%02d", from / 100, from % 100);
  82.     dbox_setfield(d, 2, buf);
  83.  
  84.     sprintf(buf, "%d.%02d", to / 100, to % 100);
  85.     dbox_setfield(d, 4, buf);
  86.  
  87.     dbox_showstatic(d);
  88.     dbox_fillin(d);
  89.     dbox_dispose(&d);
  90.   }
  91.  
  92.   wait_for_wimp();
  93. }
  94.   
  95.  
  96. void upgrade_check(void)
  97. {
  98.   FILE *fp;
  99.   int majv, minv;
  100.   int old_version = 0;
  101.   int cur_version = 0;
  102.   int new_version = 0;
  103.  
  104.   extern char release_vrsn[];
  105.   extern char release_date[];
  106.  
  107.   visdelay_begin();
  108.  
  109.   sscanf(release_vrsn, "%d.%d", &majv, &minv);
  110.   new_version = majv*100+minv;
  111.  
  112.   old_version = 203; /* last version that this will upgrade from */
  113.  
  114.   if (fp = fopen("<TCPIP$Dir>.Version", "r"), fp!=NULL)
  115.   {
  116.     if (fscanf(fp, "%d.%d", &majv, &minv)==2)
  117.       old_version = majv*100+minv;
  118.     fclose(fp);
  119.   }
  120.     
  121.   if (old_version==new_version)
  122.   {
  123.     visdelay_end();
  124.     return;
  125.   }
  126.   
  127.   wait_for_wimp();
  128.  
  129.   cur_version = upgrade_203_204(old_version);
  130.   cur_version = upgrade_204_205(cur_version);
  131.  
  132.   if (fp = fopen("<TCPIP$Dir>.Version", "w"), fp!=NULL)
  133.   {
  134.     if (cur_version==new_version)
  135.       fprintf(fp, "%s (%s)\n", release_vrsn, release_date);
  136.     else
  137.       fprintf(fp, "%d.%02d\n", cur_version/100, cur_version%100);
  138.     fclose(fp);
  139.   }
  140.  
  141.   visdelay_end();
  142.   wait_for_user(old_version, new_version);
  143. }
  144.  
  145.  
  146. /*
  147.  * Upgrade v2.03 to 2.04
  148.  *
  149.  * Files moved:
  150.  *   <TCPIP$Dir>.FTPUsers -> <TCPIP$Dir>.FTP.Users
  151.  *   <TCPIP$Dir>.PathEnt  -> <TCPIP$Dir>.FTP.PathEnt
  152.  *
  153.  * Files added:
  154.  *   <TCPIP$Dir>.FTP.Accounts
  155.  *
  156.  * For files added, a default will have been supplied in the archive
  157.  * so ideally it would be nice to extract this automatically.
  158.  */
  159. static int upgrade_203_204(int version)
  160. {
  161.   int t;
  162.  
  163.   if (version!=203)
  164.     return version;
  165.  
  166.   cwprintf(NULL, "Upgrading !TCPIP version 2.03 to 2.04\n");
  167.  
  168.   file_create("<TCPIP$Dir>.FTP", 0x1000, 0);
  169.  
  170.   file_objtype("<TCPIP$Dir>.FTPUsers", &t);
  171.   if (t==0)
  172.   {
  173.     file_objtype("<TCPIP$Dir>.FTP.Users", &t);
  174.     if (t==0)
  175.     {
  176.       cwprintf(NULL, "  Warning - No User file exist for the FTP server\n");
  177.       cwprintf(NULL, "  Copy !TCPIPUser.FTP.Users from the archive\n");
  178.     }
  179.   }
  180.   else
  181.     rename("<TCPIP$Dir>.FTPUsers", "<TCPIP$Dir>.FTP.Users");
  182.  
  183.   file_objtype("<TCPIP$Dir>.PathEnt", &t);
  184.   if (t==0)
  185.   {
  186.     file_objtype("<TCPIP$Dir>.FTP.PathEnt", &t);
  187.     if (t==0)
  188.     {
  189.       cwprintf(NULL, "  Warning - No Path data file exits for the FTP client\n");
  190.       cwprintf(NULL, "  Copy !TCPIPUser.FTP.PathEnt from the archive\n");
  191.     }
  192.   }
  193.   else
  194.     rename("<TCPIP$Dir>.PathEnt", "<TCPIP$Dir>.FTP.PathEnt");
  195.  
  196.   file_objtype("<TCPIP$Dir>.FTP.Accounts", &t);
  197.   if (t==0)
  198.   {
  199.     cwprintf(NULL, "  Warning - No FTP Accounts file exists to support the \"aftp\" command\n");
  200.     cwprintf(NULL, "  Copy !TCPIPUser.FTP.Accounts from the archive\n");
  201.   }
  202.  
  203.   cwprintf(NULL, "  Upgraded OK.\n");
  204.  
  205.   return 204;
  206. }
  207.  
  208.  
  209. /*
  210.  * Nothing changed between 2.04 and 2.05, execpt this
  211.  * facility so just return 205.
  212.  */
  213. static int upgrade_204_205(int version)
  214. {
  215.   if (version!=204)
  216.     return version;
  217.  
  218.   cwprintf(NULL, "Upgrading !TCPIP version 2.04 to 2.05\n");
  219.   cwprintf(NULL, "  Upgraded OK.\n");
  220.  
  221.   return 205;
  222. }
  223.