Subversion Repositories SvarDOS

Rev

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

Rev Author Line No. Line
28 mv_fox 1
/*
190 mateuszvis 2
 * SVARDOS INSTALL PROGRAM
206 mateuszvis 3
 *
190 mateuszvis 4
 * PUBLISHED UNDER THE TERMS OF THE MIT LICENSE
42 mv_fox 5
 *
624 mateuszvis 6
 * COPYRIGHT (C) 2016-2022 MATEUSZ VISTE, ALL RIGHTS RESERVED.
94 mv_fox 7
 *
190 mateuszvis 8
 * Permission is hereby granted, free of charge, to any person obtaining a
9
 * copy of this software and associated documentation files (the "Software"),
10
 * to deal in the Software without restriction, including without limitation
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
 * and/or sell copies of the Software, and to permit persons to whom the
13
 * Software is furnished to do so, subject to the following conditions:
94 mv_fox 14
 *
190 mateuszvis 15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
94 mv_fox 17
 *
190 mateuszvis 18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
 * DEALINGS IN THE SOFTWARE.
94 mv_fox 25
 *
868 mateusz.vi 26
 * http://svardos.org
28 mv_fox 27
 */
28
 
29
#include <dos.h>
30 mv_fox 30
#include <direct.h>  /* mkdir() */
28 mv_fox 31
#include <stdio.h>   /* printf() and friends */
32
#include <stdlib.h>  /* system() */
33
#include <string.h>  /* memcpy() */
34
#include <unistd.h>
42 mv_fox 35
 
624 mateuszvis 36
#include "svarlang.lib\svarlang.h"
42 mv_fox 37
 
28 mv_fox 38
#include "input.h"
39
#include "video.h"
40
 
67 mv_fox 41
/* keyboard layouts and locales */
42
#include "keylay.h"
43
#include "keyoff.h"
42 mv_fox 44
 
908 mateusz.vi 45
/* prototype of the int24hdl() function defined in int24hdl.asm */
46
void int24hdl(void);
47
 
48
 
29 mv_fox 49
/* color scheme (color, mono) */
50
static unsigned short COLOR_TITLEBAR[2] = {0x7000,0x7000};
51
static unsigned short COLOR_BODY[2] = {0x1700,0x0700};
52
static unsigned short COLOR_SELECT[2] = {0x7000,0x7000};
53
static unsigned short COLOR_SELECTCUR[2] = {0x1F00,0x0700};
28 mv_fox 54
 
29 mv_fox 55
/* mono flag */
56
static int mono = 0;
28 mv_fox 57
 
190 mateuszvis 58
/* how much disk space does SvarDOS require (in MiB) */
59
#define SVARDOS_DISK_REQ 8
28 mv_fox 60
 
73 mv_fox 61
/* menu screens can output only one of these: */
62
#define MENUNEXT 0
63
#define MENUPREV -1
64
#define MENUQUIT -2
65
 
67 mv_fox 66
/* a convenience 'function' used for debugging */
67
#define DBG(x) { video_putstringfix(24, 0, 0x4F00u, x, 80); }
47 mv_fox 68
 
67 mv_fox 69
struct slocales {
70
  char lang[4];
624 mateuszvis 71
  const char *keybcode;
67 mv_fox 72
  unsigned int codepage;
73
  int egafile;
74
  int keybfile;
75
  int keyboff;
76
  int keyblen;
96 mv_fox 77
  unsigned int keybid;
67 mv_fox 78
};
79
 
80
 
28 mv_fox 81
/* reboot the computer */
82
static void reboot(void) {
83
  void ((far *bootroutine)()) = (void (far *)()) 0xFFFF0000L;
84
  int far *rstaddr = (int far *)0x00400072L; /* BIOS boot flag is at 0040:0072 */
85
  *rstaddr = 0x1234; /* 0x1234 = warm boot, 0 = cold boot */
86
  (*bootroutine)(); /* jump to the BIOS reboot routine at FFFF:0000 */
87
}
88
 
42 mv_fox 89
 
56 mv_fox 90
/* outputs a string to screen with taking care of word wrapping. returns amount of lines. */
624 mateuszvis 91
static int putstringwrap(int y, int x, unsigned short attr, const char *s) {
56 mv_fox 92
  int linew, lincount;
93
  linew = 80;
94
  if (x >= 0) linew -= (x << 1);
95
 
96
  for (lincount = 1; y+lincount < 25; lincount++) {
97
    int i, len = linew;
98
    for (i = 0; i <= linew; i++) {
99
      if (s[i] == ' ') len = i;
100
      if (s[i] == '\n') {
101
        len = i;
102
        break;
103
      }
104
      if (s[i] == 0) {
105
        len = i;
106
        break;
107
      }
108
    }
109
    video_putstring(y++, x, attr, s, len);
110
    s += len;
111
    if (*s == 0) break;
112
    s += 1; /* skip the whitespace char */
113
  }
114
  return(lincount);
115
}
116
 
117
 
118
/* an NLS wrapper around video_putstring(), also performs line wrapping when
119
 * needed. returns the amount of lines that were output */
624 mateuszvis 120
static int putstringnls(int y, int x, unsigned short attr, int nlsmaj, int nlsmin) {
121
  const char *s = svarlang_str(nlsmaj, nlsmin);
122
  if (s == NULL) s = "";
56 mv_fox 123
  return(putstringwrap(y, x, attr, s));
42 mv_fox 124
}
125
 
126
 
280 mateuszvis 127
/* copy file f1 to f2 using buff as a buffer of buffsz bytes. f2 will be overwritten if it
128
 * exists already! returns 0 on success. */
129
static int fcopy(const char *f2, const char *f1, void *buff, size_t buffsz) {
130
  FILE *fd1, *fd2;
131
  size_t sz;
132
  int res = -1; /* assume failure */
133
 
134
  /* open files */
135
  fd1 = fopen(f1, "rb");
136
  fd2 = fopen(f2, "wb");
137
  if ((fd1 == NULL) || (fd2 == NULL)) goto QUIT;
138
 
139
  /* copy data */
140
  for (;;) {
141
    sz = fread(buff, 1, buffsz, fd1);
142
    if (sz == 0) {
143
      if (feof(fd1) != 0) break;
144
      goto QUIT;
145
    }
146
    if (fwrite(buff, 1, sz, fd2) != sz) goto QUIT;
147
  }
148
 
149
  res = 0; /* success */
150
 
151
  QUIT:
152
  if (fd1 != NULL) fclose(fd1);
153
  if (fd2 != NULL) fclose(fd2);
154
  return(res);
155
}
156
 
157
 
624 mateuszvis 158
static int menuselect(int ypos, int xpos, int height, const char **list, int listlen) {
28 mv_fox 159
  int i, offset = 0, res = 0, count, width = 0;
67 mv_fox 160
  /* count how many positions there is, and check their width */
161
  for (count = 0; (list[count] != NULL) && (count != listlen); count++) {
28 mv_fox 162
    int len = strlen(list[count]);
163
    if (len > width) width = len;
164
  }
165
 
166
  /* if xpos negative, means 'center out' */
167
  if (xpos < 0) xpos = 39 - (width >> 1);
168
 
29 mv_fox 169
  video_putchar(ypos, xpos+width+2, COLOR_SELECT[mono], 0xBF);         /*       \ */
170
  video_putchar(ypos, xpos-1, COLOR_SELECT[mono], 0xDA);               /*  /      */
171
  video_putchar(ypos+height-1, xpos-1, COLOR_SELECT[mono], 0xC0);      /*  \      */
172
  video_putchar(ypos+height-1, xpos+width+2, COLOR_SELECT[mono], 0xD9);/*      /  */
173
  video_putcharmulti(ypos, xpos, COLOR_SELECT[mono], 0xC4, width + 2, 1);
174
  video_putcharmulti(ypos+height-1, xpos, COLOR_SELECT[mono], 0xC4, width + 2, 1);
175
  video_putcharmulti(ypos+1, xpos-1, COLOR_SELECT[mono], 0xB3, height - 2, 80);
176
  video_putcharmulti(ypos+1, xpos+width+2, COLOR_SELECT[mono], 0xB3, height - 2, 80);
28 mv_fox 177
 
178
  for (;;) {
179
    int key;
180
    /* list of selectable items */
181
    for (i = 0; i < height - 2; i++) {
182
      if (i + offset == res) {
29 mv_fox 183
        video_putchar(ypos + 1 + i, xpos, COLOR_SELECTCUR[mono], 16);
184
        video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECTCUR[mono], 17);
28 mv_fox 185
        video_movecursor(ypos + 1 + i, xpos);
29 mv_fox 186
        video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECTCUR[mono], list[i + offset], width);
28 mv_fox 187
      } else if (i + offset < count) {
29 mv_fox 188
        video_putchar(ypos + 1 + i, xpos, COLOR_SELECT[mono], ' ');
189
        video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECT[mono], ' ');
190
        video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECT[mono], list[i + offset], width);
28 mv_fox 191
      } else {
29 mv_fox 192
        video_putcharmulti(ypos + 1 + i, xpos, COLOR_SELECT[mono], ' ', width+2, 1);
28 mv_fox 193
      }
194
    }
195
    key = input_getkey();
196
    if (key == 0x0D) { /* ENTER */
197
      return(res);
198
    } else if (key == 0x148) { /* up */
33 mv_fox 199
      if (res > 0) {
200
        res--;
201
        if (res < offset) offset = res;
202
      }
28 mv_fox 203
    } else if (key == 0x150) { /* down */
33 mv_fox 204
      if (res+1 < count) {
205
        res++;
206
        if (res > offset + height - 3) offset = res - (height - 3);
207
      }
208
    } else if (key == 0x147) { /* home */
209
      res = 0;
210
      offset = 0;
211
    } else if (key == 0x14F) { /* end */
212
      res = count - 1;
213
      if (res > offset + height - 3) offset = res - (height - 3);
28 mv_fox 214
    } else if (key == 0x1B) {  /* ESC */
215
      return(-1);
78 mv_fox 216
    }/* else {
33 mv_fox 217
      char buf[8];
55 mv_fox 218
      snprintf(buf, sizeof(buf), "0x%02X ", key);
56 mv_fox 219
      video_putstring(1, 0, COLOR_BODY[mono], buf, -1);
78 mv_fox 220
    }*/
28 mv_fox 221
  }
222
}
223
 
79 mv_fox 224
static void newscreen(int statusbartype) {
624 mateuszvis 225
  const char *msg;
226
  msg = svarlang_strid(0x00); /* "SVARDOS INSTALLATION" */
81 mv_fox 227
  video_putcharmulti(0, 0, COLOR_TITLEBAR[mono], ' ', 80, 1);
79 mv_fox 228
  video_putstring(0, 40 - (strlen(msg) >> 1), COLOR_TITLEBAR[mono], msg, -1);
81 mv_fox 229
  video_clear(COLOR_BODY[mono], 80, -80);
79 mv_fox 230
  switch (statusbartype) {
231
    case 1:
624 mateuszvis 232
      msg = svarlang_strid(0x000B); /* "Up/Down = Select entry | Enter = Validate your choice | ESC = Quit to DOS" */
79 mv_fox 233
      break;
234
    case 2:
624 mateuszvis 235
      msg = svarlang_strid(0x0005); /* "Press any key..." */
79 mv_fox 236
      break;
237
    case 3:
238
      msg = "";
239
      break;
240
    default:
624 mateuszvis 241
      msg = svarlang_strid(0x000A); /* "Up/Down = Select entry | Enter = Validate your choice | ESC = Previous screen" */
79 mv_fox 242
      break;
243
  }
244
  video_putchar(24, 0, COLOR_TITLEBAR[mono], ' ');
245
  video_putstringfix(24, 1, COLOR_TITLEBAR[mono], msg, 79);
36 mv_fox 246
  video_movecursor(25,0);
28 mv_fox 247
}
248
 
96 mv_fox 249
/* fills a slocales struct accordingly to the value of its keyboff member */
250
static void kblay2slocal(struct slocales *locales) {
624 mateuszvis 251
  const char *m;
96 mv_fox 252
  for (m = kblayouts[locales->keyboff]; *m != 0; m++); /* skip layout name */
253
  m++;
254
  /* skip keyb code and copy it to locales.keybcode */
255
  locales->keybcode = m;
256
  for (; *m != 0; m++);
257
  /* */
258
  locales->codepage = ((unsigned short)m[1] << 8) | m[2];
259
  locales->egafile = m[3];
260
  locales->keybfile = m[4];
261
  locales->keybid = ((unsigned short)m[5] << 8) | m[6];
262
}
263
 
67 mv_fox 264
static int selectlang(struct slocales *locales) {
265
  int choice, x;
624 mateuszvis 266
  const char *msg;
267
  const char *langlist[] = {
67 mv_fox 268
    "English",
269
    "French",
133 mv_fox 270
    "German",
119 mv_fox 271
    "Italian",
67 mv_fox 272
    "Polish",
116 mv_fox 273
    "Russian",
123 mv_fox 274
    "Slovene",
128 mv_fox 275
    "Swedish",
67 mv_fox 276
    "Turkish",
28 mv_fox 277
    NULL
278
  };
279
 
79 mv_fox 280
  newscreen(1);
624 mateuszvis 281
  msg = svarlang_strid(0x0100); /* "Welcome to SvarDOS" */
42 mv_fox 282
  x = 40 - (strlen(msg) >> 1);
56 mv_fox 283
  video_putstring(4, x, COLOR_BODY[mono], msg, -1);
42 mv_fox 284
  video_putcharmulti(5, x, COLOR_BODY[mono], '=', strlen(msg), 1);
624 mateuszvis 285
  putstringnls(8, -1, COLOR_BODY[mono], 1, 1); /* "Please select your language from the list below:" */
133 mv_fox 286
  choice = menuselect(11, -1, 11, langlist, -1);
73 mv_fox 287
  if (choice < 0) return(MENUPREV);
67 mv_fox 288
  /* populate locales with default values */
289
  memset(locales, 0, sizeof(struct slocales));
290
  switch (choice) {
291
    case 1:
292
      strcpy(locales->lang, "FR");
293
      locales->keyboff = OFFLOC_FR;
294
      locales->keyblen = OFFLEN_FR;
295
      break;
296
    case 2:
133 mv_fox 297
      strcpy(locales->lang, "DE");
298
      locales->keyboff = OFFLOC_DE;
299
      locales->keyblen = OFFLEN_DE;
300
      break;
301
    case 3:
119 mv_fox 302
      strcpy(locales->lang, "IT");
303
      locales->keyboff = OFFLOC_IT;
304
      locales->keyblen = OFFLEN_IT;
305
      break;
133 mv_fox 306
    case 4:
67 mv_fox 307
      strcpy(locales->lang, "PL");
308
      locales->keyboff = OFFLOC_PL;
309
      locales->keyblen = OFFLEN_PL;
310
      break;
133 mv_fox 311
    case 5:
116 mv_fox 312
      strcpy(locales->lang, "RU");
313
      locales->keyboff = OFFLOC_RU;
314
      locales->keyblen = OFFLEN_RU;
315
      break;
133 mv_fox 316
    case 6:
123 mv_fox 317
      strcpy(locales->lang, "SI");
318
      locales->keyboff = OFFLOC_SI;
319
      locales->keyblen = OFFLEN_SI;
320
      break;
133 mv_fox 321
    case 7:
128 mv_fox 322
      strcpy(locales->lang, "SV");
323
      locales->keyboff = OFFLOC_SV;
324
      locales->keyblen = OFFLEN_SV;
325
      break;
133 mv_fox 326
    case 8:
67 mv_fox 327
      strcpy(locales->lang, "TR");
328
      locales->keyboff = OFFLOC_TR;
329
      locales->keyblen = OFFLEN_TR;
330
      break;
331
    default:
332
      strcpy(locales->lang, "EN");
333
      locales->keyboff = 0;
334
      locales->keyblen = OFFCOUNT;
335
      break;
336
  }
96 mv_fox 337
  /* populate the slocales struct accordingly to the keyboff member */
338
  kblay2slocal(locales);
67 mv_fox 339
  /* */
73 mv_fox 340
  return(MENUNEXT);
28 mv_fox 341
}
342
 
343
 
67 mv_fox 344
static int selectkeyb(struct slocales *locales) {
96 mv_fox 345
  int menuheight, choice;
346
  if (locales->keyblen == 1) return(MENUNEXT); /* do not ask for keyboard layout if only one is available for given language */
79 mv_fox 347
  newscreen(0);
624 mateuszvis 348
  putstringnls(5, 1, COLOR_BODY[mono], 1, 5); /* "SvarDOS supports different keyboard layouts */
96 mv_fox 349
  menuheight = locales->keyblen + 2;
67 mv_fox 350
  if (menuheight > 13) menuheight = 13;
96 mv_fox 351
  choice = menuselect(10, -1, menuheight, &(kblayouts[locales->keyboff]), locales->keyblen);
352
  if (choice < 0) return(MENUPREV);
353
  /* (re)load the keyboard layout & codepage setup */
354
  locales->keyboff += choice;
355
  kblay2slocal(locales);
73 mv_fox 356
  return(MENUNEXT);
67 mv_fox 357
}
358
 
359
 
28 mv_fox 360
/* returns 0 if installation must proceed, non-zero otherwise */
361
static int welcomescreen(void) {
73 mv_fox 362
  int c;
624 mateuszvis 363
  const char *choice[3];
364
  choice[0] = svarlang_strid(0x0001);
365
  choice[1] = svarlang_strid(0x0002);
366
  choice[2] = NULL;
79 mv_fox 367
  newscreen(0);
624 mateuszvis 368
  putstringnls(4, 1, COLOR_BODY[mono], 2, 0); /* "You are about to install SvarDOS */
73 mv_fox 369
  c = menuselect(13, -1, 4, choice, -1);
370
  if (c < 0) return(MENUPREV);
371
  if (c == 0) return(MENUNEXT);
372
  return(MENUQUIT);
28 mv_fox 373
}
374
 
375
 
33 mv_fox 376
/* returns 1 if drive is removable, 0 if not, -1 on error */
377
static int isdriveremovable(int drv) {
28 mv_fox 378
  union REGS r;
33 mv_fox 379
  r.x.ax = 0x4408;
380
  r.h.bl = drv;
28 mv_fox 381
  int86(0x21, &r, &r);
33 mv_fox 382
  /* CF set on error, AX set to 0 if removable, 1 if fixed */
383
  if (r.x.cflag != 0) return(-1);
384
  if (r.x.ax == 0) return(1);
385
  return(0);
28 mv_fox 386
}
387
 
388
 
35 mv_fox 389
/* returns total disk space of drive drv (in MiB, max 2048), or -1 if drive invalid */
390
static int disksize(int drv) {
28 mv_fox 391
  long res;
392
  union REGS r;
393
  r.h.ah = 0x36; /* DOS 2+ get free disk space */
312 mateuszvis 394
  r.h.dl = drv;  /* A=1, B=2, etc */
28 mv_fox 395
  int86(0x21, &r, &r);
396
  if (r.x.ax == 0xffffu) return(-1); /* AX set to FFFFh if drive invalid */
49 mv_fox 397
  res = r.x.ax;  /* sectors per cluster */
398
  res *= r.x.dx; /* dx contains total clusters, bx contains free clusters */
399
  res *= r.x.cx; /* bytes per sector */
400
  res >>= 20;    /* convert bytes to MiB */
401
  return(res);
35 mv_fox 402
}
403
 
404
 
405
/* returns 0 if disk is empty, non-zero otherwise */
406
static int diskempty(int drv) {
407
  unsigned int rc;
408
  int res;
409
  char buff[8];
410
  struct find_t fileinfo;
55 mv_fox 411
  snprintf(buff, sizeof(buff), "%c:\\*.*", 'A' + drv - 1);
35 mv_fox 412
  rc = _dos_findfirst(buff, _A_NORMAL | _A_SUBDIR | _A_HIDDEN | _A_SYSTEM, &fileinfo);
413
  if (rc == 0) {
414
    res = 1; /* call successfull means disk is not empty */
28 mv_fox 415
  } else {
35 mv_fox 416
    res = 0;
28 mv_fox 417
  }
35 mv_fox 418
  /* _dos_findclose(&fileinfo); */ /* apparently required only on OS/2 */
28 mv_fox 419
  return(res);
420
}
421
 
280 mateuszvis 422
#ifdef DEADCODE
200 mateuszvis 423
/* set new DOS "current drive" to drv ('A', 'B', etc). returns 0 on success */
424
static int set_cur_drive(char drv) {
425
  union REGS r;
426
  if ((drv < 'A') || (drv > 'Z')) return(-1);
427
  r.h.ah = 0x0E; /* DOS 1+ SELECT DEFAULT DRIVE */
428
  r.h.dl = drv - 'A';
429
  int86(0x21, &r, &r);
430
  if (r.h.al < drv - 'A') return(-1);
431
  return(0);
432
}
280 mateuszvis 433
#endif
200 mateuszvis 434
 
310 mateuszvis 435
 
436
/* get the DOS "current drive" (0=A:, 1=B:, etc) */
437
static int get_cur_drive(void) {
438
  union REGS r;
439
  r.h.ah = 0x19; /* DOS 1+ GET CURRENT DEFAULT DRIVE */
440
  int86(0x21, &r, &r);
441
  return(r.h.al);
442
}
443
 
444
 
200 mateuszvis 445
/* returns 0 if file exists, non-zero otherwise */
446
static int fileexists(const char *fname) {
447
  FILE *fd;
448
  fd = fopen(fname, "rb");
449
  if (fd == NULL) return(-1);
450
  fclose(fd);
451
  return(0);
452
}
453
 
454
 
898 mateusz.vi 455
/* tries to write an empty file to drive.
456
 * asks DOS to inhibit the int 24h handler for this job, so erros are
457
 * gracefully reported - unfortunately this does not work under FreeDOS because
458
 * the DOS-C kernel does not implement the required flag.
459
 * returns 0 on success (ie. "disk exists and is writeable"). */
460
static unsigned short test_drive_write(char drive, char *buff) {
461
  unsigned short result = 0;
462
  sprintf(buff, "%c:\\SVWRTEST.123", drive);
463
  _asm {
464
    push ax
465
    push bx
466
    push cx
467
    push dx
468
 
469
    mov ah, 0x6c   /* extended open/create file */
470
    mov bx, 0x2001 /* open for write + inhibit int 24h handler */
471
    xor cx, cx     /* file attributes on the created file */
472
    mov dx, 0x0010 /* create file if does not exist, fail if it exists */
473
    mov si, buff   /* filename to create */
474
    int 0x21
475
    jc FAILURE
476
    /* close the file (handle in AX) */
477
    mov bx, ax
478
    mov ah, 0x3e /* close file */
479
    int 0x21
480
    jc FAILURE
481
    /* delete the file */
482
    mov ah, 0x41 /* delete file pointed out by DS:DX */
483
    mov dx, buff
484
    int 0x21
485
    jnc DONE
486
 
487
    FAILURE:
488
    mov result, ax
489
    DONE:
490
 
491
    pop dx
492
    pop cx
493
    pop bx
494
    pop ax
495
  }
496
  return(result);
497
}
498
 
499
 
310 mateuszvis 500
static int preparedrive(char sourcedrv) {
33 mv_fox 501
  int driveremovable;
310 mateuszvis 502
  int selecteddrive = 3; /* default to 'C:' */
36 mv_fox 503
  int cselecteddrive;
35 mv_fox 504
  int ds;
73 mv_fox 505
  int choice;
56 mv_fox 506
  char buff[1024];
312 mateuszvis 507
  int driveid = 1; /* fdisk runs on first drive (unless USB boot) */
508
  if (selecteddrive == get_cur_drive() + 1) { /* get_cur_drive() returns 0-based values (A=0) while selecteddrive is 1-based (A=1) */
509
    selecteddrive = 4; /* use D: if install is run from C: (typically because it was booted from USB?) */
510
    driveid = 2; /* primary drive is the emulated USB storage */
511
  }
36 mv_fox 512
  cselecteddrive = 'A' + selecteddrive - 1;
28 mv_fox 513
  for (;;) {
33 mv_fox 514
    driveremovable = isdriveremovable(selecteddrive);
515
    if (driveremovable < 0) {
624 mateuszvis 516
      const char *list[4];
79 mv_fox 517
      newscreen(0);
624 mateuszvis 518
      list[0] = svarlang_str(0, 3); /* Create a partition automatically */
519
      list[1] = svarlang_str(0, 4); /* Run the FDISK tool */
520
      list[2] = svarlang_str(0, 2); /* Quit to DOS */
521
      list[3] = NULL;
522
      snprintf(buff, sizeof(buff), svarlang_strid(0x0300), cselecteddrive, SVARDOS_DISK_REQ); /* "ERROR: Drive %c: could not be found. Note, that SvarDOS requires at least %d MiB of available disk space */
555 mateuszvis 523
      switch (menuselect(6 + putstringwrap(4, 1, COLOR_BODY[mono], buff), -1, 5, list, -1)) {
33 mv_fox 524
        case 0:
312 mateuszvis 525
          sprintf(buff, "FDISK /AUTO %d", driveid);
526
          system(buff);
33 mv_fox 527
          break;
528
        case 1:
81 mv_fox 529
          video_clear(0x0700, 0, 0);
33 mv_fox 530
          video_movecursor(0, 0);
312 mateuszvis 531
          sprintf(buff, "FDISK %d", driveid);
532
          system(buff);
33 mv_fox 533
          break;
73 mv_fox 534
        case 2:
535
          return(MENUQUIT);
56 mv_fox 536
        default:
33 mv_fox 537
          return(-1);
538
      }
113 mv_fox 539
      /* write a temporary MBR which only skips the drive (in case BIOS would
540
       * try to boot off the not-yet-ready C: disk) */
312 mateuszvis 541
      sprintf(buff, "FDISK /AMBR %d", driveid);
542
      system(buff); /* writes BOOT.MBR into actual MBR */
79 mv_fox 543
      newscreen(2);
624 mateuszvis 544
      putstringnls(10, 10, COLOR_BODY[mono], 3, 1); /* "Your computer will reboot now." */
545
      putstringnls(12, 10, COLOR_BODY[mono], 0, 5); /* "Press any key..." */
33 mv_fox 546
      input_getkey();
28 mv_fox 547
      reboot();
73 mv_fox 548
      return(MENUQUIT);
33 mv_fox 549
    } else if (driveremovable > 0) {
79 mv_fox 550
      newscreen(2);
624 mateuszvis 551
      snprintf(buff, sizeof(buff), svarlang_strid(0x0302), cselecteddrive); /* "ERROR: Drive %c: is a removable device */
61 mv_fox 552
      video_putstring(9, 1, COLOR_BODY[mono], buff, -1);
624 mateuszvis 553
      putstringnls(11, 2, COLOR_BODY[mono], 0, 5); /* "Press any key..." */
73 mv_fox 554
      return(MENUQUIT);
28 mv_fox 555
    }
33 mv_fox 556
    /* if not formatted, propose to format it right away (try to create a directory) */
898 mateusz.vi 557
    if (test_drive_write(cselecteddrive, buff) != 0) {
624 mateuszvis 558
      const char *list[3];
79 mv_fox 559
      newscreen(0);
624 mateuszvis 560
      snprintf(buff, sizeof(buff), svarlang_str(3, 3), cselecteddrive); /* "ERROR: Drive %c: seems to be unformated. Do you wish to format it?") */
61 mv_fox 561
      video_putstring(7, 1, COLOR_BODY[mono], buff, -1);
556 mateuszvis 562
 
624 mateuszvis 563
      snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
556 mateuszvis 564
      list[0] = buff;
624 mateuszvis 565
      list[1] = svarlang_strid(0x0002); /* "Quit to DOS" */
556 mateuszvis 566
      list[2] = NULL;
567
 
73 mv_fox 568
      choice = menuselect(12, -1, 4, list, -1);
569
      if (choice < 0) return(MENUPREV);
570
      if (choice == 1) return(MENUQUIT);
81 mv_fox 571
      video_clear(0x0700, 0, 0);
28 mv_fox 572
      video_movecursor(0, 0);
190 mateuszvis 573
      snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
36 mv_fox 574
      system(buff);
28 mv_fox 575
      continue;
576
    }
33 mv_fox 577
    /* check total disk space */
35 mv_fox 578
    ds = disksize(selecteddrive);
190 mateuszvis 579
    if (ds < SVARDOS_DISK_REQ) {
56 mv_fox 580
      int y = 9;
79 mv_fox 581
      newscreen(2);
624 mateuszvis 582
      snprintf(buff, sizeof(buff), svarlang_strid(0x0304), cselecteddrive, SVARDOS_DISK_REQ); /* "ERROR: Drive %c: is not big enough! SvarDOS requires a disk of at least %d MiB." */
61 mv_fox 583
      y += putstringwrap(y, 1, COLOR_BODY[mono], buff);
624 mateuszvis 584
      putstringnls(++y, 1, COLOR_BODY[mono], 0, 5); /* "Press any key..." */
28 mv_fox 585
      input_getkey();
73 mv_fox 586
      return(MENUQUIT);
28 mv_fox 587
    }
588
    /* is the disk empty? */
79 mv_fox 589
    newscreen(0);
35 mv_fox 590
    if (diskempty(selecteddrive) != 0) {
624 mateuszvis 591
      const char *list[3];
65 mv_fox 592
      int y = 6;
624 mateuszvis 593
      snprintf(buff, sizeof(buff), svarlang_strid(0x0305), cselecteddrive); /* "ERROR: Drive %c: not empty" */
65 mv_fox 594
      y += putstringwrap(y, 1, COLOR_BODY[mono], buff);
556 mateuszvis 595
 
624 mateuszvis 596
      snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
556 mateuszvis 597
      list[0] = buff;
624 mateuszvis 598
      list[1] = svarlang_strid(0x0002); /* "Quit to DOS" */
556 mateuszvis 599
      list[2] = NULL;
600
 
73 mv_fox 601
      choice = menuselect(++y, -1, 4, list, -1);
602
      if (choice < 0) return(MENUPREV);
603
      if (choice == 1) return(MENUQUIT);
81 mv_fox 604
      video_clear(0x0700, 0, 0);
28 mv_fox 605
      video_movecursor(0, 0);
190 mateuszvis 606
      snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
42 mv_fox 607
      system(buff);
28 mv_fox 608
      continue;
609
    } else {
610
      /* final confirmation */
624 mateuszvis 611
      const char *list[3];
612
      list[0] = svarlang_strid(0x0001); /* Install SvarDOS */
613
      list[1] = svarlang_strid(0x0002); /* Quit to DOS */
614
      list[2] = NULL;
615
      snprintf(buff, sizeof(buff), svarlang_strid(0x0306), cselecteddrive); /* "The installation of SvarDOS to %c: is about to begin." */
56 mv_fox 616
      video_putstring(7, -1, COLOR_BODY[mono], buff, -1);
73 mv_fox 617
      choice = menuselect(10, -1, 4, list, -1);
618
      if (choice < 0) return(MENUPREV);
619
      if (choice == 1) return(MENUQUIT);
310 mateuszvis 620
      snprintf(buff, sizeof(buff), "SYS %c: %c: > NUL", sourcedrv, cselecteddrive);
36 mv_fox 621
      system(buff);
312 mateuszvis 622
      sprintf(buff, "FDISK /MBR %d", driveid);
623
      system(buff);
55 mv_fox 624
      snprintf(buff, sizeof(buff), "%c:\\TEMP", cselecteddrive);
36 mv_fox 625
      mkdir(buff);
626
      return(cselecteddrive);
28 mv_fox 627
    }
628
  }
629
}
630
 
631
 
280 mateuszvis 632
/* generates locales-related configurations and writes them to file (this
633
 * is used to compute autoexec.bat content) */
634
static void genlocalesconf(FILE *fd, const struct slocales *locales) {
635
  if (locales == NULL) return;
636
 
637
  fprintf(fd, "SET LANG=%s\r\n", locales->lang);
638
 
639
  if (locales->egafile > 0) {
640
    fprintf(fd, "DISPLAY CON=(EGA,,1)\r\n");
641
    if (locales->egafile == 1) {
642
      fprintf(fd, "MODE CON CP PREPARE=((%u) %%DOSDIR%%\\CPI\\EGA.CPX)\r\n", locales->codepage);
643
    } else {
644
      fprintf(fd, "MODE CON CP PREPARE=((%u) %%DOSDIR%%\\CPI\\EGA%d.CPX)\r\n", locales->codepage, locales->egafile);
645
    }
646
    fprintf(fd, "MODE CON CP SELECT=%u\r\n", locales->codepage);
647
  }
648
 
649
  if (locales->keybfile > 0) {
650
    fprintf(fd, "KEYB %s,%d,%%DOSDIR%%\\BIN\\", locales->keybcode, locales->codepage);
651
    if (locales->keybfile == 1) {
652
      fprintf(fd, "KEYBOARD.SYS");
653
    } else {
654
      fprintf(fd, "KEYBRD%d.SYS", locales->keybfile);
655
    }
656
    if (locales->keybid != 0) fprintf(fd, " /ID:%d", locales->keybid);
657
    fprintf(fd, "\r\n");
658
  }
659
}
660
 
661
 
662
static void bootfilesgen(char targetdrv, const struct slocales *locales) {
28 mv_fox 663
  char buff[128];
664
  FILE *fd;
53 mv_fox 665
  /*** CONFIG.SYS ***/
280 mateuszvis 666
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\CONFIG.SYS", targetdrv);
53 mv_fox 667
  fd = fopen(buff, "wb");
668
  if (fd == NULL) return;
101 mv_fox 669
  fprintf(fd, "DOS=UMB,HIGH\r\n"
670
              "LASTDRIVE=Z\r\n"
671
              "FILES=50\r\n");
312 mateuszvis 672
  fprintf(fd, "DEVICE=C:\\SVARDOS\\BIN\\HIMEMX.EXE\r\n");
1104 mateusz.vi 673
  fprintf(fd, "SHELL=C:\\COMMAND.COM /E:512 /P\r\n");
625 mateuszvis 674
  fprintf(fd, "REM COUNTRY=001,%u,C:\\SVARDOS\\CFG\\COUNTRY.SYS\r\n", locales->codepage);
280 mateuszvis 675
  fprintf(fd, "REM DEVICE=C:\\DRIVERS\\UDVD2\\UDVD2.SYS /D:SVCD0001 /H\r\n");
53 mv_fox 676
  fclose(fd);
28 mv_fox 677
  /*** AUTOEXEC.BAT ***/
280 mateuszvis 678
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\AUTOEXEC.BAT", targetdrv);
28 mv_fox 679
  fd = fopen(buff, "wb");
680
  if (fd == NULL) return;
681
  fprintf(fd, "@ECHO OFF\r\n");
280 mateuszvis 682
  fprintf(fd, "SET TEMP=C:\\TEMP\r\n");
683
  fprintf(fd, "SET DOSDIR=C:\\SVARDOS\r\n");
817 mateusz.vi 684
  fprintf(fd, "SET NLSPATH=%%DOSDIR%%\\NLS;.\r\n");
53 mv_fox 685
  fprintf(fd, "SET DIRCMD=/OGNE/P/4\r\n");
303 mateuszvis 686
  fprintf(fd, "SET WATTCP.CFG=%%DOSDIR%%\\CFG\r\n");
280 mateuszvis 687
  fprintf(fd, "PATH %%DOSDIR%%\\BIN\r\n");
28 mv_fox 688
  fprintf(fd, "PROMPT $P$G\r\n");
56 mv_fox 689
  fprintf(fd, "FDAPM APMDOS\r\n");
28 mv_fox 690
  fprintf(fd, "\r\n");
280 mateuszvis 691
  genlocalesconf(fd, locales);
49 mv_fox 692
  fprintf(fd, "\r\n");
280 mateuszvis 693
  fprintf(fd, "REM Uncomment the line below for CDROM support\r\n");
694
  fprintf(fd, "REM SHSUCDX /d:SVCD0001\r\n");
695
  fprintf(fd, "\r\n");
53 mv_fox 696
  fprintf(fd, "ECHO.\r\n");
624 mateuszvis 697
  fprintf(fd, "ECHO %s\r\n", svarlang_strid(0x0600)); /* "Welcome to SvarDOS!" */
28 mv_fox 698
  fclose(fd);
200 mateuszvis 699
  /*** CREATE DIRECTORY FOR CONFIGURATION FILES ***/
277 mateuszvis 700
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS", targetdrv);
200 mateuszvis 701
  mkdir(buff);
277 mateuszvis 702
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS\\CFG", targetdrv);
53 mv_fox 703
  mkdir(buff);
277 mateuszvis 704
  /*** PKG.CFG ***/
705
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS\\CFG\\PKG.CFG", targetdrv);
706
  fd = fopen(buff, "wb");
707
  if (fd == NULL) return;
708
  fprintf(fd, "# pkg config file - specifies locations where packages should be installed\r\n"
709
              "\r\n"
710
              "# Programs\r\n"
711
              "DIR PROGS C:\\\r\n"
712
              "\r\n"
713
              "# Games \r\n"
714
              "DIR GAMES C:\\\r\n"
715
              "\r\n"
716
              "# Drivers\r\n"
717
              "DIR DRIVERS C:\\DRIVERS\r\n"
718
              "\r\n"
719
              "# Development tools\r\n"
720
              "DIR DEVEL C:\\DEVEL\r\n");
721
  fclose(fd);
53 mv_fox 722
  /*** COUNTRY.SYS ***/
723
  /*** PICOTCP ***/
724
  /*** WATTCP ***/
303 mateuszvis 725
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS\\CFG\\WATTCP.CFG", targetdrv);
726
  fd = fopen(buff, "wb");
727
  if (fd == NULL) return;
728
  fprintf(fd, "my_ip = dhcp\r\n"
729
              "#my_ip = 192.168.0.7\r\n"
730
              "#netmask = 255.255.255.0\r\n"
731
              "#nameserver = 192.168.0.1\r\n"
732
              "#nameserver = 192.168.0.2\r\n"
554 mateuszvis 733
              "#gateway = 192.168.0.1\r\n");
303 mateuszvis 734
  fclose(fd);
28 mv_fox 735
}
736
 
737
 
868 mateusz.vi 738
static int installpackages(char targetdrv, char srcdrv, const struct slocales *locales, const char *buildstring) {
192 mateuszvis 739
  char pkglist[512];
30 mv_fox 740
  int i, pkglistlen;
192 mateuszvis 741
  size_t pkglistflen;
280 mateuszvis 742
  char buff[1024]; /* must be *at least* 1 sector big for efficient file copying */
743
  FILE *fd = NULL;
192 mateuszvis 744
  char *pkgptr;
79 mv_fox 745
  newscreen(3);
192 mateuszvis 746
  /* load pkg list */
747
  fd = fopen("install.lst", "rb");
748
  if (fd == NULL) {
749
    video_putstring(10, 30, COLOR_BODY[mono], "ERROR: INSTALL.LST NOT FOUND", -1);
750
    input_getkey();
751
    return(-1);
752
  }
753
  pkglistflen = fread(pkglist, 1, sizeof(pkglist), fd);
754
  fclose(fd);
755
  if (pkglistflen == sizeof(pkglist)) {
756
    video_putstring(10, 30, COLOR_BODY[mono], "ERROR: INSTALL.LST TOO LARGE", -1);
757
    input_getkey();
758
    return(-1);
759
  }
760
  pkglist[pkglistflen] = 0xff; /* mark the end of list */
761
  /* replace all \r and \n chars by 0 bytes, and count the number of packages */
762
  pkglistlen = 0;
763
  for (i = 0; i < pkglistflen; i++) {
764
    switch (pkglist[i]) {
765
      case '\n':
766
        pkglistlen++;
767
        /* FALLTHRU */
768
      case '\r':
769
        pkglist[i] = 0;
770
        break;
771
    }
772
  }
280 mateuszvis 773
  /* copy pkg.exe to the new drive, along with all packages */
774
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\pkg.exe", targetdrv);
775
  snprintf(buff + 64, sizeof(buff) - 64, "%c:\\pkg.exe", srcdrv);
776
  fcopy(buff, buff + 64, buff, sizeof(buff));
777
 
778
  /* open the post-install autoexec.bat and prepare initial instructions */
779
  snprintf(buff, sizeof(buff), "%c:\\temp\\postinst.bat", targetdrv);
780
  fd = fopen(buff, "wb");
781
  if (fd == NULL) return(-1);
868 mateusz.vi 782
  fprintf(fd, "@ECHO OFF\r\nECHO INSTALLING SVARDOS BUILD %s\r\n", buildstring);
280 mateuszvis 783
 
1104 mateusz.vi 784
  /* move COMMAND.COM so it does not clashes with the installation of the SVARCOM package */
785
  fprintf(fd, "COPY \\COMMAND.COM \\CMD.COM\r\n");
786
  fprintf(fd, "SET COMSPEC=%c:\\CMD.COM\r\n", targetdrv);
787
  fprintf(fd, "DEL \\COMMAND.COM\r\n");
788
 
280 mateuszvis 789
  /* copy packages */
192 mateuszvis 790
  pkgptr = pkglist;
791
  for (i = 0;; i++) {
792
    /* move forward to nearest entry or end of list */
793
    while (*pkgptr == 0) pkgptr++;
794
    if (*pkgptr == 0xff) break;
795
    /* install the package */
624 mateuszvis 796
    snprintf(buff, sizeof(buff), svarlang_strid(0x0400), i+1, pkglistlen, pkgptr); /* "Installing package %d/%d: %s" */
36 mv_fox 797
    strcat(buff, "       ");
192 mateuszvis 798
    video_putstringfix(10, 1, COLOR_BODY[mono], buff, sizeof(buff));
200 mateuszvis 799
    /* wait for new diskette if package not found */
700 mateusz.vi 800
    snprintf(buff, sizeof(buff), "%c:\\%s.svp", srcdrv, pkgptr);
200 mateuszvis 801
    while (fileexists(buff) != 0) {
624 mateuszvis 802
      putstringnls(12, 1, COLOR_BODY[mono], 4, 1); /* "INSERT THE DISK THAT CONTAINS THE REQUIRED FILE AND PRESS ANY KEY" */
200 mateuszvis 803
      input_getkey();
804
      video_putstringfix(12, 1, COLOR_BODY[mono], "", 80); /* erase the 'insert disk' message */
805
    }
280 mateuszvis 806
    /* proceed with package copy (buff contains the src filename already) */
700 mateusz.vi 807
    snprintf(buff + 32, sizeof(buff) - 32, "%c:\\temp\\%s.svp", targetdrv, pkgptr);
280 mateuszvis 808
    if (fcopy(buff + 32, buff, buff, sizeof(buff)) != 0) {
809
      video_putstring(10, 30, COLOR_BODY[mono], "READ ERROR", -1);
192 mateuszvis 810
      input_getkey();
280 mateuszvis 811
      fclose(fd);
192 mateuszvis 812
      return(-1);
55 mv_fox 813
    }
280 mateuszvis 814
    /* write install instruction to post-install script */
700 mateusz.vi 815
    fprintf(fd, "pkg install %s.svp\r\ndel %s.svp\r\n", pkgptr, pkgptr);
192 mateuszvis 816
    /* jump to next entry or end of list */
817
    while ((*pkgptr != 0) && (*pkgptr != 0xff)) pkgptr++;
818
    if (*pkgptr == 0xff) break;
28 mv_fox 819
  }
280 mateuszvis 820
  /* set up locales so the "installation over" message is nicely displayed */
821
  genlocalesconf(fd, locales);
822
  /* replace autoexec.bat and config.sys now and write some nice message on screen */
823
  fprintf(fd, "DEL pkg.exe\r\n"
824
              "COPY CONFIG.SYS C:\\\r\n"
825
              "DEL CONFIG.SYS\r\n"
826
              "DEL C:\\AUTOEXEC.BAT\r\n"
827
              "COPY AUTOEXEC.BAT C:\\\r\n"
1104 mateusz.vi 828
              "DEL AUTOEXEC.BAT\r\n"
829
              "DEL \\CMD.COM\r\n");
280 mateuszvis 830
  /* print out the "installation over" message */
831
  fprintf(fd, "ECHO.\r\n"
868 mateusz.vi 832
              "ECHO ");
833
  fprintf(fd, svarlang_strid(0x0501), buildstring); /* "SvarDOS installation is over. Please restart your computer now" */
834
  fprintf(fd, "\r\n"
835
              "ECHO.\r\n");
280 mateuszvis 836
  fclose(fd);
837
 
838
  /* prepare a dummy autoexec.bat that will call temp\postinst.bat */
839
  snprintf(buff, sizeof(buff), "%c:\\autoexec.bat", targetdrv);
840
  fd = fopen(buff, "wb");
841
  if (fd == NULL) return(-1);
842
  fprintf(fd, "@ECHO OFF\r\n"
843
              "SET DOSDIR=C:\\SVARDOS\r\n"
844
              "SET NLSPATH=%%DOSDIR%%\\NLS\r\n"
845
              "PATH %%DOSDIR%%\\BIN\r\n");
846
  fprintf(fd, "CD TEMP\r\n"
847
              "postinst.bat\r\n");
848
  fclose(fd);
849
 
192 mateuszvis 850
  return(0);
28 mv_fox 851
}
852
 
853
 
42 mv_fox 854
static void finalreboot(void) {
56 mv_fox 855
  int y = 9;
79 mv_fox 856
  newscreen(2);
624 mateuszvis 857
  y += putstringnls(y, 1, COLOR_BODY[mono], 5, 0); /* "Your computer will reboot now.\nPlease remove the installation disk from your drive" */
858
  putstringnls(++y, 1, COLOR_BODY[mono], 0, 5); /* "Press any key..." */
42 mv_fox 859
  input_getkey();
860
  reboot();
861
}
862
 
863
 
192 mateuszvis 864
static void loadcp(const struct slocales *locales) {
42 mv_fox 865
  char buff[64];
67 mv_fox 866
  if (locales->codepage == 437) return;
42 mv_fox 867
  video_movecursor(1, 0);
67 mv_fox 868
  if (locales->egafile == 1) {
310 mateuszvis 869
    snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) EGA.CPX) > NUL", locales->codepage);
42 mv_fox 870
  } else {
310 mateuszvis 871
    snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) EGA%d.CPX) > NUL", locales->codepage, locales->egafile);
42 mv_fox 872
  }
873
  system(buff);
67 mv_fox 874
  snprintf(buff, sizeof(buff), "MODE CON CP SEL=%u > NUL", locales->codepage);
42 mv_fox 875
  system(buff);
876
  /* below I re-init the video controller - apparently this is required if
65 mv_fox 877
   * I want the new glyph symbols to be actually applied, at least some
878
   * (broken?) BIOSes, like VBox, apply glyphs only at next video mode change */
42 mv_fox 879
  {
880
  union REGS r;
881
  r.h.ah = 0x0F; /* get current video mode */
882
  int86(0x10, &r, &r); /* r.h.al contains the current video mode now */
56 mv_fox 883
  r.h.al |= 128; /* set the high bit of AL to instruct BIOS not to flush VRAM's content (EGA+) */
884
  r.h.ah = 0; /* re-set video mode (to whatever is set in AL) */
42 mv_fox 885
  int86(0x10, &r, &r);
886
  }
887
}
888
 
200 mateuszvis 889
 
310 mateuszvis 890
#ifdef DEADCODE
193 mateuszvis 891
/* checks that drive drv contains SvarDOS packages
65 mv_fox 892
 * returns 0 if found, non-zero otherwise */
193 mateuszvis 893
static int checkinstsrc(char drv) {
894
  char fname[16];
700 mateusz.vi 895
  snprintf(fname, sizeof(fname), "%c:\\ATTRIB.SVP", drv);
200 mateuszvis 896
  return(fileexists(fname));
69 mv_fox 897
}
310 mateuszvis 898
#endif
65 mv_fox 899
 
900
 
868 mateusz.vi 901
int main(int argc, char **argv) {
67 mv_fox 902
  struct slocales locales;
28 mv_fox 903
  int targetdrv;
193 mateuszvis 904
  int sourcedrv;
73 mv_fox 905
  int action;
868 mateusz.vi 906
  const char *buildstring = "###";
28 mv_fox 907
 
908 mateusz.vi 908
  /* setup the internal int 24h handler ("always fail") */
909
  int24hdl();
910
 
868 mateusz.vi 911
  if (argc != 1) buildstring = argv[1];
912
 
310 mateuszvis 913
  sourcedrv = get_cur_drive() + 'A';
53 mv_fox 914
 
29 mv_fox 915
  /* init screen and detect mono status */
916
  mono = video_init();
917
 
73 mv_fox 918
 SelectLang:
190 mateuszvis 919
  action = selectlang(&locales); /* welcome to svardos, select your language */
73 mv_fox 920
  if (action != MENUNEXT) goto Quit;
921
  loadcp(&locales);
817 mateusz.vi 922
  svarlang_load("INSTALL", locales.lang, NULL); /* NLS support */
865 mateusz.vi 923
 
924
 SelectKeyb:
73 mv_fox 925
  action = selectkeyb(&locales);  /* what keyb layout should we use? */
926
  if (action == MENUQUIT) goto Quit;
927
  if (action == MENUPREV) goto SelectLang;
928
 
929
 WelcomeScreen:
190 mateuszvis 930
  action = welcomescreen(); /* what svardos is, ask whether to run live dos or install */
73 mv_fox 931
  if (action == MENUQUIT) goto Quit;
865 mateusz.vi 932
  if (action == MENUPREV) {
933
    if (locales.keyblen > 1) goto SelectKeyb; /* if there is a choice of more than 1 layout, ask for it */
934
    goto SelectLang;
935
  }
312 mateuszvis 936
  targetdrv = preparedrive(sourcedrv); /* what drive should we install from? check avail. space */
73 mv_fox 937
  if (targetdrv == MENUQUIT) goto Quit;
938
  if (targetdrv == MENUPREV) goto WelcomeScreen;
280 mateuszvis 939
  bootfilesgen(targetdrv, &locales); /* generate boot files and other configurations */
868 mateusz.vi 940
  if (installpackages(targetdrv, sourcedrv, &locales, buildstring) != 0) goto Quit;    /* install packages */
73 mv_fox 941
  /*localcfg();*/ /* show local params (currency, etc), and propose to change them (based on localcfg) */
942
  /*netcfg();*/ /* basic networking config */
943
  finalreboot(); /* remove the CD and reboot */
944
 
945
 Quit:
81 mv_fox 946
  video_clear(0x0700, 0, 0);
28 mv_fox 947
  video_movecursor(0, 0);
948
  return(0);
949
}