Subversion Repositories SvarDOS

Rev

Rev 303 | Rev 312 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 303 Rev 310
Line 34... Line 34...
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"
-
 
40
#include "input.h"
39
#include "input.h"
41
#include "video.h"
40
#include "video.h"
42
 
41
 
43
/* keyboard layouts and locales */
42
/* keyboard layouts and locales */
44
#include "keylay.h"
43
#include "keylay.h"
Line 426... Line 425...
426
  if (r.h.al < drv - 'A') return(-1);
425
  if (r.h.al < drv - 'A') return(-1);
427
  return(0);
426
  return(0);
428
}
427
}
429
#endif
428
#endif
430
 
429
 
-
 
430
 
-
 
431
/* get the DOS "current drive" (0=A:, 1=B:, etc) */
-
 
432
static int get_cur_drive(void) {
-
 
433
  union REGS r;
-
 
434
  r.h.ah = 0x19; /* DOS 1+ GET CURRENT DEFAULT DRIVE */
-
 
435
  int86(0x21, &r, &r);
-
 
436
  return(r.h.al);
-
 
437
}
-
 
438
 
-
 
439
 
431
/* returns 0 if file exists, non-zero otherwise */
440
/* returns 0 if file exists, non-zero otherwise */
432
static int fileexists(const char *fname) {
441
static int fileexists(const char *fname) {
433
  FILE *fd;
442
  FILE *fd;
434
  fd = fopen(fname, "rb");
443
  fd = fopen(fname, "rb");
435
  if (fd == NULL) return(-1);
444
  if (fd == NULL) return(-1);
436
  fclose(fd);
445
  fclose(fd);
437
  return(0);
446
  return(0);
438
}
447
}
439
 
448
 
440
 
449
 
441
static int preparedrive(void) {
450
static int preparedrive(char sourcedrv) {
442
  int driveremovable;
451
  int driveremovable;
443
  int selecteddrive = 3; /* hardcoded to 'C:' for now */
452
  int selecteddrive = 3; /* default to 'C:' */
444
  int cselecteddrive;
453
  int cselecteddrive;
445
  int ds;
454
  int ds;
446
  int choice;
455
  int choice;
447
  char buff[1024];
456
  char buff[1024];
-
 
457
  if (selecteddrive == get_cur_drive()) selecteddrive = 4; /* use D: if install is run from C: (typically because it was booted from USB?) */
448
  cselecteddrive = 'A' + selecteddrive - 1;
458
  cselecteddrive = 'A' + selecteddrive - 1;
449
  for (;;) {
459
  for (;;) {
450
    driveremovable = isdriveremovable(selecteddrive);
460
    driveremovable = isdriveremovable(selecteddrive);
451
    if (driveremovable < 0) {
461
    if (driveremovable < 0) {
452
      char *list[] = { "Create a partition automatically", "Run the FDISK partitioning tool", "Quit to DOS", NULL};
462
      char *list[] = { "Create a partition automatically", "Run the FDISK partitioning tool", "Quit to DOS", NULL};
Line 456... Line 466...
456
      list[2] = kittengets(0, 2, list[2]);
466
      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);
467
      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);
468
      putstringwrap(4, 1, COLOR_BODY[mono], buff);
459
      switch (menuselect(14, -1, 5, list, -1)) {
469
      switch (menuselect(14, -1, 5, list, -1)) {
460
        case 0:
470
        case 0:
461
          system("FDISK /AUTO");
471
          system("FDISK /AUTO"); /* TODO DRIVE SHOULD BE SPECIFIED FOR MULTI-DRIVE SYSTEMS ! */
462
          break;
472
          break;
463
        case 1:
473
        case 1:
464
          video_clear(0x0700, 0, 0);
474
          video_clear(0x0700, 0, 0);
465
          video_movecursor(0, 0);
475
          video_movecursor(0, 0);
466
          system("FDISK");
476
          system("FDISK");  /* TODO DRIVE SHOULD BE SPECIFIED FOR MULTI-DRIVE SYSTEMS ! */
467
          break;
477
          break;
468
        case 2:
478
        case 2:
469
          return(MENUQUIT);
479
          return(MENUQUIT);
470
        default:
480
        default:
471
          return(-1);
481
          return(-1);
472
      }
482
      }
473
      /* write a temporary MBR which only skips the drive (in case BIOS would
483
      /* write a temporary MBR which only skips the drive (in case BIOS would
474
       * try to boot off the not-yet-ready C: disk) */
484
       * try to boot off the not-yet-ready C: disk) */
475
      system("FDISK /AMBR"); /* writes BOOT.MBR into actual MBR */
485
      system("FDISK /AMBR"); /* writes BOOT.MBR into actual MBR */  /* TODO DRIVE SHOULD BE SPECIFIED FOR MULTI-DRIVE SYSTEMS ! */
476
      newscreen(2);
486
      newscreen(2);
477
      putstringnls(10, 10, COLOR_BODY[mono], 3, 1, "Your computer will reboot now.");
487
      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...");
488
      putstringnls(12, 10, COLOR_BODY[mono], 0, 5, "Press any key...");
479
      input_getkey();
489
      input_getkey();
480
      reboot();
490
      reboot();
Line 542... Line 552...
542
      snprintf(buff, sizeof(buff), kittengets(3, 6, "The installation of SvarDOS to %c: is about to begin."), cselecteddrive);
552
      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);
553
      video_putstring(7, -1, COLOR_BODY[mono], buff, -1);
544
      choice = menuselect(10, -1, 4, list, -1);
554
      choice = menuselect(10, -1, 4, list, -1);
545
      if (choice < 0) return(MENUPREV);
555
      if (choice < 0) return(MENUPREV);
546
      if (choice == 1) return(MENUQUIT);
556
      if (choice == 1) return(MENUQUIT);
547
      snprintf(buff, sizeof(buff), "SYS A: %c: > NUL", cselecteddrive);
557
      snprintf(buff, sizeof(buff), "SYS %c: %c: > NUL", sourcedrv, cselecteddrive);
548
      system(buff);
558
      system(buff);
549
      system("FDISK /MBR");
559
      system("FDISK /MBR"); /* TODO DRIVE SHOULD BE SPECIFIED FOR MULTI-DRIVE SYSTEMS ! */
550
      snprintf(buff, sizeof(buff), "%c:\\TEMP", cselecteddrive);
560
      snprintf(buff, sizeof(buff), "%c:\\TEMP", cselecteddrive);
551
      mkdir(buff);
561
      mkdir(buff);
552
      return(cselecteddrive);
562
      return(cselecteddrive);
553
    }
563
    }
554
  }
564
  }
Line 792... Line 802...
792
static void loadcp(const struct slocales *locales) {
802
static void loadcp(const struct slocales *locales) {
793
  char buff[64];
803
  char buff[64];
794
  if (locales->codepage == 437) return;
804
  if (locales->codepage == 437) return;
795
  video_movecursor(1, 0);
805
  video_movecursor(1, 0);
796
  if (locales->egafile == 1) {
806
  if (locales->egafile == 1) {
797
    snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) A:\\EGA.CPX) > NUL", locales->codepage);
807
    snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) EGA.CPX) > NUL", locales->codepage);
798
  } else {
808
  } else {
799
    snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) A:\\EGA%d.CPX) > NUL", locales->codepage, locales->egafile);
809
    snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) EGA%d.CPX) > NUL", locales->codepage, locales->egafile);
800
  }
810
  }
801
  system(buff);
811
  system(buff);
802
  snprintf(buff, sizeof(buff), "MODE CON CP SEL=%u > NUL", locales->codepage);
812
  snprintf(buff, sizeof(buff), "MODE CON CP SEL=%u > NUL", locales->codepage);
803
  system(buff);
813
  system(buff);
804
  /* below I re-init the video controller - apparently this is required if
814
  /* below I re-init the video controller - apparently this is required if
Line 813... Line 823...
813
  int86(0x10, &r, &r);
823
  int86(0x10, &r, &r);
814
  }
824
  }
815
}
825
}
816
 
826
 
817
 
827
 
-
 
828
#ifdef DEADCODE
818
/* checks that drive drv contains SvarDOS packages
829
/* checks that drive drv contains SvarDOS packages
819
 * returns 0 if found, non-zero otherwise */
830
 * returns 0 if found, non-zero otherwise */
820
static int checkinstsrc(char drv) {
831
static int checkinstsrc(char drv) {
821
  char fname[16];
832
  char fname[16];
822
  snprintf(fname, sizeof(fname), "%c:\\ATTRIB.ZIP", drv);
833
  snprintf(fname, sizeof(fname), "%c:\\ATTRIB.ZIP", drv);
823
  return(fileexists(fname));
834
  return(fileexists(fname));
824
}
835
}
-
 
836
#endif
825
 
837
 
826
 
838
 
827
int main(void) {
839
int main(void) {
828
  struct slocales locales;
840
  struct slocales locales;
829
  int targetdrv;
841
  int targetdrv;
830
  int sourcedrv;
842
  int sourcedrv;
831
  int action;
843
  int action;
832
 
844
 
833
  /* am I running in install-from-floppy mode? */
-
 
834
  if (checkinstsrc('A') == 0) {
-
 
835
    sourcedrv = 'A';
-
 
836
  } else { /* otherwise find where the cdrom drive is */
-
 
837
    sourcedrv = cdrom_findfirst();
845
  sourcedrv = get_cur_drive() + 'A';
838
    if (sourcedrv < 0) {
-
 
839
      printf("ERROR: CD-ROM DRIVE NOT FOUND\r\n");
-
 
840
      return(1);
-
 
841
    }
-
 
842
    sourcedrv += 'A'; /* convert the source drive 'id' (A=0) to an actual drive letter */
-
 
843
    if (checkinstsrc(sourcedrv) != 0) {
-
 
844
      printf("ERROR: SVARDOS INSTALLATION CD NOT FOUND IN THE DRIVE.\r\n");
-
 
845
      return(1);
-
 
846
    }
-
 
847
  }
-
 
848
 
846
 
849
  /* init screen and detect mono status */
847
  /* init screen and detect mono status */
850
  mono = video_init();
848
  mono = video_init();
851
 
849
 
852
  kittenopen("INSTALL"); /* load initial NLS support */
850
  kittenopen("INSTALL"); /* load initial NLS support */
Line 864... Line 862...
864
 
862
 
865
 WelcomeScreen:
863
 WelcomeScreen:
866
  action = welcomescreen(); /* what svardos is, ask whether to run live dos or install */
864
  action = welcomescreen(); /* what svardos is, ask whether to run live dos or install */
867
  if (action == MENUQUIT) goto Quit;
865
  if (action == MENUQUIT) goto Quit;
868
  if (action == MENUPREV) goto SelectLang;
866
  if (action == MENUPREV) goto SelectLang;
869
  targetdrv = preparedrive(); /* what drive should we install to? check avail. space */
867
  targetdrv = preparedrive(sourcedrv); /* what drive should we install to? check avail. space */
870
  if (targetdrv == MENUQUIT) goto Quit;
868
  if (targetdrv == MENUQUIT) goto Quit;
871
  if (targetdrv == MENUPREV) goto WelcomeScreen;
869
  if (targetdrv == MENUPREV) goto WelcomeScreen;
872
  bootfilesgen(targetdrv, &locales); /* generate boot files and other configurations */
870
  bootfilesgen(targetdrv, &locales); /* generate boot files and other configurations */
873
  if (installpackages(targetdrv, sourcedrv, &locales) != 0) goto Quit;    /* install packages */
871
  if (installpackages(targetdrv, sourcedrv, &locales) != 0) goto Quit;    /* install packages */
874
  /*localcfg();*/ /* show local params (currency, etc), and propose to change them (based on localcfg) */
872
  /*localcfg();*/ /* show local params (currency, etc), and propose to change them (based on localcfg) */