xref: /haiku/src/apps/bootmanager/BootManagerController.cpp (revision 2824c5d3a428b1f52fb41e7cf84ef1690cfadc80)
1b76ca311SAxel Dörfler /*
2197f59b0SAxel Dörfler  * Copyright 2008-2011, Haiku, Inc. All rights reserved.
3b76ca311SAxel Dörfler  * Distributed under the terms of the MIT License.
4b76ca311SAxel Dörfler  *
5b76ca311SAxel Dörfler  * Authors:
649c044abSAxel Dörfler  *		Axel Dörfler, axeld@pinc-software.de
7b76ca311SAxel Dörfler  *		Michael Pfeiffer <laplace@users.sourceforge.net>
8b76ca311SAxel Dörfler  */
9b76ca311SAxel Dörfler 
10b76ca311SAxel Dörfler 
11b76ca311SAxel Dörfler #include "BootManagerController.h"
12b76ca311SAxel Dörfler 
13b76ca311SAxel Dörfler #include <Alert.h>
14b76ca311SAxel Dörfler #include <Application.h>
15b76ca311SAxel Dörfler #include <Catalog.h>
16b76ca311SAxel Dörfler #include <File.h>
17b76ca311SAxel Dörfler #include <FindDirectory.h>
18b76ca311SAxel Dörfler #include <Locale.h>
19b76ca311SAxel Dörfler #include <Path.h>
20b76ca311SAxel Dörfler #include <String.h>
21b76ca311SAxel Dörfler 
2249c044abSAxel Dörfler #include "BootDrive.h"
23b76ca311SAxel Dörfler #include "DefaultPartitionPage.h"
24b76ca311SAxel Dörfler #include "DescriptionPage.h"
255675f44eSAxel Dörfler #include "DrivesPage.h"
26b76ca311SAxel Dörfler #include "FileSelectionPage.h"
275675f44eSAxel Dörfler #include "LegacyBootMenu.h"
28b76ca311SAxel Dörfler #include "PartitionsPage.h"
29b76ca311SAxel Dörfler #include "WizardView.h"
30b76ca311SAxel Dörfler 
31b76ca311SAxel Dörfler 
32546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
33546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "BootManagerController"
34b76ca311SAxel Dörfler 
35b76ca311SAxel Dörfler 
BootManagerController()36b76ca311SAxel Dörfler BootManagerController::BootManagerController()
3749c044abSAxel Dörfler 	:
3849c044abSAxel Dörfler 	fBootDrive(NULL),
3949c044abSAxel Dörfler 	fBootMenu(NULL)
40b76ca311SAxel Dörfler {
41b76ca311SAxel Dörfler 	// set defaults
42b76ca311SAxel Dörfler 	fSettings.AddBool("install", true);
43b76ca311SAxel Dörfler 	fSettings.AddInt32("defaultPartition", 0);
44b76ca311SAxel Dörfler 	fSettings.AddInt32("timeout", -1);
45b76ca311SAxel Dörfler 
46b76ca311SAxel Dörfler 	BPath path;
47b76ca311SAxel Dörfler 	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) {
48b76ca311SAxel Dörfler 		path.Append("bootman/MBR");
49b76ca311SAxel Dörfler 		fSettings.AddString("file", path.Path());
50b76ca311SAxel Dörfler 		// create directory
51b76ca311SAxel Dörfler 		BPath parent;
52b76ca311SAxel Dörfler 		if (path.GetParent(&parent) == B_OK) {
53b76ca311SAxel Dörfler 			BDirectory directory;
54b76ca311SAxel Dörfler 			directory.CreateDirectory(parent.Path(), NULL);
55b76ca311SAxel Dörfler 		}
56b76ca311SAxel Dörfler 	} else {
57b76ca311SAxel Dörfler 		fSettings.AddString("file", "");
58b76ca311SAxel Dörfler 	}
59b76ca311SAxel Dörfler 
6049c044abSAxel Dörfler 	// That's the only boot menu we support at the moment.
6149c044abSAxel Dörfler 	fBootMenus.AddItem(new LegacyBootMenu());
62b76ca311SAxel Dörfler }
63b76ca311SAxel Dörfler 
64b76ca311SAxel Dörfler 
~BootManagerController()65b76ca311SAxel Dörfler BootManagerController::~BootManagerController()
66b76ca311SAxel Dörfler {
67b76ca311SAxel Dörfler }
68b76ca311SAxel Dörfler 
69b76ca311SAxel Dörfler 
705675f44eSAxel Dörfler void
Previous(WizardView * wizard)715675f44eSAxel Dörfler BootManagerController::Previous(WizardView* wizard)
725675f44eSAxel Dörfler {
735675f44eSAxel Dörfler 	if (CurrentState() != kStateEntry)
745675f44eSAxel Dörfler 		WizardController::Previous(wizard);
755675f44eSAxel Dörfler 	else {
765675f44eSAxel Dörfler 		fSettings.ReplaceBool("install", false);
7749c044abSAxel Dörfler 		WizardController::Next(wizard);
785675f44eSAxel Dörfler 	}
795675f44eSAxel Dörfler }
805675f44eSAxel Dörfler 
815675f44eSAxel Dörfler 
82b76ca311SAxel Dörfler int32
InitialState()83b76ca311SAxel Dörfler BootManagerController::InitialState()
84b76ca311SAxel Dörfler {
85b76ca311SAxel Dörfler 	return kStateEntry;
86b76ca311SAxel Dörfler }
87b76ca311SAxel Dörfler 
88b76ca311SAxel Dörfler 
89b76ca311SAxel Dörfler int32
NextState(int32 state)90b76ca311SAxel Dörfler BootManagerController::NextState(int32 state)
91b76ca311SAxel Dörfler {
92b76ca311SAxel Dörfler 	switch (state) {
93b76ca311SAxel Dörfler 		case kStateEntry:
94b76ca311SAxel Dörfler 		{
9549c044abSAxel Dörfler 			const char* path;
9649c044abSAxel Dörfler 			if (fSettings.FindString("disk", &path) != B_OK)
9749c044abSAxel Dörfler 				return kStateErrorEntry;
98b76ca311SAxel Dörfler 
9949c044abSAxel Dörfler 			delete fBootDrive;
10049c044abSAxel Dörfler 
10149c044abSAxel Dörfler 			fBootDrive = new BootDrive(path);
10249c044abSAxel Dörfler 			fBootMenu = fBootDrive->InstalledMenu(fBootMenus);
10349c044abSAxel Dörfler 
10449c044abSAxel Dörfler 			if (fSettings.FindBool("install")) {
10549c044abSAxel Dörfler 				int32 nextState = fBootMenu != NULL
10649c044abSAxel Dörfler 					? kStatePartitions : kStateSaveMBR;
10749c044abSAxel Dörfler 
10849c044abSAxel Dörfler 				// TODO: call BootDrive::AddSupportedMenus() once we support
10949c044abSAxel Dörfler 				// more than one type of boot menu - we'll probably need a
11049c044abSAxel Dörfler 				// requester to choose from them then as well.
11149c044abSAxel Dörfler 				if (fBootMenu == NULL)
11249c044abSAxel Dörfler 					fBootMenu = fBootMenus.ItemAt(0);
11349c044abSAxel Dörfler 
11449c044abSAxel Dörfler 				fCollectPartitionsStatus = fBootMenu->CollectPartitions(
11549c044abSAxel Dörfler 					*fBootDrive, fSettings);
11649c044abSAxel Dörfler 
11749c044abSAxel Dörfler 				return nextState;
118b76ca311SAxel Dörfler 			}
119b76ca311SAxel Dörfler 
120b76ca311SAxel Dörfler 			return kStateUninstall;
121b76ca311SAxel Dörfler 		}
122b76ca311SAxel Dörfler 
123b76ca311SAxel Dörfler 		case kStateErrorEntry:
124b76ca311SAxel Dörfler 			be_app->PostMessage(B_QUIT_REQUESTED);
125b76ca311SAxel Dörfler 			break;
126b76ca311SAxel Dörfler 
127b76ca311SAxel Dörfler 		case kStateSaveMBR:
128b76ca311SAxel Dörfler 			if (_SaveMBR())
129b76ca311SAxel Dörfler 				return kStateMBRSaved;
130b76ca311SAxel Dörfler 			break;
131b76ca311SAxel Dörfler 
132b76ca311SAxel Dörfler 		case kStateMBRSaved:
133b76ca311SAxel Dörfler 			return kStatePartitions;
134b76ca311SAxel Dörfler 
135b76ca311SAxel Dörfler 		case kStatePartitions:
136b76ca311SAxel Dörfler 			if (_HasSelectedPartitions())
137b76ca311SAxel Dörfler 				return kStateDefaultPartitions;
138b76ca311SAxel Dörfler 			break;
139b76ca311SAxel Dörfler 
140b76ca311SAxel Dörfler 		case kStateDefaultPartitions:
141b76ca311SAxel Dörfler 			return kStateInstallSummary;
142b76ca311SAxel Dörfler 
143b76ca311SAxel Dörfler 		case kStateInstallSummary:
144b76ca311SAxel Dörfler 			if (_WriteBootMenu())
145b76ca311SAxel Dörfler 				return kStateInstalled;
146b76ca311SAxel Dörfler 			break;
147b76ca311SAxel Dörfler 
148b76ca311SAxel Dörfler 		case kStateInstalled:
149b76ca311SAxel Dörfler 			be_app->PostMessage(B_QUIT_REQUESTED);
150b76ca311SAxel Dörfler 			break;
151b76ca311SAxel Dörfler 
152b76ca311SAxel Dörfler 		case kStateUninstall:
153b76ca311SAxel Dörfler 			if (_RestoreMBR())
154b76ca311SAxel Dörfler 				return kStateUninstalled;
155b76ca311SAxel Dörfler 			break;
156b76ca311SAxel Dörfler 
157b76ca311SAxel Dörfler 		case kStateUninstalled:
158b76ca311SAxel Dörfler 			be_app->PostMessage(B_QUIT_REQUESTED);
159b76ca311SAxel Dörfler 			break;
160b76ca311SAxel Dörfler 	}
161b76ca311SAxel Dörfler 	// cannot leave the current state/page
162b76ca311SAxel Dörfler 	return -1;
163b76ca311SAxel Dörfler }
164b76ca311SAxel Dörfler 
165b76ca311SAxel Dörfler 
166b76ca311SAxel Dörfler bool
_HasSelectedPartitions()167b76ca311SAxel Dörfler BootManagerController::_HasSelectedPartitions()
168b76ca311SAxel Dörfler {
169b76ca311SAxel Dörfler 	BMessage message;
170b76ca311SAxel Dörfler 	for (int32 i = 0; fSettings.FindMessage("partition", i, &message) == B_OK;
171b76ca311SAxel Dörfler 			i++) {
172b76ca311SAxel Dörfler 		bool show;
173b76ca311SAxel Dörfler 		if (message.FindBool("show", &show) == B_OK && show)
174b76ca311SAxel Dörfler 			return true;
175b76ca311SAxel Dörfler 	}
176b76ca311SAxel Dörfler 
177b76ca311SAxel Dörfler 	BAlert* alert = new BAlert("info",
178b76ca311SAxel Dörfler 		B_TRANSLATE("At least one partition must be selected!"),
179b76ca311SAxel Dörfler 		B_TRANSLATE_COMMENT("OK", "Button"));
180aed35104SHumdinger 	alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
181b76ca311SAxel Dörfler 	alert->Go();
182b76ca311SAxel Dörfler 
183b76ca311SAxel Dörfler 	return false;
184b76ca311SAxel Dörfler }
185b76ca311SAxel Dörfler 
186b76ca311SAxel Dörfler 
187b76ca311SAxel Dörfler bool
_WriteBootMenu()188b76ca311SAxel Dörfler BootManagerController::_WriteBootMenu()
189b76ca311SAxel Dörfler {
190b76ca311SAxel Dörfler 	BAlert* alert = new BAlert("confirm", B_TRANSLATE("About to write the "
191b76ca311SAxel Dörfler 			"boot menu to disk. Are you sure you want to continue?"),
192b76ca311SAxel Dörfler 		B_TRANSLATE_COMMENT("Write boot menu", "Button"),
193b76ca311SAxel Dörfler 		B_TRANSLATE_COMMENT("Back", "Button"), NULL, B_WIDTH_AS_USUAL,
194b76ca311SAxel Dörfler 		B_WARNING_ALERT);
195b76ca311SAxel Dörfler 
196b76ca311SAxel Dörfler 	if (alert->Go() == 1)
197b76ca311SAxel Dörfler 		return false;
198b76ca311SAxel Dörfler 
19949c044abSAxel Dörfler 	fWriteBootMenuStatus = fBootMenu->Install(*fBootDrive, fSettings);
200b76ca311SAxel Dörfler 	return true;
201b76ca311SAxel Dörfler }
202b76ca311SAxel Dörfler 
203b76ca311SAxel Dörfler 
204b76ca311SAxel Dörfler bool
_SaveMBR()205b76ca311SAxel Dörfler BootManagerController::_SaveMBR()
206b76ca311SAxel Dörfler {
207b76ca311SAxel Dörfler 	BString path;
208b76ca311SAxel Dörfler 	fSettings.FindString("file", &path);
209b76ca311SAxel Dörfler 	BFile file(path.String(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
2105675f44eSAxel Dörfler 	fSaveMBRStatus = fBootMenu->SaveMasterBootRecord(&fSettings, &file);
211b76ca311SAxel Dörfler 	return true;
212b76ca311SAxel Dörfler }
213b76ca311SAxel Dörfler 
214b76ca311SAxel Dörfler 
215b76ca311SAxel Dörfler bool
_RestoreMBR()216b76ca311SAxel Dörfler BootManagerController::_RestoreMBR()
217b76ca311SAxel Dörfler {
218b76ca311SAxel Dörfler 	BString disk;
219b76ca311SAxel Dörfler 	BString path;
220b76ca311SAxel Dörfler 	fSettings.FindString("disk", &disk);
221b76ca311SAxel Dörfler 	fSettings.FindString("file", &path);
222b76ca311SAxel Dörfler 
223b76ca311SAxel Dörfler 	BString message;
224b76ca311SAxel Dörfler 	message << B_TRANSLATE_COMMENT("About to restore the Master Boot Record "
225b76ca311SAxel Dörfler 		"(MBR) of %disk from %file. Do you wish to continue?",
226b76ca311SAxel Dörfler 		"Don't translate the place holders: %disk and %file");
227b76ca311SAxel Dörfler 	message.ReplaceFirst("%disk", disk);
228b76ca311SAxel Dörfler 	message.ReplaceFirst("%file", path);
229b76ca311SAxel Dörfler 
230b76ca311SAxel Dörfler 	BAlert* alert = new BAlert("confirm", message.String(),
231b76ca311SAxel Dörfler 		B_TRANSLATE_COMMENT("Restore MBR", "Button"),
232b76ca311SAxel Dörfler 		B_TRANSLATE_COMMENT("Back", "Button"),
233b76ca311SAxel Dörfler 		NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
234b76ca311SAxel Dörfler 	if (alert->Go() == 1)
235b76ca311SAxel Dörfler 		return false;
236b76ca311SAxel Dörfler 
237b76ca311SAxel Dörfler 	BFile file(path.String(), B_READ_ONLY);
2385675f44eSAxel Dörfler 	fRestoreMBRStatus = fBootMenu->RestoreMasterBootRecord(&fSettings, &file);
239b76ca311SAxel Dörfler 	return true;
240b76ca311SAxel Dörfler }
241b76ca311SAxel Dörfler 
242b76ca311SAxel Dörfler 
243b76ca311SAxel Dörfler WizardPageView*
CreatePage(int32 state,WizardView * wizard)244b76ca311SAxel Dörfler BootManagerController::CreatePage(int32 state, WizardView* wizard)
245b76ca311SAxel Dörfler {
246b76ca311SAxel Dörfler 	WizardPageView* page = NULL;
247197f59b0SAxel Dörfler 	BRect frame(0, 0, 300, 250);
248b76ca311SAxel Dörfler 
249b76ca311SAxel Dörfler 	switch (state) {
250b76ca311SAxel Dörfler 		case kStateEntry:
25149c044abSAxel Dörfler 			fSettings.ReplaceBool("install", true);
25249c044abSAxel Dörfler 			page = new DrivesPage(wizard, fBootMenus, &fSettings, "drives");
253b76ca311SAxel Dörfler 			break;
254b76ca311SAxel Dörfler 		case kStateErrorEntry:
255197f59b0SAxel Dörfler 			page = _CreateErrorEntryPage();
256b76ca311SAxel Dörfler 			wizard->SetPreviousButtonHidden(true);
257b76ca311SAxel Dörfler 			wizard->SetNextButtonLabel(B_TRANSLATE_COMMENT("Done", "Button"));
258b76ca311SAxel Dörfler 			break;
259b76ca311SAxel Dörfler 		case kStateSaveMBR:
260b76ca311SAxel Dörfler 			page = _CreateSaveMBRPage(frame);
261b76ca311SAxel Dörfler 			wizard->SetPreviousButtonHidden(false);
262b76ca311SAxel Dörfler 			break;
263b76ca311SAxel Dörfler 		case kStateMBRSaved:
264197f59b0SAxel Dörfler 			page = _CreateMBRSavedPage();
265b76ca311SAxel Dörfler 			break;
266b76ca311SAxel Dörfler 		case kStatePartitions:
267197f59b0SAxel Dörfler 			page = new PartitionsPage(&fSettings, "partitions");
268b76ca311SAxel Dörfler 			wizard->SetPreviousButtonHidden(false);
269b76ca311SAxel Dörfler 			break;
270b76ca311SAxel Dörfler 		case kStateDefaultPartitions:
271b76ca311SAxel Dörfler 			page = new DefaultPartitionPage(&fSettings, frame, "default");
272b76ca311SAxel Dörfler 			break;
273b76ca311SAxel Dörfler 		case kStateInstallSummary:
274197f59b0SAxel Dörfler 			page = _CreateInstallSummaryPage();
275b76ca311SAxel Dörfler 			break;
276b76ca311SAxel Dörfler 		case kStateInstalled:
277197f59b0SAxel Dörfler 			page = _CreateInstalledPage();
278b76ca311SAxel Dörfler 			wizard->SetNextButtonLabel(B_TRANSLATE_COMMENT("Done", "Button"));
279b76ca311SAxel Dörfler 			break;
280b76ca311SAxel Dörfler 		case kStateUninstall:
281b76ca311SAxel Dörfler 			page = _CreateUninstallPage(frame);
282b76ca311SAxel Dörfler 			wizard->SetPreviousButtonHidden(false);
283b76ca311SAxel Dörfler 			break;
284b76ca311SAxel Dörfler 		case kStateUninstalled:
285b76ca311SAxel Dörfler 			// TODO prevent overwriting MBR after clicking "Previous"
286197f59b0SAxel Dörfler 			page = _CreateUninstalledPage();
287b76ca311SAxel Dörfler 			wizard->SetNextButtonLabel(B_TRANSLATE_COMMENT("Done", "Button"));
288b76ca311SAxel Dörfler 			break;
289b76ca311SAxel Dörfler 	}
290b76ca311SAxel Dörfler 
291b76ca311SAxel Dörfler 	return page;
292b76ca311SAxel Dörfler }
293b76ca311SAxel Dörfler 
294b76ca311SAxel Dörfler 
295b76ca311SAxel Dörfler WizardPageView*
_CreateErrorEntryPage()296197f59b0SAxel Dörfler BootManagerController::_CreateErrorEntryPage()
297b76ca311SAxel Dörfler {
298b76ca311SAxel Dörfler 	BString description;
299b76ca311SAxel Dörfler 
3004011cb5dSAdrien Destugues 	if (fCollectPartitionsStatus == B_ENTRY_NOT_FOUND) {
301b76ca311SAxel Dörfler 		description << B_TRANSLATE_COMMENT("Partition table not compatible",
302b76ca311SAxel Dörfler 				"Title") << "\n\n"
303b76ca311SAxel Dörfler 			<< B_TRANSLATE("The partition table of the first hard disk is not "
304b76ca311SAxel Dörfler 				"compatible with Boot Manager.\n"
3054011cb5dSAdrien Destugues 				"Boot Manager only works with IBM PC MBR partitions.");
3064011cb5dSAdrien Destugues 	} else if (fCollectPartitionsStatus == B_PARTITION_TOO_SMALL) {
3074011cb5dSAdrien Destugues 		description << B_TRANSLATE_COMMENT("First partition starts too early",
3084011cb5dSAdrien Destugues 				"Title") << "\n\n"
3094011cb5dSAdrien Destugues 			<< B_TRANSLATE("The first partition on the disk starts too early "
3104011cb5dSAdrien Destugues 				"and does not leave enough space free for a boot menu.\n"
3114011cb5dSAdrien Destugues 				"Boot Manager needs 2 KiB available space before the first "
312b76ca311SAxel Dörfler 				"partition.");
313b76ca311SAxel Dörfler 	} else {
314b76ca311SAxel Dörfler 		description << B_TRANSLATE_COMMENT("Error reading partition table",
315b76ca311SAxel Dörfler 				"Title") << "\n\n"
316b76ca311SAxel Dörfler 			<< B_TRANSLATE("Boot Manager is unable to read the partition "
317b76ca311SAxel Dörfler 				"table!");
318b76ca311SAxel Dörfler 	}
319b76ca311SAxel Dörfler 
320197f59b0SAxel Dörfler 	return new DescriptionPage("errorEntry", description.String(), true);
321b76ca311SAxel Dörfler }
322b76ca311SAxel Dörfler 
323b76ca311SAxel Dörfler 
324b76ca311SAxel Dörfler WizardPageView*
_CreateSaveMBRPage(BRect frame)325b76ca311SAxel Dörfler BootManagerController::_CreateSaveMBRPage(BRect frame)
326b76ca311SAxel Dörfler {
327b76ca311SAxel Dörfler 	BString description;
328b76ca311SAxel Dörfler 	BString disk;
329b76ca311SAxel Dörfler 	fSettings.FindString("disk", &disk);
330b76ca311SAxel Dörfler 
331b76ca311SAxel Dörfler 	description << B_TRANSLATE_COMMENT("Backup Master Boot Record", "Title")
332197f59b0SAxel Dörfler 		<< "\n" << B_TRANSLATE("The Master Boot Record (MBR) of the boot "
333b76ca311SAxel Dörfler 			"device:\n"
334b76ca311SAxel Dörfler 			"\t%s\n"
335b76ca311SAxel Dörfler 			"will now be saved to disk. Please select a file to "
336b76ca311SAxel Dörfler 			"save the MBR into.\n\n"
337b76ca311SAxel Dörfler 			"If something goes wrong with the installation or if "
338b76ca311SAxel Dörfler 			"you later wish to remove the boot menu, simply run the "
339b76ca311SAxel Dörfler 			"bootman program and choose the 'Uninstall' option.");
340b76ca311SAxel Dörfler 	description.ReplaceFirst("%s", disk);
341b76ca311SAxel Dörfler 
342b76ca311SAxel Dörfler 	return new FileSelectionPage(&fSettings, frame, "saveMBR",
343b76ca311SAxel Dörfler 		description.String(),
344b76ca311SAxel Dörfler 		B_SAVE_PANEL);
345b76ca311SAxel Dörfler }
346b76ca311SAxel Dörfler 
347b76ca311SAxel Dörfler 
348b76ca311SAxel Dörfler WizardPageView*
_CreateMBRSavedPage()349197f59b0SAxel Dörfler BootManagerController::_CreateMBRSavedPage()
350b76ca311SAxel Dörfler {
351b76ca311SAxel Dörfler 	BString description;
352b76ca311SAxel Dörfler 	BString file;
353b76ca311SAxel Dörfler 	fSettings.FindString("file", &file);
354b76ca311SAxel Dörfler 
355b76ca311SAxel Dörfler 	if (fSaveMBRStatus == B_OK) {
356b76ca311SAxel Dörfler 		description << B_TRANSLATE_COMMENT("Old Master Boot Record saved",
357197f59b0SAxel Dörfler 				"Title") << "\n"
358b76ca311SAxel Dörfler 			<< B_TRANSLATE("The old Master Boot Record was successfully "
359b76ca311SAxel Dörfler 				"saved to %s.") << "\n";
360b76ca311SAxel Dörfler 	} else {
361*2824c5d3SAdrien Destugues 		description << B_TRANSLATE_COMMENT("Old Master Boot Record backup "
362197f59b0SAxel Dörfler 				"failure", "Title") << "\n"
363b76ca311SAxel Dörfler 			<< B_TRANSLATE("The old Master Boot Record could not be saved "
364*2824c5d3SAdrien Destugues 				"to %s. You can continue the installation but there will be no "
365*2824c5d3SAdrien Destugues 				"way to uninstall the boot menu.") << "\n";
366b76ca311SAxel Dörfler 	}
367b76ca311SAxel Dörfler 	description.ReplaceFirst("%s", file);
368b76ca311SAxel Dörfler 
369197f59b0SAxel Dörfler 	return new DescriptionPage("summary", description.String(), true);
370b76ca311SAxel Dörfler }
371b76ca311SAxel Dörfler 
372b76ca311SAxel Dörfler 
373b76ca311SAxel Dörfler WizardPageView*
_CreateInstallSummaryPage()374197f59b0SAxel Dörfler BootManagerController::_CreateInstallSummaryPage()
375b76ca311SAxel Dörfler {
376b76ca311SAxel Dörfler 	BString description;
377b76ca311SAxel Dörfler 	BString disk;
378b76ca311SAxel Dörfler 	fSettings.FindString("disk", &disk);
379b76ca311SAxel Dörfler 
380197f59b0SAxel Dörfler 	description << B_TRANSLATE_COMMENT("Summary", "Title") << "\n"
381b76ca311SAxel Dörfler 		<< B_TRANSLATE("About to write the following boot menu to the boot "
382b76ca311SAxel Dörfler 			"disk (%s). Please verify the information below before continuing.")
383b76ca311SAxel Dörfler 		<< "\n\n";
384b76ca311SAxel Dörfler 	description.ReplaceFirst("%s", disk);
385b76ca311SAxel Dörfler 
386b76ca311SAxel Dörfler 	BMessage message;
387b76ca311SAxel Dörfler 	for (int32 i = 0; fSettings.FindMessage("partition", i, &message) == B_OK;
388b76ca311SAxel Dörfler 			i++) {
389b76ca311SAxel Dörfler 		bool show;
390b76ca311SAxel Dörfler 		if (message.FindBool("show", &show) != B_OK || !show)
391b76ca311SAxel Dörfler 			continue;
392b76ca311SAxel Dörfler 
393b76ca311SAxel Dörfler 		BString name;
394b76ca311SAxel Dörfler 		BString path;
395b76ca311SAxel Dörfler 		message.FindString("name", &name);
396b76ca311SAxel Dörfler 		message.FindString("path", &path);
397b76ca311SAxel Dörfler 
398b76ca311SAxel Dörfler 		BString displayName;
3995675f44eSAxel Dörfler 		if (fBootMenu->GetDisplayText(name.String(), displayName) == B_OK)
400b76ca311SAxel Dörfler 			description << displayName << "\t(" << path << ")\n";
401b76ca311SAxel Dörfler 		else
402b76ca311SAxel Dörfler 			description << name << "\t(" << path << ")\n";
403b76ca311SAxel Dörfler 	}
404b76ca311SAxel Dörfler 
405197f59b0SAxel Dörfler 	return new DescriptionPage("summary", description.String(), true);
406b76ca311SAxel Dörfler }
407b76ca311SAxel Dörfler 
408b76ca311SAxel Dörfler 
409b76ca311SAxel Dörfler WizardPageView*
_CreateInstalledPage()410197f59b0SAxel Dörfler BootManagerController::_CreateInstalledPage()
411b76ca311SAxel Dörfler {
412b76ca311SAxel Dörfler 	BString description;
413b76ca311SAxel Dörfler 
414b76ca311SAxel Dörfler 	if (fWriteBootMenuStatus == B_OK) {
415b76ca311SAxel Dörfler 		description << B_TRANSLATE_COMMENT("Installation of boot menu "
416197f59b0SAxel Dörfler 				"completed", "Title") << "\n"
417b76ca311SAxel Dörfler 			<< B_TRANSLATE("The boot manager has been successfully installed "
418b76ca311SAxel Dörfler 				"on your system.");
419b76ca311SAxel Dörfler 	} else {
420b76ca311SAxel Dörfler 		description << B_TRANSLATE_COMMENT("Installation of boot menu failed",
421197f59b0SAxel Dörfler 				"Title") << "\n"
422b76ca311SAxel Dörfler 			<< B_TRANSLATE("An error occurred writing the boot menu. "
423b76ca311SAxel Dörfler 				"The Master Boot Record might be destroyed, "
424b76ca311SAxel Dörfler 				"you should restore the MBR now!");
425b76ca311SAxel Dörfler 	}
426b76ca311SAxel Dörfler 
427197f59b0SAxel Dörfler 	return new DescriptionPage("done", description, true);
428b76ca311SAxel Dörfler }
429b76ca311SAxel Dörfler 
430b76ca311SAxel Dörfler 
431b76ca311SAxel Dörfler WizardPageView*
_CreateUninstallPage(BRect frame)432b76ca311SAxel Dörfler BootManagerController::_CreateUninstallPage(BRect frame)
433b76ca311SAxel Dörfler {
434b76ca311SAxel Dörfler 	BString description;
435b76ca311SAxel Dörfler 	description << B_TRANSLATE_COMMENT("Uninstall boot manager", "Title")
436b76ca311SAxel Dörfler 		<< "\n\n"
437b76ca311SAxel Dörfler 		<< B_TRANSLATE("Please locate the Master Boot Record (MBR) save file "
438b76ca311SAxel Dörfler 			"to restore from. This is the file that was created when the "
439b76ca311SAxel Dörfler 			"boot manager was first installed.");
440b76ca311SAxel Dörfler 
441b76ca311SAxel Dörfler 	return new FileSelectionPage(&fSettings, frame, "restoreMBR",
442b76ca311SAxel Dörfler 		description.String(), B_OPEN_PANEL);
443b76ca311SAxel Dörfler }
444b76ca311SAxel Dörfler 
445b76ca311SAxel Dörfler 
446b76ca311SAxel Dörfler WizardPageView*
_CreateUninstalledPage()447197f59b0SAxel Dörfler BootManagerController::_CreateUninstalledPage()
448b76ca311SAxel Dörfler {
449b76ca311SAxel Dörfler 	BString description;
450b76ca311SAxel Dörfler 	BString disk;
451b76ca311SAxel Dörfler 	BString file;
452b76ca311SAxel Dörfler 	fSettings.FindString("disk", &disk);
453b76ca311SAxel Dörfler 	fSettings.FindString("file", &file);
454b76ca311SAxel Dörfler 
455b76ca311SAxel Dörfler 	if (fRestoreMBRStatus == B_OK) {
456b76ca311SAxel Dörfler 		description << B_TRANSLATE_COMMENT("Uninstallation of boot menu "
457197f59b0SAxel Dörfler 				"completed", "Title") << "\n"
458b76ca311SAxel Dörfler 			<< B_TRANSLATE("The Master Boot Record of the boot device "
459b76ca311SAxel Dörfler 				"(%DISK) has been successfully restored from %FILE.");
460b76ca311SAxel Dörfler 		description.ReplaceFirst("%DISK", disk);
461b76ca311SAxel Dörfler 		description.ReplaceFirst("%FILE", file);
462b76ca311SAxel Dörfler 	} else {
463b76ca311SAxel Dörfler 		description << B_TRANSLATE_COMMENT("Uninstallation of boot menu "
464197f59b0SAxel Dörfler 				"failed", "Title") << "\n"
465b76ca311SAxel Dörfler 			<< B_TRANSLATE("The Master Boot Record could not be restored!");
466b76ca311SAxel Dörfler 	}
467b76ca311SAxel Dörfler 
468197f59b0SAxel Dörfler 	return new DescriptionPage("summary", description.String(), true);
469b76ca311SAxel Dörfler }
470