[SETUPLIB][USETUP] Remove the deprecated GenericListHasSingleEntry() function and...
[reactos.git] / base / setup / usetup / usetup.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002, 2003, 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: base/setup/usetup/usetup.c
23 * PURPOSE: Text-mode setup
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * Hervé Poussineau (hpoussin@reactos.org)
26 */
27
28 #include <usetup.h>
29 #include <math.h>
30
31 #include "bootsup.h"
32 #include "chkdsk.h"
33 #include "cmdcons.h"
34 #include "format.h"
35
36 #define NDEBUG
37 #include <debug.h>
38
39
40 /* GLOBALS & LOCALS *********************************************************/
41
42 HANDLE ProcessHeap;
43
44 BOOLEAN IsUnattendedSetup = FALSE;
45 static USETUP_DATA USetupData;
46
47 /*
48 * NOTE: Technically only used for the COPYCONTEXT InstallPath member
49 * for the filequeue functionality.
50 */
51 static UNICODE_STRING InstallPath;
52
53 // FIXME: Is it really useful?? Just used for SetDefaultPagefile...
54 static WCHAR DestinationDriveLetter;
55
56
57 /* OTHER Stuff *****/
58
59 PCWSTR SelectedLanguageId;
60 static WCHAR DefaultLanguage[20]; // Copy of string inside LanguageList
61 static WCHAR DefaultKBLayout[20]; // Copy of string inside KeyboardList
62
63 static BOOLEAN RepairUpdateFlag = FALSE;
64
65 static HANDLE hPnpThread = NULL;
66
67 static PPARTLIST PartitionList = NULL;
68 static PPARTENTRY TempPartition = NULL;
69 static PFILE_SYSTEM_LIST FileSystemList = NULL;
70 static FORMATMACHINESTATE FormatState = Start;
71
72 /*****************************************************/
73
74 static HINF SetupInf;
75
76 static HSPFILEQ SetupFileQueue = NULL;
77
78 static PNTOS_INSTALLATION CurrentInstallation = NULL;
79 static PGENERIC_LIST NtOsInstallsList = NULL;
80
81 static PGENERIC_LIST ComputerList = NULL;
82 static PGENERIC_LIST DisplayList = NULL;
83 static PGENERIC_LIST KeyboardList = NULL;
84 static PGENERIC_LIST LayoutList = NULL;
85 static PGENERIC_LIST LanguageList = NULL;
86
87
88 /* FUNCTIONS ****************************************************************/
89
90 static VOID
91 PrintString(char* fmt,...)
92 {
93 char buffer[512];
94 va_list ap;
95 UNICODE_STRING UnicodeString;
96 ANSI_STRING AnsiString;
97
98 va_start(ap, fmt);
99 vsprintf(buffer, fmt, ap);
100 va_end(ap);
101
102 RtlInitAnsiString(&AnsiString, buffer);
103 RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString, TRUE);
104 NtDisplayString(&UnicodeString);
105 RtlFreeUnicodeString(&UnicodeString);
106 }
107
108
109 static VOID
110 DrawBox(IN SHORT xLeft,
111 IN SHORT yTop,
112 IN SHORT Width,
113 IN SHORT Height)
114 {
115 COORD coPos;
116 DWORD Written;
117
118 /* Draw upper left corner */
119 coPos.X = xLeft;
120 coPos.Y = yTop;
121 FillConsoleOutputCharacterA(StdOutput,
122 0xDA, // '+',
123 1,
124 coPos,
125 &Written);
126
127 /* Draw upper edge */
128 coPos.X = xLeft + 1;
129 coPos.Y = yTop;
130 FillConsoleOutputCharacterA(StdOutput,
131 0xC4, // '-',
132 Width - 2,
133 coPos,
134 &Written);
135
136 /* Draw upper right corner */
137 coPos.X = xLeft + Width - 1;
138 coPos.Y = yTop;
139 FillConsoleOutputCharacterA(StdOutput,
140 0xBF, // '+',
141 1,
142 coPos,
143 &Written);
144
145 /* Draw right edge, inner space and left edge */
146 for (coPos.Y = yTop + 1; coPos.Y < yTop + Height - 1; coPos.Y++)
147 {
148 coPos.X = xLeft;
149 FillConsoleOutputCharacterA(StdOutput,
150 0xB3, // '|',
151 1,
152 coPos,
153 &Written);
154
155 coPos.X = xLeft + 1;
156 FillConsoleOutputCharacterA(StdOutput,
157 ' ',
158 Width - 2,
159 coPos,
160 &Written);
161
162 coPos.X = xLeft + Width - 1;
163 FillConsoleOutputCharacterA(StdOutput,
164 0xB3, // '|',
165 1,
166 coPos,
167 &Written);
168 }
169
170 /* Draw lower left corner */
171 coPos.X = xLeft;
172 coPos.Y = yTop + Height - 1;
173 FillConsoleOutputCharacterA(StdOutput,
174 0xC0, // '+',
175 1,
176 coPos,
177 &Written);
178
179 /* Draw lower edge */
180 coPos.X = xLeft + 1;
181 coPos.Y = yTop + Height - 1;
182 FillConsoleOutputCharacterA(StdOutput,
183 0xC4, // '-',
184 Width - 2,
185 coPos,
186 &Written);
187
188 /* Draw lower right corner */
189 coPos.X = xLeft + Width - 1;
190 coPos.Y = yTop + Height - 1;
191 FillConsoleOutputCharacterA(StdOutput,
192 0xD9, // '+',
193 1,
194 coPos,
195 &Written);
196 }
197
198
199 VOID
200 PopupError(PCCH Text,
201 PCCH Status,
202 PINPUT_RECORD Ir,
203 ULONG WaitEvent)
204 {
205 SHORT yTop;
206 SHORT xLeft;
207 COORD coPos;
208 DWORD Written;
209 ULONG Length;
210 ULONG MaxLength;
211 ULONG Lines;
212 PCHAR p;
213 PCCH pnext;
214 BOOLEAN LastLine;
215 SHORT Width;
216 SHORT Height;
217
218 /* Count text lines and longest line */
219 MaxLength = 0;
220 Lines = 0;
221 pnext = Text;
222
223 while (TRUE)
224 {
225 p = strchr(pnext, '\n');
226
227 if (p == NULL)
228 {
229 Length = strlen(pnext);
230 LastLine = TRUE;
231 }
232 else
233 {
234 Length = (ULONG)(p - pnext);
235 LastLine = FALSE;
236 }
237
238 Lines++;
239
240 if (Length > MaxLength)
241 MaxLength = Length;
242
243 if (LastLine)
244 break;
245
246 pnext = p + 1;
247 }
248
249 /* Check length of status line */
250 if (Status != NULL)
251 {
252 Length = strlen(Status);
253
254 if (Length > MaxLength)
255 MaxLength = Length;
256 }
257
258 Width = MaxLength + 4;
259 Height = Lines + 2;
260
261 if (Status != NULL)
262 Height += 2;
263
264 yTop = (yScreen - Height) / 2;
265 xLeft = (xScreen - Width) / 2;
266
267
268 /* Set screen attributes */
269 coPos.X = xLeft;
270 for (coPos.Y = yTop; coPos.Y < yTop + Height; coPos.Y++)
271 {
272 FillConsoleOutputAttribute(StdOutput,
273 FOREGROUND_RED | BACKGROUND_WHITE,
274 Width,
275 coPos,
276 &Written);
277 }
278
279 DrawBox(xLeft, yTop, Width, Height);
280
281 /* Print message text */
282 coPos.Y = yTop + 1;
283 pnext = Text;
284 while (TRUE)
285 {
286 p = strchr(pnext, '\n');
287
288 if (p == NULL)
289 {
290 Length = strlen(pnext);
291 LastLine = TRUE;
292 }
293 else
294 {
295 Length = (ULONG)(p - pnext);
296 LastLine = FALSE;
297 }
298
299 if (Length != 0)
300 {
301 coPos.X = xLeft + 2;
302 WriteConsoleOutputCharacterA(StdOutput,
303 pnext,
304 Length,
305 coPos,
306 &Written);
307 }
308
309 if (LastLine)
310 break;
311
312 coPos.Y++;
313 pnext = p + 1;
314 }
315
316 /* Print separator line and status text */
317 if (Status != NULL)
318 {
319 coPos.Y = yTop + Height - 3;
320 coPos.X = xLeft;
321 FillConsoleOutputCharacterA(StdOutput,
322 0xC3, // '+',
323 1,
324 coPos,
325 &Written);
326
327 coPos.X = xLeft + 1;
328 FillConsoleOutputCharacterA(StdOutput,
329 0xC4, // '-',
330 Width - 2,
331 coPos,
332 &Written);
333
334 coPos.X = xLeft + Width - 1;
335 FillConsoleOutputCharacterA(StdOutput,
336 0xB4, // '+',
337 1,
338 coPos,
339 &Written);
340
341 coPos.Y++;
342 coPos.X = xLeft + 2;
343 WriteConsoleOutputCharacterA(StdOutput,
344 Status,
345 min(strlen(Status), (SIZE_T)Width - 4),
346 coPos,
347 &Written);
348 }
349
350 if (WaitEvent == POPUP_WAIT_NONE)
351 return;
352
353 while (TRUE)
354 {
355 CONSOLE_ConInKey(Ir);
356
357 if (WaitEvent == POPUP_WAIT_ANY_KEY ||
358 Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D)
359 {
360 return;
361 }
362 }
363 }
364
365
366 /*
367 * Confirm quit setup
368 * RETURNS
369 * TRUE: Quit setup.
370 * FALSE: Don't quit setup.
371 */
372 static BOOL
373 ConfirmQuit(PINPUT_RECORD Ir)
374 {
375 BOOL Result = FALSE;
376 MUIDisplayError(ERROR_NOT_INSTALLED, NULL, POPUP_WAIT_NONE);
377
378 while (TRUE)
379 {
380 CONSOLE_ConInKey(Ir);
381
382 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
383 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
384 {
385 Result = TRUE;
386 break;
387 }
388 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
389 {
390 Result = FALSE;
391 break;
392 }
393 }
394
395 return Result;
396 }
397
398
399 static VOID
400 UpdateKBLayout(VOID)
401 {
402 PGENERIC_LIST_ENTRY ListEntry;
403 PCWSTR pszNewLayout;
404
405 pszNewLayout = MUIDefaultKeyboardLayout(SelectedLanguageId);
406
407 if (LayoutList == NULL)
408 {
409 LayoutList = CreateKeyboardLayoutList(SetupInf, SelectedLanguageId, DefaultKBLayout);
410 if (LayoutList == NULL)
411 {
412 /* FIXME: Handle error! */
413 return;
414 }
415 }
416
417 /* Search for default layout (if provided) */
418 if (pszNewLayout != NULL)
419 {
420 for (ListEntry = GetFirstListEntry(LayoutList); ListEntry;
421 ListEntry = GetNextListEntry(ListEntry))
422 {
423 if (!wcscmp(pszNewLayout, ((PGENENTRY)GetListEntryData(ListEntry))->Id))
424 {
425 SetCurrentListEntry(LayoutList, ListEntry);
426 break;
427 }
428 }
429 }
430 }
431
432
433 static NTSTATUS
434 NTAPI
435 GetSettingDescription(
436 IN PGENERIC_LIST_ENTRY Entry,
437 OUT PSTR Buffer,
438 IN SIZE_T cchBufferSize)
439 {
440 return RtlStringCchPrintfA(Buffer, cchBufferSize, "%S",
441 ((PGENENTRY)GetListEntryData(Entry))->Value);
442 }
443
444 static NTSTATUS
445 NTAPI
446 GetNTOSInstallationName(
447 IN PGENERIC_LIST_ENTRY Entry,
448 OUT PSTR Buffer,
449 IN SIZE_T cchBufferSize)
450 {
451 PNTOS_INSTALLATION NtOsInstall = (PNTOS_INSTALLATION)GetListEntryData(Entry);
452 PPARTENTRY PartEntry = NtOsInstall->PartEntry;
453
454 if (PartEntry && PartEntry->DriveLetter)
455 {
456 /* We have retrieved a partition that is mounted */
457 return RtlStringCchPrintfA(Buffer, cchBufferSize,
458 "%c:%S \"%S\"",
459 PartEntry->DriveLetter,
460 NtOsInstall->PathComponent,
461 NtOsInstall->InstallationName);
462 }
463 else
464 {
465 /* We failed somewhere, just show the NT path */
466 return RtlStringCchPrintfA(Buffer, cchBufferSize,
467 "%wZ \"%S\"",
468 &NtOsInstall->SystemNtPath,
469 NtOsInstall->InstallationName);
470 }
471 }
472
473
474 /*
475 * Displays the LanguagePage.
476 *
477 * Next pages: WelcomePage, QuitPage
478 *
479 * SIDEEFFECTS
480 * Init SelectedLanguageId
481 * Init USetupData.LanguageId
482 *
483 * RETURNS
484 * Number of the next page.
485 */
486 static PAGE_NUMBER
487 LanguagePage(PINPUT_RECORD Ir)
488 {
489 GENERIC_LIST_UI ListUi;
490 PCWSTR NewLanguageId;
491 BOOL RefreshPage = FALSE;
492
493 /* Initialize the computer settings list */
494 if (LanguageList == NULL)
495 {
496 LanguageList = CreateLanguageList(SetupInf, DefaultLanguage);
497 if (LanguageList == NULL)
498 {
499 PopupError("Setup failed to initialize available translations", NULL, NULL, POPUP_WAIT_NONE);
500 return WELCOME_PAGE;
501 }
502 }
503
504 SelectedLanguageId = DefaultLanguage;
505 USetupData.LanguageId = 0;
506
507 /* Load the font */
508 SetConsoleCodePage();
509 UpdateKBLayout();
510
511 /*
512 * If there is no language or just a single one in the list,
513 * skip the language selection process altogether.
514 */
515 if (GetNumberOfListEntries(LanguageList) <= 1)
516 {
517 USetupData.LanguageId = (LANGID)(wcstol(SelectedLanguageId, NULL, 16) & 0xFFFF);
518 return WELCOME_PAGE;
519 }
520
521 InitGenericListUi(&ListUi, LanguageList, GetSettingDescription);
522 DrawGenericList(&ListUi,
523 2, 18,
524 xScreen - 3,
525 yScreen - 3);
526
527 ScrollToPositionGenericList(&ListUi, GetDefaultLanguageIndex());
528
529 MUIDisplayPage(LANGUAGE_PAGE);
530
531 while (TRUE)
532 {
533 CONSOLE_ConInKey(Ir);
534
535 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
536 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DOWN)) /* DOWN */
537 {
538 ScrollDownGenericList(&ListUi);
539 RefreshPage = TRUE;
540 }
541 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
542 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_UP)) /* UP */
543 {
544 ScrollUpGenericList(&ListUi);
545 RefreshPage = TRUE;
546 }
547 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
548 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_NEXT)) /* PAGE DOWN */
549 {
550 ScrollPageDownGenericList(&ListUi);
551 RefreshPage = TRUE;
552 }
553 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
554 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_PRIOR)) /* PAGE UP */
555 {
556 ScrollPageUpGenericList(&ListUi);
557 RefreshPage = TRUE;
558 }
559 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
560 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
561 {
562 if (ConfirmQuit(Ir))
563 return QUIT_PAGE;
564 else
565 RedrawGenericList(&ListUi);
566 }
567 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
568 {
569 ASSERT(GetNumberOfListEntries(LanguageList) >= 1);
570
571 SelectedLanguageId =
572 ((PGENENTRY)GetListEntryData(GetCurrentListEntry(LanguageList)))->Id;
573
574 USetupData.LanguageId = (LANGID)(wcstol(SelectedLanguageId, NULL, 16) & 0xFFFF);
575
576 if (wcscmp(SelectedLanguageId, DefaultLanguage))
577 {
578 UpdateKBLayout();
579 }
580
581 /* Load the font */
582 SetConsoleCodePage();
583
584 return WELCOME_PAGE;
585 }
586 else if ((Ir->Event.KeyEvent.uChar.AsciiChar > 0x60) && (Ir->Event.KeyEvent.uChar.AsciiChar < 0x7b))
587 {
588 /* a-z */
589 GenericListKeyPress(&ListUi, Ir->Event.KeyEvent.uChar.AsciiChar);
590 RefreshPage = TRUE;
591 }
592
593 if (RefreshPage)
594 {
595 ASSERT(GetNumberOfListEntries(LanguageList) >= 1);
596
597 NewLanguageId =
598 ((PGENENTRY)GetListEntryData(GetCurrentListEntry(LanguageList)))->Id;
599
600 if (wcscmp(SelectedLanguageId, NewLanguageId))
601 {
602 /* Clear the language page */
603 MUIClearPage(LANGUAGE_PAGE);
604
605 SelectedLanguageId = NewLanguageId;
606
607 /* Load the font */
608 SetConsoleCodePage();
609
610 /* Redraw language selection page in native language */
611 MUIDisplayPage(LANGUAGE_PAGE);
612 }
613
614 RefreshPage = FALSE;
615 }
616 }
617
618 return WELCOME_PAGE;
619 }
620
621
622 /*
623 * Start page
624 *
625 * Next pages:
626 * LanguagePage (at once, default)
627 * InstallIntroPage (at once, if unattended)
628 * QuitPage
629 *
630 * SIDEEFFECTS
631 * Init Sdi
632 * Init USetupData.SourcePath
633 * Init USetupData.SourceRootPath
634 * Init USetupData.SourceRootDir
635 * Init SetupInf
636 * Init USetupData.RequiredPartitionDiskSpace
637 * Init IsUnattendedSetup
638 * If unattended, init *List and sets the Codepage
639 * If unattended, init SelectedLanguageId
640 * If unattended, init USetupData.LanguageId
641 *
642 * RETURNS
643 * Number of the next page.
644 */
645 static PAGE_NUMBER
646 SetupStartPage(PINPUT_RECORD Ir)
647 {
648 NTSTATUS Status;
649 ULONG Error;
650 PGENERIC_LIST_ENTRY ListEntry;
651 PCWSTR LocaleId;
652
653 CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
654
655 /* Get the source path and source root path */
656 Status = GetSourcePaths(&USetupData.SourcePath,
657 &USetupData.SourceRootPath,
658 &USetupData.SourceRootDir);
659 if (!NT_SUCCESS(Status))
660 {
661 CONSOLE_PrintTextXY(6, 15, "GetSourcePaths() failed (Status 0x%08lx)", Status);
662 MUIDisplayError(ERROR_NO_SOURCE_DRIVE, Ir, POPUP_WAIT_ENTER);
663 return QUIT_PAGE;
664 }
665 DPRINT1("SourcePath: '%wZ'\n", &USetupData.SourcePath);
666 DPRINT1("SourceRootPath: '%wZ'\n", &USetupData.SourceRootPath);
667 DPRINT1("SourceRootDir: '%wZ'\n", &USetupData.SourceRootDir);
668
669 /* Load 'txtsetup.sif' from the installation media */
670 Error = LoadSetupInf(&SetupInf, &USetupData);
671 if (Error != ERROR_SUCCESS)
672 {
673 MUIDisplayError(Error, Ir, POPUP_WAIT_ENTER);
674 return QUIT_PAGE;
675 }
676
677 /* Start the PnP thread */
678 if (hPnpThread != NULL)
679 {
680 NtResumeThread(hPnpThread, NULL);
681 hPnpThread = NULL;
682 }
683
684 CheckUnattendedSetup(&USetupData);
685
686 if (IsUnattendedSetup)
687 {
688 // TODO: Read options from inf
689 /* Load the hardware, language and keyboard layout lists */
690
691 ComputerList = CreateComputerTypeList(SetupInf);
692 DisplayList = CreateDisplayDriverList(SetupInf);
693 KeyboardList = CreateKeyboardDriverList(SetupInf);
694
695 LanguageList = CreateLanguageList(SetupInf, DefaultLanguage);
696
697 /* new part */
698 SelectedLanguageId = DefaultLanguage;
699 wcscpy(DefaultLanguage, USetupData.LocaleID);
700 USetupData.LanguageId = (LANGID)(wcstol(SelectedLanguageId, NULL, 16) & 0xFFFF);
701
702 LayoutList = CreateKeyboardLayoutList(SetupInf, SelectedLanguageId, DefaultKBLayout);
703
704 /* first we hack LanguageList */
705 for (ListEntry = GetFirstListEntry(LanguageList); ListEntry;
706 ListEntry = GetNextListEntry(ListEntry))
707 {
708 LocaleId = ((PGENENTRY)GetListEntryData(ListEntry))->Id;
709 if (!wcsicmp(USetupData.LocaleID, LocaleId))
710 {
711 DPRINT("found %S in LanguageList\n", LocaleId);
712 SetCurrentListEntry(LanguageList, ListEntry);
713 break;
714 }
715 }
716
717 /* now LayoutList */
718 for (ListEntry = GetFirstListEntry(LayoutList); ListEntry;
719 ListEntry = GetNextListEntry(ListEntry))
720 {
721 LocaleId = ((PGENENTRY)GetListEntryData(ListEntry))->Id;
722 if (!wcsicmp(USetupData.LocaleID, LocaleId))
723 {
724 DPRINT("found %S in LayoutList\n", LocaleId);
725 SetCurrentListEntry(LayoutList, ListEntry);
726 break;
727 }
728 }
729
730 SetConsoleCodePage();
731
732 return INSTALL_INTRO_PAGE;
733 }
734
735 return LANGUAGE_PAGE;
736 }
737
738
739 /*
740 * Displays the WelcomePage.
741 *
742 * Next pages:
743 * InstallIntroPage (default)
744 * RepairIntroPage
745 * RecoveryPage
746 * LicensePage
747 * QuitPage
748 *
749 * RETURNS
750 * Number of the next page.
751 */
752 static PAGE_NUMBER
753 WelcomePage(PINPUT_RECORD Ir)
754 {
755 MUIDisplayPage(WELCOME_PAGE);
756
757 while (TRUE)
758 {
759 CONSOLE_ConInKey(Ir);
760
761 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
762 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
763 {
764 if (ConfirmQuit(Ir))
765 return QUIT_PAGE;
766
767 break;
768 }
769 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
770 {
771 return INSTALL_INTRO_PAGE;
772 }
773 else if (toupper(Ir->Event.KeyEvent.uChar.AsciiChar) == 'R') /* R */
774 {
775 return RECOVERY_PAGE; // REPAIR_INTRO_PAGE;
776 }
777 else if (toupper(Ir->Event.KeyEvent.uChar.AsciiChar) == 'L') /* L */
778 {
779 return LICENSE_PAGE;
780 }
781 }
782
783 return WELCOME_PAGE;
784 }
785
786
787 /*
788 * Displays the License page.
789 *
790 * Next page:
791 * WelcomePage (default)
792 *
793 * RETURNS
794 * Number of the next page.
795 */
796 static PAGE_NUMBER
797 LicensePage(PINPUT_RECORD Ir)
798 {
799 MUIDisplayPage(LICENSE_PAGE);
800
801 while (TRUE)
802 {
803 CONSOLE_ConInKey(Ir);
804
805 if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
806 {
807 return WELCOME_PAGE;
808 }
809 }
810
811 return LICENSE_PAGE;
812 }
813
814
815 /*
816 * Displays the RepairIntroPage.
817 *
818 * Next pages:
819 * RebootPage (default)
820 * InstallIntroPage
821 * RecoveryPage
822 * IntroPage
823 *
824 * RETURNS
825 * Number of the next page.
826 */
827 static PAGE_NUMBER
828 RepairIntroPage(PINPUT_RECORD Ir)
829 {
830 MUIDisplayPage(REPAIR_INTRO_PAGE);
831
832 while(TRUE)
833 {
834 CONSOLE_ConInKey(Ir);
835
836 if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
837 {
838 return REBOOT_PAGE;
839 }
840 else if (toupper(Ir->Event.KeyEvent.uChar.AsciiChar) == 'U') /* U */
841 {
842 RepairUpdateFlag = TRUE;
843 return INSTALL_INTRO_PAGE;
844 }
845 else if (toupper(Ir->Event.KeyEvent.uChar.AsciiChar) == 'R') /* R */
846 {
847 return RECOVERY_PAGE;
848 }
849 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
850 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)) /* ESC */
851 {
852 return WELCOME_PAGE;
853 }
854 }
855
856 return REPAIR_INTRO_PAGE;
857 }
858
859 /*
860 * Displays the UpgradeRepairPage.
861 *
862 * Next pages:
863 * RebootPage (default)
864 * InstallIntroPage
865 * RecoveryPage
866 * WelcomePage
867 *
868 * RETURNS
869 * Number of the next page.
870 */
871 static PAGE_NUMBER
872 UpgradeRepairPage(PINPUT_RECORD Ir)
873 {
874 GENERIC_LIST_UI ListUi;
875
876 /*** HACK!! ***/
877 if (PartitionList == NULL)
878 {
879 PartitionList = CreatePartitionList();
880 if (PartitionList == NULL)
881 {
882 /* FIXME: show an error dialog */
883 MUIDisplayError(ERROR_DRIVE_INFORMATION, Ir, POPUP_WAIT_ENTER);
884 return QUIT_PAGE;
885 }
886 else if (IsListEmpty(&PartitionList->DiskListHead))
887 {
888 MUIDisplayError(ERROR_NO_HDD, Ir, POPUP_WAIT_ENTER);
889 return QUIT_PAGE;
890 }
891
892 TempPartition = NULL;
893 FormatState = Start;
894 }
895 /**************/
896
897 NtOsInstallsList = CreateNTOSInstallationsList(PartitionList);
898 if (!NtOsInstallsList)
899 DPRINT1("Failed to get a list of NTOS installations; continue installation...\n");
900
901 /*
902 * If there is no available installation (or just a single one??) that can
903 * be updated in the list, just continue with the regular installation.
904 */
905 if (!NtOsInstallsList || GetNumberOfListEntries(NtOsInstallsList) == 0)
906 {
907 RepairUpdateFlag = FALSE;
908
909 // return INSTALL_INTRO_PAGE;
910 return DEVICE_SETTINGS_PAGE;
911 // return SCSI_CONTROLLER_PAGE;
912 }
913
914 MUIDisplayPage(UPGRADE_REPAIR_PAGE);
915
916 InitGenericListUi(&ListUi, NtOsInstallsList, GetNTOSInstallationName);
917 DrawGenericList(&ListUi,
918 2, 23,
919 xScreen - 3,
920 yScreen - 3);
921
922 // return HandleGenericList(&ListUi, DEVICE_SETTINGS_PAGE, Ir);
923 while (TRUE)
924 {
925 CONSOLE_ConInKey(Ir);
926
927 if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x00)
928 {
929 switch (Ir->Event.KeyEvent.wVirtualKeyCode)
930 {
931 case VK_DOWN: /* DOWN */
932 ScrollDownGenericList(&ListUi);
933 break;
934 case VK_UP: /* UP */
935 ScrollUpGenericList(&ListUi);
936 break;
937 case VK_NEXT: /* PAGE DOWN */
938 ScrollPageDownGenericList(&ListUi);
939 break;
940 case VK_PRIOR: /* PAGE UP */
941 ScrollPageUpGenericList(&ListUi);
942 break;
943 case VK_F3: /* F3 */
944 {
945 if (ConfirmQuit(Ir))
946 return QUIT_PAGE;
947 else
948 RedrawGenericList(&ListUi);
949 break;
950 }
951 case VK_ESCAPE: /* ESC */
952 {
953 RestoreGenericListUiState(&ListUi);
954 // return nextPage; // prevPage;
955
956 // return INSTALL_INTRO_PAGE;
957 return DEVICE_SETTINGS_PAGE;
958 // return SCSI_CONTROLLER_PAGE;
959 }
960 }
961 }
962 else
963 {
964 // switch (toupper(Ir->Event.KeyEvent.uChar.AsciiChar))
965 // if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
966 if (toupper(Ir->Event.KeyEvent.uChar.AsciiChar) == 'U') /* U */
967 {
968 /* Retrieve the current installation */
969 ASSERT(GetNumberOfListEntries(NtOsInstallsList) >= 1);
970
971 CurrentInstallation =
972 (PNTOS_INSTALLATION)GetListEntryData(GetCurrentListEntry(NtOsInstallsList));
973
974 DPRINT1("Selected installation for repair: \"%S\" ; DiskNumber = %d , PartitionNumber = %d\n",
975 CurrentInstallation->InstallationName, CurrentInstallation->DiskNumber, CurrentInstallation->PartitionNumber);
976
977 RepairUpdateFlag = TRUE;
978
979 // return nextPage;
980 /***/return INSTALL_INTRO_PAGE;/***/
981 }
982 else if ((Ir->Event.KeyEvent.uChar.AsciiChar > 0x60) &&
983 (Ir->Event.KeyEvent.uChar.AsciiChar < 0x7b)) /* a-z */
984 {
985 GenericListKeyPress(&ListUi, Ir->Event.KeyEvent.uChar.AsciiChar);
986 }
987 }
988 }
989
990 return UPGRADE_REPAIR_PAGE;
991 }
992
993
994 /*
995 * Displays the InstallIntroPage.
996 *
997 * Next pages:
998 * DeviceSettingsPage (At once if repair or update is selected)
999 * SelectPartitionPage (At once if unattended setup)
1000 * DeviceSettingsPage (default)
1001 * QuitPage
1002 *
1003 * RETURNS
1004 * Number of the next page.
1005 */
1006 static PAGE_NUMBER
1007 InstallIntroPage(PINPUT_RECORD Ir)
1008 {
1009 if (RepairUpdateFlag)
1010 {
1011 #if 1 /* Old code that looks good */
1012
1013 // return SELECT_PARTITION_PAGE;
1014 return DEVICE_SETTINGS_PAGE;
1015
1016 #else /* Possible new code? */
1017
1018 return DEVICE_SETTINGS_PAGE;
1019 // return SCSI_CONTROLLER_PAGE;
1020
1021 #endif
1022 }
1023
1024 if (IsUnattendedSetup)
1025 return SELECT_PARTITION_PAGE;
1026
1027 MUIDisplayPage(INSTALL_INTRO_PAGE);
1028
1029 while (TRUE)
1030 {
1031 CONSOLE_ConInKey(Ir);
1032
1033 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1034 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
1035 {
1036 if (ConfirmQuit(Ir))
1037 return QUIT_PAGE;
1038
1039 break;
1040 }
1041 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
1042 {
1043 return UPGRADE_REPAIR_PAGE;
1044 }
1045 }
1046
1047 return INSTALL_INTRO_PAGE;
1048 }
1049
1050
1051 #if 0
1052 static PAGE_NUMBER
1053 ScsiControllerPage(PINPUT_RECORD Ir)
1054 {
1055 // MUIDisplayPage(SCSI_CONTROLLER_PAGE);
1056
1057 CONSOLE_SetTextXY(6, 8, "Setup detected the following mass storage devices:");
1058
1059 /* FIXME: print loaded mass storage driver descriptions */
1060 #if 0
1061 CONSOLE_SetTextXY(8, 10, "TEST device");
1062 #endif
1063
1064 CONSOLE_SetStatusText(" ENTER = Continue F3 = Quit");
1065
1066 while (TRUE)
1067 {
1068 CONSOLE_ConInKey(Ir);
1069
1070 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1071 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
1072 {
1073 if (ConfirmQuit(Ir))
1074 return QUIT_PAGE;
1075
1076 break;
1077 }
1078 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
1079 {
1080 return DEVICE_SETTINGS_PAGE;
1081 }
1082 }
1083
1084 return SCSI_CONTROLLER_PAGE;
1085 }
1086
1087 static PAGE_NUMBER
1088 OemDriverPage(PINPUT_RECORD Ir)
1089 {
1090 // MUIDisplayPage(OEM_DRIVER_PAGE);
1091
1092 CONSOLE_SetTextXY(6, 8, "This is the OEM driver page!");
1093
1094 /* FIXME: Implement!! */
1095
1096 CONSOLE_SetStatusText(" ENTER = Continue F3 = Quit");
1097
1098 while (TRUE)
1099 {
1100 CONSOLE_ConInKey(Ir);
1101
1102 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1103 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
1104 {
1105 if (ConfirmQuit(Ir))
1106 return QUIT_PAGE;
1107
1108 break;
1109 }
1110 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
1111 {
1112 return DEVICE_SETTINGS_PAGE;
1113 }
1114 }
1115
1116 return OEM_DRIVER_PAGE;
1117 }
1118 #endif
1119
1120
1121 /*
1122 * Displays the DeviceSettingsPage.
1123 *
1124 * Next pages:
1125 * SelectPartitionPage (At once if repair or update is selected)
1126 * ComputerSettingsPage
1127 * DisplaySettingsPage
1128 * KeyboardSettingsPage
1129 * LayoutsettingsPage
1130 * SelectPartitionPage
1131 * QuitPage
1132 *
1133 * SIDEEFFECTS
1134 * Init ComputerList
1135 * Init DisplayList
1136 * Init KeyboardList
1137 * Init LayoutList
1138 *
1139 * RETURNS
1140 * Number of the next page.
1141 */
1142 static PAGE_NUMBER
1143 DeviceSettingsPage(PINPUT_RECORD Ir)
1144 {
1145 static ULONG Line = 16;
1146
1147 /* Initialize the computer settings list */
1148 if (ComputerList == NULL)
1149 {
1150 ComputerList = CreateComputerTypeList(SetupInf);
1151 if (ComputerList == NULL)
1152 {
1153 MUIDisplayError(ERROR_LOAD_COMPUTER, Ir, POPUP_WAIT_ENTER);
1154 return QUIT_PAGE;
1155 }
1156 }
1157
1158 /* Initialize the display settings list */
1159 if (DisplayList == NULL)
1160 {
1161 DisplayList = CreateDisplayDriverList(SetupInf);
1162 if (DisplayList == NULL)
1163 {
1164 MUIDisplayError(ERROR_LOAD_DISPLAY, Ir, POPUP_WAIT_ENTER);
1165 return QUIT_PAGE;
1166 }
1167 }
1168
1169 /* Initialize the keyboard settings list */
1170 if (KeyboardList == NULL)
1171 {
1172 KeyboardList = CreateKeyboardDriverList(SetupInf);
1173 if (KeyboardList == NULL)
1174 {
1175 MUIDisplayError(ERROR_LOAD_KEYBOARD, Ir, POPUP_WAIT_ENTER);
1176 return QUIT_PAGE;
1177 }
1178 }
1179
1180 /* Initialize the keyboard layout list */
1181 if (LayoutList == NULL)
1182 {
1183 LayoutList = CreateKeyboardLayoutList(SetupInf, SelectedLanguageId, DefaultKBLayout);
1184 if (LayoutList == NULL)
1185 {
1186 /* FIXME: report error */
1187 MUIDisplayError(ERROR_LOAD_KBLAYOUT, Ir, POPUP_WAIT_ENTER);
1188 return QUIT_PAGE;
1189 }
1190 }
1191
1192 if (RepairUpdateFlag)
1193 return SELECT_PARTITION_PAGE;
1194
1195 // if (IsUnattendedSetup)
1196 // return SELECT_PARTITION_PAGE;
1197
1198 MUIDisplayPage(DEVICE_SETTINGS_PAGE);
1199
1200 DrawGenericListCurrentItem(ComputerList, GetSettingDescription, 25, 11);
1201 DrawGenericListCurrentItem(DisplayList , GetSettingDescription, 25, 12);
1202 DrawGenericListCurrentItem(KeyboardList, GetSettingDescription, 25, 13);
1203 DrawGenericListCurrentItem(LayoutList , GetSettingDescription, 25, 14);
1204
1205 CONSOLE_InvertTextXY(24, Line, 48, 1);
1206
1207 while (TRUE)
1208 {
1209 CONSOLE_ConInKey(Ir);
1210
1211 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1212 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DOWN)) /* DOWN */
1213 {
1214 CONSOLE_NormalTextXY(24, Line, 48, 1);
1215
1216 if (Line == 14)
1217 Line = 16;
1218 else if (Line == 16)
1219 Line = 11;
1220 else
1221 Line++;
1222
1223 CONSOLE_InvertTextXY(24, Line, 48, 1);
1224 }
1225 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1226 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_UP)) /* UP */
1227 {
1228 CONSOLE_NormalTextXY(24, Line, 48, 1);
1229
1230 if (Line == 11)
1231 Line = 16;
1232 else if (Line == 16)
1233 Line = 14;
1234 else
1235 Line--;
1236
1237 CONSOLE_InvertTextXY(24, Line, 48, 1);
1238 }
1239 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1240 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
1241 {
1242 if (ConfirmQuit(Ir))
1243 return QUIT_PAGE;
1244
1245 break;
1246 }
1247 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
1248 {
1249 if (Line == 11)
1250 return COMPUTER_SETTINGS_PAGE;
1251 else if (Line == 12)
1252 return DISPLAY_SETTINGS_PAGE;
1253 else if (Line == 13)
1254 return KEYBOARD_SETTINGS_PAGE;
1255 else if (Line == 14)
1256 return LAYOUT_SETTINGS_PAGE;
1257 else if (Line == 16)
1258 return SELECT_PARTITION_PAGE;
1259 }
1260 }
1261
1262 return DEVICE_SETTINGS_PAGE;
1263 }
1264
1265
1266 /*
1267 * Handles generic selection lists.
1268 *
1269 * PARAMS
1270 * GenericList: The list to handle.
1271 * nextPage: The page it needs to jump to after this page.
1272 * Ir: The PINPUT_RECORD
1273 */
1274 static PAGE_NUMBER
1275 HandleGenericList(PGENERIC_LIST_UI ListUi,
1276 PAGE_NUMBER nextPage,
1277 PINPUT_RECORD Ir)
1278 {
1279 while (TRUE)
1280 {
1281 CONSOLE_ConInKey(Ir);
1282
1283 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1284 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DOWN)) /* DOWN */
1285 {
1286 ScrollDownGenericList(ListUi);
1287 }
1288 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1289 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_UP)) /* UP */
1290 {
1291 ScrollUpGenericList(ListUi);
1292 }
1293 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1294 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_NEXT)) /* PAGE DOWN */
1295 {
1296 ScrollPageDownGenericList(ListUi);
1297 }
1298 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1299 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_PRIOR)) /* PAGE UP */
1300 {
1301 ScrollPageUpGenericList(ListUi);
1302 }
1303 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1304 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
1305 {
1306 if (ConfirmQuit(Ir))
1307 return QUIT_PAGE;
1308 else
1309 RedrawGenericList(ListUi);
1310 }
1311 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1312 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)) /* ESC */
1313 {
1314 RestoreGenericListUiState(ListUi);
1315 return nextPage; // Use some "prevPage;" instead?
1316 }
1317 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
1318 {
1319 return nextPage;
1320 }
1321 else if ((Ir->Event.KeyEvent.uChar.AsciiChar > 0x60) && (Ir->Event.KeyEvent.uChar.AsciiChar < 0x7b))
1322 {
1323 /* a-z */
1324 GenericListKeyPress(ListUi, Ir->Event.KeyEvent.uChar.AsciiChar);
1325 }
1326 }
1327 }
1328
1329
1330 /*
1331 * Displays the ComputerSettingsPage.
1332 *
1333 * Next pages:
1334 * DeviceSettingsPage
1335 * QuitPage
1336 *
1337 * RETURNS
1338 * Number of the next page.
1339 */
1340 static PAGE_NUMBER
1341 ComputerSettingsPage(PINPUT_RECORD Ir)
1342 {
1343 GENERIC_LIST_UI ListUi;
1344 MUIDisplayPage(COMPUTER_SETTINGS_PAGE);
1345
1346 InitGenericListUi(&ListUi, ComputerList, GetSettingDescription);
1347 DrawGenericList(&ListUi,
1348 2, 18,
1349 xScreen - 3,
1350 yScreen - 3);
1351
1352 return HandleGenericList(&ListUi, DEVICE_SETTINGS_PAGE, Ir);
1353 }
1354
1355
1356 /*
1357 * Displays the DisplaySettingsPage.
1358 *
1359 * Next pages:
1360 * DeviceSettingsPage
1361 * QuitPage
1362 *
1363 * RETURNS
1364 * Number of the next page.
1365 */
1366 static PAGE_NUMBER
1367 DisplaySettingsPage(PINPUT_RECORD Ir)
1368 {
1369 GENERIC_LIST_UI ListUi;
1370 MUIDisplayPage(DISPLAY_SETTINGS_PAGE);
1371
1372 InitGenericListUi(&ListUi, DisplayList, GetSettingDescription);
1373 DrawGenericList(&ListUi,
1374 2, 18,
1375 xScreen - 3,
1376 yScreen - 3);
1377
1378 return HandleGenericList(&ListUi, DEVICE_SETTINGS_PAGE, Ir);
1379 }
1380
1381
1382 /*
1383 * Displays the KeyboardSettingsPage.
1384 *
1385 * Next pages:
1386 * DeviceSettingsPage
1387 * QuitPage
1388 *
1389 * RETURNS
1390 * Number of the next page.
1391 */
1392 static PAGE_NUMBER
1393 KeyboardSettingsPage(PINPUT_RECORD Ir)
1394 {
1395 GENERIC_LIST_UI ListUi;
1396 MUIDisplayPage(KEYBOARD_SETTINGS_PAGE);
1397
1398 InitGenericListUi(&ListUi, KeyboardList, GetSettingDescription);
1399 DrawGenericList(&ListUi,
1400 2, 18,
1401 xScreen - 3,
1402 yScreen - 3);
1403
1404 return HandleGenericList(&ListUi, DEVICE_SETTINGS_PAGE, Ir);
1405 }
1406
1407
1408 /*
1409 * Displays the LayoutSettingsPage.
1410 *
1411 * Next pages:
1412 * DeviceSettingsPage
1413 * QuitPage
1414 *
1415 * RETURNS
1416 * Number of the next page.
1417 */
1418 static PAGE_NUMBER
1419 LayoutSettingsPage(PINPUT_RECORD Ir)
1420 {
1421 GENERIC_LIST_UI ListUi;
1422 MUIDisplayPage(LAYOUT_SETTINGS_PAGE);
1423
1424 InitGenericListUi(&ListUi, LayoutList, GetSettingDescription);
1425 DrawGenericList(&ListUi,
1426 2, 18,
1427 xScreen - 3,
1428 yScreen - 3);
1429
1430 return HandleGenericList(&ListUi, DEVICE_SETTINGS_PAGE, Ir);
1431 }
1432
1433
1434 static BOOL
1435 IsDiskSizeValid(PPARTENTRY PartEntry)
1436 {
1437 ULONGLONG size;
1438
1439 size = PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector;
1440 size = (size + (512 * KB)) / MB; /* in MBytes */
1441
1442 if (size < USetupData.RequiredPartitionDiskSpace)
1443 {
1444 /* Partition is too small so ask for another one */
1445 DPRINT1("Partition is too small (size: %I64u MB), required disk space is %lu MB\n", size, USetupData.RequiredPartitionDiskSpace);
1446 return FALSE;
1447 }
1448 else
1449 {
1450 return TRUE;
1451 }
1452 }
1453
1454
1455 /*
1456 * Displays the SelectPartitionPage.
1457 *
1458 * Next pages:
1459 * SelectFileSystemPage (At once if unattended)
1460 * SelectFileSystemPage (Default if free space is selected)
1461 * CreatePrimaryPartitionPage
1462 * CreateExtendedPartitionPage
1463 * CreateLogicalPartitionPage
1464 * ConfirmDeleteSystemPartitionPage (if the selected partition is the system partition, aka with the boot flag set)
1465 * DeletePartitionPage
1466 * QuitPage
1467 *
1468 * SIDEEFFECTS
1469 * Set InstallShortcut (only if not unattended + free space is selected)
1470 *
1471 * RETURNS
1472 * Number of the next page.
1473 */
1474 static PAGE_NUMBER
1475 SelectPartitionPage(PINPUT_RECORD Ir)
1476 {
1477 PARTLIST_UI ListUi;
1478 ULONG Error;
1479
1480 if (PartitionList == NULL)
1481 {
1482 PartitionList = CreatePartitionList();
1483 if (PartitionList == NULL)
1484 {
1485 /* FIXME: show an error dialog */
1486 MUIDisplayError(ERROR_DRIVE_INFORMATION, Ir, POPUP_WAIT_ENTER);
1487 return QUIT_PAGE;
1488 }
1489 else if (IsListEmpty(&PartitionList->DiskListHead))
1490 {
1491 MUIDisplayError(ERROR_NO_HDD, Ir, POPUP_WAIT_ENTER);
1492 return QUIT_PAGE;
1493 }
1494
1495 TempPartition = NULL;
1496 FormatState = Start;
1497 }
1498
1499 if (RepairUpdateFlag)
1500 {
1501 /* Determine the selected installation disk & partition */
1502 if (!SelectPartition(PartitionList,
1503 CurrentInstallation->DiskNumber,
1504 CurrentInstallation->PartitionNumber))
1505 {
1506 DPRINT1("RepairUpdateFlag == TRUE, SelectPartition() returned FALSE, assert!\n");
1507 ASSERT(FALSE);
1508 }
1509
1510 return SELECT_FILE_SYSTEM_PAGE;
1511 }
1512
1513 MUIDisplayPage(SELECT_PARTITION_PAGE);
1514
1515 InitPartitionListUi(&ListUi, PartitionList,
1516 2,
1517 23,
1518 xScreen - 3,
1519 yScreen - 3);
1520 DrawPartitionList(&ListUi);
1521
1522 if (IsUnattendedSetup)
1523 {
1524 if (!SelectPartition(PartitionList,
1525 USetupData.DestinationDiskNumber,
1526 USetupData.DestinationPartitionNumber))
1527 {
1528 if (USetupData.AutoPartition)
1529 {
1530 if (PartitionList->CurrentPartition->LogicalPartition)
1531 {
1532 CreateLogicalPartition(PartitionList,
1533 PartitionList->CurrentPartition->SectorCount.QuadPart,
1534 TRUE);
1535 }
1536 else
1537 {
1538 CreatePrimaryPartition(PartitionList,
1539 PartitionList->CurrentPartition->SectorCount.QuadPart,
1540 TRUE);
1541 }
1542
1543 // FIXME?? Aren't we going to enter an infinite loop, if this test fails??
1544 if (!IsDiskSizeValid(PartitionList->CurrentPartition))
1545 {
1546 MUIDisplayError(ERROR_INSUFFICIENT_PARTITION_SIZE, Ir, POPUP_WAIT_ANY_KEY,
1547 USetupData.RequiredPartitionDiskSpace);
1548 return SELECT_PARTITION_PAGE; /* let the user select another partition */
1549 }
1550
1551 return SELECT_FILE_SYSTEM_PAGE;
1552 }
1553 }
1554 else
1555 {
1556 DrawPartitionList(&ListUi);
1557
1558 // FIXME?? Aren't we going to enter an infinite loop, if this test fails??
1559 if (!IsDiskSizeValid(PartitionList->CurrentPartition))
1560 {
1561 MUIDisplayError(ERROR_INSUFFICIENT_PARTITION_SIZE, Ir, POPUP_WAIT_ANY_KEY,
1562 USetupData.RequiredPartitionDiskSpace);
1563 return SELECT_PARTITION_PAGE; /* let the user select another partition */
1564 }
1565
1566 return SELECT_FILE_SYSTEM_PAGE;
1567 }
1568 }
1569
1570 while (TRUE)
1571 {
1572 /* Update status text */
1573 if (PartitionList->CurrentPartition == NULL)
1574 {
1575 CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATEPARTITION));
1576 }
1577 else if (PartitionList->CurrentPartition->LogicalPartition)
1578 {
1579 if (PartitionList->CurrentPartition->IsPartitioned)
1580 {
1581 CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION));
1582 }
1583 else
1584 {
1585 CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATELOGICAL));
1586 }
1587 }
1588 else
1589 {
1590 if (PartitionList->CurrentPartition->IsPartitioned)
1591 {
1592 if (IsContainerPartition(PartitionList->CurrentPartition->PartitionType))
1593 {
1594 CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION));
1595 }
1596 else
1597 {
1598 CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLDELETEPARTITION));
1599 }
1600 }
1601 else
1602 {
1603 CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATEPARTITION));
1604 }
1605 }
1606
1607 CONSOLE_ConInKey(Ir);
1608
1609 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1610 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
1611 {
1612 if (ConfirmQuit(Ir))
1613 {
1614 DestroyPartitionList(PartitionList);
1615 PartitionList = NULL;
1616 return QUIT_PAGE;
1617 }
1618
1619 break;
1620 }
1621 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1622 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DOWN)) /* DOWN */
1623 {
1624 ScrollDownPartitionList(&ListUi);
1625 }
1626 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1627 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_UP)) /* UP */
1628 {
1629 ScrollUpPartitionList(&ListUi);
1630 }
1631 else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
1632 {
1633 if (IsContainerPartition(PartitionList->CurrentPartition->PartitionType))
1634 continue; // return SELECT_PARTITION_PAGE;
1635
1636 if (PartitionList->CurrentPartition == NULL ||
1637 PartitionList->CurrentPartition->IsPartitioned == FALSE)
1638 {
1639 if (PartitionList->CurrentPartition->LogicalPartition)
1640 {
1641 CreateLogicalPartition(PartitionList,
1642 0ULL,
1643 TRUE);
1644 }
1645 else
1646 {
1647 CreatePrimaryPartition(PartitionList,
1648 0ULL,
1649 TRUE);
1650 }
1651 }
1652
1653 if (!IsDiskSizeValid(PartitionList->CurrentPartition))
1654 {
1655 MUIDisplayError(ERROR_INSUFFICIENT_PARTITION_SIZE, Ir, POPUP_WAIT_ANY_KEY,
1656 USetupData.RequiredPartitionDiskSpace);
1657 return SELECT_PARTITION_PAGE; /* let the user select another partition */
1658 }
1659
1660 return SELECT_FILE_SYSTEM_PAGE;
1661 }
1662 else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'P') /* P */
1663 {
1664 if (PartitionList->CurrentPartition->LogicalPartition == FALSE)
1665 {
1666 Error = PrimaryPartitionCreationChecks(PartitionList);
1667 if (Error != NOT_AN_ERROR)
1668 {
1669 MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
1670 return SELECT_PARTITION_PAGE;
1671 }
1672
1673 return CREATE_PRIMARY_PARTITION_PAGE;
1674 }
1675 }
1676 else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'E') /* E */
1677 {
1678 if (PartitionList->CurrentPartition->LogicalPartition == FALSE)
1679 {
1680 Error = ExtendedPartitionCreationChecks(PartitionList);
1681 if (Error != NOT_AN_ERROR)
1682 {
1683 MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
1684 return SELECT_PARTITION_PAGE;
1685 }
1686
1687 return CREATE_EXTENDED_PARTITION_PAGE;
1688 }
1689 }
1690 else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'L') /* L */
1691 {
1692 if (PartitionList->CurrentPartition->LogicalPartition)
1693 {
1694 Error = LogicalPartitionCreationChecks(PartitionList);
1695 if (Error != NOT_AN_ERROR)
1696 {
1697 MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
1698 return SELECT_PARTITION_PAGE;
1699 }
1700
1701 return CREATE_LOGICAL_PARTITION_PAGE;
1702 }
1703 }
1704 else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'D') /* D */
1705 {
1706 WCHAR PathBuffer[MAX_PATH];
1707 UNICODE_STRING CurrentPartition;
1708
1709 if (PartitionList->CurrentPartition->IsPartitioned == FALSE)
1710 {
1711 MUIDisplayError(ERROR_DELETE_SPACE, Ir, POPUP_WAIT_ANY_KEY);
1712 return SELECT_PARTITION_PAGE;
1713 }
1714
1715 RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
1716 L"\\Device\\Harddisk%lu\\Partition%lu\\",
1717 PartitionList->CurrentDisk->DiskNumber,
1718 PartitionList->CurrentPartition->PartitionNumber);
1719 RtlInitUnicodeString(&CurrentPartition, PathBuffer);
1720
1721 /*
1722 * Check whether the user attempts to delete the partition on which
1723 * the installation source is present. If so, fail with an error.
1724 */
1725 // &USetupData.SourceRootPath
1726 if (RtlPrefixUnicodeString(&CurrentPartition, &USetupData.SourcePath, TRUE))
1727 {
1728 PopupError("You cannot delete the partition containing the installation source!",
1729 MUIGetString(STRING_CONTINUE),
1730 Ir, POPUP_WAIT_ENTER);
1731 return SELECT_PARTITION_PAGE;
1732 }
1733
1734 if (PartitionList->CurrentPartition->BootIndicator ||
1735 PartitionList->CurrentPartition == PartitionList->SystemPartition)
1736 {
1737 return CONFIRM_DELETE_SYSTEM_PARTITION_PAGE;
1738 }
1739
1740 return DELETE_PARTITION_PAGE;
1741 }
1742 }
1743
1744 return SELECT_PARTITION_PAGE;
1745 }
1746
1747
1748 #define PARTITION_SIZE_INPUT_FIELD_LENGTH 9
1749 /* Restriction for MaxSize: pow(10, (PARTITION_SIZE_INPUT_FIELD_LENGTH - 1)) - 1 */
1750 #define PARTITION_MAXSIZE (pow(10, (PARTITION_SIZE_INPUT_FIELD_LENGTH - 1)) - 1)
1751
1752 static VOID
1753 ShowPartitionSizeInputBox(SHORT Left,
1754 SHORT Top,
1755 SHORT Right,
1756 SHORT Bottom,
1757 ULONG MaxSize,
1758 PWSTR InputBuffer,
1759 PBOOLEAN Quit,
1760 PBOOLEAN Cancel)
1761 {
1762 INPUT_RECORD Ir;
1763 COORD coPos;
1764 DWORD Written;
1765 CHAR Buffer[128];
1766 INT Length, Pos;
1767 WCHAR ch;
1768 SHORT iLeft;
1769 SHORT iTop;
1770
1771 if (Quit != NULL)
1772 *Quit = FALSE;
1773
1774 if (Cancel != NULL)
1775 *Cancel = FALSE;
1776
1777 DrawBox(Left, Top, Right - Left + 1, Bottom - Top + 1);
1778
1779 /* Print message */
1780 coPos.X = Left + 2;
1781 coPos.Y = Top + 2;
1782 strcpy(Buffer, MUIGetString(STRING_PARTITIONSIZE));
1783 iLeft = coPos.X + strlen(Buffer) + 1;
1784 iTop = coPos.Y;
1785
1786 WriteConsoleOutputCharacterA(StdOutput,
1787 Buffer,
1788 strlen(Buffer),
1789 coPos,
1790 &Written);
1791
1792 sprintf(Buffer, MUIGetString(STRING_MAXSIZE), MaxSize);
1793 coPos.X = iLeft + PARTITION_SIZE_INPUT_FIELD_LENGTH + 1;
1794 coPos.Y = iTop;
1795 WriteConsoleOutputCharacterA(StdOutput,
1796 Buffer,
1797 strlen(Buffer),
1798 coPos,
1799 &Written);
1800
1801 swprintf(InputBuffer, L"%lu", MaxSize);
1802 Length = wcslen(InputBuffer);
1803 Pos = Length;
1804 CONSOLE_SetInputTextXY(iLeft,
1805 iTop,
1806 PARTITION_SIZE_INPUT_FIELD_LENGTH,
1807 InputBuffer);
1808 CONSOLE_SetCursorXY(iLeft + Length, iTop);
1809 CONSOLE_SetCursorType(TRUE, TRUE);
1810
1811 while (TRUE)
1812 {
1813 CONSOLE_ConInKey(&Ir);
1814
1815 if ((Ir.Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1816 (Ir.Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
1817 {
1818 if (Quit != NULL)
1819 *Quit = TRUE;
1820
1821 InputBuffer[0] = UNICODE_NULL;
1822 CONSOLE_SetCursorType(TRUE, FALSE);
1823 break;
1824 }
1825 else if (Ir.Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
1826 {
1827 CONSOLE_SetCursorType(TRUE, FALSE);
1828 break;
1829 }
1830 else if (Ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) /* ESCAPE */
1831 {
1832 if (Cancel != NULL)
1833 *Cancel = TRUE;
1834
1835 InputBuffer[0] = UNICODE_NULL;
1836 CONSOLE_SetCursorType(TRUE, FALSE);
1837 break;
1838 }
1839 else if ((Ir.Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1840 (Ir.Event.KeyEvent.wVirtualKeyCode == VK_HOME)) /* HOME */
1841 {
1842 Pos = 0;
1843 CONSOLE_SetCursorXY(iLeft + Pos, iTop);
1844 }
1845 else if ((Ir.Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1846 (Ir.Event.KeyEvent.wVirtualKeyCode == VK_END)) /* END */
1847 {
1848 Pos = Length;
1849 CONSOLE_SetCursorXY(iLeft + Pos, iTop);
1850 }
1851 else if ((Ir.Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1852 (Ir.Event.KeyEvent.wVirtualKeyCode == VK_LEFT)) /* LEFT */
1853 {
1854 if (Pos > 0)
1855 {
1856 Pos--;
1857 CONSOLE_SetCursorXY(iLeft + Pos, iTop);
1858 }
1859 }
1860 else if ((Ir.Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1861 (Ir.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)) /* RIGHT */
1862 {
1863 if (Pos < Length)
1864 {
1865 Pos++;
1866 CONSOLE_SetCursorXY(iLeft + Pos, iTop);
1867 }
1868 }
1869 else if ((Ir.Event.KeyEvent.uChar.AsciiChar == 0x00) &&
1870 (Ir.Event.KeyEvent.wVirtualKeyCode == VK_DELETE)) /* DEL */
1871 {
1872 if (Pos < Length)
1873 {
1874 memmove(&InputBuffer[Pos],
1875 &InputBuffer[Pos + 1],
1876 (Length - Pos - 1) * sizeof(WCHAR));
1877 InputBuffer[Length - 1] = UNICODE_NULL;
1878
1879 Length--;
1880 CONSOLE_SetInputTextXY(iLeft,
1881 iTop,
1882 PARTITION_SIZE_INPUT_FIELD_LENGTH,
1883 InputBuffer);
1884 CONSOLE_SetCursorXY(iLeft + Pos, iTop);
1885 }
1886 }
1887 else if (Ir.Event.KeyEvent.wVirtualKeyCode == VK_BACK) /* BACKSPACE */
1888 {
1889 if (Pos > 0)
1890 {
1891 if (Pos < Length)
1892 memmove(&InputBuffer[Pos - 1],
1893 &InputBuffer[Pos],
1894 (Length - Pos) * sizeof(WCHAR));
1895 InputBuffer[Length - 1] = UNICODE_NULL;
1896
1897 Pos--;
1898 Length--;
1899 CONSOLE_SetInputTextXY(iLeft,
1900 iTop,
1901 PARTITION_SIZE_INPUT_FIELD_LENGTH,
1902 InputBuffer);
1903 CONSOLE_SetCursorXY(iLeft + Pos, iTop);
1904 }
1905 }
1906 else if (Ir.Event.KeyEvent.uChar.AsciiChar != 0x00)
1907 {
1908 if (Length < PARTITION_SIZE_INPUT_FIELD_LENGTH - 1)
1909 {
1910 ch = (WCHAR)Ir.Event.KeyEvent.uChar.AsciiChar;
1911
1912 if ((ch >= L'0') && (ch <= L'9'))
1913 {
1914 if (Pos < Length)
1915 memmove(&InputBuffer[Pos + 1],
1916 &InputBuffer[Pos],
1917 (Length - Pos) * sizeof(WCHAR));
1918 InputBuffer[Length + 1] = UNICODE_NULL;
1919 InputBuffer[Pos] = ch;
1920
1921 Pos++;
1922 Length++;
1923 CONSOLE_SetInputTextXY(iLeft,
1924 iTop,
1925 PARTITION_SIZE_INPUT_FIELD_LENGTH,
1926 InputBuffer);
1927 CONSOLE_SetCursorXY(iLeft + Pos, iTop);
1928 }
1929 }
1930 }
1931 }
1932 }
1933
1934
1935 /*
1936 * Displays the CreatePrimaryPartitionPage.
1937 *
1938 * Next pages:
1939 * SelectPartitionPage
1940 * SelectFileSystemPage (default)
1941 * QuitPage
1942 *
1943 * RETURNS
1944 * Number of the next page.
1945 */
1946 static PAGE_NUMBER
1947 CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
1948 {
1949 PDISKENTRY DiskEntry;
1950 PPARTENTRY PartEntry;
1951 BOOLEAN Quit;
1952 BOOLEAN Cancel;
1953 WCHAR InputBuffer[50];
1954 ULONG MaxSize;
1955 ULONGLONG PartSize;
1956 ULONGLONG DiskSize;
1957 ULONGLONG SectorCount;
1958 PCHAR Unit;
1959
1960 if (PartitionList == NULL ||
1961 PartitionList->CurrentDisk == NULL ||
1962 PartitionList->CurrentPartition == NULL)
1963 {
1964 /* FIXME: show an error dialog */
1965 return QUIT_PAGE;
1966 }
1967
1968 DiskEntry = PartitionList->CurrentDisk;
1969 PartEntry = PartitionList->CurrentPartition;
1970
1971 CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
1972
1973 CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_CHOOSENEWPARTITION));
1974
1975 DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
1976 #if 0
1977 if (DiskSize >= 10 * GB) /* 10 GB */
1978 {
1979 DiskSize = DiskSize / GB;
1980 Unit = MUIGetString(STRING_GB);
1981 }
1982 else
1983 #endif
1984 {
1985 DiskSize = DiskSize / MB;
1986 if (DiskSize == 0)
1987 DiskSize = 1;
1988
1989 Unit = MUIGetString(STRING_MB);
1990 }
1991
1992 if (DiskEntry->DriverName.Length > 0)
1993 {
1994 CONSOLE_PrintTextXY(6, 10,
1995 MUIGetString(STRING_HDINFOPARTCREATE_1),
1996 DiskSize,
1997 Unit,
1998 DiskEntry->DiskNumber,
1999 DiskEntry->Port,
2000 DiskEntry->Bus,
2001 DiskEntry->Id,
2002 &DiskEntry->DriverName,
2003 DiskEntry->NoMbr ? "GPT" : "MBR");
2004 }
2005 else
2006 {
2007 CONSOLE_PrintTextXY(6, 10,
2008 MUIGetString(STRING_HDINFOPARTCREATE_2),
2009 DiskSize,
2010 Unit,
2011 DiskEntry->DiskNumber,
2012 DiskEntry->Port,
2013 DiskEntry->Bus,
2014 DiskEntry->Id,
2015 DiskEntry->NoMbr ? "GPT" : "MBR");
2016 }
2017
2018 CONSOLE_SetTextXY(6, 12, MUIGetString(STRING_HDDSIZE));
2019
2020 #if 0
2021 CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB",
2022 PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB);
2023 #endif
2024
2025 CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));
2026
2027 PartEntry = PartitionList->CurrentPartition;
2028 while (TRUE)
2029 {
2030 MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */
2031
2032 if (MaxSize > PARTITION_MAXSIZE)
2033 MaxSize = PARTITION_MAXSIZE;
2034
2035 ShowPartitionSizeInputBox(12, 14, xScreen - 12, 17, /* left, top, right, bottom */
2036 MaxSize, InputBuffer, &Quit, &Cancel);
2037
2038 if (Quit)
2039 {
2040 if (ConfirmQuit(Ir))
2041 return QUIT_PAGE;
2042
2043 break;
2044 }
2045 else if (Cancel)
2046 {
2047 return SELECT_PARTITION_PAGE;
2048 }
2049 else
2050 {
2051 PartSize = _wcstoui64(InputBuffer, NULL, 10);
2052
2053 if (PartSize < 1)
2054 {
2055 /* Too small */
2056 continue;
2057 }
2058
2059 if (PartSize > MaxSize)
2060 {
2061 /* Too large */
2062 continue;
2063 }
2064
2065 /* Convert to bytes */
2066 if (PartSize == MaxSize)
2067 {
2068 /* Use all of the unpartitioned disk space */
2069 SectorCount = PartEntry->SectorCount.QuadPart;
2070 }
2071 else
2072 {
2073 /* Calculate the sector count from the size in MB */
2074 SectorCount = PartSize * MB / DiskEntry->BytesPerSector;
2075
2076 /* But never get larger than the unpartitioned disk space */
2077 if (SectorCount > PartEntry->SectorCount.QuadPart)
2078 SectorCount = PartEntry->SectorCount.QuadPart;
2079 }
2080
2081 DPRINT ("Partition size: %I64u bytes\n", PartSize);
2082
2083 CreatePrimaryPartition(PartitionList,
2084 SectorCount,
2085 FALSE);
2086
2087 return SELECT_PARTITION_PAGE;
2088 }
2089 }
2090
2091 return CREATE_PRIMARY_PARTITION_PAGE;
2092 }
2093
2094
2095 /*
2096 * Displays the CreateExtendedPartitionPage.
2097 *
2098 * Next pages:
2099 * SelectPartitionPage (default)
2100 * QuitPage
2101 *
2102 * RETURNS
2103 * Number of the next page.
2104 */
2105 static PAGE_NUMBER
2106 CreateExtendedPartitionPage(PINPUT_RECORD Ir)
2107 {
2108 PDISKENTRY DiskEntry;
2109 PPARTENTRY PartEntry;
2110 BOOLEAN Quit;
2111 BOOLEAN Cancel;
2112 WCHAR InputBuffer[50];
2113 ULONG MaxSize;
2114 ULONGLONG PartSize;
2115 ULONGLONG DiskSize;
2116 ULONGLONG SectorCount;
2117 PCHAR Unit;
2118
2119 if (PartitionList == NULL ||
2120 PartitionList->CurrentDisk == NULL ||
2121 PartitionList->CurrentPartition == NULL)
2122 {
2123 /* FIXME: show an error dialog */
2124 return QUIT_PAGE;
2125 }
2126
2127 DiskEntry = PartitionList->CurrentDisk;
2128 PartEntry = PartitionList->CurrentPartition;
2129
2130 CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
2131
2132 CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_CHOOSE_NEW_EXTENDED_PARTITION));
2133
2134 DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2135 #if 0
2136 if (DiskSize >= 10 * GB) /* 10 GB */
2137 {
2138 DiskSize = DiskSize / GB;
2139 Unit = MUIGetString(STRING_GB);
2140 }
2141 else
2142 #endif
2143 {
2144 DiskSize = DiskSize / MB;
2145 if (DiskSize == 0)
2146 DiskSize = 1;
2147
2148 Unit = MUIGetString(STRING_MB);
2149 }
2150
2151 if (DiskEntry->DriverName.Length > 0)
2152 {
2153 CONSOLE_PrintTextXY(6, 10,
2154 MUIGetString(STRING_HDINFOPARTCREATE_1),
2155 DiskSize,
2156 Unit,
2157 DiskEntry->DiskNumber,
2158 DiskEntry->Port,
2159 DiskEntry->Bus,
2160 DiskEntry->Id,
2161 &DiskEntry->DriverName,
2162 DiskEntry->NoMbr ? "GPT" : "MBR");
2163 }
2164 else
2165 {
2166 CONSOLE_PrintTextXY(6, 10,
2167 MUIGetString(STRING_HDINFOPARTCREATE_2),
2168 DiskSize,
2169 Unit,
2170 DiskEntry->DiskNumber,
2171 DiskEntry->Port,
2172 DiskEntry->Bus,
2173 DiskEntry->Id,
2174 DiskEntry->NoMbr ? "GPT" : "MBR");
2175 }
2176
2177 CONSOLE_SetTextXY(6, 12, MUIGetString(STRING_HDDSIZE));
2178
2179 #if 0
2180 CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB",
2181 PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB);
2182 #endif
2183
2184 CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));
2185
2186 PartEntry = PartitionList->CurrentPartition;
2187 while (TRUE)
2188 {
2189 MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */
2190
2191 if (MaxSize > PARTITION_MAXSIZE)
2192 MaxSize = PARTITION_MAXSIZE;
2193
2194 ShowPartitionSizeInputBox(12, 14, xScreen - 12, 17, /* left, top, right, bottom */
2195 MaxSize, InputBuffer, &Quit, &Cancel);
2196
2197 if (Quit)
2198 {
2199 if (ConfirmQuit(Ir))
2200 return QUIT_PAGE;
2201
2202 break;
2203 }
2204 else if (Cancel)
2205 {
2206 return SELECT_PARTITION_PAGE;
2207 }
2208 else
2209 {
2210 PartSize = _wcstoui64(InputBuffer, NULL, 10);
2211
2212 if (PartSize < 1)
2213 {
2214 /* Too small */
2215 continue;
2216 }
2217
2218 if (PartSize > MaxSize)
2219 {
2220 /* Too large */
2221 continue;
2222 }
2223
2224 /* Convert to bytes */
2225 if (PartSize == MaxSize)
2226 {
2227 /* Use all of the unpartitioned disk space */
2228 SectorCount = PartEntry->SectorCount.QuadPart;
2229 }
2230 else
2231 {
2232 /* Calculate the sector count from the size in MB */
2233 SectorCount = PartSize * MB / DiskEntry->BytesPerSector;
2234
2235 /* But never get larger than the unpartitioned disk space */
2236 if (SectorCount > PartEntry->SectorCount.QuadPart)
2237 SectorCount = PartEntry->SectorCount.QuadPart;
2238 }
2239
2240 DPRINT ("Partition size: %I64u bytes\n", PartSize);
2241
2242 CreateExtendedPartition(PartitionList,
2243 SectorCount);
2244
2245 return SELECT_PARTITION_PAGE;
2246 }
2247 }
2248
2249 return CREATE_EXTENDED_PARTITION_PAGE;
2250 }
2251
2252
2253 /*
2254 * Displays the CreateLogicalPartitionPage.
2255 *
2256 * Next pages:
2257 * SelectFileSystemPage (default)
2258 * QuitPage
2259 *
2260 * RETURNS
2261 * Number of the next page.
2262 */
2263 static PAGE_NUMBER
2264 CreateLogicalPartitionPage(PINPUT_RECORD Ir)
2265 {
2266 PDISKENTRY DiskEntry;
2267 PPARTENTRY PartEntry;
2268 BOOLEAN Quit;
2269 BOOLEAN Cancel;
2270 WCHAR InputBuffer[50];
2271 ULONG MaxSize;
2272 ULONGLONG PartSize;
2273 ULONGLONG DiskSize;
2274 ULONGLONG SectorCount;
2275 PCHAR Unit;
2276
2277 if (PartitionList == NULL ||
2278 PartitionList->CurrentDisk == NULL ||
2279 PartitionList->CurrentPartition == NULL)
2280 {
2281 /* FIXME: show an error dialog */
2282 return QUIT_PAGE;
2283 }
2284
2285 DiskEntry = PartitionList->CurrentDisk;
2286 PartEntry = PartitionList->CurrentPartition;
2287
2288 CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
2289
2290 CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_CHOOSE_NEW_LOGICAL_PARTITION));
2291
2292 DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2293 #if 0
2294 if (DiskSize >= 10 * GB) /* 10 GB */
2295 {
2296 DiskSize = DiskSize / GB;
2297 Unit = MUIGetString(STRING_GB);
2298 }
2299 else
2300 #endif
2301 {
2302 DiskSize = DiskSize / MB;
2303 if (DiskSize == 0)
2304 DiskSize = 1;
2305
2306 Unit = MUIGetString(STRING_MB);
2307 }
2308
2309 if (DiskEntry->DriverName.Length > 0)
2310 {
2311 CONSOLE_PrintTextXY(6, 10,
2312 MUIGetString(STRING_HDINFOPARTCREATE_1),
2313 DiskSize,
2314 Unit,
2315 DiskEntry->DiskNumber,
2316 DiskEntry->Port,
2317 DiskEntry->Bus,
2318 DiskEntry->Id,
2319 &DiskEntry->DriverName,
2320 DiskEntry->NoMbr ? "GPT" : "MBR");
2321 }
2322 else
2323 {
2324 CONSOLE_PrintTextXY(6, 10,
2325 MUIGetString(STRING_HDINFOPARTCREATE_2),
2326 DiskSize,
2327 Unit,
2328 DiskEntry->DiskNumber,
2329 DiskEntry->Port,
2330 DiskEntry->Bus,
2331 DiskEntry->Id,
2332 DiskEntry->NoMbr ? "GPT" : "MBR");
2333 }
2334
2335 CONSOLE_SetTextXY(6, 12, MUIGetString(STRING_HDDSIZE));
2336
2337 #if 0
2338 CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB",
2339 PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB);
2340 #endif
2341
2342 CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));
2343
2344 PartEntry = PartitionList->CurrentPartition;
2345 while (TRUE)
2346 {
2347 MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */
2348
2349 if (MaxSize > PARTITION_MAXSIZE)
2350 MaxSize = PARTITION_MAXSIZE;
2351
2352 ShowPartitionSizeInputBox(12, 14, xScreen - 12, 17, /* left, top, right, bottom */
2353 MaxSize, InputBuffer, &Quit, &Cancel);
2354
2355 if (Quit)
2356 {
2357 if (ConfirmQuit(Ir))
2358 return QUIT_PAGE;
2359
2360 break;
2361 }
2362 else if (Cancel)
2363 {
2364 return SELECT_PARTITION_PAGE;
2365 }
2366 else
2367 {
2368 PartSize = _wcstoui64(InputBuffer, NULL, 10);
2369
2370 if (PartSize < 1)
2371 {
2372 /* Too small */
2373 continue;
2374 }
2375
2376 if (PartSize > MaxSize)
2377 {
2378 /* Too large */
2379 continue;
2380 }
2381
2382 /* Convert to bytes */
2383 if (PartSize == MaxSize)
2384 {
2385 /* Use all of the unpartitioned disk space */
2386 SectorCount = PartEntry->SectorCount.QuadPart;
2387 }
2388 else
2389 {
2390 /* Calculate the sector count from the size in MB */
2391 SectorCount = PartSize * MB / DiskEntry->BytesPerSector;
2392
2393 /* But never get larger than the unpartitioned disk space */
2394 if (SectorCount > PartEntry->SectorCount.QuadPart)
2395 SectorCount = PartEntry->SectorCount.QuadPart;
2396 }
2397
2398 DPRINT("Partition size: %I64u bytes\n", PartSize);
2399
2400 CreateLogicalPartition(PartitionList,
2401 SectorCount,
2402 FALSE);
2403
2404 return SELECT_PARTITION_PAGE;
2405 }
2406 }
2407
2408 return CREATE_LOGICAL_PARTITION_PAGE;
2409 }
2410
2411
2412 /*
2413 * Displays the ConfirmDeleteSystemPartitionPage.
2414 *
2415 * Next pages:
2416 * DeletePartitionPage (default)
2417 * SelectPartitionPage
2418 *
2419 * RETURNS
2420 * Number of the next page.
2421 */
2422 static PAGE_NUMBER
2423 ConfirmDeleteSystemPartitionPage(PINPUT_RECORD Ir)
2424 {
2425 MUIDisplayPage(CONFIRM_DELETE_SYSTEM_PARTITION_PAGE);
2426
2427 while (TRUE)
2428 {
2429 CONSOLE_ConInKey(Ir);
2430
2431 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
2432 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
2433 {
2434 if (ConfirmQuit(Ir))
2435 return QUIT_PAGE;
2436
2437 break;
2438 }
2439 else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
2440 {
2441 return DELETE_PARTITION_PAGE;
2442 }
2443 else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) /* ESC */
2444 {
2445 return SELECT_PARTITION_PAGE;
2446 }
2447 }
2448
2449 return CONFIRM_DELETE_SYSTEM_PARTITION_PAGE;
2450 }
2451
2452
2453 /*
2454 * Displays the DeletePartitionPage.
2455 *
2456 * Next pages:
2457 * SelectPartitionPage (default)
2458 * QuitPage
2459 *
2460 * RETURNS
2461 * Number of the next page.
2462 */
2463 static PAGE_NUMBER
2464 DeletePartitionPage(PINPUT_RECORD Ir)
2465 {
2466 PDISKENTRY DiskEntry;
2467 PPARTENTRY PartEntry;
2468 ULONGLONG DiskSize;
2469 ULONGLONG PartSize;
2470 PCHAR Unit;
2471 CHAR PartTypeString[32];
2472
2473 if (PartitionList == NULL ||
2474 PartitionList->CurrentDisk == NULL ||
2475 PartitionList->CurrentPartition == NULL)
2476 {
2477 /* FIXME: show an error dialog */
2478 return QUIT_PAGE;
2479 }
2480
2481 DiskEntry = PartitionList->CurrentDisk;
2482 PartEntry = PartitionList->CurrentPartition;
2483
2484 MUIDisplayPage(DELETE_PARTITION_PAGE);
2485
2486 GetPartTypeStringFromPartitionType(PartEntry->PartitionType,
2487 PartTypeString,
2488 ARRAYSIZE(PartTypeString));
2489
2490 PartSize = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2491 #if 0
2492 if (PartSize >= 10 * GB) /* 10 GB */
2493 {
2494 PartSize = PartSize / GB;
2495 Unit = MUIGetString(STRING_GB);
2496 }
2497 else
2498 #endif
2499 if (PartSize >= 10 * MB) /* 10 MB */
2500 {
2501 PartSize = PartSize / MB;
2502 Unit = MUIGetString(STRING_MB);
2503 }
2504 else
2505 {
2506 PartSize = PartSize / KB;
2507 Unit = MUIGetString(STRING_KB);
2508 }
2509
2510 if (*PartTypeString == '\0') // STRING_FORMATUNKNOWN ??
2511 {
2512 CONSOLE_PrintTextXY(6, 10,
2513 MUIGetString(STRING_HDDINFOUNK2),
2514 (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
2515 (PartEntry->DriveLetter == 0) ? '-' : ':',
2516 PartEntry->PartitionType,
2517 PartSize,
2518 Unit);
2519 }
2520 else
2521 {
2522 CONSOLE_PrintTextXY(6, 10,
2523 " %c%c %s %I64u %s",
2524 (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
2525 (PartEntry->DriveLetter == 0) ? '-' : ':',
2526 PartTypeString,
2527 PartSize,
2528 Unit);
2529 }
2530
2531 DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2532 #if 0
2533 if (DiskSize >= 10 * GB) /* 10 GB */
2534 {
2535 DiskSize = DiskSize / GB;
2536 Unit = MUIGetString(STRING_GB);
2537 }
2538 else
2539 #endif
2540 {
2541 DiskSize = DiskSize / MB;
2542 if (DiskSize == 0)
2543 DiskSize = 1;
2544
2545 Unit = MUIGetString(STRING_MB);
2546 }
2547
2548 if (DiskEntry->DriverName.Length > 0)
2549 {
2550 CONSOLE_PrintTextXY(6, 12,
2551 MUIGetString(STRING_HDINFOPARTDELETE_1),
2552 DiskSize,
2553 Unit,
2554 DiskEntry->DiskNumber,
2555 DiskEntry->Port,
2556 DiskEntry->Bus,
2557 DiskEntry->Id,
2558 &DiskEntry->DriverName,
2559 DiskEntry->NoMbr ? "GPT" : "MBR");
2560 }
2561 else
2562 {
2563 CONSOLE_PrintTextXY(6, 12,
2564 MUIGetString(STRING_HDINFOPARTDELETE_2),
2565 DiskSize,
2566 Unit,
2567 DiskEntry->DiskNumber,
2568 DiskEntry->Port,
2569 DiskEntry->Bus,
2570 DiskEntry->Id,
2571 DiskEntry->NoMbr ? "GPT" : "MBR");
2572 }
2573
2574 while (TRUE)
2575 {
2576 CONSOLE_ConInKey(Ir);
2577
2578 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
2579 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
2580 {
2581 if (ConfirmQuit(Ir))
2582 return QUIT_PAGE;
2583
2584 break;
2585 }
2586 else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) /* ESC */
2587 {
2588 return SELECT_PARTITION_PAGE;
2589 }
2590 else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'D') /* D */
2591 {
2592 DeleteCurrentPartition(PartitionList);
2593
2594 return SELECT_PARTITION_PAGE;
2595 }
2596 }
2597
2598 return DELETE_PARTITION_PAGE;
2599 }
2600
2601
2602 /*
2603 * Displays the SelectFileSystemPage.
2604 *
2605 * Next pages:
2606 * CheckFileSystemPage (At once if RepairUpdate is selected)
2607 * CheckFileSystemPage (At once if Unattended and not USetupData.FormatPartition)
2608 * FormatPartitionPage (At once if Unattended and USetupData.FormatPartition)
2609 * SelectPartitionPage (If the user aborts)
2610 * FormatPartitionPage (Default)
2611 * QuitPage
2612 *
2613 * SIDEEFFECTS
2614 * Sets PartEntry->DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType (via UpdatePartitionType)
2615 * Calls CheckActiveSystemPartition()
2616 *
2617 * RETURNS
2618 * Number of the next page.
2619 */
2620 static PAGE_NUMBER
2621 SelectFileSystemPage(PINPUT_RECORD Ir)
2622 {
2623 PDISKENTRY DiskEntry;
2624 PPARTENTRY PartEntry;
2625 ULONGLONG DiskSize;
2626 ULONGLONG PartSize;
2627 PCHAR DiskUnit;
2628 PCHAR PartUnit;
2629 CHAR PartTypeString[32];
2630 FORMATMACHINESTATE PreviousFormatState;
2631
2632 DPRINT("SelectFileSystemPage()\n");
2633
2634 if (PartitionList == NULL ||
2635 PartitionList->CurrentDisk == NULL ||
2636 PartitionList->CurrentPartition == NULL)
2637 {
2638 /* FIXME: show an error dialog */
2639 return QUIT_PAGE;
2640 }
2641
2642 /* Find or set the active system partition */
2643 CheckActiveSystemPartition(PartitionList);
2644 if (PartitionList->SystemPartition == NULL)
2645 {
2646 /* FIXME: show an error dialog */
2647 //
2648 // Error dialog should say that we cannot find a suitable
2649 // system partition and create one on the system. At this point,
2650 // it may be nice to ask the user whether he wants to continue,
2651 // or use an external drive as the system drive/partition
2652 // (e.g. floppy, USB drive, etc...)
2653 //
2654 return QUIT_PAGE;
2655 }
2656
2657 PreviousFormatState = FormatState;
2658 switch (FormatState)
2659 {
2660 case Start:
2661 {
2662 if (PartitionList->CurrentPartition != PartitionList->SystemPartition)
2663 {
2664 TempPartition = PartitionList->SystemPartition;
2665 TempPartition->NeedsCheck = TRUE;
2666
2667 FormatState = FormatSystemPartition;
2668 DPRINT1("FormatState: Start --> FormatSystemPartition\n");
2669 }
2670 else
2671 {
2672 TempPartition = PartitionList->CurrentPartition;
2673 TempPartition->NeedsCheck = TRUE;
2674
2675 FormatState = FormatInstallPartition;
2676 DPRINT1("FormatState: Start --> FormatInstallPartition\n");
2677 }
2678 break;
2679 }
2680
2681 case FormatSystemPartition:
2682 {
2683 TempPartition = PartitionList->CurrentPartition;
2684 TempPartition->NeedsCheck = TRUE;
2685
2686 FormatState = FormatInstallPartition;
2687 DPRINT1("FormatState: FormatSystemPartition --> FormatInstallPartition\n");
2688 break;
2689 }
2690
2691 case FormatInstallPartition:
2692 {
2693 if (GetNextUnformattedPartition(PartitionList,
2694 NULL,
2695 &TempPartition))
2696 {
2697 FormatState = FormatOtherPartition;
2698 TempPartition->NeedsCheck = TRUE;
2699 DPRINT1("FormatState: FormatInstallPartition --> FormatOtherPartition\n");
2700 }
2701 else
2702 {
2703 FormatState = FormatDone;
2704 DPRINT1("FormatState: FormatInstallPartition --> FormatDone\n");
2705 return CHECK_FILE_SYSTEM_PAGE;
2706 }
2707 break;
2708 }
2709
2710 case FormatOtherPartition:
2711 {
2712 if (GetNextUnformattedPartition(PartitionList,
2713 NULL,
2714 &TempPartition))
2715 {
2716 FormatState = FormatOtherPartition;
2717 TempPartition->NeedsCheck = TRUE;
2718 DPRINT1("FormatState: FormatOtherPartition --> FormatOtherPartition\n");
2719 }
2720 else
2721 {
2722 FormatState = FormatDone;
2723 DPRINT1("FormatState: FormatOtherPartition --> FormatDone\n");
2724 return CHECK_FILE_SYSTEM_PAGE;
2725 }
2726 break;
2727 }
2728
2729 default:
2730 {
2731 DPRINT1("FormatState: Invalid value %ld\n", FormatState);
2732 /* FIXME: show an error dialog */
2733 return QUIT_PAGE;
2734 }
2735 }
2736
2737 PartEntry = TempPartition;
2738 DiskEntry = PartEntry->DiskEntry;
2739
2740 /* Adjust disk size */
2741 DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2742 if (DiskSize >= 10 * GB) /* 10 GB */
2743 {
2744 DiskSize = DiskSize / GB;
2745 DiskUnit = MUIGetString(STRING_GB);
2746 }
2747 else
2748 {
2749 DiskSize = DiskSize / MB;
2750 DiskUnit = MUIGetString(STRING_MB);
2751 }
2752
2753 /* Adjust partition size */
2754 PartSize = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2755 if (PartSize >= 10 * GB) /* 10 GB */
2756 {
2757 PartSize = PartSize / GB;
2758 PartUnit = MUIGetString(STRING_GB);
2759 }
2760 else
2761 {
2762 PartSize = PartSize / MB;
2763 PartUnit = MUIGetString(STRING_MB);
2764 }
2765
2766 /* Adjust partition type */
2767 GetPartTypeStringFromPartitionType(PartEntry->PartitionType,
2768 PartTypeString,
2769 ARRAYSIZE(PartTypeString));
2770
2771 MUIDisplayPage(SELECT_FILE_SYSTEM_PAGE);
2772
2773 if (PartEntry->AutoCreate)
2774 {
2775 CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_NEWPARTITION));
2776
2777 #if 0
2778 CONSOLE_PrintTextXY(8, 10, "Partition %lu (%I64u %s) %s of",
2779 PartEntry->PartitionNumber,
2780 PartSize,
2781 PartUnit,
2782 PartTypeString);
2783 #endif
2784
2785 CONSOLE_PrintTextXY(8, 10, MUIGetString(STRING_HDINFOPARTZEROED_1),
2786 DiskEntry->DiskNumber,
2787 DiskSize,
2788 DiskUnit,
2789 DiskEntry->Port,
2790 DiskEntry->Bus,
2791 DiskEntry->Id,
2792 &DiskEntry->DriverName,
2793 DiskEntry->NoMbr ? "GPT" : "MBR");
2794
2795 CONSOLE_SetTextXY(6, 12, MUIGetString(STRING_PARTFORMAT));
2796
2797 PartEntry->AutoCreate = FALSE;
2798 }
2799 else if (PartEntry->New)
2800 {
2801 switch (FormatState)
2802 {
2803 case FormatSystemPartition:
2804 CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_NONFORMATTEDSYSTEMPART));
2805 break;
2806
2807 case FormatInstallPartition:
2808 CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_NONFORMATTEDPART));
2809 break;
2810
2811 case FormatOtherPartition:
2812 CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_NONFORMATTEDOTHERPART));
2813 break;
2814
2815 default:
2816 break;
2817 }
2818
2819 CONSOLE_SetTextXY(6, 10, MUIGetString(STRING_PARTFORMAT));
2820 }
2821 else
2822 {
2823 CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_INSTALLONPART));
2824
2825 if (*PartTypeString == '\0') // STRING_FORMATUNKNOWN ??
2826 {
2827 CONSOLE_PrintTextXY(8, 10,
2828 MUIGetString(STRING_HDDINFOUNK4),
2829 (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
2830 (PartEntry->DriveLetter == 0) ? '-' : ':',
2831 PartEntry->PartitionType,
2832 PartSize,
2833 PartUnit);
2834 }
2835 else
2836 {
2837 CONSOLE_PrintTextXY(8, 10,
2838 "%c%c %s %I64u %s",
2839 (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
2840 (PartEntry->DriveLetter == 0) ? '-' : ':',
2841 PartTypeString,
2842 PartSize,
2843 PartUnit);
2844 }
2845
2846 CONSOLE_PrintTextXY(6, 12, MUIGetString(STRING_HDINFOPARTEXISTS_1),
2847 DiskEntry->DiskNumber,
2848 DiskSize,
2849 DiskUnit,
2850 DiskEntry->Port,
2851 DiskEntry->Bus,
2852 DiskEntry->Id,
2853 &DiskEntry->DriverName,
2854 DiskEntry->NoMbr ? "GPT" : "MBR");
2855 }
2856
2857 if (FileSystemList == NULL)
2858 {
2859 /* Create the file system list, and by default select the "FAT" file system */
2860 FileSystemList = CreateFileSystemList(6, 26, PartEntry->New, L"FAT");
2861 if (FileSystemList == NULL)
2862 {
2863 /* FIXME: show an error dialog */
2864 return QUIT_PAGE;
2865 }
2866 }
2867
2868 if (RepairUpdateFlag)
2869 {
2870 return CHECK_FILE_SYSTEM_PAGE;
2871 //return SELECT_PARTITION_PAGE;
2872 }
2873
2874 if (IsUnattendedSetup)
2875 {
2876 if (USetupData.FormatPartition)
2877 {
2878 /*
2879 * We use whatever currently selected file system we have
2880 * (by default, this is "FAT", as per the initialization
2881 * performed above). Note that it may be interesting to specify
2882 * which file system to use in unattended installations, in the
2883 * txtsetup.sif file.
2884 */
2885 return FORMAT_PARTITION_PAGE;
2886 }
2887
2888 return CHECK_FILE_SYSTEM_PAGE;
2889 }
2890
2891 DrawFileSystemList(FileSystemList);
2892
2893 while (TRUE)
2894 {
2895 CONSOLE_ConInKey(Ir);
2896
2897 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
2898 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
2899 {
2900 if (ConfirmQuit(Ir))
2901 return QUIT_PAGE;
2902
2903 break;
2904 }
2905 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
2906 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)) /* ESC */
2907 {
2908 FormatState = Start;
2909 return SELECT_PARTITION_PAGE;
2910 }
2911 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
2912 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DOWN)) /* DOWN */
2913 {
2914 ScrollDownFileSystemList(FileSystemList);
2915 }
2916 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
2917 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_UP)) /* UP */
2918 {
2919 ScrollUpFileSystemList(FileSystemList);
2920 }
2921 else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
2922 {
2923 if (!FileSystemList->Selected->FileSystem)
2924 return SELECT_FILE_SYSTEM_PAGE;
2925 else
2926 return FORMAT_PARTITION_PAGE;
2927 }
2928 }
2929
2930 FormatState = PreviousFormatState;
2931
2932 return SELECT_FILE_SYSTEM_PAGE;
2933 }
2934
2935
2936 /*
2937 * Displays the FormatPartitionPage.
2938 *
2939 * Next pages:
2940 * InstallDirectoryPage (At once if IsUnattendedSetup or InstallShortcut)
2941 * SelectPartitionPage (At once)
2942 * QuitPage
2943 *
2944 * SIDEEFFECTS
2945 * Sets PartitionList->CurrentPartition->FormatState
2946 * Sets USetupData.DestinationRootPath
2947 *
2948 * RETURNS
2949 * Number of the next page.
2950 */
2951 static PAGE_NUMBER
2952 FormatPartitionPage(PINPUT_RECORD Ir)
2953 {
2954 NTSTATUS Status;
2955 PDISKENTRY DiskEntry;
2956 PPARTENTRY PartEntry;
2957 PFILE_SYSTEM_ITEM SelectedFileSystem;
2958 UNICODE_STRING PartitionRootPath;
2959 WCHAR PathBuffer[MAX_PATH];
2960 CHAR Buffer[MAX_PATH];
2961
2962 #ifndef NDEBUG
2963 ULONG Line;
2964 ULONG i;
2965 PPARTITION_INFORMATION PartitionInfo;
2966 #endif
2967
2968 DPRINT("FormatPartitionPage()\n");
2969
2970 MUIDisplayPage(FORMAT_PARTITION_PAGE);
2971
2972 if (PartitionList == NULL || TempPartition == NULL)
2973 {
2974 /* FIXME: show an error dialog */
2975 return QUIT_PAGE;
2976 }
2977
2978 PartEntry = TempPartition;
2979 DiskEntry = PartEntry->DiskEntry;
2980
2981 SelectedFileSystem = FileSystemList->Selected;
2982
2983 while (TRUE)
2984 {
2985 if (!IsUnattendedSetup)
2986 {
2987 CONSOLE_ConInKey(Ir);
2988 }
2989
2990 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
2991 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
2992 {
2993 if (ConfirmQuit(Ir))
2994 return QUIT_PAGE;
2995
2996 break;
2997 }
2998 else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN || IsUnattendedSetup) /* ENTER */
2999 {
3000 CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
3001
3002 if (!PreparePartitionForFormatting(PartEntry, SelectedFileSystem->FileSystem))
3003 {
3004 /* FIXME: show an error dialog */
3005 return QUIT_PAGE;
3006 }
3007
3008 #ifndef NDEBUG
3009 CONSOLE_PrintTextXY(6, 12,
3010 "Cylinders: %I64u Tracks/Cyl: %lu Sectors/Trk: %lu Bytes/Sec: %lu %c",
3011 DiskEntry->Cylinders,
3012 DiskEntry->TracksPerCylinder,
3013 DiskEntry->SectorsPerTrack,
3014 DiskEntry->BytesPerSector,
3015 DiskEntry->Dirty ? '*' : ' ');
3016
3017 Line = 13;
3018
3019 for (i = 0; i < DiskEntry->LayoutBuffer->PartitionCount; i++)
3020 {
3021 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[i];
3022
3023 CONSOLE_PrintTextXY(6, Line,
3024 "%2u: %2lu %c %12I64u %12I64u %02x",
3025 i,
3026 PartitionInfo->PartitionNumber,
3027 PartitionInfo->BootIndicator ? 'A' : '-',
3028 PartitionInfo->StartingOffset.QuadPart / DiskEntry->BytesPerSector,
3029 PartitionInfo->PartitionLength.QuadPart / DiskEntry->BytesPerSector,
3030 PartitionInfo->PartitionType);
3031 Line++;
3032 }
3033 #endif
3034
3035 /* Commit the partition changes to the disk */
3036 if (!WritePartitionsToDisk(PartitionList))
3037 {
3038 DPRINT("WritePartitionsToDisk() failed\n");
3039 MUIDisplayError(ERROR_WRITE_PTABLE, Ir, POPUP_WAIT_ENTER);
3040 return QUIT_PAGE;
3041 }
3042
3043 /* Set PartitionRootPath */
3044 RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
3045 L"\\Device\\Harddisk%lu\\Partition%lu",
3046 DiskEntry->DiskNumber,
3047 PartEntry->PartitionNumber);
3048 RtlInitUnicodeString(&PartitionRootPath, PathBuffer);
3049 DPRINT("PartitionRootPath: %wZ\n", &PartitionRootPath);
3050
3051 /* Format the partition */
3052 if (SelectedFileSystem->FileSystem)
3053 {
3054 Status = FormatPartition(&PartitionRootPath,
3055 SelectedFileSystem);
3056 if (Status == STATUS_NOT_SUPPORTED)
3057 {
3058 sprintf(Buffer,
3059 "Setup is currently unable to format a partition in %S.\n"
3060 "\n"
3061 " \x07 Press ENTER to continue Setup.\n"
3062 " \x07 Press F3 to quit Setup.",
3063 SelectedFileSystem->FileSystem->FileSystemName);
3064
3065 PopupError(Buffer,
3066 MUIGetString(STRING_QUITCONTINUE),
3067 NULL, POPUP_WAIT_NONE);
3068
3069 while (TRUE)
3070 {
3071 CONSOLE_ConInKey(Ir);
3072
3073 if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x00 &&
3074 Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3) /* F3 */
3075 {
3076 if (ConfirmQuit(Ir))
3077 return QUIT_PAGE;
3078 else
3079 return SELECT_FILE_SYSTEM_PAGE;
3080 }
3081 else if (Ir->Event.KeyEvent.uChar.AsciiChar == VK_RETURN) /* ENTER */
3082 {
3083 return SELECT_FILE_SYSTEM_PAGE;
3084 }
3085 }
3086 }
3087 else if (!NT_SUCCESS(Status))
3088 {
3089 DPRINT1("FormatPartition() failed with status 0x%08lx\n", Status);
3090 MUIDisplayError(ERROR_FORMATTING_PARTITION, Ir, POPUP_WAIT_ANY_KEY, PathBuffer);
3091 return QUIT_PAGE;
3092 }
3093
3094 PartEntry->FormatState = Formatted;
3095 // PartEntry->FileSystem = FileSystem;
3096 PartEntry->New = FALSE;
3097 }
3098
3099 #ifndef NDEBUG
3100 CONSOLE_SetStatusText(" Done. Press any key ...");
3101 CONSOLE_ConInKey(Ir);
3102 #endif
3103
3104 return SELECT_FILE_SYSTEM_PAGE;
3105 }
3106 }
3107
3108 return FORMAT_PARTITION_PAGE;
3109 }
3110
3111
3112 /*
3113 * Displays the CheckFileSystemPage.
3114 *
3115 * Next pages:
3116 * InstallDirectoryPage (At once)
3117 * QuitPage
3118 *
3119 * SIDEEFFECTS
3120 * Inits or reloads FileSystemList
3121 *
3122 * RETURNS
3123 * Number of the next page.
3124 */
3125 static PAGE_NUMBER
3126 CheckFileSystemPage(PINPUT_RECORD Ir)
3127 {
3128 NTSTATUS Status;
3129 PDISKENTRY DiskEntry;
3130 PPARTENTRY PartEntry;
3131 PFILE_SYSTEM CurrentFileSystem;
3132 UNICODE_STRING PartitionRootPath;
3133 WCHAR PathBuffer[MAX_PATH];
3134 CHAR Buffer[MAX_PATH];
3135
3136 if (PartitionList == NULL)
3137 {
3138 /* FIXME: show an error dialog */
3139 return QUIT_PAGE;
3140 }
3141
3142 if (!GetNextUncheckedPartition(PartitionList, &DiskEntry, &PartEntry))
3143 {
3144 return INSTALL_DIRECTORY_PAGE;
3145 }
3146
3147 /* Set PartitionRootPath */
3148 RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
3149 L"\\Device\\Harddisk%lu\\Partition%lu",
3150 DiskEntry->DiskNumber,
3151 PartEntry->PartitionNumber);
3152 RtlInitUnicodeString(&PartitionRootPath, PathBuffer);
3153 DPRINT("PartitionRootPath: %wZ\n", &PartitionRootPath);
3154
3155 CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_CHECKINGPART));
3156
3157 CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
3158
3159 CurrentFileSystem = PartEntry->FileSystem;
3160 DPRINT1("CheckFileSystemPage -- PartitionType: 0x%02X ; FileSystemName: %S\n",
3161 PartEntry->PartitionType, (CurrentFileSystem ? CurrentFileSystem->FileSystemName : L"n/a"));
3162
3163 /* HACK: Do not try to check a partition with an unknown filesystem */
3164 if (CurrentFileSystem == NULL)
3165 {
3166 PartEntry->NeedsCheck = FALSE;
3167 return CHECK_FILE_SYSTEM_PAGE;
3168 }
3169
3170 Status = ChkdskPartition(&PartitionRootPath, CurrentFileSystem);
3171 if (Status == STATUS_NOT_SUPPORTED)
3172 {
3173 sprintf(Buffer,
3174 "Setup is currently unable to check a partition formatted in %S.\n"
3175 "\n"
3176 " \x07 Press ENTER to continue Setup.\n"
3177 " \x07 Press F3 to quit Setup.",
3178 CurrentFileSystem->FileSystemName);
3179
3180 PopupError(Buffer,
3181 MUIGetString(STRING_QUITCONTINUE),
3182 NULL, POPUP_WAIT_NONE);
3183
3184 while (TRUE)
3185 {
3186 CONSOLE_ConInKey(Ir);
3187
3188 if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x00 &&
3189 Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3) /* F3 */
3190 {
3191 if (ConfirmQuit(Ir))
3192 return QUIT_PAGE;
3193 else
3194 return CHECK_FILE_SYSTEM_PAGE;
3195 }
3196 else if (Ir->Event.KeyEvent.uChar.AsciiChar == VK_RETURN) /* ENTER */
3197 {
3198 PartEntry->NeedsCheck = FALSE;
3199 return CHECK_FILE_SYSTEM_PAGE;
3200 }
3201 }
3202 }
3203 else if (!NT_SUCCESS(Status))
3204 {
3205 DPRINT("ChkdskPartition() failed with status 0x%08lx\n", Status);
3206 // sprintf(Buffer, "Setup failed to verify the selected partition.\n"
3207 sprintf(Buffer, "ChkDsk detected some disk errors.\n"
3208 "(Status 0x%08lx).\n", Status);
3209 PopupError(Buffer,
3210 // MUIGetString(STRING_REBOOTCOMPUTER),
3211 MUIGetString(STRING_CONTINUE),
3212 Ir, POPUP_WAIT_ENTER);
3213
3214 // return QUIT_PAGE;
3215 }
3216
3217 PartEntry->NeedsCheck = FALSE;
3218 return CHECK_FILE_SYSTEM_PAGE;
3219 }
3220
3221
3222 static VOID
3223 BuildInstallPaths(PWSTR InstallDir,
3224 PDISKENTRY DiskEntry,
3225 PPARTENTRY PartEntry)
3226 {
3227 WCHAR PathBuffer[MAX_PATH];
3228
3229 /** Equivalent of 'NTOS_INSTALLATION::PathComponent' **/
3230 /* Create 'InstallPath' string */
3231 RtlFreeUnicodeString(&InstallPath);
3232 RtlCreateUnicodeString(&InstallPath, InstallDir);
3233
3234 /* Create 'USetupData.DestinationRootPath' string */
3235 RtlFreeUnicodeString(&USetupData.DestinationRootPath);
3236 RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
3237 L"\\Device\\Harddisk%lu\\Partition%lu\\",
3238 DiskEntry->DiskNumber,
3239 PartEntry->PartitionNumber);
3240 RtlCreateUnicodeString(&USetupData.DestinationRootPath, PathBuffer);
3241 DPRINT("DestinationRootPath: %wZ\n", &USetupData.DestinationRootPath);
3242
3243 /** Equivalent of 'NTOS_INSTALLATION::SystemNtPath' **/
3244 /* Create 'USetupData.DestinationPath' string */
3245 RtlFreeUnicodeString(&USetupData.DestinationPath);
3246 CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2,
3247 USetupData.DestinationRootPath.Buffer, InstallDir);
3248 RtlCreateUnicodeString(&USetupData.DestinationPath, PathBuffer);
3249
3250 /** Equivalent of 'NTOS_INSTALLATION::SystemArcPath' **/
3251 /* Create 'USetupData.DestinationArcPath' */
3252 RtlFreeUnicodeString(&USetupData.DestinationArcPath);
3253 RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
3254 L"multi(0)disk(0)rdisk(%lu)partition(%lu)\\",
3255 DiskEntry->BiosDiskNumber,
3256 PartEntry->PartitionNumber);
3257 ConcatPaths(PathBuffer, ARRAYSIZE(PathBuffer), 1, InstallDir);
3258 RtlCreateUnicodeString(&USetupData.DestinationArcPath, PathBuffer);
3259
3260 /* Initialize DestinationDriveLetter */
3261 DestinationDriveLetter = (WCHAR)PartEntry->DriveLetter;
3262 }
3263
3264
3265 /*
3266 * Displays the InstallDirectoryPage.
3267 *
3268 * Next pages:
3269 * PrepareCopyPage
3270 * QuitPage
3271 *
3272 * RETURNS
3273 * Number of the next page.
3274 */
3275 static PAGE_NUMBER
3276 InstallDirectoryPage(PINPUT_RECORD Ir)
3277 {
3278 PDISKENTRY DiskEntry;
3279 PPARTENTRY PartEntry;
3280 WCHAR InstallDir[MAX_PATH];
3281 WCHAR c;
3282 ULONG Length, Pos;
3283
3284 /* We do not need the filesystem list anymore */
3285 if (FileSystemList != NULL)
3286 {
3287 DestroyFileSystemList(FileSystemList);
3288 FileSystemList = NULL;
3289 }
3290
3291 if (PartitionList == NULL ||
3292 PartitionList->CurrentDisk == NULL ||
3293 PartitionList->CurrentPartition == NULL)
3294 {
3295 /* FIXME: show an error dialog */
3296 return QUIT_PAGE;
3297 }
3298
3299 DiskEntry = PartitionList->CurrentDisk;
3300 PartEntry = PartitionList->CurrentPartition;
3301
3302 // if (IsUnattendedSetup)
3303 if (RepairUpdateFlag)
3304 wcscpy(InstallDir, CurrentInstallation->PathComponent); // SystemNtPath
3305 else if (USetupData.InstallationDirectory[0])
3306 wcscpy(InstallDir, USetupData.InstallationDirectory);
3307 else
3308 wcscpy(InstallDir, L"\\ReactOS");
3309
3310 /*
3311 * Check the validity of the predefined 'InstallDir'. If we are either
3312 * in unattended setup or in update/repair mode, and the installation path
3313 * is valid, just perform the installation. Otherwise (either in the case
3314 * of an invalid path, or we are in regular setup), display the UI and allow
3315 * the user to specify a new installation path.
3316 */
3317 if ((RepairUpdateFlag || IsUnattendedSetup) && IsValidPath(InstallDir))
3318 {
3319 BuildInstallPaths(InstallDir,
3320 DiskEntry,
3321 PartEntry);
3322
3323 /*
3324 * Check whether the user attempts to install ReactOS within the
3325 * installation source directory, or in a subdirectory thereof.
3326 * If so, fail with an error.
3327 */
3328 if (RtlPrefixUnicodeString(&USetupData.SourcePath, &USetupData.DestinationPath, TRUE))
3329 {
3330 PopupError("You cannot install ReactOS within the installation source directory!",
3331 MUIGetString(STRING_CONTINUE),
3332 Ir, POPUP_WAIT_ENTER);
3333 return INSTALL_DIRECTORY_PAGE;
3334 }
3335
3336 return PREPARE_COPY_PAGE;
3337 }
3338
3339 Length = wcslen(InstallDir);
3340 Pos = Length;
3341
3342 MUIDisplayPage(INSTALL_DIRECTORY_PAGE);
3343 CONSOLE_SetInputTextXY(8, 11, 51, InstallDir);
3344 CONSOLE_SetCursorXY(8 + Pos, 11);
3345 CONSOLE_SetCursorType(TRUE, TRUE);
3346
3347 while (TRUE)
3348 {
3349 CONSOLE_ConInKey(Ir);
3350
3351 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
3352 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
3353 {
3354 CONSOLE_SetCursorType(TRUE, FALSE);
3355
3356 if (ConfirmQuit(Ir))
3357 return QUIT_PAGE;
3358
3359 CONSOLE_SetCursorType(TRUE, TRUE);
3360 break;
3361 }
3362 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
3363 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DELETE)) /* DEL */
3364 {
3365 if (Pos < Length)
3366 {
3367 memmove(&InstallDir[Pos],
3368 &InstallDir[Pos + 1],
3369 (Length - Pos - 1) * sizeof(WCHAR));
3370 InstallDir[Length - 1] = UNICODE_NULL;
3371
3372 Length--;
3373 CONSOLE_SetInputTextXY(8, 11, 51, InstallDir);
3374 CONSOLE_SetCursorXY(8 + Pos, 11);
3375 }
3376 }
3377 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
3378 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_HOME)) /* HOME */
3379 {
3380 Pos = 0;
3381 CONSOLE_SetCursorXY(8 + Pos, 11);
3382 }
3383 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
3384 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_END)) /* END */
3385 {
3386 Pos = Length;
3387 CONSOLE_SetCursorXY(8 + Pos, 11);
3388 }
3389 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
3390 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_LEFT)) /* LEFT */
3391 {
3392 if (Pos > 0)
3393 {
3394 Pos--;
3395 CONSOLE_SetCursorXY(8 + Pos, 11);
3396 }
3397 }
3398 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
3399 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)) /* RIGHT */
3400 {
3401 if (Pos < Length)
3402 {
3403 Pos++;
3404 CONSOLE_SetCursorXY(8 + Pos, 11);
3405 }
3406 }
3407 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
3408 {
3409 CONSOLE_SetCursorType(TRUE, FALSE);
3410
3411 /*
3412 * Check for the validity of the installation directory and pop up
3413 * an error if it is not the case. Then the user can fix its input.
3414 */
3415 if (!IsValidPath(InstallDir))
3416 {
3417 MUIDisplayError(ERROR_DIRECTORY_NAME, Ir, POPUP_WAIT_ENTER);
3418 return INSTALL_DIRECTORY_PAGE;
3419 }
3420
3421 BuildInstallPaths(InstallDir,
3422 DiskEntry,
3423 PartEntry);
3424
3425 /*
3426 * Check whether the user attempts to install ReactOS within the
3427 * installation source directory, or in a subdirectory thereof.
3428 * If so, fail with an error.
3429 */
3430 if (RtlPrefixUnicodeString(&USetupData.SourcePath, &USetupData.DestinationPath, TRUE))
3431 {
3432 PopupError("You cannot install ReactOS within the installation source directory!",
3433 MUIGetString(STRING_CONTINUE),
3434 Ir, POPUP_WAIT_ENTER);
3435 return INSTALL_DIRECTORY_PAGE;
3436 }
3437
3438 return PREPARE_COPY_PAGE;
3439 }
3440 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x08) /* BACKSPACE */
3441 {
3442 if (Pos > 0)
3443 {
3444 if (Pos < Length)
3445 memmove(&InstallDir[Pos - 1],
3446 &InstallDir[Pos],
3447 (Length - Pos) * sizeof(WCHAR));
3448 InstallDir[Length - 1] = UNICODE_NULL;
3449
3450 Pos--;
3451 Length--;
3452 CONSOLE_SetInputTextXY(8, 11, 51, InstallDir);
3453 CONSOLE_SetCursorXY(8 + Pos, 11);
3454 }
3455 }
3456 else if (isprint(Ir->Event.KeyEvent.uChar.AsciiChar))
3457 {
3458 if (Length < 50)
3459 {
3460 c = (WCHAR)Ir->Event.KeyEvent.uChar.AsciiChar;
3461 if (iswalpha(c) || iswdigit(c) || c == '.' || c == '\\' || c == '-' || c == '_')
3462 {
3463 if (Pos < Length)
3464 memmove(&InstallDir[Pos + 1],
3465 &InstallDir[Pos],
3466 (Length - Pos) * sizeof(WCHAR));
3467 InstallDir[Length + 1] = UNICODE_NULL;
3468 InstallDir[Pos] = c;
3469
3470 Pos++;
3471 Length++;
3472 CONSOLE_SetInputTextXY(8, 11, 51, InstallDir);
3473 CONSOLE_SetCursorXY(8 + Pos, 11);
3474 }
3475 }
3476 }
3477 }
3478
3479 return INSTALL_DIRECTORY_PAGE;
3480 }
3481
3482
3483 static BOOLEAN
3484 AddSectionToCopyQueueCab(HINF InfFile,
3485 PWCHAR SectionName,
3486 PWCHAR SourceCabinet,
3487 PCUNICODE_STRING DestinationPath,
3488 PINPUT_RECORD Ir)
3489 {
3490 INFCONTEXT FilesContext;
3491 INFCONTEXT DirContext;
3492 PWCHAR FileKeyName;
3493 PWCHAR FileKeyValue;
3494 PWCHAR DirKeyValue;
3495 PWCHAR TargetFileName;
3496
3497 /*
3498 * This code enumerates the list of files in reactos.dff / reactos.inf
3499 * that need to be extracted from reactos.cab and be installed in their
3500 * respective directories.
3501 */
3502
3503 /* Search for the SectionName section */
3504 if (!SetupFindFirstLineW(InfFile, SectionName, NULL, &FilesContext))
3505 {
3506 MUIDisplayError(ERROR_TXTSETUP_SECTION, Ir, POPUP_WAIT_ENTER, SectionName);
3507 return FALSE;
3508 }
3509
3510 /*
3511 * Enumerate the files in the section and add them to the file queue.
3512 */
3513 do
3514 {
3515 /* Get source file name and target directory id */
3516 if (!INF_GetData(&FilesContext, &FileKeyName, &FileKeyValue))
3517 {
3518 /* FIXME: Handle error! */
3519 DPRINT1("INF_GetData() failed\n");
3520 break;
3521 }
3522
3523 /* Get optional target file name */
3524 if (!INF_GetDataField(&FilesContext, 2, &TargetFileName))
3525 TargetFileName = NULL;
3526
3527 DPRINT("FileKeyName: '%S' FileKeyValue: '%S'\n", FileKeyName, FileKeyValue);
3528
3529 /* Lookup target directory */
3530 if (!SetupFindFirstLineW(InfFile, L"Directories", FileKeyValue, &DirContext))
3531 {
3532 /* FIXME: Handle error! */
3533 DPRINT1("SetupFindFirstLine() failed\n");
3534 INF_FreeData(FileKeyName);
3535 INF_FreeData(FileKeyValue);
3536 INF_FreeData(TargetFileName);
3537 break;
3538 }
3539
3540 INF_FreeData(FileKeyValue);
3541
3542 if (!INF_GetData(&DirContext, NULL, &DirKeyValue))
3543 {
3544 /* FIXME: Handle error! */
3545 DPRINT1("INF_GetData() failed\n");
3546 INF_FreeData(FileKeyName);
3547 INF_FreeData(TargetFileName);
3548 break;
3549 }
3550
3551 if (!SetupQueueCopy(SetupFileQueue,
3552 SourceCabinet,
3553 USetupData.SourceRootPath.Buffer,
3554 USetupData.SourceRootDir.Buffer,
3555 FileKeyName,
3556 DirKeyValue,
3557 TargetFileName))
3558 {
3559 /* FIXME: Handle error! */
3560 DPRINT1("SetupQueueCopy() failed\n");
3561 }
3562
3563 INF_FreeData(FileKeyName);
3564 INF_FreeData(TargetFileName);
3565 INF_FreeData(DirKeyValue);
3566 } while (SetupFindNextLine(&FilesContext, &FilesContext));
3567
3568 return TRUE;
3569 }
3570
3571
3572 static BOOLEAN
3573 AddSectionToCopyQueue(HINF InfFile,
3574 PWCHAR SectionName,
3575 PWCHAR SourceCabinet,
3576 PCUNICODE_STRING DestinationPath,
3577 PINPUT_RECORD Ir)
3578 {
3579 INFCONTEXT FilesContext;
3580 INFCONTEXT DirContext;
3581 PWCHAR FileKeyName;
3582 PWCHAR FileKeyValue;
3583 PWCHAR DirKeyValue;
3584 PWCHAR TargetFileName;
3585 WCHAR CompleteOrigDirName[512]; // FIXME: MAX_PATH is not enough?
3586
3587 if (SourceCabinet)
3588 return AddSectionToCopyQueueCab(InfFile, L"SourceFiles", SourceCabinet, DestinationPath, Ir);
3589
3590 /*
3591 * This code enumerates the list of files in txtsetup.sif
3592 * that need to be installed in their respective directories.
3593 */
3594
3595 /* Search for the SectionName section */
3596 if (!SetupFindFirstLineW(InfFile, SectionName, NULL, &FilesContext))
3597 {
3598 MUIDisplayError(ERROR_TXTSETUP_SECTION, Ir, POPUP_WAIT_ENTER, SectionName);
3599 return FALSE;
3600 }
3601
3602 /*
3603 * Enumerate the files in the section and add them to the file queue.
3604 */
3605 do
3606 {
3607 /* Get source file name */
3608 if (!INF_GetDataField(&FilesContext, 0, &FileKeyName))
3609 {
3610 /* FIXME: Handle error! */
3611 DPRINT1("INF_GetData() failed\n");
3612 break;
3613 }
3614
3615 /* Get target directory id */
3616 if (!INF_GetDataField(&FilesContext, 13, &FileKeyValue))
3617 {
3618 /* FIXME: Handle error! */
3619 DPRINT1("INF_GetData() failed\n");
3620 INF_FreeData(FileKeyName);
3621 break;
3622 }
3623
3624 /* Get optional target file name */
3625 if (!INF_GetDataField(&FilesContext, 11, &TargetFileName))
3626 TargetFileName = NULL;
3627 else if (!*TargetFileName)
3628 TargetFileName = NULL;
3629
3630 DPRINT("FileKeyName: '%S' FileKeyValue: '%S'\n", FileKeyName, FileKeyValue);
3631
3632 /* Lookup target directory */
3633 if (!SetupFindFirstLineW(InfFile, L"Directories", FileKeyValue, &DirContext))
3634 {
3635 /* FIXME: Handle error! */
3636 DPRINT1("SetupFindFirstLine() failed\n");
3637 INF_FreeData(FileKeyName);
3638 INF_FreeData(FileKeyValue);
3639 INF_FreeData(TargetFileName);
3640 break;
3641 }
3642
3643 INF_FreeData(FileKeyValue);
3644
3645 if (!INF_GetData(&DirContext, NULL, &DirKeyValue))
3646 {
3647 /* FIXME: Handle error! */
3648 DPRINT1("INF_GetData() failed\n");
3649 INF_FreeData(FileKeyName);
3650 INF_FreeData(TargetFileName);
3651 break;
3652 }
3653
3654 if ((DirKeyValue[0] == UNICODE_NULL) || (DirKeyValue[0] == L'\\' && DirKeyValue[1] == UNICODE_NULL))
3655 {
3656 /* Installation path */
3657 DPRINT("InstallationPath: '%S'\n", DirKeyValue);
3658
3659 RtlStringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName),
3660 USetupData.SourceRootDir.Buffer);
3661
3662 DPRINT("InstallationPath(2): '%S'\n", CompleteOrigDirName);
3663 }
3664 else if (DirKeyValue[0] == L'\\')
3665 {
3666 /* Absolute path */
3667 DPRINT("AbsolutePath: '%S'\n", DirKeyValue);
3668
3669 RtlStringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName),
3670 DirKeyValue);
3671
3672 DPRINT("AbsolutePath(2): '%S'\n", CompleteOrigDirName);
3673 }
3674 else // if (DirKeyValue[0] != L'\\')
3675 {
3676 /* Path relative to the installation path */
3677 DPRINT("RelativePath: '%S'\n", DirKeyValue);
3678
3679 CombinePaths(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), 2,
3680 USetupData.SourceRootDir.Buffer, DirKeyValue);
3681
3682 DPRINT("RelativePath(2): '%S'\n", CompleteOrigDirName);
3683 }
3684
3685 if (!SetupQueueCopy(SetupFileQueue,
3686 SourceCabinet,
3687 USetupData.SourceRootPath.Buffer,
3688 CompleteOrigDirName,
3689 FileKeyName,
3690 DirKeyValue,
3691 TargetFileName))
3692 {
3693 /* FIXME: Handle error! */
3694 DPRINT1("SetupQueueCopy() failed\n");
3695 }
3696
3697 INF_FreeData(FileKeyName);
3698 INF_FreeData(TargetFileName);
3699 INF_FreeData(DirKeyValue);
3700 } while (SetupFindNextLine(&FilesContext, &FilesContext));
3701
3702 return TRUE;
3703 }
3704
3705
3706 static BOOLEAN
3707 PrepareCopyPageInfFile(HINF InfFile,
3708 PWCHAR SourceCabinet,
3709 PINPUT_RECORD Ir)
3710 {
3711 NTSTATUS Status;
3712 INFCONTEXT DirContext;
3713 PWCHAR AdditionalSectionName = NULL;
3714 PWCHAR DirKeyValue;
3715 WCHAR PathBuffer[MAX_PATH];
3716
3717 /* Add common files */
3718 if (!AddSectionToCopyQueue(InfFile, L"SourceDisksFiles", SourceCabinet, &USetupData.DestinationPath, Ir))
3719 return FALSE;
3720
3721 /* Add specific files depending of computer type */
3722 if (SourceCabinet == NULL)
3723 {
3724 if (!ProcessComputerFiles(InfFile, ComputerList, &AdditionalSectionName))
3725 return FALSE;
3726
3727 if (AdditionalSectionName)
3728 {
3729 if (!AddSectionToCopyQueue(InfFile, AdditionalSectionName, SourceCabinet, &USetupData.DestinationPath, Ir))
3730 return FALSE;
3731 }
3732 }
3733
3734 /* Create directories */
3735
3736 /*
3737 * FIXME:
3738 * Copying files to USetupData.DestinationRootPath should be done from within
3739 * the SystemPartitionFiles section.
3740 * At the moment we check whether we specify paths like '\foo' or '\\' for that.
3741 * For installing to USetupData.DestinationPath specify just '\' .
3742 */
3743
3744 /* Get destination path */
3745 RtlStringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), USetupData.DestinationPath.Buffer);
3746
3747 DPRINT("FullPath(1): '%S'\n", PathBuffer);
3748
3749 /* Create the install directory */
3750 Status = SetupCreateDirectory(PathBuffer);
3751 if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION)
3752 {
3753 DPRINT1("Creating directory '%S' failed: Status = 0x%08lx\n", PathBuffer, Status);
3754 MUIDisplayError(ERROR_CREATE_INSTALL_DIR, Ir, POPUP_WAIT_ENTER);
3755 return FALSE;
3756 }
3757
3758 /* Search for the 'Directories' section */
3759 if (!SetupFindFirstLineW(InfFile, L"Directories", NULL, &DirContext))
3760 {
3761 if (SourceCabinet)
3762 MUIDisplayError(ERROR_CABINET_SECTION, Ir, POPUP_WAIT_ENTER, L"Directories");
3763 else
3764 MUIDisplayError(ERROR_TXTSETUP_SECTION, Ir, POPUP_WAIT_ENTER, L"Directories");
3765
3766 return FALSE;
3767 }
3768
3769 /* Enumerate the directory values and create the subdirectories */
3770 do
3771 {
3772 if (!INF_GetData(&DirContext, NULL, &DirKeyValue))
3773 {
3774 DPRINT1("break\n");
3775 break;
3776 }
3777
3778 if ((DirKeyValue[0] == UNICODE_NULL) || (DirKeyValue[0] == L'\\' && DirKeyValue[1] == UNICODE_NULL))
3779 {
3780 /* Installation path */
3781 DPRINT("InstallationPath: '%S'\n", DirKeyValue);
3782
3783 RtlStringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer),
3784 USetupData.DestinationPath.Buffer);
3785
3786 DPRINT("InstallationPath(2): '%S'\n", PathBuffer);
3787 }
3788 else if (DirKeyValue[0] == L'\\')
3789 {
3790 /* Absolute path */
3791 DPRINT("AbsolutePath: '%S'\n", DirKeyValue);
3792
3793 CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2,
3794 USetupData.DestinationRootPath.Buffer, DirKeyValue);
3795
3796 DPRINT("AbsolutePath(2): '%S'\n", PathBuffer);
3797
3798 Status = SetupCreateDirectory(PathBuffer);
3799 if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION)
3800 {
3801 INF_FreeData(DirKeyValue);
3802 DPRINT("Creating directory '%S' failed: Status = 0x%08lx", PathBuffer, Status);
3803 MUIDisplayError(ERROR_CREATE_DIR, Ir, POPUP_WAIT_ENTER);
3804 return FALSE;
3805 }
3806 }
3807 else // if (DirKeyValue[0] != L'\\')
3808 {
3809 /* Path relative to the installation path */
3810 DPRINT("RelativePath: '%S'\n", DirKeyValue);
3811
3812 CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2,
3813 USetupData.DestinationPath.Buffer, DirKeyValue);
3814
3815 DPRINT("RelativePath(2): '%S'\n", PathBuffer);
3816
3817 Status = SetupCreateDirectory(PathBuffer);
3818 if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION)
3819 {
3820 INF_FreeData(DirKeyValue);
3821 DPRINT("Creating directory '%S' failed: Status = 0x%08lx", PathBuffer, Status);
3822 MUIDisplayError(ERROR_CREATE_DIR, Ir, POPUP_WAIT_ENTER);
3823 return FALSE;
3824 }
3825 }
3826
3827 INF_FreeData(DirKeyValue);
3828 } while (SetupFindNextLine(&DirContext, &DirContext));
3829
3830 return TRUE;
3831 }
3832
3833
3834 /*
3835 * Displays the PrepareCopyPage.
3836 *
3837 * Next pages:
3838 * FileCopyPage(At once)
3839 * QuitPage
3840 *
3841 * SIDEEFFECTS
3842 * Inits SetupFileQueue
3843 * Calls PrepareCopyPageInfFile
3844 *
3845 * RETURNS
3846 * Number of the next page.
3847 */
3848 static PAGE_NUMBER
3849 PrepareCopyPage(PINPUT_RECORD Ir)
3850 {
3851 HINF InfHandle;
3852 WCHAR PathBuffer[MAX_PATH];
3853 INFCONTEXT CabinetsContext;
3854 ULONG InfFileSize;
3855 PWCHAR KeyValue;
3856 UINT ErrorLine;
3857 PVOID InfFileData;
3858
3859 MUIDisplayPage(PREPARE_COPY_PAGE);
3860
3861 /* Create the file queue */
3862 SetupFileQueue = SetupOpenFileQueue();
3863 if (SetupFileQueue == NULL)
3864 {
3865 MUIDisplayError(ERROR_COPY_QUEUE, Ir, POPUP_WAIT_ENTER);
3866 return QUIT_PAGE;
3867 }
3868
3869 if (!PrepareCopyPageInfFile(SetupInf, NULL, Ir))
3870 {
3871 /* FIXME: show an error dialog */
3872 return QUIT_PAGE;
3873 }
3874
3875 /* Search for the 'Cabinets' section */
3876 if (!SetupFindFirstLineW(SetupInf, L"Cabinets", NULL, &CabinetsContext))
3877 {
3878 return FILE_COPY_PAGE;
3879 }
3880
3881 /*
3882 * Enumerate the directory values in the 'Cabinets'
3883 * section and parse their inf files.
3884 */
3885 do
3886 {
3887 if (!INF_GetData(&CabinetsContext, NULL, &KeyValue))
3888 break;
3889
3890 CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2,
3891 USetupData.SourcePath.Buffer, KeyValue);
3892
3893 CabinetInitialize();
3894 CabinetSetEventHandlers(NULL, NULL, NULL);
3895 CabinetSetCabinetName(PathBuffer);
3896
3897 if (CabinetOpen() == CAB_STATUS_SUCCESS)
3898 {
3899 DPRINT("Cabinet %S\n", CabinetGetCabinetName());
3900
3901 InfFileData = CabinetGetCabinetReservedArea(&InfFileSize);
3902 if (InfFileData == NULL)
3903 {
3904 MUIDisplayError(ERROR_CABINET_SCRIPT, Ir, POPUP_WAIT_ENTER);
3905 return QUIT_PAGE;
3906 }
3907 }
3908 else
3909 {
3910 DPRINT("Cannot open cabinet: %S.\n", CabinetGetCabinetName());
3911 MUIDisplayError(ERROR_CABINET_MISSING, Ir, POPUP_WAIT_ENTER);
3912 return QUIT_PAGE;
3913 }
3914
3915 InfHandle = INF_OpenBufferedFileA((PSTR)InfFileData,
3916 InfFileSize,
3917 NULL,
3918 INF_STYLE_WIN4,
3919 USetupData.LanguageId,
3920 &ErrorLine);
3921
3922 if (InfHandle == INVALID_HANDLE_VALUE)
3923 {
3924 MUIDisplayError(ERROR_INVALID_CABINET_INF, Ir, POPUP_WAIT_ENTER);
3925 return QUIT_PAGE;
3926 }
3927
3928 CabinetCleanup();
3929
3930 if (!PrepareCopyPageInfFile(InfHandle, KeyValue, Ir))
3931 {
3932 /* FIXME: show an error dialog */
3933 return QUIT_PAGE;
3934 }
3935 } while (SetupFindNextLine(&CabinetsContext, &CabinetsContext));
3936
3937 return FILE_COPY_PAGE;
3938 }
3939
3940
3941 VOID
3942 NTAPI
3943 SetupUpdateMemoryInfo(IN PCOPYCONTEXT CopyContext,
3944 IN BOOLEAN First)
3945 {
3946 SYSTEM_PERFORMANCE_INFORMATION PerfInfo;
3947
3948 /* Get the memory information from the system */
3949 NtQuerySystemInformation(SystemPerformanceInformation,
3950 &PerfInfo,
3951 sizeof(PerfInfo),
3952 NULL);
3953
3954 /* Check if this is initial setup */
3955 if (First)
3956 {
3957 /* Set maximum limits to be total RAM pages */
3958 ProgressSetStepCount(CopyContext->MemoryBars[0], PerfInfo.CommitLimit);
3959 ProgressSetStepCount(CopyContext->MemoryBars[1], PerfInfo.CommitLimit);
3960 ProgressSetStepCount(CopyContext->MemoryBars[2], PerfInfo.CommitLimit);
3961 }
3962
3963 /* Set current values */
3964 ProgressSetStep(CopyContext->MemoryBars[0], PerfInfo.PagedPoolPages + PerfInfo.NonPagedPoolPages);
3965 ProgressSetStep(CopyContext->MemoryBars[1], PerfInfo.ResidentSystemCachePage);
3966 ProgressSetStep(CopyContext->MemoryBars[2], PerfInfo.AvailablePages);
3967 }
3968
3969
3970 static UINT
3971 CALLBACK
3972 FileCopyCallback(PVOID Context,
3973 UINT Notification,
3974 UINT_PTR Param1,
3975 UINT_PTR Param2)
3976 {
3977 PCOPYCONTEXT CopyContext;
3978
3979 CopyContext = (PCOPYCONTEXT)Context;
3980
3981 switch (Notification)
3982 {
3983 case SPFILENOTIFY_STARTSUBQUEUE:
3984 CopyContext->TotalOperations = (ULONG)Param2;
3985 ProgressSetStepCount(CopyContext->ProgressBar,
3986 CopyContext->TotalOperations);
3987 SetupUpdateMemoryInfo(CopyContext, TRUE);
3988 break;
3989
3990 case SPFILENOTIFY_STARTCOPY:
3991 /* Display copy message */
3992 CONSOLE_SetStatusText(MUIGetString(STRING_COPYING), (PWSTR)Param1);
3993 SetupUpdateMemoryInfo(CopyContext, FALSE);
3994 break;
3995
3996 case SPFILENOTIFY_ENDCOPY:
3997 CopyContext->CompletedOperations++;
3998
3999 /* SYSREG checkpoint */
4000 if (CopyContext->TotalOperations >> 1 == CopyContext->CompletedOperations)
4001 DPRINT1("CHECKPOINT:HALF_COPIED\n");
4002
4003 ProgressNextStep(CopyContext->ProgressBar);
4004 SetupUpdateMemoryInfo(CopyContext, FALSE);
4005 break;
4006 }
4007
4008 return 0;
4009 }
4010
4011
4012 /*
4013 * Displays the FileCopyPage.
4014 *
4015 * Next pages:
4016 * RegistryPage(At once)
4017 *
4018 * SIDEEFFECTS
4019 * Calls SetupCommitFileQueueW
4020 * Calls SetupCloseFileQueue
4021 *
4022 * RETURNS
4023 * Number of the next page.
4024 */
4025 static PAGE_NUMBER
4026 FileCopyPage(PINPUT_RECORD Ir)
4027 {
4028 COPYCONTEXT CopyContext;
4029 unsigned int mem_bar_width;
4030
4031 MUIDisplayPage(FILE_COPY_PAGE);
4032
4033 /* Create context for the copy process */
4034 CopyContext.DestinationRootPath = USetupData.DestinationRootPath.Buffer;
4035 CopyContext.InstallPath = InstallPath.Buffer;
4036 CopyContext.TotalOperations = 0;
4037 CopyContext.CompletedOperations = 0;
4038
4039 /* Create the progress bar as well */
4040 CopyContext.ProgressBar = CreateProgressBar(13,
4041 26,
4042 xScreen - 13,
4043 yScreen - 20,
4044 10,
4045 24,
4046 TRUE,
4047 MUIGetString(STRING_SETUPCOPYINGFILES));
4048
4049 // fit memory bars to screen width, distribute them uniform
4050 mem_bar_width = (xScreen - 26) / 5;
4051 mem_bar_width -= mem_bar_width % 2; // make even
4052 /* ATTENTION: The following progress bars are debug stuff, which should not be translated!! */
4053 /* Create the paged pool progress bar */
4054 CopyContext.MemoryBars[0] = CreateProgressBar(13,
4055 40,
4056 13 + mem_bar_width,
4057 43,
4058 13,
4059 44,
4060 FALSE,
4061 "Kernel Pool");
4062
4063 /* Create the non paged pool progress bar */
4064 CopyContext.MemoryBars[1] = CreateProgressBar((xScreen / 2)- (mem_bar_width / 2),
4065 40,
4066 (xScreen / 2) + (mem_bar_width / 2),
4067 43,
4068 (xScreen / 2)- (mem_bar_width / 2),
4069 44,
4070 FALSE,
4071 "Kernel Cache");
4072
4073 /* Create the global memory progress bar */
4074 CopyContext.MemoryBars[2] = CreateProgressBar(xScreen - 13 - mem_bar_width,
4075 40,
4076 xScreen - 13,
4077 43,
4078 xScreen - 13 - mem_bar_width,
4079 44,
4080 FALSE,
4081 "Free Memory");
4082
4083 /* Do the file copying */
4084 SetupCommitFileQueueW(NULL,
4085 SetupFileQueue,
4086 FileCopyCallback,
4087 &CopyContext);
4088
4089 /* If we get here, we're done, so cleanup the queue and progress bar */
4090 SetupCloseFileQueue(SetupFileQueue);
4091 DestroyProgressBar(CopyContext.ProgressBar);
4092 DestroyProgressBar(CopyContext.MemoryBars[0]);
4093 DestroyProgressBar(CopyContext.MemoryBars[1]);
4094 DestroyProgressBar(CopyContext.MemoryBars[2]);
4095
4096 /* Create the $winnt$.inf file */
4097 InstallSetupInfFile(&USetupData);
4098
4099 /* Go display the next page */
4100 return REGISTRY_PAGE;
4101 }
4102
4103
4104 static VOID
4105 __cdecl
4106 RegistryStatus(IN REGISTRY_STATUS RegStatus, ...)
4107 {
4108 /* WARNING: Please keep this lookup table in sync with the resources! */
4109 static const UINT StringIDs[] =
4110 {
4111 STRING_DONE, /* Success */
4112 STRING_REGHIVEUPDATE, /* RegHiveUpdate */
4113 STRING_IMPORTFILE, /* ImportRegHive */
4114 STRING_DISPLAYSETTINGSUPDATE, /* DisplaySettingsUpdate */
4115 STRING_LOCALESETTINGSUPDATE, /* LocaleSettingsUpdate */
4116 STRING_ADDKBLAYOUTS, /* KeybLayouts */
4117 STRING_KEYBOARDSETTINGSUPDATE, /* KeybSettingsUpdate */
4118 STRING_CODEPAGEINFOUPDATE, /* CodePageInfoUpdate */
4119 };
4120
4121 va_list args;
4122
4123 if (RegStatus < ARRAYSIZE(StringIDs))
4124 {
4125 va_start(args, RegStatus);
4126 CONSOLE_SetStatusTextV(MUIGetString(StringIDs[RegStatus]), args);
4127 va_end(args);
4128 }
4129 else
4130 {
4131 CONSOLE_SetStatusText("Unknown status %d", RegStatus);
4132 }
4133 }
4134
4135 /*
4136 * Displays the RegistryPage.
4137 *
4138 * Next pages:
4139 * SuccessPage (if RepairUpdate)
4140 * BootLoaderPage (default)
4141 * QuitPage
4142 *
4143 * SIDEEFFECTS
4144 * Calls UpdateRegistry
4145 *
4146 * RETURNS
4147 * Number of the next page.
4148 */
4149 static PAGE_NUMBER
4150 RegistryPage(PINPUT_RECORD Ir)
4151 {
4152 ULONG Error;
4153
4154 MUIDisplayPage(REGISTRY_PAGE);
4155
4156 Error = UpdateRegistry(SetupInf,
4157 &USetupData,
4158 RepairUpdateFlag,
4159 PartitionList,
4160 DestinationDriveLetter,
4161 SelectedLanguageId,
4162 DisplayList,
4163 LayoutList,
4164 LanguageList,
4165 RegistryStatus);
4166 if (Error != ERROR_SUCCESS)
4167 {
4168 MUIDisplayError(Error, Ir, POPUP_WAIT_ENTER);
4169 return QUIT_PAGE;
4170 }
4171 else
4172 {
4173 CONSOLE_SetStatusText(MUIGetString(STRING_DONE));
4174 return BOOT_LOADER_PAGE;
4175 }
4176 }
4177
4178
4179 /*
4180 * Displays the BootLoaderPage.
4181 *
4182 * Next pages:
4183 * SuccessPage (if RepairUpdate)
4184 * BootLoaderHarddiskMbrPage
4185 * BootLoaderHarddiskVbrPage
4186 * BootLoaderFloppyPage
4187 * SuccessPage
4188 * QuitPage
4189 *
4190 * SIDEEFFECTS
4191 * Calls RegInitializeRegistry
4192 * Calls ImportRegistryFile
4193 * Calls SetDefaultPagefile
4194 * Calls SetMountedDeviceValues
4195 *
4196 * RETURNS
4197 * Number of the next page.
4198 */
4199 static PAGE_NUMBER
4200 BootLoaderPage(PINPUT_RECORD Ir)
4201 {
4202 UCHAR PartitionType;
4203 BOOLEAN InstallOnFloppy;
4204 USHORT Line = 12;
4205 WCHAR PathBuffer[MAX_PATH];
4206
4207 CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
4208
4209 RtlFreeUnicodeString(&USetupData.SystemRootPath);
4210 RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
4211 L"\\Device\\Harddisk%lu\\Partition%lu\\",
4212 PartitionList->SystemPartition->DiskEntry->DiskNumber,
4213 PartitionList->SystemPartition->PartitionNumber);
4214 RtlCreateUnicodeString(&USetupData.SystemRootPath, PathBuffer);
4215 DPRINT1("SystemRootPath: %wZ\n", &USetupData.SystemRootPath);
4216
4217 PartitionType = PartitionList->SystemPartition->PartitionType;
4218
4219 /* For unattended setup, skip MBR installation or install on floppy if needed */
4220 if (IsUnattendedSetup)
4221 {
4222 if ((USetupData.MBRInstallType == 0) ||
4223 (USetupData.MBRInstallType == 1))
4224 {
4225 goto Quit;
4226 }
4227 }
4228
4229 /*
4230 * We may install an MBR or VBR, but before that, check whether
4231 * we need to actually install the VBR on floppy.
4232 */
4233 if (PartitionType == PARTITION_ENTRY_UNUSED)
4234 {
4235 DPRINT("Error: system partition invalid (unused)\n");
4236 InstallOnFloppy = TRUE;
4237 }
4238 else if (PartitionType == PARTITION_OS2BOOTMGR)
4239 {
4240 /* OS/2 boot manager partition */
4241 DPRINT("Found OS/2 boot manager partition\n");
4242 InstallOnFloppy = TRUE;
4243 }
4244 else if (PartitionType == PARTITION_EXT2)
4245 {
4246 /* Linux EXT2 partition */
4247 DPRINT("Found Linux EXT2 partition\n");
4248 InstallOnFloppy = FALSE;
4249 }
4250 else if (PartitionType == PARTITION_IFS)
4251 {
4252 /* NTFS partition */
4253 DPRINT("Found NTFS partition\n");
4254
4255 // FIXME: Make it FALSE when we'll support NTFS installation!
4256 InstallOnFloppy = TRUE;
4257 }
4258 else if ((PartitionType == PARTITION_FAT_12) ||
4259 (PartitionType == PARTITION_FAT_16) ||
4260 (PartitionType == PARTITION_HUGE) ||
4261 (PartitionType == PARTITION_XINT13) ||
4262 (PartitionType == PARTITION_FAT32) ||
4263 (PartitionType == PARTITION_FAT32_XINT13))
4264 {
4265 DPRINT("Found FAT partition\n");
4266 InstallOnFloppy = FALSE;
4267 }
4268 else
4269 {
4270 /* Unknown partition */
4271 DPRINT("Unknown partition found\n");
4272 InstallOnFloppy = TRUE;
4273 }
4274
4275 /* We should install on floppy */
4276 if (InstallOnFloppy)
4277 {
4278 USetupData.MBRInstallType = 1;
4279 goto Quit;
4280 }
4281
4282 /* Is it an unattended install on hdd? */
4283 if (IsUnattendedSetup)
4284 {
4285 if ((USetupData.MBRInstallType == 2) ||
4286 (USetupData.MBRInstallType == 3))
4287 {
4288 goto Quit;
4289 }
4290 }
4291
4292 MUIDisplayPage(BOOT_LOADER_PAGE);
4293 CONSOLE_InvertTextXY(8, Line, 60, 1);
4294
4295 while (TRUE)
4296 {
4297 CONSOLE_ConInKey(Ir);
4298
4299 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
4300 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DOWN)) /* DOWN */
4301 {
4302 CONSOLE_NormalTextXY(8, Line, 60, 1);
4303
4304 Line++;
4305 if (Line < 12)
4306 Line = 15;
4307
4308 if (Line > 15)
4309 Line = 12;
4310
4311 CONSOLE_InvertTextXY(8, Line, 60, 1);
4312 }
4313 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
4314 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_UP)) /* UP */
4315 {
4316 CONSOLE_NormalTextXY(8, Line, 60, 1);
4317
4318 Line--;
4319 if (Line < 12)
4320 Line = 15;
4321
4322 if (Line > 15)
4323 Line = 12;
4324
4325 CONSOLE_InvertTextXY(8, Line, 60, 1);
4326 }
4327 else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
4328 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
4329 {
4330 if (ConfirmQuit(Ir))
4331 return QUIT_PAGE;
4332
4333 break;
4334 }
4335 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
4336 {
4337 if (Line == 12)
4338 {
4339 /* Install on both MBR and VBR */
4340 USetupData.MBRInstallType = 2;
4341 break;
4342 }
4343 else if (Line == 13)
4344 {
4345 /* Install on VBR only */
4346 USetupData.MBRInstallType = 3;
4347 break;
4348 }
4349 else if (Line == 14)
4350 {
4351 /* Install on floppy */
4352 USetupData.MBRInstallType = 1;
4353 break;
4354 }
4355 else if (Line == 15)
4356 {
4357 /* Skip MBR installation */
4358 USetupData.MBRInstallType = 0;
4359 break;
4360 }
4361
4362 return BOOT_LOADER_PAGE;
4363 }
4364 }
4365
4366 Quit:
4367 switch (USetupData.MBRInstallType)
4368 {
4369 /* Skip MBR installation */
4370 case 0:
4371 return SUCCESS_PAGE;
4372
4373 /* Install on floppy */
4374 case 1:
4375 return BOOT_LOADER_FLOPPY_PAGE;
4376
4377 /* Install on both MBR and VBR */
4378 case 2:
4379 return BOOT_LOADER_HARDDISK_MBR_PAGE;
4380
4381 /* Install on VBR only */
4382 case 3:
4383 return BOOT_LOADER_HARDDISK_VBR_PAGE;
4384 }
4385
4386 return BOOT_LOADER_PAGE;
4387 }
4388
4389
4390 /*
4391 * Displays the BootLoaderFloppyPage.
4392 *
4393 * Next pages:
4394 * SuccessPage (At once)
4395 * QuitPage
4396 *
4397 * SIDEEFFECTS
4398 * Calls InstallFatBootcodeToFloppy()
4399 *
4400 * RETURNS
4401 * Number of the next page.
4402 */
4403 static PAGE_NUMBER
4404 BootLoaderFloppyPage(PINPUT_RECORD Ir)
4405 {
4406 NTSTATUS Status;
4407
4408 MUIDisplayPage(BOOT_LOADER_FLOPPY_PAGE);
4409
4410 // CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
4411
4412 while (TRUE)
4413 {
4414 CONSOLE_ConInKey(Ir);
4415
4416 if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
4417 (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
4418 {
4419 if (ConfirmQuit(Ir))
4420 return QUIT_PAGE;
4421
4422 break;
4423 }
4424 else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
4425 {
4426 Status = InstallFatBootcodeToFloppy(&USetupData.SourceRootPath,
4427 &USetupData.DestinationArcPath);
4428 if (!NT_SUCCESS(Status))
4429 {
4430 if (Status == STATUS_DEVICE_NOT_READY)
4431 MUIDisplayError(ERROR_NO_FLOPPY, Ir, POPUP_WAIT_ENTER);
4432
4433 /* TODO: Print error message */
4434 return BOOT_LOADER_FLOPPY_PAGE;
4435 }
4436
4437 return SUCCESS_PAGE;
4438 }
4439 }
4440
4441 return BOOT_LOADER_FLOPPY_PAGE;
4442 }
4443
4444
4445 /*
4446 * Displays the BootLoaderHarddiskVbrPage.
4447 *
4448 * Next pages:
4449 * SuccessPage (At once)
4450 * QuitPage
4451 *
4452 * SIDEEFFECTS
4453 * Calls InstallVBRToPartition()
4454 *
4455 * RETURNS
4456 * Number of the next page.
4457 */
4458 static PAGE_NUMBER
4459 BootLoaderHarddiskVbrPage(PINPUT_RECORD Ir)
4460 {
4461 NTSTATUS Status;
4462
4463 Status = InstallVBRToPartition(&USetupData.SystemRootPath,
4464 &USetupData.SourceRootPath,
4465 &USetupData.DestinationArcPath,
4466 PartitionList->SystemPartition->PartitionType);
4467 if (!NT_SUCCESS(Status))
4468 {
4469 MUIDisplayError(ERROR_WRITE_BOOT, Ir, POPUP_WAIT_ENTER);
4470 return QUIT_PAGE;
4471 }
4472
4473 return SUCCESS_PAGE;
4474 }
4475
4476
4477 /*
4478 * Displays the BootLoaderHarddiskMbrPage.
4479 *
4480 * Next pages:
4481 * SuccessPage (At once)
4482 * QuitPage
4483 *
4484 * SIDEEFFECTS
4485 * Calls InstallVBRToPartition()
4486 * Calls InstallMbrBootCodeToDisk()
4487 *
4488 * RETURNS
4489 * Number of the next page.
4490 */
4491 static PAGE_NUMBER
4492 BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir)
4493 {
4494 NTSTATUS Status;
4495 WCHAR DestinationDevicePathBuffer[MAX_PATH];
4496
4497 /* Step 1: Write the VBR */
4498 Status = InstallVBRToPartition(&USetupData.SystemRootPath,
4499 &USetupData.SourceRootPath,
4500 &USetupData.DestinationArcPath,
4501 PartitionList->SystemPartition->PartitionType);
4502 if (!NT_SUCCESS(Status))
4503 {
4504 MUIDisplayError(ERROR_WRITE_BOOT, Ir, POPUP_WAIT_ENTER);
4505 return QUIT_PAGE;
4506 }
4507
4508 /* Step 2: Write the MBR */
4509 RtlStringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer),
4510 L"\\Device\\Harddisk%d\\Partition0",
4511 PartitionList->SystemPartition->DiskEntry->DiskNumber);
4512 Status = InstallMbrBootCodeToDisk(&USetupData.SystemRootPath,
4513 &USetupData.SourceRootPath,
4514 DestinationDevicePathBuffer);
4515 if (!NT_SUCCESS(Status))
4516 {
4517 DPRINT1("InstallMbrBootCodeToDisk() failed (Status %lx)\n", Status);
4518 MUIDisplayError(ERROR_INSTALL_BOOTCODE, Ir, POPUP_WAIT_ENTER);
4519 return QUIT_PAGE;
4520 }
4521
4522 return SUCCESS_PAGE;
4523 }
4524
4525
4526 /**
4527 * @name ProgressTimeOutStringHandler
4528 *
4529 * Handles the generation (displaying) of the timeout
4530 * countdown to the screen dynamically.
4531 *
4532 * @param Bar
4533 * A pointer to a progress bar.
4534 *
4535 * @param AlwaysUpdate
4536 * Constantly update the progress bar (boolean type).
4537 *
4538 * @param Buffer
4539 * A pointer to a string buffer.
4540 *
4541 * @param cchBufferSize
4542 * The buffer's size in number of characters.
4543 *
4544 * @return
4545 * TRUE or FALSE on function termination.
4546 *
4547 */
4548 static
4549 BOOLEAN NTAPI
4550 ProgressTimeOutStringHandler(
4551 IN PPROGRESSBAR Bar,
4552 IN BOOLEAN AlwaysUpdate,
4553 OUT PSTR Buffer,
4554 IN SIZE_T cchBufferSize)
4555 {
4556 ULONG OldProgress = Bar->Progress;
4557
4558 if (Bar->StepCount == 0)
4559 {
4560 Bar->Progress = 0;
4561 }
4562 else
4563 {
4564 Bar->Progress = Bar->StepCount - Bar->CurrentStep;
4565 }
4566
4567 /* Build the progress string if it has changed */
4568 if (Bar->ProgressFormatText &&
4569 (AlwaysUpdate || (Bar->Progress != OldProgress)))
4570 {
4571 RtlStringCchPrintfA(Buffer, cchBufferSize,
4572 Bar->ProgressFormatText, Bar->Progress / max(1, Bar->Width) + 1);
4573
4574 return TRUE;
4575 }
4576
4577 return FALSE;
4578 }
4579
4580 /**
4581 * @name ProgressCountdown
4582 *
4583 * Displays and draws a red-coloured progress bar with a countdown.
4584 * When the timeout is reached, the flush page is displayed for reboot.
4585 *
4586 * @param Ir
4587 * A pointer to an input keyboard record.
4588 *
4589 * @param TimeOut
4590 * Initial countdown value in seconds.
4591 *
4592 * @return
4593 * Nothing.
4594 *
4595 */
4596 static VOID
4597 ProgressCountdown(
4598 IN PINPUT_RECORD Ir,
4599 IN LONG TimeOut)
4600 {
4601 NTSTATUS Status;
4602 ULONG StartTime, BarWidth, TimerDiv;
4603 LONG TimeElapsed;
4604 LONG TimerValue, OldTimerValue;
4605 LARGE_INTEGER Timeout;
4606 PPROGRESSBAR ProgressBar;
4607 BOOLEAN RefreshProgress = TRUE;
4608
4609 /* Bail out if the timeout is already zero */
4610 if (TimeOut <= 0)
4611 return;
4612
4613 /* Create the timeout progress bar and set it up */
4614 ProgressBar = CreateProgressBarEx(13,
4615 26,
4616 xScreen - 13,
4617 yScreen - 20,
4618 10,
4619 24,
4620 TRUE,
4621 FOREGROUND_RED | BACKGROUND_BLUE,
4622 0,
4623 NULL,
4624 MUIGetString(STRING_REBOOTPROGRESSBAR),
4625 ProgressTimeOutStringHandler);
4626
4627 BarWidth = max(1, ProgressBar->Width);
4628 TimerValue = TimeOut * BarWidth;
4629 ProgressSetStepCount(ProgressBar, TimerValue);
4630
4631 StartTime = NtGetTickCount();
4632 CONSOLE_Flush();
4633
4634 TimerDiv = 1000 / BarWidth;
4635 TimerDiv = max(1, TimerDiv);
4636 OldTimerValue = TimerValue;
4637 while (TRUE)
4638 {
4639 /* Decrease the timer */
4640
4641 /*
4642 * Compute how much time the previous operations took.
4643 * This allows us in particular to take account for any time
4644 * elapsed if something slowed down.
4645 */
4646 TimeElapsed = NtGetTickCount() - StartTime;
4647 if (TimeElapsed >= TimerDiv)
4648 {
4649 /* Increase StartTime by steps of 1 / ProgressBar->Width seconds */
4650 TimeElapsed /= TimerDiv;
4651 StartTime += (TimerDiv * TimeElapsed);
4652
4653 if (TimeElapsed <= TimerValue)
4654 TimerValue -= TimeElapsed;
4655 else
4656 TimerValue = 0;
4657
4658 RefreshProgress = TRUE;
4659 }
4660
4661 if (RefreshProgress)
4662 {
4663 ProgressSetStep(ProgressBar, OldTimerValue - TimerValue);
4664 RefreshProgress = FALSE;
4665 }
4666
4667 /* Stop when the timer reaches zero */
4668 if (TimerValue <= 0)
4669 break;
4670
4671 /* Check for user key presses */
4672
4673 /*
4674 * If the timer is used, use a passive wait of maximum 1 second
4675 * while monitoring for incoming console input events, so that
4676 * we are still able to display the timing count.
4677 */
4678
4679 /* Wait a maximum of 1 second for input events */
4680 TimeElapsed = NtGetTickCount() - StartTime;
4681 if (TimeElapsed < TimerDiv)
4682 {
4683 /* Convert the time to NT Format */
4684 Timeout.QuadPart = (TimerDiv - TimeElapsed) * -10000LL;
4685 Status = NtWaitForSingleObject(StdInput, FALSE, &Timeout);
4686 }
4687 else
4688 {
4689 Status = STATUS_TIMEOUT;
4690 }
4691
4692 /* Check whether the input event has been signaled, or a timeout happened */
4693 if (Status == STATUS_TIMEOUT)
4694 {
4695 continue;
4696 }
4697 if (Status != STATUS_WAIT_0)
4698 {
4699 /* An error happened, bail out */
4700 DPRINT1("NtWaitForSingleObject() failed, Status 0x%08lx\n", Status);
4701 break;
4702 }
4703
4704 /* Check for an ENTER key press */
4705 while (CONSOLE_ConInKeyPeek(Ir))
4706 {
4707 if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
4708 {
4709 /* Found it, stop waiting */
4710 goto Exit;
4711 }
4712 }
4713 }
4714
4715 Exit:
4716 /* Destroy the progress bar and quit */
4717 DestroyProgressBar(ProgressBar);
4718 }
4719
4720
4721 /*
4722 * Displays the QuitPage.
4723 *
4724 * Next pages:
4725 * FlushPage (At once)
4726 *
4727 * SIDEEFFECTS
4728 * Destroy the Lists
4729 *
4730 * RETURNS
4731 * Number of the next page.
4732 */
4733 static PAGE_NUMBER
4734 QuitPage(PINPUT_RECORD Ir)
4735 {
4736 MUIDisplayPage(QUIT_PAGE);
4737
4738 /* Destroy the NTOS installations list */
4739 if (NtOsInstallsList != NULL)
4740 {
4741 DestroyGenericList(NtOsInstallsList, TRUE);
4742 NtOsInstallsList = NULL;
4743 }
4744
4745 /* Destroy the partition list */
4746 if (PartitionList != NULL)
4747 {
4748 DestroyPartitionList(PartitionList);
4749 PartitionList = NULL;
4750 }
4751 TempPartition = NULL;
4752 FormatState = Start;
4753
4754 /* Destroy the filesystem list */
4755 if (FileSystemList != NULL)
4756 {
4757 DestroyFileSystemList(FileSystemList);
4758 FileSystemList = NULL;
4759 }
4760
4761 /* Destroy the computer settings list */
4762 if (ComputerList != NULL)
4763 {
4764 DestroyGenericList(ComputerList, TRUE);
4765 ComputerList = NULL;
4766 }
4767
4768 /* Destroy the display settings list */
4769 if (DisplayList != NULL)
4770 {
4771 DestroyGenericList(DisplayList, TRUE);
4772 DisplayList = NULL;
4773 }
4774
4775 /* Destroy the keyboard settings list */
4776 if (KeyboardList != NULL)
4777 {
4778 DestroyGenericList(KeyboardList, TRUE);
4779 KeyboardList = NULL;
4780 }
4781
4782 /* Destroy the keyboard layout list */
4783 if (LayoutList != NULL)
4784 {
4785 DestroyGenericList(LayoutList, TRUE);
4786 LayoutList = NULL;
4787 }
4788
4789 /* Destroy the languages list */
4790 if (LanguageList != NULL)
4791 {
4792 DestroyGenericList(LanguageList, FALSE);
4793 LanguageList = NULL;
4794 }
4795
4796 CONSOLE_SetStatusText(MUIGetString(STRING_REBOOTCOMPUTER2));
4797
4798 /* Wait for maximum 15 seconds or an ENTER key before quitting */
4799 ProgressCountdown(Ir, 15);
4800 return FLUSH_PAGE;
4801 }
4802
4803
4804 /*
4805 * Displays the SuccessPage.
4806 *
4807 * Next pages:
4808 * FlushPage (At once)
4809 *
4810 * SIDEEFFECTS
4811 * Destroy the Lists
4812 *
4813 * RETURNS
4814 * Number of the next page.
4815 */
4816 static PAGE_NUMBER
4817 SuccessPage(PINPUT_RECORD Ir)
4818 {
4819 MUIDisplayPage(SUCCESS_PAGE);
4820
4821 if (IsUnattendedSetup)
4822 return FLUSH_PAGE;
4823
4824 /* Wait for maximum 15 seconds or an ENTER key before quitting */
4825 ProgressCountdown(Ir, 15);
4826 return FLUSH_PAGE;
4827 }
4828
4829
4830 /*
4831 * Displays the FlushPage.
4832 *
4833 * Next pages:
4834 * RebootPage (At once)
4835 *
4836 * RETURNS
4837 * Number of the next page.
4838 */
4839 static PAGE_NUMBER
4840 FlushPage(PINPUT_RECORD Ir)
4841 {
4842 MUIDisplayPage(FLUSH_PAGE);
4843 return REBOOT_PAGE;
4844 }
4845
4846
4847 DWORD WINAPI
4848 PnpEventThread(IN LPVOID lpParameter);
4849
4850
4851 /*
4852 * The start routine and page management
4853 */
4854 NTSTATUS
4855 RunUSetup(VOID)
4856 {
4857 NTSTATUS Status;
4858 INPUT_RECORD Ir;
4859 PAGE_NUMBER Page;
4860 BOOLEAN Old;
4861
4862 InfSetHeap(ProcessHeap);
4863
4864 /* Tell the Cm this is a setup boot, and it has to behave accordingly */
4865 Status = NtInitializeRegistry(CM_BOOT_FLAG_SETUP);
4866 if (!NT_SUCCESS(Status))
4867 DPRINT1("NtInitializeRegistry() failed (Status 0x%08lx)\n", Status);
4868
4869 /* Create the PnP thread in suspended state */
4870 Status = RtlCreateUserThread(NtCurrentProcess(),
4871 NULL,
4872 TRUE,
4873 0,
4874 0,
4875 0,
4876 PnpEventThread,
4877 &SetupInf,
4878 &hPnpThread,
4879 NULL);
4880 if (!NT_SUCCESS(Status))
4881 hPnpThread = NULL;
4882
4883 if (!CONSOLE_Init())
4884 {
4885 PrintString(MUIGetString(STRING_CONSOLEFAIL1));
4886 PrintString(MUIGetString(STRING_CONSOLEFAIL2));
4887 PrintString(MUIGetString(STRING_CONSOLEFAIL3));
4888
4889 /* We failed to initialize the video, just quit the installer */
4890 return STATUS_APP_INIT_FAILURE;
4891 }
4892
4893 /* Initialize global unicode strings */
4894 RtlInitUnicodeString(&USetupData.SourcePath, NULL);
4895 RtlInitUnicodeString(&USetupData.SourceRootPath, NULL);
4896 RtlInitUnicodeString(&USetupData.SourceRootDir, NULL);
4897 RtlInitUnicodeString(&InstallPath, NULL);
4898 RtlInitUnicodeString(&USetupData.DestinationPath, NULL);
4899 RtlInitUnicodeString(&USetupData.DestinationArcPath, NULL);
4900 RtlInitUnicodeString(&USetupData.DestinationRootPath, NULL);
4901 RtlInitUnicodeString(&USetupData.SystemRootPath, NULL);
4902
4903 /* Hide the cursor */
4904 CONSOLE_SetCursorType(TRUE, FALSE);
4905
4906 /* Global Initialization page */
4907 CONSOLE_ClearScreen();
4908 CONSOLE_Flush();
4909 Page = SetupStartPage(&Ir);
4910
4911 while (Page != REBOOT_PAGE && Page != RECOVERY_PAGE)
4912 {
4913 CONSOLE_ClearScreen();
4914 CONSOLE_Flush();
4915
4916 // CONSOLE_SetUnderlinedTextXY(4, 3, " ReactOS " KERNEL_VERSION_STR " Setup ");
4917 // CONSOLE_Flush();
4918
4919 switch (Page)
4920 {
4921 /* Language page */
4922 case LANGUAGE_PAGE:
4923 Page = LanguagePage(&Ir);
4924 break;
4925
4926 /* Welcome page */
4927 case WELCOME_PAGE:
4928 Page = WelcomePage(&Ir);
4929 break;
4930
4931 /* License page */
4932 case LICENSE_PAGE:
4933 Page = LicensePage(&Ir);
4934 break;
4935
4936 /* Install pages */
4937 case INSTALL_INTRO_PAGE:
4938 Page = InstallIntroPage(&Ir);
4939 break;
4940
4941 #if 0
4942 case SCSI_CONTROLLER_PAGE:
4943 Page = ScsiControllerPage(&Ir);
4944 break;
4945
4946 case OEM_DRIVER_PAGE:
4947 Page = OemDriverPage(&Ir);
4948 break;
4949 #endif
4950
4951 case DEVICE_SETTINGS_PAGE:
4952 Page = DeviceSettingsPage(&Ir);
4953 break;
4954
4955 case COMPUTER_SETTINGS_PAGE:
4956 Page = ComputerSettingsPage(&Ir);
4957 break;
4958
4959 case DISPLAY_SETTINGS_PAGE:
4960 Page = DisplaySettingsPage(&Ir);
4961 break;
4962
4963 case KEYBOARD_SETTINGS_PAGE:
4964 Page = KeyboardSettingsPage(&Ir);
4965 break;
4966
4967 case LAYOUT_SETTINGS_PAGE:
4968 Page = LayoutSettingsPage(&Ir);
4969 break;
4970
4971 case SELECT_PARTITION_PAGE:
4972 Page = SelectPartitionPage(&Ir);
4973 break;
4974
4975 case CREATE_PRIMARY_PARTITION_PAGE:
4976 Page = CreatePrimaryPartitionPage(&Ir);
4977 break;
4978
4979 case CREATE_EXTENDED_PARTITION_PAGE:
4980 Page = CreateExtendedPartitionPage(&Ir);
4981 break;
4982
4983 case CREATE_LOGICAL_PARTITION_PAGE:
4984 Page = CreateLogicalPartitionPage(&Ir);
4985 break;
4986
4987 case CONFIRM_DELETE_SYSTEM_PARTITION_PAGE:
4988 Page = ConfirmDeleteSystemPartitionPage(&Ir);
4989 break;
4990
4991 case DELETE_PARTITION_PAGE:
4992 Page = DeletePartitionPage(&Ir);
4993 break;
4994
4995 case SELECT_FILE_SYSTEM_PAGE:
4996 Page = SelectFileSystemPage(&Ir);
4997 break;
4998
4999 case FORMAT_PARTITION_PAGE:
5000 Page = FormatPartitionPage(&Ir);
5001 break;
5002
5003 case CHECK_FILE_SYSTEM_PAGE:
5004 Page = CheckFileSystemPage(&Ir);
5005 break;
5006
5007 case INSTALL_DIRECTORY_PAGE:
5008 Page = InstallDirectoryPage(&Ir);
5009 break;
5010
5011 case PREPARE_COPY_PAGE:
5012 Page = PrepareCopyPage(&Ir);
5013 break;
5014
5015 case FILE_COPY_PAGE:
5016 Page = FileCopyPage(&Ir);
5017 break;
5018
5019 case REGISTRY_PAGE:
5020 Page = RegistryPage(&Ir);
5021 break;
5022
5023 case BOOT_LOADER_PAGE:
5024 Page = BootLoaderPage(&Ir);
5025 break;
5026
5027 case BOOT_LOADER_FLOPPY_PAGE:
5028 Page = BootLoaderFloppyPage(&Ir);
5029 break;
5030
5031 case BOOT_LOADER_HARDDISK_MBR_PAGE:
5032 Page = BootLoaderHarddiskMbrPage(&Ir);
5033 break;
5034
5035 case BOOT_LOADER_HARDDISK_VBR_PAGE:
5036 Page = BootLoaderHarddiskVbrPage(&Ir);
5037 break;
5038
5039 /* Repair pages */
5040 case REPAIR_INTRO_PAGE:
5041 Page = RepairIntroPage(&Ir);
5042 break;
5043
5044 case UPGRADE_REPAIR_PAGE:
5045 Page = UpgradeRepairPage(&Ir);
5046 break;
5047
5048 case SUCCESS_PAGE:
5049 Page = SuccessPage(&Ir);
5050 break;
5051
5052 case FLUSH_PAGE:
5053 Page = FlushPage(&Ir);
5054 break;
5055
5056 case QUIT_PAGE:
5057 Page = QuitPage(&Ir);
5058 break;
5059
5060 case RECOVERY_PAGE:
5061 case REBOOT_PAGE:
5062 break;
5063 }
5064 }
5065
5066 SetupCloseInfFile(SetupInf);
5067
5068 if (Page == RECOVERY_PAGE)
5069 RecoveryConsole();
5070
5071 FreeConsole();
5072
5073 /* Reboot */
5074 RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, TRUE, FALSE, &Old);
5075 NtShutdownSystem(ShutdownReboot);
5076 RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, Old, FALSE, &Old);
5077
5078 return STATUS_SUCCESS;
5079 }
5080
5081
5082 VOID NTAPI
5083 NtProcessStartup(PPEB Peb)
5084 {
5085 NTSTATUS Status;
5086 LARGE_INTEGER Time;
5087
5088 RtlNormalizeProcessParams(Peb->ProcessParameters);
5089
5090 ProcessHeap = Peb->ProcessHeap;
5091
5092 NtQuerySystemTime(&Time);
5093
5094 Status = RunUSetup();
5095
5096 if (NT_SUCCESS(Status))
5097 {
5098 /*
5099 * Avoid a bugcheck if RunUSetup() finishes too quickly by implementing
5100 * a protective waiting.
5101 * This wait is needed because, since we are started as SMSS.EXE,
5102 * the NT kernel explicitly waits 5 seconds for the initial process
5103 * SMSS.EXE to initialize (as a protective measure), and otherwise
5104 * bugchecks with the code SESSION5_INITIALIZATION_FAILED.
5105 */
5106 Time.QuadPart += 50000000;
5107 NtDelayExecution(FALSE, &Time);
5108 }
5109 else
5110 {
5111 /* The installer failed to start: raise a hard error (crash the system/BSOD) */
5112 Status = NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED,
5113 0, 0, NULL, 0, NULL);
5114 }
5115
5116 NtTerminateProcess(NtCurrentProcess(), Status);
5117 }
5118
5119 /* EOF */