Subversion Repositories SvarDOS

Rev

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

Rev 1934 Rev 1935
Line 602... Line 602...
602
  return(result);
602
  return(result);
603
}
603
}
604
 
604
 
605
 
605
 
606
static int preparedrive(void) {
606
static int preparedrive(void) {
607
  int driveremovable;
607
  int selecteddrive;
608
  int selecteddrive = 3; /* default to 'C:' */
-
 
609
  int cselecteddrive;
608
  char cselecteddrive;
610
  int ds;
609
  int ds;
611
  int choice;
610
  int choice;
612
  char buff[1024];
611
  char buff[512];
613
  int driveid = 1; /* fdisk runs on first drive (unless USB boot) */
612
  int driveid = 1; /* fdisk runs on first drive (unless USB boot) */
614
  if (selecteddrive == get_cur_drive() + 1) { /* get_cur_drive() returns 0-based values (A=0) while selecteddrive is 1-based (A=1) */
-
 
615
    selecteddrive = 4; /* use D: if install is run from C: (typically because it was booted from USB?) */
-
 
616
    driveid = 2; /* primary drive is the emulated USB storage */
-
 
617
  }
613
 
618
  cselecteddrive = 'A' + selecteddrive - 1;
-
 
619
  for (;;) {
614
  for (;;) {
-
 
615
    char drvlist[4][16]; /* C: [2048 MB] */
-
 
616
    int i, drvlistlen = 0;
-
 
617
 
620
    driveremovable = isdriveremovable(selecteddrive);
618
    /* build a menu with all non-removable drives from C to F */
-
 
619
    for (i = 3; i < 7; i++) {
621
    if (driveremovable == 0) {
620
      if (isdriveremovable(i) > 0) {
622
      newscreen(2);
621
        unsigned short sz = disksize(i);
623
      snprintf(buff, sizeof(buff), svarlang_strid(0x0302), cselecteddrive); /* "ERROR: Drive %c: is a removable device */
622
        if (sz == 0xffff) { /* size not avail (probably unformatted disk) */
624
      mdr_cout_str(9, 1, buff, COLOR_BODY, 80);
623
          snprintf(drvlist[drvlistlen], sizeof(drvlist[0]), "%c:", '@' + i, disksize(i));
-
 
624
        } else {
625
      putstringnls(11, 2, COLOR_BODY, 0, 5); /* "Press any key..." */
625
          snprintf(drvlist[drvlistlen], sizeof(drvlist[0]), "%c: [%u MiB]", '@' + i, disksize(i));
-
 
626
        }
626
      mdr_dos_getkey();
627
        drvlistlen++;
627
      return(MENUQUIT);
628
      }
628
    }
629
    }
629
 
630
 
630
    /* if C: not found - disk not partitioned? */
631
    /* if no drive found - disk not partitioned? */
631
    if (driveremovable < 0) {
632
    if (drvlistlen == 0) {
632
      const char *list[4];
633
      const char *list[4];
633
      newscreen(0);
634
      newscreen(0);
634
      list[0] = svarlang_str(0, 3); /* Create a partition automatically */
635
      list[0] = svarlang_str(0, 3); /* Create a partition automatically */
635
      list[1] = svarlang_str(0, 4); /* Run the FDISK tool */
636
      list[1] = svarlang_str(0, 4); /* Run the FDISK tool */
636
      list[2] = svarlang_str(0, 2); /* Quit to DOS */
637
      list[2] = svarlang_str(0, 2); /* Quit to DOS */
637
      list[3] = NULL;
638
      list[3] = NULL;
638
      snprintf(buff, sizeof(buff), svarlang_strid(0x0300), cselecteddrive, SVARDOS_DISK_REQ); /* "ERROR: Drive %c: could not be found. Note, that SvarDOS requires at least %d MiB of available disk space */
639
      snprintf(buff, sizeof(buff), svarlang_strid(0x0300), SVARDOS_DISK_REQ); /* "ERROR: No drive could be found. Note, that SvarDOS requires at least %d MiB of available disk space */
639
      switch (menuselect(6 + putstringwrap(4, 1, COLOR_BODY, buff), 3, list, -1)) {
640
      switch (menuselect(6 + putstringwrap(4, 1, COLOR_BODY, buff), 3, list, -1)) {
640
        case 0:
641
        case 0:
641
          sprintf(buff, "FDISK /PRI:MAX %d", driveid);
642
          sprintf(buff, "FDISK /PRI:MAX %d", driveid);
642
          exec(buff);
643
          exec(buff);
643
          break;
644
          break;
Line 662... Line 663...
662
      mdr_dos_getkey();
663
      mdr_dos_getkey();
663
      reboot();
664
      reboot();
664
      return(MENUQUIT);
665
      return(MENUQUIT);
665
    }
666
    }
666
 
667
 
-
 
668
    /* select the drive from list */
-
 
669
    {
-
 
670
      const char *list[16];
-
 
671
      int i;
-
 
672
      for (i = 0; i < drvlistlen; i++) list[i] = drvlist[i];
-
 
673
      list[i++] = svarlang_str(0, 2); /* Quit to DOS */
-
 
674
      list[i] = NULL;
-
 
675
      newscreen(0);
-
 
676
 
-
 
677
      i = menuselect(6 /*ypos*/, i /*height*/, list, -1);
-
 
678
      if (i < 0) {
-
 
679
        return(MENUPREV);
-
 
680
      } else if (i < drvlistlen) {
-
 
681
        selecteddrive = list[i][0] - '@';
-
 
682
      } else {
-
 
683
        return(MENUQUIT);
-
 
684
      }
-
 
685
 
-
 
686
      cselecteddrive = '@' + selecteddrive;
-
 
687
    }
-
 
688
 
667
    /* if not formatted, propose to format it right away (try to create a directory) */
689
    /* if not formatted, propose to format it right away (try to create a directory) */
668
    if (test_drive_write(cselecteddrive) != 0) {
690
    if (test_drive_write(cselecteddrive) != 0) {
669
      const char *list[3];
691
      const char *list[3];
670
      newscreen(0);
692
      newscreen(0);
671
      snprintf(buff, sizeof(buff), svarlang_str(3, 3), cselecteddrive); /* "ERROR: Drive %c: seems to be unformated. Do you wish to format it?") */
693
      snprintf(buff, sizeof(buff), svarlang_str(3, 3), cselecteddrive); /* "ERROR: Drive %c: seems to be unformated. Do you wish to format it?") */
Line 683... Line 705...
683
      mdr_cout_locate(0, 0);
705
      mdr_cout_locate(0, 0);
684
      snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
706
      snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
685
      exec(buff);
707
      exec(buff);
686
      continue;
708
      continue;
687
    }
709
    }
-
 
710
 
688
    /* check total disk space */
711
    /* check total disk space */
689
    ds = disksize(selecteddrive);
712
    ds = disksize(selecteddrive);
690
    if (ds < SVARDOS_DISK_REQ) {
713
    if (ds < SVARDOS_DISK_REQ) {
691
      int y = 9;
714
      int y = 9;
692
      newscreen(2);
715
      newscreen(2);
Line 694... Line 717...
694
      y += putstringwrap(y, 1, COLOR_BODY, buff);
717
      y += putstringwrap(y, 1, COLOR_BODY, buff);
695
      putstringnls(++y, 1, COLOR_BODY, 0, 5); /* "Press any key..." */
718
      putstringnls(++y, 1, COLOR_BODY, 0, 5); /* "Press any key..." */
696
      mdr_dos_getkey();
719
      mdr_dos_getkey();
697
      return(MENUQUIT);
720
      return(MENUQUIT);
698
    }
721
    }
-
 
722
 
699
    /* is the disk empty? */
723
    /* is the disk empty? */
700
    newscreen(0);
724
    newscreen(0);
701
    if (diskempty(selecteddrive) != 0) {
725
    if (diskempty(selecteddrive) != 0) {
702
      const char *list[3];
726
      const char *list[3];
703
      int y = 6;
727
      int y = 6;
Line 818... Line 842...
818
  if (fd == NULL) {
842
  if (fd == NULL) {
819
    return;
843
    return;
820
  } else {
844
  } else {
821
    char *autoexec_bat1 =
845
    char *autoexec_bat1 =
822
      "@ECHO OFF\r\n"
846
      "@ECHO OFF\r\n"
823
      "SET TEMP=@:\\TEMP\r\n"
847
      "SET TEMP=#:\\TEMP\r\n"
824
      "SET DOSDIR=@:\\SVARDOS\r\n"
848
      "SET DOSDIR=#:\\SVARDOS\r\n"
825
      "SET NLSPATH=%DOSDIR%\\NLS\r\n"
849
      "SET NLSPATH=%DOSDIR%\\NLS\r\n"
826
      "SET DIRCMD=/O/P\r\n"
850
      "SET DIRCMD=/O/P\r\n"
827
      "SET WATTCP.CFG=%DOSDIR%\\CFG\r\n"
851
      "SET WATTCP.CFG=%DOSDIR%\\CFG\r\n"
828
      "PATH %DOSDIR%\r\n"
852
      "PATH %DOSDIR%\r\n"
829
      "PROMPT $P$G\r\n"
853
      "PROMPT $P$G\r\n"
Line 835... Line 859...
835
      "REM Uncomment the line below for CDROM support\r\n"
859
      "REM Uncomment the line below for CDROM support\r\n"
836
      "REM SHSUCDX /d:SVCD0001\r\n"
860
      "REM SHSUCDX /d:SVCD0001\r\n"
837
      "\r\n"
861
      "\r\n"
838
      "ECHO.\r\n";
862
      "ECHO.\r\n";
839
 
863
 
840
    /* replace all '@' occurences by bootdrive */
864
    /* replace all '#' occurences by bootdrive */
841
    strtr(autoexec_bat1, '@', bootdrv);
865
    strtr(autoexec_bat1, '#', bootdrv);
842
 
866
 
843
    /* write all to file */
867
    /* write all to file */
844
    fputs(autoexec_bat1, fd);
868
    fputs(autoexec_bat1, fd);
845
    if (locales != NULL) genlocalesconf(fd, locales);
869
    if (locales != NULL) genlocalesconf(fd, locales);
846
    fputs(autoexec_bat2, fd);
870
    fputs(autoexec_bat2, fd);
Line 854... Line 878...
854
  mkdir(buff);
878
  mkdir(buff);
855
 
879
 
856
  /****************
880
  /****************
857
   * PKG.CFG      *
881
   * PKG.CFG      *
858
   ****************/
882
   ****************/
859
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS\\CFG\\PKG.CFG", bootdrv);
883
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS\\PKG.CFG", bootdrv);
860
  fd = fopen(buff, "wb");
884
  fd = fopen(buff, "wb");
861
  if (fd == NULL) {
885
  if (fd == NULL) {
862
    return;
886
    return;
863
  } else {
887
  } else {
864
    char *pkg_cfg =
888
    char *pkg_cfg =
865
      "# pkg config file - specifies locations where packages should be installed\r\n"
889
      "# pkg config file - specifies locations where packages should be installed\r\n"
866
      "\r\n"
890
      "\r\n"
867
      "# System boot drive\r\n"
891
      "# System boot drive\r\n"
868
      "bootdrive = @\r\n"
892
      "BOOTDRIVE @\r\n"
869
      "\r\n"
893
      "\r\n"
870
      "# DOS core binaries\r\n"
894
      "# DOS core binaries\r\n"
871
      "DIR BIN @:\\SVARDOS\r\n"
895
      "DIR BIN @:\\SVARDOS\r\n"
872
      "\r\n"
896
      "\r\n"
873
      "# Programs\r\n"
897
      "# Programs\r\n"