Subversion Repositories SvarDOS

Rev

Rev 1911 | 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 */
1911 mateusz.vi 457
static int disksize(unsigned char drv) {
458
  unsigned short sec_per_cluster = 0;
459
  unsigned short tot_clusters = 0;
460
  unsigned short bytes_per_sec = 0;
461
  long res;
462
  _asm {
463
    push ax
464
    push bx
465
    push cx
466
    push dx
35 mv_fox 467
 
1911 mateusz.vi 468
    mov ah, 0x36
469
    mov dl, drv
470
    int 0x21
471
    /* AX=sec_per_cluster DX=tot_clusters BX=free_clusters CX=bytes_per_sec */
472
    mov sec_per_cluster, ax
473
    mov bytes_per_sec, cx
474
    mov tot_clusters, dx
35 mv_fox 475
 
1911 mateusz.vi 476
    pop dx
477
    pop cx
478
    pop bx
479
    pop ax
480
  }
481
 
482
  if (sec_per_cluster == 0xffff) return(-1);
483
  res = sec_per_cluster;
484
  res *= tot_clusters;
485
  res *= bytes_per_sec;
486
  res >>= 20;
487
  return((int)res);
488
}
489
 
490
 
35 mv_fox 491
/* returns 0 if disk is empty, non-zero otherwise */
492
static int diskempty(int drv) {
493
  unsigned int rc;
494
  int res;
495
  char buff[8];
496
  struct find_t fileinfo;
55 mv_fox 497
  snprintf(buff, sizeof(buff), "%c:\\*.*", 'A' + drv - 1);
35 mv_fox 498
  rc = _dos_findfirst(buff, _A_NORMAL | _A_SUBDIR | _A_HIDDEN | _A_SYSTEM, &fileinfo);
499
  if (rc == 0) {
500
    res = 1; /* call successfull means disk is not empty */
28 mv_fox 501
  } else {
35 mv_fox 502
    res = 0;
28 mv_fox 503
  }
35 mv_fox 504
  /* _dos_findclose(&fileinfo); */ /* apparently required only on OS/2 */
28 mv_fox 505
  return(res);
506
}
507
 
200 mateuszvis 508
 
310 mateuszvis 509
/* get the DOS "current drive" (0=A:, 1=B:, etc) */
1908 mateusz.vi 510
static unsigned char get_cur_drive(void);
511
#pragma aux get_cur_drive = \
512
"mov ah, 0x19" /* DOS 1+ GET CURRENT DEFAULT DRIVE */ \
513
"int 0x21" \
514
modify [ah] \
515
value [al]
310 mateuszvis 516
 
517
 
898 mateusz.vi 518
/* tries to write an empty file to drive.
519
 * asks DOS to inhibit the int 24h handler for this job, so erros are
520
 * gracefully reported - unfortunately this does not work under FreeDOS because
521
 * the DOS-C kernel does not implement the required flag.
522
 * returns 0 on success (ie. "disk exists and is writeable"). */
1908 mateusz.vi 523
static unsigned short test_drive_write(char drive) {
898 mateusz.vi 524
  unsigned short result = 0;
1908 mateusz.vi 525
  char *buff = "@:\\SVWRTEST.123";
526
  buff[0] = drive;
898 mateusz.vi 527
  _asm {
528
    push ax
529
    push bx
530
    push cx
531
    push dx
532
 
533
    mov ah, 0x6c   /* extended open/create file */
534
    mov bx, 0x2001 /* open for write + inhibit int 24h handler */
535
    xor cx, cx     /* file attributes on the created file */
536
    mov dx, 0x0010 /* create file if does not exist, fail if it exists */
537
    mov si, buff   /* filename to create */
538
    int 0x21
539
    jc FAILURE
540
    /* close the file (handle in AX) */
541
    mov bx, ax
542
    mov ah, 0x3e /* close file */
543
    int 0x21
544
    jc FAILURE
545
    /* delete the file */
546
    mov ah, 0x41 /* delete file pointed out by DS:DX */
547
    mov dx, buff
548
    int 0x21
549
    jnc DONE
550
 
551
    FAILURE:
552
    mov result, ax
553
    DONE:
554
 
555
    pop dx
556
    pop cx
557
    pop bx
558
    pop ax
559
  }
560
  return(result);
561
}
562
 
563
 
310 mateuszvis 564
static int preparedrive(char sourcedrv) {
33 mv_fox 565
  int driveremovable;
310 mateuszvis 566
  int selecteddrive = 3; /* default to 'C:' */
36 mv_fox 567
  int cselecteddrive;
35 mv_fox 568
  int ds;
73 mv_fox 569
  int choice;
56 mv_fox 570
  char buff[1024];
312 mateuszvis 571
  int driveid = 1; /* fdisk runs on first drive (unless USB boot) */
572
  if (selecteddrive == get_cur_drive() + 1) { /* get_cur_drive() returns 0-based values (A=0) while selecteddrive is 1-based (A=1) */
573
    selecteddrive = 4; /* use D: if install is run from C: (typically because it was booted from USB?) */
574
    driveid = 2; /* primary drive is the emulated USB storage */
575
  }
36 mv_fox 576
  cselecteddrive = 'A' + selecteddrive - 1;
28 mv_fox 577
  for (;;) {
33 mv_fox 578
    driveremovable = isdriveremovable(selecteddrive);
1908 mateusz.vi 579
    if (driveremovable == 0) {
580
      newscreen(2);
581
      snprintf(buff, sizeof(buff), svarlang_strid(0x0302), cselecteddrive); /* "ERROR: Drive %c: is a removable device */
582
      mdr_cout_str(9, 1, buff, COLOR_BODY, 80);
583
      putstringnls(11, 2, COLOR_BODY, 0, 5); /* "Press any key..." */
584
      mdr_dos_getkey();
585
      return(MENUQUIT);
586
    }
587
 
588
    /* if C: not found - disk not partitioned? */
33 mv_fox 589
    if (driveremovable < 0) {
624 mateuszvis 590
      const char *list[4];
79 mv_fox 591
      newscreen(0);
624 mateuszvis 592
      list[0] = svarlang_str(0, 3); /* Create a partition automatically */
593
      list[1] = svarlang_str(0, 4); /* Run the FDISK tool */
594
      list[2] = svarlang_str(0, 2); /* Quit to DOS */
595
      list[3] = NULL;
596
      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 597
      switch (menuselect(6 + putstringwrap(4, 1, COLOR_BODY, buff), 3, list, -1)) {
33 mv_fox 598
        case 0:
1239 mateusz.vi 599
          sprintf(buff, "FDISK /PRI:MAX %d", driveid);
312 mateuszvis 600
          system(buff);
33 mv_fox 601
          break;
602
        case 1:
1662 mateusz.vi 603
          mdr_cout_cls(0x07);
604
          mdr_cout_locate(0, 0);
312 mateuszvis 605
          sprintf(buff, "FDISK %d", driveid);
606
          system(buff);
33 mv_fox 607
          break;
73 mv_fox 608
        case 2:
609
          return(MENUQUIT);
56 mv_fox 610
        default:
33 mv_fox 611
          return(-1);
612
      }
113 mv_fox 613
      /* write a temporary MBR which only skips the drive (in case BIOS would
614
       * try to boot off the not-yet-ready C: disk) */
1239 mateusz.vi 615
      sprintf(buff, "FDISK /LOADIPL %d", driveid);
312 mateuszvis 616
      system(buff); /* writes BOOT.MBR into actual MBR */
79 mv_fox 617
      newscreen(2);
1664 mateusz.vi 618
      putstringnls(10, 10, COLOR_BODY, 3, 1); /* "Your computer will reboot now." */
619
      putstringnls(12, 10, COLOR_BODY, 0, 5); /* "Press any key..." */
1661 mateusz.vi 620
      mdr_dos_getkey();
28 mv_fox 621
      reboot();
73 mv_fox 622
      return(MENUQUIT);
28 mv_fox 623
    }
1908 mateusz.vi 624
 
33 mv_fox 625
    /* if not formatted, propose to format it right away (try to create a directory) */
1908 mateusz.vi 626
    if (test_drive_write(cselecteddrive) != 0) {
624 mateuszvis 627
      const char *list[3];
79 mv_fox 628
      newscreen(0);
624 mateuszvis 629
      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 630
      mdr_cout_str(7, 1, buff, COLOR_BODY, 80);
556 mateuszvis 631
 
624 mateuszvis 632
      snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
556 mateuszvis 633
      list[0] = buff;
624 mateuszvis 634
      list[1] = svarlang_strid(0x0002); /* "Quit to DOS" */
556 mateuszvis 635
      list[2] = NULL;
636
 
1666 mateusz.vi 637
      choice = menuselect(12, 2, list, -1);
73 mv_fox 638
      if (choice < 0) return(MENUPREV);
639
      if (choice == 1) return(MENUQUIT);
1662 mateusz.vi 640
      mdr_cout_cls(0x07);
641
      mdr_cout_locate(0, 0);
190 mateuszvis 642
      snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
36 mv_fox 643
      system(buff);
28 mv_fox 644
      continue;
645
    }
33 mv_fox 646
    /* check total disk space */
35 mv_fox 647
    ds = disksize(selecteddrive);
190 mateuszvis 648
    if (ds < SVARDOS_DISK_REQ) {
56 mv_fox 649
      int y = 9;
79 mv_fox 650
      newscreen(2);
624 mateuszvis 651
      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 652
      y += putstringwrap(y, 1, COLOR_BODY, buff);
653
      putstringnls(++y, 1, COLOR_BODY, 0, 5); /* "Press any key..." */
1661 mateusz.vi 654
      mdr_dos_getkey();
73 mv_fox 655
      return(MENUQUIT);
28 mv_fox 656
    }
657
    /* is the disk empty? */
79 mv_fox 658
    newscreen(0);
35 mv_fox 659
    if (diskempty(selecteddrive) != 0) {
624 mateuszvis 660
      const char *list[3];
65 mv_fox 661
      int y = 6;
624 mateuszvis 662
      snprintf(buff, sizeof(buff), svarlang_strid(0x0305), cselecteddrive); /* "ERROR: Drive %c: not empty" */
1664 mateusz.vi 663
      y += putstringwrap(y, 1, COLOR_BODY, buff);
556 mateuszvis 664
 
624 mateuszvis 665
      snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
556 mateuszvis 666
      list[0] = buff;
624 mateuszvis 667
      list[1] = svarlang_strid(0x0002); /* "Quit to DOS" */
556 mateuszvis 668
      list[2] = NULL;
669
 
1666 mateusz.vi 670
      choice = menuselect(++y, 2, list, -1);
73 mv_fox 671
      if (choice < 0) return(MENUPREV);
672
      if (choice == 1) return(MENUQUIT);
1662 mateusz.vi 673
      mdr_cout_cls(0x07);
674
      mdr_cout_locate(0, 0);
190 mateuszvis 675
      snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
42 mv_fox 676
      system(buff);
28 mv_fox 677
      continue;
678
    } else {
679
      /* final confirmation */
624 mateuszvis 680
      const char *list[3];
681
      list[0] = svarlang_strid(0x0001); /* Install SvarDOS */
682
      list[1] = svarlang_strid(0x0002); /* Quit to DOS */
683
      list[2] = NULL;
684
      snprintf(buff, sizeof(buff), svarlang_strid(0x0306), cselecteddrive); /* "The installation of SvarDOS to %c: is about to begin." */
1672 mateusz.vi 685
      mdr_cout_str(7, 40 - (strlen(buff) / 2), buff, COLOR_BODY, 80);
1666 mateusz.vi 686
      choice = menuselect(10, 2, list, -1);
73 mv_fox 687
      if (choice < 0) return(MENUPREV);
688
      if (choice == 1) return(MENUQUIT);
310 mateuszvis 689
      snprintf(buff, sizeof(buff), "SYS %c: %c: > NUL", sourcedrv, cselecteddrive);
36 mv_fox 690
      system(buff);
312 mateuszvis 691
      sprintf(buff, "FDISK /MBR %d", driveid);
692
      system(buff);
55 mv_fox 693
      snprintf(buff, sizeof(buff), "%c:\\TEMP", cselecteddrive);
36 mv_fox 694
      mkdir(buff);
695
      return(cselecteddrive);
28 mv_fox 696
    }
697
  }
698
}
699
 
700
 
280 mateuszvis 701
/* generates locales-related configurations and writes them to file (this
702
 * is used to compute autoexec.bat content) */
703
static void genlocalesconf(FILE *fd, const struct slocales *locales) {
704
  if (locales == NULL) return;
705
 
706
  fprintf(fd, "SET LANG=%s\r\n", locales->lang);
707
 
708
  if (locales->egafile > 0) {
709
    fprintf(fd, "DISPLAY CON=(EGA,,1)\r\n");
710
    if (locales->egafile == 1) {
711
      fprintf(fd, "MODE CON CP PREPARE=((%u) %%DOSDIR%%\\CPI\\EGA.CPX)\r\n", locales->codepage);
712
    } else {
1908 mateusz.vi 713
      fprintf(fd, "MODE CON CP PREPARE=((%u) %%DOSDIR%%\\CPI\\EGA%u.CPX)\r\n", locales->codepage, locales->egafile);
280 mateuszvis 714
    }
715
    fprintf(fd, "MODE CON CP SELECT=%u\r\n", locales->codepage);
716
  }
717
 
718
  if (locales->keybfile > 0) {
1659 bttr 719
    fprintf(fd, "KEYB %s,%d,%%DOSDIR%%\\", locales->keybcode, locales->codepage);
280 mateuszvis 720
    if (locales->keybfile == 1) {
721
      fprintf(fd, "KEYBOARD.SYS");
722
    } else {
1908 mateusz.vi 723
      fprintf(fd, "KEYBRD%u.SYS", locales->keybfile);
280 mateuszvis 724
    }
725
    if (locales->keybid != 0) fprintf(fd, " /ID:%d", locales->keybid);
726
    fprintf(fd, "\r\n");
727
  }
728
}
729
 
730
 
731
static void bootfilesgen(char targetdrv, const struct slocales *locales) {
28 mv_fox 732
  char buff[128];
733
  FILE *fd;
53 mv_fox 734
  /*** CONFIG.SYS ***/
280 mateuszvis 735
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\CONFIG.SYS", targetdrv);
53 mv_fox 736
  fd = fopen(buff, "wb");
737
  if (fd == NULL) return;
1751 mateusz.vi 738
  fprintf(fd, "; SvarDOS kernel configuration\r\n"
739
              "\r\n"
740
              "; highest allowed drive letter\r\n"
741
              "LASTDRIVE=Z\r\n"
742
              "\r\n"
743
              "; max. number of files that programs are allowed to open simultaneously\r\n"
744
              "FILES=25\r\n");
745
  fprintf(fd, "\r\n"
746
              "; XMS memory driver\r\n"
747
              "DEVICE=C:\\SVARDOS\\HIMEMX.EXE\r\n");
748
  fprintf(fd, "\r\n"
749
              "; try moving DOS to upper memory, then to high memory\r\n"
750
              "DOS=UMB,HIGH\r\n");
751
  fprintf(fd, "\r\n"
752
              "; command interpreter (shell) location and default environment size\r\n"
753
              "SHELL=C:\\COMMAND.COM /E:512 /P\r\n");
754
  fprintf(fd, "\r\n"
1908 mateusz.vi 755
              "; NLS configuration\r\n");
756
  if (locales != NULL) {
757
    fprintf(fd, "COUNTRY=%03u,%u,C:\\SVARDOS\\COUNTRY.SYS\r\n", locales->countryid, locales->codepage);
758
  } else {
759
    fprintf(fd, "COUNTRY=001,437,C:\\SVARDOS\\COUNTRY.SYS\r\n");
760
  }
1751 mateusz.vi 761
  fprintf(fd, "\r\n"
762
              "; CD-ROM driver initialization\r\n"
763
              ";DEVICE=C:\\DRIVERS\\VIDECDD\\VIDE-CDD.SYS /D:SVCD0001\r\n");
53 mv_fox 764
  fclose(fd);
28 mv_fox 765
  /*** AUTOEXEC.BAT ***/
280 mateuszvis 766
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\AUTOEXEC.BAT", targetdrv);
28 mv_fox 767
  fd = fopen(buff, "wb");
768
  if (fd == NULL) return;
769
  fprintf(fd, "@ECHO OFF\r\n");
280 mateuszvis 770
  fprintf(fd, "SET TEMP=C:\\TEMP\r\n");
771
  fprintf(fd, "SET DOSDIR=C:\\SVARDOS\r\n");
1908 mateusz.vi 772
  fprintf(fd, "SET NLSPATH=%%DOSDIR%%\\NLS\r\n");
1757 mateusz.vi 773
  fprintf(fd, "SET DIRCMD=/O/P\r\n");
303 mateuszvis 774
  fprintf(fd, "SET WATTCP.CFG=%%DOSDIR%%\\CFG\r\n");
1637 mateusz.vi 775
  fprintf(fd, "PATH %%DOSDIR%%\r\n");
28 mv_fox 776
  fprintf(fd, "PROMPT $P$G\r\n");
1757 mateusz.vi 777
  fprintf(fd, "\r\n"
778
              "REM enable CPU power saving\r\n"
1835 mateusz.vi 779
              "FDAPM ADV:REG\r\n");
28 mv_fox 780
  fprintf(fd, "\r\n");
1908 mateusz.vi 781
  if (locales != NULL) genlocalesconf(fd, locales);
49 mv_fox 782
  fprintf(fd, "\r\n");
280 mateuszvis 783
  fprintf(fd, "REM Uncomment the line below for CDROM support\r\n");
784
  fprintf(fd, "REM SHSUCDX /d:SVCD0001\r\n");
785
  fprintf(fd, "\r\n");
53 mv_fox 786
  fprintf(fd, "ECHO.\r\n");
624 mateuszvis 787
  fprintf(fd, "ECHO %s\r\n", svarlang_strid(0x0600)); /* "Welcome to SvarDOS!" */
28 mv_fox 788
  fclose(fd);
200 mateuszvis 789
  /*** CREATE DIRECTORY FOR CONFIGURATION FILES ***/
277 mateuszvis 790
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS", targetdrv);
200 mateuszvis 791
  mkdir(buff);
277 mateuszvis 792
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS\\CFG", targetdrv);
53 mv_fox 793
  mkdir(buff);
277 mateuszvis 794
  /*** PKG.CFG ***/
795
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS\\CFG\\PKG.CFG", targetdrv);
796
  fd = fopen(buff, "wb");
797
  if (fd == NULL) return;
798
  fprintf(fd, "# pkg config file - specifies locations where packages should be installed\r\n"
799
              "\r\n"
1637 mateusz.vi 800
              "# DOS core binaries\r\n"
801
              "DIR BIN C:\\SVARDOS\r\n"
802
              "\r\n"
277 mateuszvis 803
              "# Programs\r\n"
804
              "DIR PROGS C:\\\r\n"
805
              "\r\n"
806
              "# Games \r\n"
807
              "DIR GAMES C:\\\r\n"
808
              "\r\n"
809
              "# Drivers\r\n"
810
              "DIR DRIVERS C:\\DRIVERS\r\n"
811
              "\r\n"
812
              "# Development tools\r\n"
813
              "DIR DEVEL C:\\DEVEL\r\n");
814
  fclose(fd);
53 mv_fox 815
  /*** COUNTRY.SYS ***/
816
  /*** PICOTCP ***/
817
  /*** WATTCP ***/
303 mateuszvis 818
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS\\CFG\\WATTCP.CFG", targetdrv);
819
  fd = fopen(buff, "wb");
820
  if (fd == NULL) return;
821
  fprintf(fd, "my_ip = dhcp\r\n"
822
              "#my_ip = 192.168.0.7\r\n"
823
              "#netmask = 255.255.255.0\r\n"
824
              "#nameserver = 192.168.0.1\r\n"
825
              "#nameserver = 192.168.0.2\r\n"
554 mateuszvis 826
              "#gateway = 192.168.0.1\r\n");
303 mateuszvis 827
  fclose(fd);
28 mv_fox 828
}
829
 
830
 
1671 mateusz.vi 831
static int installpackages(char targetdrv, char srcdrv, const struct slocales *locales) {
192 mateuszvis 832
  char pkglist[512];
30 mv_fox 833
  int i, pkglistlen;
192 mateuszvis 834
  size_t pkglistflen;
280 mateuszvis 835
  char buff[1024]; /* must be *at least* 1 sector big for efficient file copying */
836
  FILE *fd = NULL;
192 mateuszvis 837
  char *pkgptr;
79 mv_fox 838
  newscreen(3);
192 mateuszvis 839
  /* load pkg list */
840
  fd = fopen("install.lst", "rb");
841
  if (fd == NULL) {
1664 mateusz.vi 842
    mdr_cout_str(10, 30, "ERROR: INSTALL.LST NOT FOUND", COLOR_BODY, 80);
1661 mateusz.vi 843
    mdr_dos_getkey();
192 mateuszvis 844
    return(-1);
845
  }
1125 mateusz.vi 846
  pkglistflen = fread(pkglist, 1, sizeof(pkglist) - 2, fd);
192 mateuszvis 847
  fclose(fd);
1125 mateusz.vi 848
  if (pkglistflen == sizeof(pkglist) - 2) {
1664 mateusz.vi 849
    mdr_cout_str(10, 30, "ERROR: INSTALL.LST TOO LARGE", COLOR_BODY, 80);
1661 mateusz.vi 850
    mdr_dos_getkey();
192 mateuszvis 851
    return(-1);
852
  }
1125 mateusz.vi 853
  /* mark the end of list */
854
  pkglist[pkglistflen] = 0;
855
  pkglist[pkglistflen + 1] = 0xff;
192 mateuszvis 856
  /* replace all \r and \n chars by 0 bytes, and count the number of packages */
857
  pkglistlen = 0;
858
  for (i = 0; i < pkglistflen; i++) {
859
    switch (pkglist[i]) {
860
      case '\n':
861
        pkglistlen++;
862
        /* FALLTHRU */
863
      case '\r':
864
        pkglist[i] = 0;
865
        break;
866
    }
867
  }
280 mateuszvis 868
  /* copy pkg.exe to the new drive, along with all packages */
869
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\pkg.exe", targetdrv);
870
  snprintf(buff + 64, sizeof(buff) - 64, "%c:\\pkg.exe", srcdrv);
871
  fcopy(buff, buff + 64, buff, sizeof(buff));
872
 
873
  /* open the post-install autoexec.bat and prepare initial instructions */
874
  snprintf(buff, sizeof(buff), "%c:\\temp\\postinst.bat", targetdrv);
875
  fd = fopen(buff, "wb");
876
  if (fd == NULL) return(-1);
1671 mateusz.vi 877
  fprintf(fd, "@ECHO OFF\r\nECHO INSTALLING SVARDOS BUILD %s\r\n", BUILDSTRING);
280 mateuszvis 878
 
1104 mateusz.vi 879
  /* move COMMAND.COM so it does not clashes with the installation of the SVARCOM package */
880
  fprintf(fd, "COPY \\COMMAND.COM \\CMD.COM\r\n");
1805 mateusz.vi 881
  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 882
  fprintf(fd, "DEL \\COMMAND.COM\r\n");
883
 
1831 mateusz.vi 884
  /* delete the temporary KERNEL.SYS - it will be properly installed from the package in a short moment */
885
  fprintf(fd, "DEL \\KERNEL.SYS\r\n");
886
 
280 mateuszvis 887
  /* copy packages */
192 mateuszvis 888
  for (i = 0;; i++) {
1125 mateusz.vi 889
    RETRY_ENTIRE_LIST:
890
 
192 mateuszvis 891
    /* move forward to nearest entry or end of list */
1125 mateusz.vi 892
    for (pkgptr = pkglist; *pkgptr == 0; pkgptr++);
893
    if (*pkgptr == 0xff) break; /* end of list: means all packages have been processed */
894
 
895
    /* is this package present on the floppy disk? */
896
    TRY_NEXTPKG:
897
    sprintf(buff, "%s.svp", pkgptr);
1669 mateusz.vi 898
    if (!fileexists(buff)) {
1125 mateusz.vi 899
      while (*pkgptr != 0) pkgptr++;
900
      while (*pkgptr == 0) pkgptr++;
901
      /* end of list? ask for next floppy, there's nothing interesting left on this one */
902
      if (*pkgptr == 0xff) {
1664 mateusz.vi 903
        putstringnls(12, 1, COLOR_BODY, 4, 1); /* "INSERT THE DISK THAT CONTAINS THE REQUIRED FILE AND PRESS ANY KEY" */
1661 mateusz.vi 904
        mdr_dos_getkey();
1664 mateusz.vi 905
        video_putstringfix(12, 1, COLOR_BODY, "", 80); /* erase the 'insert disk' message */
1125 mateusz.vi 906
        goto RETRY_ENTIRE_LIST;
907
      }
908
      goto TRY_NEXTPKG;
909
    }
910
 
192 mateuszvis 911
    /* install the package */
624 mateuszvis 912
    snprintf(buff, sizeof(buff), svarlang_strid(0x0400), i+1, pkglistlen, pkgptr); /* "Installing package %d/%d: %s" */
36 mv_fox 913
    strcat(buff, "       ");
1664 mateusz.vi 914
    mdr_cout_str(10, 1, buff, COLOR_BODY, 40);
1125 mateusz.vi 915
 
916
    /* proceed with package copy */
917
    sprintf(buff, "%c:\\temp\\%s.svp", targetdrv, pkgptr);
918
    if (fcopy(buff, buff + 7, buff, sizeof(buff)) != 0) {
1664 mateusz.vi 919
      mdr_cout_str(10, 30, "READ ERROR", COLOR_BODY, 80);
1661 mateusz.vi 920
      mdr_dos_getkey();
280 mateuszvis 921
      fclose(fd);
192 mateuszvis 922
      return(-1);
55 mv_fox 923
    }
280 mateuszvis 924
    /* write install instruction to post-install script */
700 mateusz.vi 925
    fprintf(fd, "pkg install %s.svp\r\ndel %s.svp\r\n", pkgptr, pkgptr);
1125 mateusz.vi 926
    /* jump to next entry or end of list and zero out the pkg name in the process */
927
    while ((*pkgptr != 0) && (*pkgptr != 0xff)) {
928
      *pkgptr = 0;
929
      pkgptr++;
930
    }
28 mv_fox 931
  }
280 mateuszvis 932
  /* set up locales so the "installation over" message is nicely displayed */
933
  genlocalesconf(fd, locales);
934
  /* replace autoexec.bat and config.sys now and write some nice message on screen */
935
  fprintf(fd, "DEL pkg.exe\r\n"
1828 mateusz.vi 936
              "DEL C:\\CONFIG.SYS\r\n"
280 mateuszvis 937
              "COPY CONFIG.SYS C:\\\r\n"
938
              "DEL CONFIG.SYS\r\n"
939
              "DEL C:\\AUTOEXEC.BAT\r\n"
940
              "COPY AUTOEXEC.BAT C:\\\r\n"
1104 mateusz.vi 941
              "DEL AUTOEXEC.BAT\r\n"
1109 bttr 942
              "SET COMSPEC=C:\\COMMAND.COM\r\n"
1104 mateusz.vi 943
              "DEL \\CMD.COM\r\n");
280 mateuszvis 944
  /* print out the "installation over" message */
945
  fprintf(fd, "ECHO.\r\n"
868 mateusz.vi 946
              "ECHO ");
1673 mateusz.vi 947
  fprintf(fd, svarlang_strid(0x0502), BUILDSTRING); /* "SvarDOS installation is over. Please restart your computer now" */
868 mateusz.vi 948
  fprintf(fd, "\r\n"
949
              "ECHO.\r\n");
280 mateuszvis 950
  fclose(fd);
951
 
1828 mateusz.vi 952
  /* dummy config.sys with a SHELL directive, EDR does not call command.com
953
   * with /P otherwise, see https://github.com/SvarDOS/edrdos/issues/74 */
954
  snprintf(buff, sizeof(buff), "%c:\\config.sys", targetdrv);
955
  fd = fopen(buff, "wb");
956
  if (fd == NULL) return(-1);
957
  fprintf(fd, "SHELL=C:\\COMMAND.COM /P\r\n");
958
  fclose(fd);
959
 
280 mateuszvis 960
  /* prepare a dummy autoexec.bat that will call temp\postinst.bat */
961
  snprintf(buff, sizeof(buff), "%c:\\autoexec.bat", targetdrv);
962
  fd = fopen(buff, "wb");
963
  if (fd == NULL) return(-1);
964
  fprintf(fd, "@ECHO OFF\r\n"
965
              "SET DOSDIR=C:\\SVARDOS\r\n"
966
              "SET NLSPATH=%%DOSDIR%%\\NLS\r\n"
1659 bttr 967
              "PATH %%DOSDIR%%\r\n");
280 mateuszvis 968
  fprintf(fd, "CD TEMP\r\n"
969
              "postinst.bat\r\n");
970
  fclose(fd);
971
 
192 mateuszvis 972
  return(0);
28 mv_fox 973
}
974
 
975
 
42 mv_fox 976
static void finalreboot(void) {
56 mv_fox 977
  int y = 9;
79 mv_fox 978
  newscreen(2);
1673 mateusz.vi 979
  y += putstringnls(y, 1, COLOR_BODY, 5, 0); /* "Your computer will reboot now." */
980
  y += putstringnls(y, 1, COLOR_BODYWARN, 5, 1); /* Please remove the installation disk from your drive" */
1664 mateusz.vi 981
  putstringnls(++y, 1, COLOR_BODY, 0, 5); /* "Press any key..." */
1661 mateusz.vi 982
  mdr_dos_getkey();
42 mv_fox 983
  reboot();
984
}
985
 
986
 
192 mateuszvis 987
static void loadcp(const struct slocales *locales) {
42 mv_fox 988
  char buff[64];
67 mv_fox 989
  if (locales->codepage == 437) return;
1662 mateusz.vi 990
  mdr_cout_locate(1, 0);
67 mv_fox 991
  if (locales->egafile == 1) {
310 mateuszvis 992
    snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) EGA.CPX) > NUL", locales->codepage);
42 mv_fox 993
  } else {
310 mateuszvis 994
    snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) EGA%d.CPX) > NUL", locales->codepage, locales->egafile);
42 mv_fox 995
  }
996
  system(buff);
67 mv_fox 997
  snprintf(buff, sizeof(buff), "MODE CON CP SEL=%u > NUL", locales->codepage);
42 mv_fox 998
  system(buff);
999
  /* below I re-init the video controller - apparently this is required if
65 mv_fox 1000
   * I want the new glyph symbols to be actually applied, at least some
1001
   * (broken?) BIOSes, like VBox, apply glyphs only at next video mode change */
1908 mateusz.vi 1002
  _asm {
1003
    push bx
1004
    mov ah, 0x0F  /* get current video mode */
1005
    int 0x10      /* al contains the current video mode now */
1006
    or al, 128    /* set high bit of AL to instruct BIOS not to flush VRAM's content (EGA+) */
1007
    xor ah, ah    /* re-set video mode (to whatever is set in AL) */
1008
    int 0x10
1009
    pop bx
42 mv_fox 1010
  }
1011
}
1012
 
200 mateuszvis 1013
 
1671 mateusz.vi 1014
int main(void) {
1908 mateusz.vi 1015
  struct slocales locales_data;
1016
  struct slocales *locales = &locales_data;
28 mv_fox 1017
  int targetdrv;
193 mateuszvis 1018
  int sourcedrv;
73 mv_fox 1019
  int action;
28 mv_fox 1020
 
1911 mateusz.vi 1021
  /* setup an internal int 24h handler ("always fail") so DOS does not output
1022
   * the ugly "abort, retry, fail" messages */
908 mateusz.vi 1023
  int24hdl();
1024
 
1671 mateusz.vi 1025
  /* read the svardos build revision (from floppy label) */
1026
  {
1027
    const char *fspec = "*.*";
1028
    const char *res = (void*)0x9E; /* default DTA is at PSP:80h, field 1Eh of DTA is the ASCIZ file name */
868 mateusz.vi 1029
 
1671 mateusz.vi 1030
    _asm {
1031
      push cx
1032
      push dx
1033
 
1034
      mov ax, 0x4e00  /* findfirst */
1035
      mov cx, 0x08    /* file attr mask, 0x08 = volume label */
1036
      mov dx, fspec
1037
      int 0x21
1038
      jnc good
1672 mateusz.vi 1039
      mov bx, res
1040
      mov [bx], byte ptr 0
1671 mateusz.vi 1041
      good:
1042
 
1043
      pop dx
1044
      pop cx
1045
    }
1046
 
1047
    memcpy(BUILDSTRING, res, 12);
1048
  }
1049
 
310 mateuszvis 1050
  sourcedrv = get_cur_drive() + 'A';
53 mv_fox 1051
 
1664 mateusz.vi 1052
  /* init screen and detect mono adapters */
1053
  if (mdr_cout_init(NULL, NULL) == 0) {
1054
    /* overload color scheme with mono settings */
1055
    COLOR_TITLEBAR = 0x70;
1671 mateusz.vi 1056
    COLOR_TITLEVER = 0x70;
1664 mateusz.vi 1057
    COLOR_BODY = 0x07;
1673 mateusz.vi 1058
    COLOR_BODYWARN = 0x07;
1664 mateusz.vi 1059
    COLOR_SELECT = 0x70;
1060
    COLOR_SELECTCUR = 0x07;
1061
  }
29 mv_fox 1062
 
1908 mateusz.vi 1063
  /* am I EN-only? */
1064
  if (!fileexists("INSTALL.LNG")) locales = NULL;
1065
 
73 mv_fox 1066
 SelectLang:
1908 mateusz.vi 1067
  if (locales == NULL) goto WelcomeScreen;
1068
  action = selectlang(locales); /* welcome to svardos, select your language */
73 mv_fox 1069
  if (action != MENUNEXT) goto Quit;
1908 mateusz.vi 1070
  loadcp(locales);
1071
  svarlang_load("INSTALL.LNG", locales->lang); /* NLS support */
865 mateusz.vi 1072
 
1908 mateusz.vi 1073
  action = selectkeyb(locales);  /* what keyb layout should we use? */
73 mv_fox 1074
  if (action == MENUQUIT) goto Quit;
1908 mateusz.vi 1075
  if (action == MENUPREV) goto SelectLang;
73 mv_fox 1076
 
1077
 WelcomeScreen:
190 mateuszvis 1078
  action = welcomescreen(); /* what svardos is, ask whether to run live dos or install */
73 mv_fox 1079
  if (action == MENUQUIT) goto Quit;
1908 mateusz.vi 1080
  if (action == MENUPREV) {
1081
    if (locales == NULL) goto Quit;
1082
    goto SelectLang;
1083
  }
1669 mateusz.vi 1084
 
312 mateuszvis 1085
  targetdrv = preparedrive(sourcedrv); /* what drive should we install from? check avail. space */
73 mv_fox 1086
  if (targetdrv == MENUQUIT) goto Quit;
1087
  if (targetdrv == MENUPREV) goto WelcomeScreen;
1908 mateusz.vi 1088
  bootfilesgen(targetdrv, locales); /* generate boot files and other configurations */
1089
  if (installpackages(targetdrv, sourcedrv, locales) != 0) goto Quit;    /* install packages */
73 mv_fox 1090
  /*localcfg();*/ /* show local params (currency, etc), and propose to change them (based on localcfg) */
1091
  /*netcfg();*/ /* basic networking config */
1092
  finalreboot(); /* remove the CD and reboot */
1093
 
1094
 Quit:
1662 mateusz.vi 1095
  mdr_cout_locate(0, 0);
1096
  mdr_cout_close();
28 mv_fox 1097
  return(0);
1098
}