Subversion Repositories SvarDOS

Rev

Rev 34 | Rev 36 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34 Rev 35
Line 160... Line 160...
160
  if (r.x.ax == 0) return(1);
160
  if (r.x.ax == 0) return(1);
161
  return(0);
161
  return(0);
162
}
162
}
163
 
163
 
164
 
164
 
165
/* returns total disk space of drive drv (in MiB, max 2048), or -1 if drive invalid
165
/* returns total disk space of drive drv (in MiB, max 2048), or -1 if drive invalid */
166
 * also sets emptyflag to 1 if drive is empty, or to 0 otherwise */
-
 
167
static int disksize(int drv, int *emptyflag) {
166
static int disksize(int drv) {
168
  long res;
167
  long res;
169
  union REGS r;
168
  union REGS r;
170
  r.h.ah = 0x36; /* DOS 2+ get free disk space */
169
  r.h.ah = 0x36; /* DOS 2+ get free disk space */
171
  r.h.dl = drv;
170
  r.h.dl = drv;
172
  int86(0x21, &r, &r);
171
  int86(0x21, &r, &r);
173
  if (r.x.ax == 0xffffu) return(-1); /* AX set to FFFFh if drive invalid */
172
  if (r.x.ax == 0xffffu) return(-1); /* AX set to FFFFh if drive invalid */
174
  res = r.x.ax;
173
  res = r.x.ax;
175
  res *= r.x.bx;
174
  res *= r.x.bx;
176
  res *= r.x.cx;
175
  res *= r.x.cx;
177
  res >>= 20; /* bytes to MiB */
176
  return(res >> 20); /* return result after converting bytes to MiB */
-
 
177
}
-
 
178
 
-
 
179
 
178
  if (r.x.dx != r.x.bx) { /* DX is total number of clusters, while BX is only free clusters */
180
/* returns 0 if disk is empty, non-zero otherwise */
-
 
181
static int diskempty(int drv) {
179
    *emptyflag = 0;
182
  unsigned int rc;
-
 
183
  int res;
-
 
184
  char buff[8];
-
 
185
  struct find_t fileinfo;
-
 
186
  sprintf(buff, "%c:\\*.*", 'A' + drv - 1);
-
 
187
  rc = _dos_findfirst(buff, _A_NORMAL | _A_SUBDIR | _A_HIDDEN | _A_SYSTEM, &fileinfo);
-
 
188
  if (rc == 0) {
-
 
189
    res = 1; /* call successfull means disk is not empty */
180
  } else {
190
  } else {
181
    *emptyflag = 1;
191
    res = 0;
182
  }
192
  }
-
 
193
  /* _dos_findclose(&fileinfo); */ /* apparently required only on OS/2 */
183
  return(res);
194
  return(res);
184
}
195
}
185
 
196
 
186
 
197
 
187
static int preparedrive(void) {
198
static int preparedrive(void) {
188
  int driveremovable;
199
  int driveremovable;
189
  int selecteddrive = 3; /* hardcoded to 'C:' */
200
  int selecteddrive = 3; /* hardcoded to 'C:' */
190
  int ds, emptydriveflag;
201
  int ds;
191
  for (;;) {
202
  for (;;) {
192
    newscreen();
203
    newscreen();
193
    driveremovable = isdriveremovable(selecteddrive);
204
    driveremovable = isdriveremovable(selecteddrive);
194
    if (driveremovable < 0) {
205
    if (driveremovable < 0) {
195
      char *list[] = { "Create an automatic partition", "Run the FDISK partitioning tool", "Quit to DOS", NULL};
206
      char *list[] = { "Create an automatic partition", "Run the FDISK partitioning tool", "Quit to DOS", NULL};
Line 212... Line 223...
212
          break;
223
          break;
213
        case 2:
224
        case 2:
214
          return(-1);
225
          return(-1);
215
      }
226
      }
216
      newscreen();
227
      newscreen();
217
      video_putstring(12, 10, COLOR_BODY[mono], "Your computer will reboot now. Press any key.");
228
      video_putstring(11, 10, COLOR_BODY[mono], "Your computer will reboot now. Press any key.");
218
      input_getkey();
229
      input_getkey();
219
      reboot();
230
      reboot();
220
      return(-1);
231
      return(-1);
221
    } else if (driveremovable > 0) {
232
    } else if (driveremovable > 0) {
222
      video_putstring(8, 2, COLOR_BODY[mono], "ERROR: Drive C: appears to be a removable device.");
233
      video_putstring(9, 2, COLOR_BODY[mono], "ERROR: Drive C: appears to be a removable device.");
223
      video_putstring(10, 2, COLOR_BODY[mono], "Installation aborted. Press any key.");
234
      video_putstring(11, 2, COLOR_BODY[mono], "Installation aborted. Press any key.");
224
      return(-1);
235
      return(-1);
225
    }
236
    }
226
    /* if not formatted, propose to format it right away (try to create a directory) */
237
    /* if not formatted, propose to format it right away (try to create a directory) */
227
    if (mkdir("C:\\SVWRTEST.123") != 0) {
238
    if (mkdir("C:\\SVWRTEST.123") != 0) {
228
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
239
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
Line 234... Line 245...
234
      system("FORMAT C: /Q /U /V:SVAROG");
245
      system("FORMAT C: /Q /U /V:SVAROG");
235
      continue;
246
      continue;
236
    }
247
    }
237
    rmdir("C:\\SVWRTEST.123");
248
    rmdir("C:\\SVWRTEST.123");
238
    /* check total disk space */
249
    /* check total disk space */
239
    ds = disksize(selecteddrive, &emptydriveflag);
250
    ds = disksize(selecteddrive);
240
    if (ds < 16) {
251
    if (ds < 16) {
241
      video_putstring(9, 2, COLOR_BODY[mono], "ERROR: Drive C: is not big enough!");
252
      video_putstring(9, 2, COLOR_BODY[mono], "ERROR: Drive C: is not big enough!");
242
      video_putstring(10, 2, COLOR_BODY[mono], "      Svarog386 requires a disk of at least 16 MiB.");
253
      video_putstring(10, 2, COLOR_BODY[mono], "      Svarog386 requires a disk of at least 16 MiB.");
243
      video_putstring(12, 2, COLOR_BODY[mono], "Press any key to return to DOS.");
254
      video_putstring(12, 2, COLOR_BODY[mono], "Press any key to return to DOS.");
244
      input_getkey();
255
      input_getkey();
245
      return(-1);
256
      return(-1);
246
    }
257
    }
247
    /* is the disk empty? */
258
    /* is the disk empty? */
248
    if (emptydriveflag != 0) {
259
    if (diskempty(selecteddrive) != 0) {
249
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
260
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
250
      video_putstring(7, 2, COLOR_BODY[mono], "ERROR: Drive C: is not empty. Svarog386 must be installed on an empty disk.");
261
      video_putstring(7, 2, COLOR_BODY[mono], "ERROR: Drive C: is not empty. Svarog386 must be installed on an empty disk.");
251
      video_putstring(8, 2, COLOR_BODY[mono], "       You can format the disk now, to make it empty. Note however, that");
262
      video_putstring(8, 2, COLOR_BODY[mono], "       You can format the disk now, to make it empty. Note however, that");
252
      video_putstring(9, 2, COLOR_BODY[mono], "       this will ERASE ALL CURRENT DATA on your disk.");
263
      video_putstring(9, 2, COLOR_BODY[mono], "       this will ERASE ALL CURRENT DATA on your disk.");
253
      if (menuselect(12, -1, 4, list) != 0) return(-1);
264
      if (menuselect(12, -1, 4, list) != 0) return(-1);
254
      video_clear(0x0700, 0);
265
      video_clear(0x0700, 0);
255
      video_movecursor(0, 0);
266
      video_movecursor(0, 0);
256
      system("FORMAT /Q C:");
267
      system("FORMAT C: /Q /U /V:SVAROG");
257
      continue;
268
      continue;
258
    } else {
269
    } else {
259
      /* final confirmation */
270
      /* final confirmation */
260
      char *list[] = { "Install Svarog386", "Quit to DOS", NULL};
271
      char *list[] = { "Install Svarog386", "Quit to DOS", NULL};
261
      video_putstring(8, 2, COLOR_BODY[mono], "The installation of Svarog386 to your C: disk is about to begin.");
272
      video_putstring(7, 2, COLOR_BODY[mono], "The installation of Svarog386 to your C: disk is about to begin.");
262
      if (menuselect(10, -1, 4, list) != 0) return(-1);
273
      if (menuselect(10, -1, 4, list) != 0) return(-1);
263
      system("SYS A: C:");
274
      system("SYS A: C:");
264
      mkdir("C:\\TEMP");
275
      mkdir("C:\\TEMP");
265
      return(0);
276
      return(0);
266
    }
277
    }
Line 377... Line 388...
377
  /* count how long the pkg list is */
388
  /* count how long the pkg list is */
378
  for (pkglistlen = 0; pkglist[pkglistlen] != NULL; pkglistlen++);
389
  for (pkglistlen = 0; pkglist[pkglistlen] != NULL; pkglistlen++);
379
  /* install packages */
390
  /* install packages */
380
  for (i = 0; pkglist[i] != NULL; i++) {
391
  for (i = 0; pkglist[i] != NULL; i++) {
381
    char buff[16];
392
    char buff[16];
382
    sprintf(buff, "Installing package %d/%d: %s", i, pkglistlen, pkglist[i]);
393
    sprintf(buff, "Installing package %d/%d: %s", i+1, pkglistlen, pkglist[i]);
383
    video_putstring(10, 2, COLOR_BODY[mono], buff);
394
    video_putstring(10, 2, COLOR_BODY[mono], buff);
384
    sprintf(buff, "FDNPKG INSTALL %s > NULL");
395
    sprintf(buff, "FDNPKG INSTALL %s > NULL");
385
    system(buff);
396
    system(buff);
386
  }
397
  }
387
}
398
}