Subversion Repositories SvarDOS

Rev

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

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