inst_t disk_install(const char *datfile, const char *descfile, char *fromdir, char *destdir) { char *s; char lsmfile[_MAX_PATH]; /* Linux software map file */ int ret; int ch; int i; int dat_size = 30; /* malloc size of the dat array */ int dat_count; /* size of the dat array */ dat_t *dat_ary; /* the DAT array */ inst_t this; /* return: no. of errors,warnings */ /* Initialize variables */ this.errors = 0; this.warnings = 0; /* Read dat file */ dat_ary = malloc (sizeof (dat_t) * dat_size); if (dat_ary == NULL) { fprintf (stderr, "Error!\n"); fprintf (stderr, "Unable to allocate enough memory for install floppy data file!\n"); gotoxy (1, 25); s = catgets (cat, 1, 0, "Press any key to continue"); cputs (s); getch(); return (this); } dat_count = dat_read (datfile, dat_ary, dat_size); if (dat_count < 1) { fprintf (stderr, "Error!\n"); fprintf (stderr, "The install floppy data file is empty!\n"); gotoxy (1, 25); s = catgets (cat, 1, 0, "Press any key to continue"); cputs (s); getch(); free (dat_ary); return (this); } /* Run the install */ for (i = 0; i < dat_count; i++) { /* Print the screen and progress bargraph */ repaint_empty(); gotoxy (15, 20); bargraph (i, dat_count, 50 /* width */); /* Print the package name */ gotoxy (1, 5); s = catgets (cat, 3, 3, "Package: "); cputs (s); cputs (dat_ary[i].name); /* Show the package description */ /* Generate the lsmfile name */ _makepath (lsmfile, "", fromdir, dat_ary[i].name, "LSM"); if (isfile (lsmfile)) { lsm_description (8, 1, 10, lsmfile); } else { /* no lsm file. try it again with a plain txt file */ _makepath (lsmfile, "", fromdir, dat_ary[i].name, "TXT"); if (isfile (lsmfile)) { cat_file (lsmfile, 8 /* start line */, 10 /* no. lines */); } } /* Find out which ones the user wants to install */ gotoxy (1, 23); switch (dat_ary[i].rank) { case 'n': case 'N': /* Do not install */ s = catgets (cat, 4, 2, "SKIPPED"); cputs (s); break; case 'y': case 'Y': /* Always install */ s = catgets (cat, 4, 1, "REQUIRED"); cputs (s); ret = unzip_file (dat_ary[i].name, fromdir, destdir); if (ret != 0) { /* Print an error message */ s = catgets (cat, 3, 6, "ERROR! Failed to install REQUIRED package."); cputs (s); /* Return an error */ this.errors++; /* Does the user want to continue anyway? */ gotoxy (1, 25); s = catgets (cat, 2, 3, "Continue installing this disk? [yn]"); cputs (s); ch = getch_yn(); if ((ch != 'y') && (ch != 'Y')) { return (this); } } break; default: /* Optional */ s = catgets (cat, 4, 0, "OPTIONAL"); cputs (s); /* Ask the user if you want to install it */ gotoxy (1, 23); s = catgets (cat, 2, 4, "Install this package? [yn]"); cputs (s); ch = getch_yn(); if ((ch == 'y') || (ch == 'Y')) { ret = unzip_file (dat_ary[i].name, fromdir, destdir); if (ret != 0) { /* Print a warning message */ gotoxy (1, 23); s = catgets (cat, 3, 7, "WARNING! Failed to install OPTIONAL package."); cputs (s); gotoxy (1, 25); s = catgets (cat, 1, 0, "Press any key to continue"); cputs (s); getch(); this.warnings++; } } break; } /* switch */ } /* for */ /* Free memory for this disk */ free (dat_ary); return (this); }
inst_t disk_install(const char *datfile, char *fromdir, char *destdir) { char lsmfile[MAXPATH]; /* Linux software map file */ char *s; int dat_count; /* size of the dat array */ int ret; int ch; int i; int pkg_yesToAll = 0; /* Assume default yes to all = not specified */ dat_t *dat_ary; /* the DAT array */ inst_t this; /* return: no. of errors,warnings */ /* Initialize variables */ this.errors = 0; this.warnings = 0; /* Read dat file */ dat_ary = dat_read (datfile, &dat_count); if (dat_ary == NULL) { s = catgets (cat, SET_ERRORS, MSG_ERROR, MSG_ERROR_STR); fprintf (stderr, s); log("<error msg=\"%s\" />\n", s); s = catgets (cat, SET_ERRORS, MSG_ERRALLOCMEMFDF, MSG_ERRALLOCMEMFDF_STR); fprintf (stderr, s); log("<error msg=\"%s\" />\n", s); pause(); return (this); } if (dat_count < 1) { s = catgets (cat, SET_ERRORS, MSG_ERROR, MSG_ERROR_STR); fprintf (stderr, s); log("<error msg=\"%s\" />\n", s); s = catgets (cat, SET_ERRORS, MSG_ERREMPTYFLOPPYDATAFILE, MSG_ERREMPTYFLOPPYDATAFILE_STR); fprintf (stderr, s); log("<error msg=\"%s\" />\n", s); pause(); free (dat_ary); return (this); } /* Run the install */ for (i = 0; i < dat_count; i++) { /* Print the screen and progress bargraph */ repaint_empty(); box (14, 16, 66, 18); gotoxy (15, 17); bargraph (i, dat_count, 50 /* width */); /* Print the package name */ gotoxy (2, 5); s = catgets (cat, SET_PKG_GENERAL, MSG_PACKAGE, MSG_PACKAGE_STR); cputs (s); cputs (dat_ary[i].name); /* Show the package description */ /* Generate the lsmfile name */ fnmerge (lsmfile, "", fromdir, dat_ary[i].name, "LSM"); if (isfile (lsmfile)) { lsm_description (8, 2, 10, lsmfile); } else { /* no lsm file. try it again with a plain txt file (or localized version) */ fnmerge (lsmfile, "", fromdir, dat_ary[i].name, ""); gotoxy (2, 8); cat_file (lsmfile, 10 /* no. lines */); } /* Find out which ones the user wants to install */ gotoxy (2, 25); switch (dat_ary[i].rank) { case 'n': case 'N': /* Do not install */ log("<package name=\"%s\" choice=\"n\" />\n", dat_ary[i].name); s = catgets (cat, SET_PKG_NEED, MSG_SKIPPED, MSG_SKIPPED_STR); cputs (s); break; case 'y': case 'Y': /* Always install */ log("<package name=\"%s\" choice=\"y\" ", dat_ary[i].name); s = catgets (cat, SET_PKG_NEED, MSG_REQUIRED, MSG_REQUIRED_STR); cputs (s); ret = unzip_file (dat_ary[i].name, fromdir, destdir); reregisterSIGINTHandler(); /* unzip installs its own SIGINT handler */ if (ret != 0) { /* Print an error message */ s = catgets (cat, SET_PKG_GENERAL, MSG_ERRREQPKG, MSG_ERRREQPKG_STR); cputs (s); log(">\n"); log("<error msg=\"%s\" />\n", s); log("</package>\n"); /* Return an error */ this.errors++; /* Does the user want to continue anyway? */ s = catgets (cat, SET_PROMPT_YN, MSG_CONTINSTDISK, MSG_CONTINSTDISK_STR); ch = select_yn(s, yes, no, NULL, NULL); if (ch) { log("<abort msg=\"User choose not to continue after error.\" />\n"); return (this); } } else /* ret == 0, ie no errors */ log("/>\n"); break; default: /* Optional */ s = catgets (cat, SET_PKG_NEED, MSG_OPTIONAL, MSG_OPTIONAL_STR); cputs (s); /* Ask the user if you want to install it */ s = catgets (cat, SET_PROMPT_YN, MSG_INSTALLPKG, MSG_INSTALLPKG_STR); if (!pkg_yesToAll) { ch = select_yn (s, yes, no, catgets (cat, SET_PROMPT_YN, MSG_YESTOALL, MSG_YESTOALL_STR), NULL); if (ch == 2) pkg_yesToAll = 1; } if (pkg_yesToAll || ch==0) /* Yes or YesToAll */ { log("<package name=\"%s\" choice=\"y\" ", dat_ary[i].name); ret = unzip_file (dat_ary[i].name, fromdir, destdir); reregisterSIGINTHandler(); /* unzip installs its own SIGINT handler */ if (ret != 0) { /* Print a warning message */ gotoxy (2, 13); s = catgets (cat, SET_PKG_GENERAL, MSG_WARNOPTPKG, MSG_WARNOPTPKG_STR); cputs (s); log(">\n"); log("<warning msg=\"%s\" />\n", s); log("</package>\n"); pause(); this.warnings++; } else log("/>\n"); } else /* user selected no */ log("<package name=\"%s\" choice=\"n\" />\n", dat_ary[i].name); break; } /* switch */ } /* for */ /* Print the screen and 100% complete progress bargraph */ repaint_empty(); box (14, 16, 66, 18); gotoxy (15, 17); bargraph (1, 1, 50 /* width */); /* Free memory for this disk */ free (dat_ary); return (this); }
dat_t *listbox(dat_t *dat_ary, int dat_count, char *fromdir) { int boxlength = dat_count / 5, centre = 12 - boxlength, i, j; key_t ch; char *thecwd = getcwd(NULL, 0); centre += 4; textbackground(BLUE); textcolor(WHITE); /* OK, lets draw all of the selections using some simple calculations */ for(i = 0, j = 0; i < dat_count; i++, j++) { gotoxy(8 + (j * 13), centre + (i / 5)); if(toupper(dat_ary[i].rank) == 'N') cputs("[ ] "); else { cputs("[X] "); dat_ary[i].rank = 'Y'; } /* Don't bother printing the pathname (if it exists) */ cputs(strrchr(dat_ary[i].name, '\\') != NULL ? &strrchr(dat_ary[i].name, '\\')[1] : dat_ary[i].name); if(j == 4) j = -1; } /* Draw the DONE button */ gotoxy(37, centre + (dat_count / 5) + 2); cputs("[DONE]"); gotoxy(8, centre); cputs(toupper(dat_ary[i].rank) == 'N' ? "< >" : "<X>"); gotoxy(9, centre); i = j = 0; /* Begin the selection loop; runs forever until ENTER is pressed */ for(;;) { unsigned x = wherex(), y = wherey(), k, l; for(k = 19; k < 22; k++) for(l = 2; l < 80; l++) { gotoxy(l, k); putch(' '); } gotoxy(2, 20); if(i != dat_count) { char lsmfile[MAXPATH]; unsigned total; chdir(fromdir); _dos_setdrive(toupper(fromdir[0]) - 'A' + 1, &total); fnmerge(lsmfile, "", fromdir, dat_ary[i].name, ".LSM"); if(isfile(lsmfile)) lsm_description(20, 2, 3, lsmfile); else cat_file(dat_ary[i].name, 3); chdir(thecwd); _dos_setdrive(toupper(thecwd[0]) - 'A' + 1, &total); } gotoxy(x, y); ch = getkey(); switch(ch.extended) { /* Moves the current selection to the next row */ case KEY_DOWN: if(i < (dat_count - 4)) i += 5; else { j = (dat_count - ((dat_count / 5) * 5) + 5) - 5; i = dat_count; } break; /* * Moves the current selection to the next column (or the first * column of the next row) */ case KEY_RIGHT: if(i < dat_count) { i++; j++; } break; /* * Moves the current selection to the previous row or to the * first column of the current row */ case KEY_UP: if(i > 4) i -= 5; else j = i = 0; break; /* * Moves the current selection to the previous column (or the * last column of the previous row */ case KEY_LEFT: if(i != 0) { i--; j--; } break; } switch(ch.key) { /* Complete the selection, return the results */ case KEY_ENTER: free(thecwd); return(dat_ary); /* * If pressed on the DONE button, return the results, else * toggle the current selection yes or no */ case ' ': if(i == dat_count) { free(thecwd); return(dat_ary); } dat_ary[i].rank = (toupper(dat_ary[i].rank) == 'Y') ? 'N' : 'Y'; break; } if(j > 4) j = 0; if(j < 0) j = 4; /* * Change the previous selection borders to [], move the current to * <> */ if (wherex() != 38) { gotoxy(wherex() - 1, wherey()); putch('['); gotoxy(wherex() + 1, wherey()); putch(']'); } if(i == dat_count) gotoxy(38, centre + (dat_count / 5) + 2); else { gotoxy(8 + (j * 13), centre + (i / 5)); cputs(toupper(dat_ary[i].rank) == 'Y' ? "<X>" : "< >"); gotoxy(9 + (j * 13), centre + (i / 5)); } } }