Subversion Repositories SvarDOS

Rev

Rev 280 | Rev 310 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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