Subversion Repositories SvarDOS

Rev

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