Subversion Repositories SvarDOS

Rev

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