home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include "wimpt.h"
- #include "event.h"
- #include "werr.h"
- #include "wimp.h"
- #include "win.h"
- #include "dbox.h"
- #include "visdelay.h"
- #include "bbc.h"
-
- #include "global.h"
- #include "misc.h"
- #include "arc.h"
-
- #include "vterm.h"
-
- static int upgrade_203_204(int version);
- static int upgrade_204_205(int version);
-
- /*
- * The idea of this lot is to take care of upgrades as automatically as
- * possible.
- *
- * Basically any file formats changes that occure, or files that get
- * moved will be processed here.
- *
- * The last version known to the user is kept in a file called
- * !TCPIPUser.Version.
- *
- * At startup, this file is read and compared to the actual version
- * number of the sofware in use.
- *
- * If they are different, then a sequence of upgrades is performed until files
- * match the latest version.
- *
- * Each of these upgrades is performed one at a time, something that has
- * changed more than once will end up getting changed more than once.
- *
- * This will hopefully put a end to the problems that occure evrytime
- * something is re-arranged/added between one version and the next.
- *
- * Of course version prior to 2.05 (the first to have this facility)
- * dont have the version control file, so thing are a little more
- * complicated because we dont actually know what version the user might
- * have, so for this, we assume they have version 2.03 or 2.04 as by now
- * most should have one or the other of these, and doubtless those who
- * dont will probably do a new instalation.
- */
-
- /*
- * Calls event process a few times until
- * some indication that the wimp is likely to have
- * opened the main window. Once this window is open
- * then a user can see the upgrade progressing.
- *
- * Also called to wait for completeion dbox to close.
- */
- static void wait_for_wimp(void)
- {
- wimp_eventstr *e;
-
- do
- {
- event_process();
- e = wimpt_last_event();
- }
- while (e->e!=wimp_EREDRAW && e->e!=wimp_EOPEN && e->e!=wimp_ECLOSE);
- }
-
- static void wait_for_user(int from, int to)
- {
- dbox d;
-
- char buf[8];
-
- if (d = dbox_new("upgraded"), d!=NULL)
- {
- sprintf(buf, "%d.%02d", from / 100, from % 100);
- dbox_setfield(d, 2, buf);
-
- sprintf(buf, "%d.%02d", to / 100, to % 100);
- dbox_setfield(d, 4, buf);
-
- dbox_showstatic(d);
- dbox_fillin(d);
- dbox_dispose(&d);
- }
-
- wait_for_wimp();
- }
-
-
- void upgrade_check(void)
- {
- FILE *fp;
- int majv, minv;
- int old_version = 0;
- int cur_version = 0;
- int new_version = 0;
-
- extern char release_vrsn[];
- extern char release_date[];
-
- visdelay_begin();
-
- sscanf(release_vrsn, "%d.%d", &majv, &minv);
- new_version = majv*100+minv;
-
- old_version = 203; /* last version that this will upgrade from */
-
- if (fp = fopen("<TCPIP$Dir>.Version", "r"), fp!=NULL)
- {
- if (fscanf(fp, "%d.%d", &majv, &minv)==2)
- old_version = majv*100+minv;
- fclose(fp);
- }
-
- if (old_version==new_version)
- {
- visdelay_end();
- return;
- }
-
- wait_for_wimp();
-
- cur_version = upgrade_203_204(old_version);
- cur_version = upgrade_204_205(cur_version);
-
- if (fp = fopen("<TCPIP$Dir>.Version", "w"), fp!=NULL)
- {
- if (cur_version==new_version)
- fprintf(fp, "%s (%s)\n", release_vrsn, release_date);
- else
- fprintf(fp, "%d.%02d\n", cur_version/100, cur_version%100);
- fclose(fp);
- }
-
- visdelay_end();
- wait_for_user(old_version, new_version);
- }
-
-
- /*
- * Upgrade v2.03 to 2.04
- *
- * Files moved:
- * <TCPIP$Dir>.FTPUsers -> <TCPIP$Dir>.FTP.Users
- * <TCPIP$Dir>.PathEnt -> <TCPIP$Dir>.FTP.PathEnt
- *
- * Files added:
- * <TCPIP$Dir>.FTP.Accounts
- *
- * For files added, a default will have been supplied in the archive
- * so ideally it would be nice to extract this automatically.
- */
- static int upgrade_203_204(int version)
- {
- int t;
-
- if (version!=203)
- return version;
-
- cwprintf(NULL, "Upgrading !TCPIP version 2.03 to 2.04\n");
-
- file_create("<TCPIP$Dir>.FTP", 0x1000, 0);
-
- file_objtype("<TCPIP$Dir>.FTPUsers", &t);
- if (t==0)
- {
- file_objtype("<TCPIP$Dir>.FTP.Users", &t);
- if (t==0)
- {
- cwprintf(NULL, " Warning - No User file exist for the FTP server\n");
- cwprintf(NULL, " Copy !TCPIPUser.FTP.Users from the archive\n");
- }
- }
- else
- rename("<TCPIP$Dir>.FTPUsers", "<TCPIP$Dir>.FTP.Users");
-
- file_objtype("<TCPIP$Dir>.PathEnt", &t);
- if (t==0)
- {
- file_objtype("<TCPIP$Dir>.FTP.PathEnt", &t);
- if (t==0)
- {
- cwprintf(NULL, " Warning - No Path data file exits for the FTP client\n");
- cwprintf(NULL, " Copy !TCPIPUser.FTP.PathEnt from the archive\n");
- }
- }
- else
- rename("<TCPIP$Dir>.PathEnt", "<TCPIP$Dir>.FTP.PathEnt");
-
- file_objtype("<TCPIP$Dir>.FTP.Accounts", &t);
- if (t==0)
- {
- cwprintf(NULL, " Warning - No FTP Accounts file exists to support the \"aftp\" command\n");
- cwprintf(NULL, " Copy !TCPIPUser.FTP.Accounts from the archive\n");
- }
-
- cwprintf(NULL, " Upgraded OK.\n");
-
- return 204;
- }
-
-
- /*
- * Nothing changed between 2.04 and 2.05, execpt this
- * facility so just return 205.
- */
- static int upgrade_204_205(int version)
- {
- if (version!=204)
- return version;
-
- cwprintf(NULL, "Upgrading !TCPIP version 2.04 to 2.05\n");
- cwprintf(NULL, " Upgraded OK.\n");
-
- return 205;
- }
-