Subversion Repositories SvarDOS

Rev

Rev 42 | Rev 47 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
28 mv_fox 1
/*
2
 * SVAROG386 INSTALL
3
 * COPYRIGHT (C) 2016 MATEUSZ VISTE
42 mv_fox 4
 *
5
 * http://svarog386.sf.net
28 mv_fox 6
 */
7
 
8
#include <dos.h>
30 mv_fox 9
#include <direct.h>  /* mkdir() */
28 mv_fox 10
#include <stdio.h>   /* printf() and friends */
11
#include <stdlib.h>  /* system() */
12
#include <string.h>  /* memcpy() */
13
#include <unistd.h>
42 mv_fox 14
 
15
#include "kitten\kitten.h"
16
 
28 mv_fox 17
#include "input.h"
18
#include "video.h"
19
 
42 mv_fox 20
 
29 mv_fox 21
/* color scheme (color, mono) */
22
static unsigned short COLOR_TITLEBAR[2] = {0x7000,0x7000};
23
static unsigned short COLOR_BODY[2] = {0x1700,0x0700};
24
static unsigned short COLOR_SELECT[2] = {0x7000,0x7000};
25
static unsigned short COLOR_SELECTCUR[2] = {0x1F00,0x0700};
28 mv_fox 26
 
29 mv_fox 27
/* mono flag */
28
static int mono = 0;
28 mv_fox 29
 
30
 
31
/* reboot the computer */
32
static void reboot(void) {
33
  void ((far *bootroutine)()) = (void (far *)()) 0xFFFF0000L;
34
  int far *rstaddr = (int far *)0x00400072L; /* BIOS boot flag is at 0040:0072 */
35
  *rstaddr = 0x1234; /* 0x1234 = warm boot, 0 = cold boot */
36
  (*bootroutine)(); /* jump to the BIOS reboot routine at FFFF:0000 */
37
}
38
 
42 mv_fox 39
 
40
/* an NLS wrapper around video_putstring() */
41
static void putstringnls(int y, int x, unsigned short attr, int nlsmaj, int nlsmin, char *s) {
42
  s = kittengets(nlsmaj, nlsmin, s);
43
  video_putstring(y, x, attr, s);
44
}
45
 
46
 
47
#define LDEC(x,y) (((unsigned short)x << 8) | (unsigned short)y)
48
/* provides codepage and country files required by lang */
49
static int getnlscp(char *lang, int *egafile) {
50
  unsigned short l;
51
  l = lang[0];
52
  l <<= 8;
53
  l |= lang[1];
54
  switch (l) {
55
    case LDEC('E','N'):
56
      *egafile = 0;
57
      return(437);
58
    case LDEC('P','L'):
59
      *egafile = 10;
60
      return(991);
61
  }
62
  *egafile = 0;
63
  return(437);
64
}
65
 
66
 
28 mv_fox 67
static int menuselect(int ypos, int xpos, int height, char **list) {
68
  int i, offset = 0, res = 0, count, width = 0;
69
  /* count how many languages there is */
70
  for (count = 0; list[count] != NULL; count++) {
71
    int len = strlen(list[count]);
72
    if (len > width) width = len;
73
  }
74
 
75
  /* if xpos negative, means 'center out' */
76
  if (xpos < 0) xpos = 39 - (width >> 1);
77
 
29 mv_fox 78
  video_putchar(ypos, xpos+width+2, COLOR_SELECT[mono], 0xBF);         /*       \ */
79
  video_putchar(ypos, xpos-1, COLOR_SELECT[mono], 0xDA);               /*  /      */
80
  video_putchar(ypos+height-1, xpos-1, COLOR_SELECT[mono], 0xC0);      /*  \      */
81
  video_putchar(ypos+height-1, xpos+width+2, COLOR_SELECT[mono], 0xD9);/*      /  */
82
  video_putcharmulti(ypos, xpos, COLOR_SELECT[mono], 0xC4, width + 2, 1);
83
  video_putcharmulti(ypos+height-1, xpos, COLOR_SELECT[mono], 0xC4, width + 2, 1);
84
  video_putcharmulti(ypos+1, xpos-1, COLOR_SELECT[mono], 0xB3, height - 2, 80);
85
  video_putcharmulti(ypos+1, xpos+width+2, COLOR_SELECT[mono], 0xB3, height - 2, 80);
28 mv_fox 86
 
87
  for (;;) {
88
    int key;
89
    /* list of selectable items */
90
    for (i = 0; i < height - 2; i++) {
91
      if (i + offset == res) {
29 mv_fox 92
        video_putchar(ypos + 1 + i, xpos, COLOR_SELECTCUR[mono], 16);
93
        video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECTCUR[mono], 17);
28 mv_fox 94
        video_movecursor(ypos + 1 + i, xpos);
29 mv_fox 95
        video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECTCUR[mono], list[i + offset], width);
28 mv_fox 96
      } else if (i + offset < count) {
29 mv_fox 97
        video_putchar(ypos + 1 + i, xpos, COLOR_SELECT[mono], ' ');
98
        video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECT[mono], ' ');
99
        video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECT[mono], list[i + offset], width);
28 mv_fox 100
      } else {
29 mv_fox 101
        video_putcharmulti(ypos + 1 + i, xpos, COLOR_SELECT[mono], ' ', width+2, 1);
28 mv_fox 102
      }
103
    }
104
    key = input_getkey();
105
    if (key == 0x0D) { /* ENTER */
106
      return(res);
107
    } else if (key == 0x148) { /* up */
33 mv_fox 108
      if (res > 0) {
109
        res--;
110
        if (res < offset) offset = res;
111
      }
28 mv_fox 112
    } else if (key == 0x150) { /* down */
33 mv_fox 113
      if (res+1 < count) {
114
        res++;
115
        if (res > offset + height - 3) offset = res - (height - 3);
116
      }
117
    } else if (key == 0x147) { /* home */
118
      res = 0;
119
      offset = 0;
120
    } else if (key == 0x14F) { /* end */
121
      res = count - 1;
122
      if (res > offset + height - 3) offset = res - (height - 3);
28 mv_fox 123
    } else if (key == 0x1B) {  /* ESC */
124
      return(-1);
33 mv_fox 125
    } else {
126
      char buf[8];
127
      sprintf(buf, "0x%02X ", key);
128
      video_putstring(1, 0, COLOR_BODY[mono], buf);
28 mv_fox 129
    }
130
  }
131
}
132
 
133
static void newscreen(void) {
134
  int x;
42 mv_fox 135
  char *title;
136
  title = kittengets(0, 0, "SVAROG386 INSTALLATION");
29 mv_fox 137
  for (x = 0; x < 80; x++) video_putchar(0, x, COLOR_TITLEBAR[mono], ' ');
42 mv_fox 138
  video_putstring(0, 40 - (strlen(title) >> 1), COLOR_TITLEBAR[mono], title);
29 mv_fox 139
  video_clear(COLOR_BODY[mono], 80);
36 mv_fox 140
  video_movecursor(25,0);
28 mv_fox 141
}
142
 
143
static int selectlang(char *lang) {
144
  int choice;
42 mv_fox 145
  int x;
146
  char *msg;
28 mv_fox 147
  char *code;
148
  char *langlist[] = {
149
    "English\0EN",
150
    "French\0FR",
151
    "German\0DE",
152
    "Italian\0IT",
153
    "Polish\0PL",
154
    "Russian\0RU",
155
    "Slovenian\0SL",
156
    "Spanish\0ES",
157
    "Turkish\0TR",
158
    NULL
159
  };
160
 
161
  newscreen();
42 mv_fox 162
  msg = kittengets(1, 0, "Welcome to Svarog386");
163
  x = 40 - (strlen(msg) >> 1);
164
  video_putstring(4, x, COLOR_BODY[mono], msg);
165
  video_putcharmulti(5, x, COLOR_BODY[mono], '=', strlen(msg), 1);
166
  putstringnls(8, 2, COLOR_BODY[mono], 1, 1, "Please select your language from the list below:");
36 mv_fox 167
  choice = menuselect(10, -1, 12, langlist);
28 mv_fox 168
  if (choice < 0) return(-1);
169
  /* write short language code into lang */
170
  for (code = langlist[choice]; *code != 0; code++);
171
  memcpy(lang, code + 1, 2);
172
  lang[2] = 0;
173
  return(0);
174
}
175
 
176
 
177
/* returns 0 if installation must proceed, non-zero otherwise */
178
static int welcomescreen(void) {
179
  char *choice[] = {"Install Svarog386 to disk", "Quit to DOS", NULL};
42 mv_fox 180
  choice[0] = kittengets(0, 1, choice[0]);
181
  choice[1] = kittengets(0, 2, choice[1]);
28 mv_fox 182
  newscreen();
42 mv_fox 183
  putstringnls(4, 1, COLOR_BODY[mono], 2, 0, "You are about to install Svarog386: a free, MSDOS-compatible operating system");
184
  putstringnls(5, 1, COLOR_BODY[mono], 2, 1, "based on the FreeDOS kernel. Svarog386 targets 386+ computers and comes with a");
185
  putstringnls(6, 1, COLOR_BODY[mono], 2, 2, "variety of third-party applications.");
186
  putstringnls(8, 1, COLOR_BODY[mono], 2, 3, "WARNING: If your PC has another operating system installed, this other system");
187
  putstringnls(9, 1, COLOR_BODY[mono], 2, 4, "         might be unable to boot once Svarog386 is installed.");
188
  return(menuselect(13, -1, 4, choice));
28 mv_fox 189
}
190
 
191
 
33 mv_fox 192
/* returns 1 if drive is removable, 0 if not, -1 on error */
193
static int isdriveremovable(int drv) {
28 mv_fox 194
  union REGS r;
33 mv_fox 195
  r.x.ax = 0x4408;
196
  r.h.bl = drv;
28 mv_fox 197
  int86(0x21, &r, &r);
33 mv_fox 198
  /* CF set on error, AX set to 0 if removable, 1 if fixed */
199
  if (r.x.cflag != 0) return(-1);
200
  if (r.x.ax == 0) return(1);
201
  return(0);
28 mv_fox 202
}
203
 
204
 
35 mv_fox 205
/* returns total disk space of drive drv (in MiB, max 2048), or -1 if drive invalid */
206
static int disksize(int drv) {
28 mv_fox 207
  long res;
208
  union REGS r;
209
  r.h.ah = 0x36; /* DOS 2+ get free disk space */
210
  r.h.dl = drv;
211
  int86(0x21, &r, &r);
212
  if (r.x.ax == 0xffffu) return(-1); /* AX set to FFFFh if drive invalid */
213
  res = r.x.ax;
214
  res *= r.x.bx;
215
  res *= r.x.cx;
35 mv_fox 216
  return(res >> 20); /* return result after converting bytes to MiB */
217
}
218
 
219
 
220
/* returns 0 if disk is empty, non-zero otherwise */
221
static int diskempty(int drv) {
222
  unsigned int rc;
223
  int res;
224
  char buff[8];
225
  struct find_t fileinfo;
226
  sprintf(buff, "%c:\\*.*", 'A' + drv - 1);
227
  rc = _dos_findfirst(buff, _A_NORMAL | _A_SUBDIR | _A_HIDDEN | _A_SYSTEM, &fileinfo);
228
  if (rc == 0) {
229
    res = 1; /* call successfull means disk is not empty */
28 mv_fox 230
  } else {
35 mv_fox 231
    res = 0;
28 mv_fox 232
  }
35 mv_fox 233
  /* _dos_findclose(&fileinfo); */ /* apparently required only on OS/2 */
28 mv_fox 234
  return(res);
235
}
236
 
237
 
238
static int preparedrive(void) {
33 mv_fox 239
  int driveremovable;
36 mv_fox 240
  int selecteddrive = 3; /* hardcoded to 'C:' for now */
241
  int cselecteddrive;
35 mv_fox 242
  int ds;
36 mv_fox 243
  char buff[128];
244
  cselecteddrive = 'A' + selecteddrive - 1;
28 mv_fox 245
  for (;;) {
246
    newscreen();
33 mv_fox 247
    driveremovable = isdriveremovable(selecteddrive);
248
    if (driveremovable < 0) {
34 mv_fox 249
      char *list[] = { "Create an automatic partition", "Run the FDISK partitioning tool", "Quit to DOS", NULL};
42 mv_fox 250
      list[0] = kittengets(0, 3, list[0]);
251
      list[1] = kittengets(0, 4, list[1]);
252
      list[2] = kittengets(0, 2, list[2]);
253
      sprintf(buff, kittengets(3, 0, "ERROR: Drive %c: could not be found. Perhaps your hard disk needs to be"), cselecteddrive);
254
      video_putstring(4, 2, COLOR_BODY[mono], buff);
255
      putstringnls(5, 2, COLOR_BODY[mono], 3, 1, "       partitioned first. Please create at least one partition on your");
256
      putstringnls(6, 2, COLOR_BODY[mono], 3, 2, "       hard disk, so Svarog386 can be installed on it. Note, that");
257
      sprintf(buff, kittengets(3, 3, "       Svarog386 requires at least %d MiB of available disk space."), 16);
258
      video_putstring(7, 2, COLOR_BODY[mono], buff);
259
      putstringnls(9, 2, COLOR_BODY[mono], 3, 4, "You can use the FDISK partitioning tool for creating the required partition");
260
      putstringnls(10, 2, COLOR_BODY[mono], 3, 5, "manually, or you can let the installer partitioning your disk");
261
      putstringnls(11, 2, COLOR_BODY[mono], 3, 6, "automatically. You can also abort the installation to use any other");
262
      putstringnls(12, 2, COLOR_BODY[mono], 3, 7, "partition manager of your choice.");
33 mv_fox 263
      switch (menuselect(14, -1, 5, list)) {
264
        case 0:
265
          system("FDISK /AUTO");
266
          break;
267
        case 1:
268
          video_clear(0x0700, 0);
269
          video_movecursor(0, 0);
270
          system("FDISK");
271
          break;
272
        case 2:
273
          return(-1);
274
      }
28 mv_fox 275
      newscreen();
42 mv_fox 276
      putstringnls(11, 10, COLOR_BODY[mono], 3, 8, "Your computer will reboot now.");
277
      putstringnls(12, 10, COLOR_BODY[mono], 0, 5, "Press any key...");
33 mv_fox 278
      input_getkey();
28 mv_fox 279
      reboot();
280
      return(-1);
33 mv_fox 281
    } else if (driveremovable > 0) {
42 mv_fox 282
      sprintf(buff, kittengets(3, 9, "ERROR: Drive %c: is a removable device. Installation aborted."), cselecteddrive);
36 mv_fox 283
      video_putstring(9, 2, COLOR_BODY[mono], buff);
42 mv_fox 284
      putstringnls(11, 2, COLOR_BODY[mono], 0, 5, "Press any key...");
33 mv_fox 285
      return(-1);
28 mv_fox 286
    }
33 mv_fox 287
    /* if not formatted, propose to format it right away (try to create a directory) */
36 mv_fox 288
    sprintf(buff, "%c:\\SVWRTEST.123", cselecteddrive);
289
    if (mkdir(buff) != 0) {
28 mv_fox 290
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
42 mv_fox 291
      list[0] = kittengets(0, 6, list[0]);
292
      list[1] = kittengets(0, 2, list[1]);
293
      sprintf(buff, kittengets(3, 10, "ERROR: Drive %c: seems to be unformated."), cselecteddrive);
36 mv_fox 294
      video_putstring(7, 2, COLOR_BODY[mono], buff);
42 mv_fox 295
      putstringnls(8, 2, COLOR_BODY[mono], 3, 11, "       Do you wish to format it?");
28 mv_fox 296
      if (menuselect(12, -1, 4, list) != 0) return(-1);
297
      video_clear(0x0700, 0);
298
      video_movecursor(0, 0);
42 mv_fox 299
      sprintf(buff, "FORMAT %c: /Q /U /Z:seriously /V:SVAROG386", cselecteddrive);
36 mv_fox 300
      system(buff);
28 mv_fox 301
      continue;
302
    }
36 mv_fox 303
    sprintf(buff, "%c:\\SVWRTEST.123", cselecteddrive);
42 mv_fox 304
    rmdir(buff);
33 mv_fox 305
    /* check total disk space */
35 mv_fox 306
    ds = disksize(selecteddrive);
28 mv_fox 307
    if (ds < 16) {
42 mv_fox 308
      sprintf(buff, kittengets(3, 12, "ERROR: Drive %c: is not big enough!"), cselecteddrive);
309
      video_putstring(9, 2, COLOR_BODY[mono], buff);
310
      sprintf(buff, kittengets(3, 13, "      Svarog386 requires a disk of at least %d MiB."), 16);
311
      video_putstring(10, 2, COLOR_BODY[mono], buff);
312
      putstringnls(12, 2, COLOR_BODY[mono], 0, 5, "Press any key...");
28 mv_fox 313
      input_getkey();
314
      return(-1);
315
    }
316
    /* is the disk empty? */
35 mv_fox 317
    if (diskempty(selecteddrive) != 0) {
28 mv_fox 318
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
42 mv_fox 319
      list[0] = kittengets(0, 6, list[0]);
320
      list[1] = kittengets(0, 2, list[1]);
321
      sprintf(buff, kittengets(3, 14, "ERROR: Drive %c: is not empty. Svarog386 must be installed on an empty disk."), cselecteddrive);
322
      video_putstring(7, 2, COLOR_BODY[mono], buff);
323
      putstringnls(8, 2, COLOR_BODY[mono], 3, 15, "       You can format the disk now, to make it empty. Note however, that");
324
      putstringnls(9, 2, COLOR_BODY[mono], 3, 16, "       this will ERASE ALL CURRENT DATA on your disk.");
28 mv_fox 325
      if (menuselect(12, -1, 4, list) != 0) return(-1);
326
      video_clear(0x0700, 0);
327
      video_movecursor(0, 0);
42 mv_fox 328
      sprintf(buff, "FORMAT %c: /Q /U /Z:seriously /V:SVAROG386", cselecteddrive);
329
      system(buff);
28 mv_fox 330
      continue;
331
    } else {
332
      /* final confirmation */
333
      char *list[] = { "Install Svarog386", "Quit to DOS", NULL};
42 mv_fox 334
      list[0] = kittengets(0, 1, list[0]);
335
      list[1] = kittengets(0, 2, list[1]);
336
      sprintf(buff, kittengets(3, 17, "The installation of Svarog386 to %c: is about to begin."), cselecteddrive);
36 mv_fox 337
      video_putstring(7, 2, COLOR_BODY[mono], buff);
28 mv_fox 338
      if (menuselect(10, -1, 4, list) != 0) return(-1);
36 mv_fox 339
      sprintf(buff, "SYS A: %c:", cselecteddrive);
340
      system(buff);
341
      sprintf(buff, "%c:\\TEMP", cselecteddrive);
342
      mkdir(buff);
343
      return(cselecteddrive);
28 mv_fox 344
    }
345
  }
346
}
347
 
348
 
349
static void bootfilesgen(int targetdrv, char *lang) {
350
  char buff[128];
351
  FILE *fd;
352
  /*** AUTOEXEC.BAT ***/
36 mv_fox 353
  sprintf(buff, "%c:\\AUTOEXEC.BAT", targetdrv);
28 mv_fox 354
  fd = fopen(buff, "wb");
355
  if (fd == NULL) return;
356
  fprintf(fd, "@ECHO OFF\r\n");
36 mv_fox 357
  fprintf(fd, "SET TEMP=%c:\\TEMP\r\n", targetdrv);
358
  fprintf(fd, "SET DOSDIR=%c:\\SYSTEM\\SVAROG.386\r\n", targetdrv);
359
  fprintf(fd, "SET NLSPATH=%%DOSDIR%%\\NLS\r\n", targetdrv);
28 mv_fox 360
  fprintf(fd, "SET LANG=%s\r\n", lang);
361
  fprintf(fd, "SET DIRCMD=/OGNE/P\r\n");
362
  fprintf(fd, "SET FDNPKG.CFG=%c:\\SYSTEM\\CFG\\FDNPKG.CFG\r\n");
363
  fprintf(fd, "SET WATTCP.CFG=%c:\\SYSTEM\\CFG\\WATTCP.CFG\r\n");
364
  fprintf(fd, "PATH %%DOSDIR%%\\BIN;%%DOSDIR%%\\LINKS\r\n");
365
  fprintf(fd, "PROMPT $P$G\r\n");
30 mv_fox 366
  fprintf(fd, "ALIAS REBOOT=FDAPM COLDBOOT\r\n");
367
  fprintf(fd, "ALIAS HALT=FDAPM POWEROFF\r\n");
28 mv_fox 368
  fprintf(fd, "\r\n\r\n");
42 mv_fox 369
  fprintf(fd, "MODE CON CP PREPARE=((991) %c:\\SYSTEM\\SVAROG.386\\CPI\\EGA10.CPX)\r\n");
28 mv_fox 370
  fprintf(fd, "MODE CON CP SELECT=991\r\n");
371
  fprintf(fd, "\r\n");
372
  fprintf(fd, "SHSUCDX /d:FDCD0001\r\n");
373
  fclose(fd);
374
  /*** CONFIG.SYS ***/
36 mv_fox 375
  sprintf(buff, "%c:\\CONFIG.SYS", targetdrv);
28 mv_fox 376
  fd = fopen(buff, "wb");
377
  if (fd == NULL) return;
378
  fprintf(fd, "DOS=UMB,HIGH\r\n");
379
  fprintf(fd, "FILES=50\r\n");
36 mv_fox 380
  fprintf(fd, "DEVICE=%c:\\SYSTEM\\SVAROG.386\\BIN\\HIMEM.EXE\r\n", targetdrv);
381
  fprintf(fd, "SHELLHIGH=%c:\\SYSTEM\\SVAROG.386\\BIN\\COMMAND.COM /E:512", targetdrv);
382
  fprintf(fd, "REM COUNTRY=001,437,%c:\\SYSTEM\\SVAROG.386\r\n", targetdrv);
383
  fprintf(fd, "DEVICE=%c:\\SYSTEM\\SVAROG.386\\BIN\\CDROM.SYS /D:FDCD0001\r\n", targetdrv);
28 mv_fox 384
  fclose(fd);
385
}
386
 
387
 
46 mv_fox 388
static void installpackages(int targetdrv) {
28 mv_fox 389
  char *pkglist[] = {
390
    "APPEND",
391
    "ASSIGN",
392
    "ATTRIB",
393
    "CHKDSK",
394
    "CHOICE",
395
    "COMMAND",
396
    "COMP",
397
    "CPIDOS",
398
    "CTMOUSE",
399
    "DEBUG",
400
    "DEFRAG",
401
    "DELTREE",
402
    "DEVLOAD",
403
    "DISKCOMP",
404
    "DISKCOPY",
405
    "DISPLAY",
406
    "DOSFSCK",
407
    "EDIT",
408
    "EDLIN",
409
    "EXE2BIN",
410
    "FC",
411
    "FDAPM",
412
    "FDISK",
413
    "FDNPKG",
414
    "FIND",
415
    "FORMAT",
416
    "HELP",
417
    "HIMEMX",
418
    "KERNEL",
419
    "KEYB",
420
    "LABEL",
421
    "LBACACHE",
422
    "MEM",
423
    "MIRROR",
424
    "MODE",
425
    "MORE",
426
    "MOVE",
427
    "NANSI",
428
    "NLSFUNC",
429
    "PRINT",
430
    "RDISK",
431
    "RECOVER",
432
    "REPLACE",
433
    "SHARE",
434
    "SHSUCDX",
435
    "SORT",
436
    "SWSUBST",
437
    "TREE",
438
    "UNDELETE",
439
    "XCOPY",
440
    NULL
441
  };
30 mv_fox 442
  int i, pkglistlen;
46 mv_fox 443
  char buff[64];
28 mv_fox 444
  newscreen();
30 mv_fox 445
  /* count how long the pkg list is */
446
  for (pkglistlen = 0; pkglist[pkglistlen] != NULL; pkglistlen++);
46 mv_fox 447
  /* set DOSDIR and friends */
448
  snprintf(buff, sizeof(buff), "%c:\\SYSTEM\\SVAROG.386", targetdrv);
449
  setenv("DOSDIR", buff, 1);
450
  snprintf(buff, sizeof(buff), "%c:\\TEMP", targetdrv);
451
  setenv("TEMP", buff, 1);
30 mv_fox 452
  /* install packages */
28 mv_fox 453
  for (i = 0; pkglist[i] != NULL; i++) {
36 mv_fox 454
    char buff[128];
42 mv_fox 455
    snprintf(buff, sizeof(buff), kittengets(4, 0, "Installing package %d/%d: %s"), i+1, pkglistlen, pkglist[i]);
36 mv_fox 456
    strcat(buff, "       ");
30 mv_fox 457
    video_putstring(10, 2, COLOR_BODY[mono], buff);
46 mv_fox 458
    sprintf(buff, "FDINST INSTALL X:\\BASE\\%s.ZIP > NUL", pkglist[i]);
28 mv_fox 459
    system(buff);
460
  }
461
}
462
 
463
 
42 mv_fox 464
static void finalreboot(void) {
465
  newscreen();
466
  putstringnls(10, 2, COLOR_BODY[mono], 5, 0, "Svarog386 installation is over. Your computer will reboot now.");
467
  putstringnls(11, 2, COLOR_BODY[mono], 5, 1, "Please remove the installation disk from your drive.");
468
  putstringnls(13, 2, COLOR_BODY[mono], 0, 5, "Press any key...");
469
  input_getkey();
470
  reboot();
471
}
472
 
473
 
474
static void loadcp(char *lang) {
475
  int cp, egafile;
476
  char buff[64];
477
  cp = getnlscp(lang, &egafile);
478
  if (cp == 437) return;
479
  video_movecursor(1, 0);
480
  if (egafile == 1) {
481
    sprintf(buff, "MODE CON CP PREP=((%d) A:\\EGA.CPX)", cp);
482
  } else {
483
    sprintf(buff, "MODE CON CP PREP=((%d) A:\\EGA%d.CPX)", cp, egafile);
484
  }
485
  system(buff);
486
  sprintf(buff, "MODE CON CP SEL=%d", cp);
487
  system(buff);
488
  /* below I re-init the video controller - apparently this is required if
489
   * I want the new glyph symbols to be actually applied */
490
  {
491
  union REGS r;
492
  r.h.ah = 0x0F; /* get current video mode */
493
  int86(0x10, &r, &r); /* r.h.al contains the current video mode now */
494
  r.h.ah = 0; /* set video mode (to whatever is set in AL) */
495
  int86(0x10, &r, &r);
496
  }
497
}
498
 
499
 
28 mv_fox 500
int main(void) {
501
  char lang[4];
502
  int targetdrv;
503
 
29 mv_fox 504
  /* init screen and detect mono status */
505
  mono = video_init();
506
 
28 mv_fox 507
  for (;;) { /* fake loop, it's here just to break out easily */
508
    if (selectlang(lang) < 0) break; /* welcome to svarog, select your language */
42 mv_fox 509
    setenv("LANG", lang, 1);
510
    loadcp(lang);
511
    kittenopen("INSTALL"); /* NLS support */
30 mv_fox 512
    /*selectkeyb();*/ /* what keyb layout should we use? */
28 mv_fox 513
    if (welcomescreen() != 0) break; /* what svarog386 is, ask whether to run live dos or install */
514
    targetdrv = preparedrive(); /* what drive should we install to? check avail. space */
515
    if (targetdrv < 0) break;
516
    /*askaboutsources();*/ /* IF sources are available, ask if installing with them */
46 mv_fox 517
    installpackages(targetdrv);   /* install packages */
28 mv_fox 518
    bootfilesgen(targetdrv, lang); /* generate simple boot files */
519
    /*localcfg();*/ /* show local params (currency, etc), and propose to change them (based on localcfg) */
42 mv_fox 520
    /*netcfg();*/ /* basic networking config */
521
    /* TODO compute a customized FDNPKG file that looks either to local CD or net */
28 mv_fox 522
    finalreboot(); /* remove the CD and reboot */
523
    break;
524
  }
42 mv_fox 525
  kittenclose(); /* close NLS support */
28 mv_fox 526
  video_clear(0x0700, 0);
527
  video_movecursor(0, 0);
528
  return(0);
529
}