xref: /haiku/src/apps/installer/InstallerApp.cpp (revision 546208a53940a26c6379c48a7854ade1a8250fc5)
16ffb6a6eSJérôme Duval /*
27ff74a7bSStephan Aßmus  * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>
37ff74a7bSStephan Aßmus  * Copyright 2005, Jérôme DUVAL.
47ff74a7bSStephan Aßmus  * All rights reserved. Distributed under the terms of the MIT License.
56ffb6a6eSJérôme Duval  */
66ffb6a6eSJérôme Duval 
77ff74a7bSStephan Aßmus #include "InstallerApp.h"
87ff74a7bSStephan Aßmus 
96ffb6a6eSJérôme Duval #include <Alert.h>
107ff74a7bSStephan Aßmus #include <Button.h>
115dcd3cd1SHannah Boneß #include <LayoutBuilder.h>
124a2da425SStephan Aßmus #include <Locale.h>
1335d3acb2SJérôme Duval #include <ScrollView.h>
146ffb6a6eSJérôme Duval #include <TextView.h>
156ffb6a6eSJérôme Duval 
166ffb6a6eSJérôme Duval 
177ff74a7bSStephan Aßmus static const uint32 kMsgAgree = 'agre';
187ff74a7bSStephan Aßmus 
193ac4a739SStephan Aßmus //static const char* kEULAText =
203ac4a739SStephan Aßmus //"NOTICE: READ THIS BEFORE INSTALLING OR USING HAIKU\n\n"
213ac4a739SStephan Aßmus //
223ac4a739SStephan Aßmus //"Copyright " B_UTF8_COPYRIGHT " 2001-2009 The Haiku Project. All rights "
233ac4a739SStephan Aßmus //"reserved. The copyright to the Haiku code is property of Haiku, Inc. or of "
243ac4a739SStephan Aßmus //"the respective authors where expressly noted in the source.\n\n"
253ac4a739SStephan Aßmus //
263ac4a739SStephan Aßmus //"Permission is hereby granted, free of charge, to any person obtaining a "
273ac4a739SStephan Aßmus //"copy of this software and associated documentation files (the \"Software\"), "
283ac4a739SStephan Aßmus //"to deal in the Software without restriction, including without limitation "
293ac4a739SStephan Aßmus //"the rights to use, copy, modify, merge, publish, distribute, sublicense, "
303ac4a739SStephan Aßmus //"and/or sell copies of the Software, and to permit persons to whom the "
313ac4a739SStephan Aßmus //"Software is furnished to do so, subject to the following conditions:\n\n"
323ac4a739SStephan Aßmus //"The above copyright notice and this permission notice shall be included in "
333ac4a739SStephan Aßmus //"all copies or substantial portions of the Software.\n\n"
343ac4a739SStephan Aßmus //
353ac4a739SStephan Aßmus //"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS "
363ac4a739SStephan Aßmus //"OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
373ac4a739SStephan Aßmus //"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
383ac4a739SStephan Aßmus //"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
393ac4a739SStephan Aßmus //"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING "
403ac4a739SStephan Aßmus //"FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS "
413ac4a739SStephan Aßmus //"IN THE SOFTWARE.";
427ff74a7bSStephan Aßmus 
437ff74a7bSStephan Aßmus 
44*546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
45*546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "InstallerApp"
467ff74a7bSStephan Aßmus 
4735d3acb2SJérôme Duval 
486ffb6a6eSJérôme Duval int main(int, char **)
496ffb6a6eSJérôme Duval {
506ffb6a6eSJérôme Duval 	InstallerApp theApp;
516ffb6a6eSJérôme Duval 	theApp.Run();
526ffb6a6eSJérôme Duval 	return 0;
536ffb6a6eSJérôme Duval }
546ffb6a6eSJérôme Duval 
557ff74a7bSStephan Aßmus 
566ffb6a6eSJérôme Duval InstallerApp::InstallerApp()
574a2da425SStephan Aßmus 	:
584a2da425SStephan Aßmus 	BApplication("application/x-vnd.Haiku-Installer")
596ffb6a6eSJérôme Duval {
6053ad1814SJérôme Duval }
6153ad1814SJérôme Duval 
627ff74a7bSStephan Aßmus 
637ff74a7bSStephan Aßmus void
647ff74a7bSStephan Aßmus InstallerApp::MessageReceived(BMessage* message)
657ff74a7bSStephan Aßmus {
667ff74a7bSStephan Aßmus 	switch (message->what) {
677ff74a7bSStephan Aßmus 		case kMsgAgree:
687ff74a7bSStephan Aßmus 			fEULAWindow->Lock();
697ff74a7bSStephan Aßmus 			fEULAWindow->Quit();
707ff74a7bSStephan Aßmus 			new InstallerWindow();
717ff74a7bSStephan Aßmus 			break;
727ff74a7bSStephan Aßmus 
737ff74a7bSStephan Aßmus 		default:
747ff74a7bSStephan Aßmus 			BApplication::MessageReceived(message);
756ffb6a6eSJérôme Duval 	}
767ff74a7bSStephan Aßmus }
777ff74a7bSStephan Aßmus 
786ffb6a6eSJérôme Duval 
796ffb6a6eSJérôme Duval void
806ffb6a6eSJérôme Duval InstallerApp::AboutRequested()
816ffb6a6eSJérôme Duval {
82e904ecc9SMatt Madia 	BAlert *alert = new BAlert("about", B_TRANSLATE("Installer\n"
834a2da425SStephan Aßmus 		"\twritten by Jérôme Duval and Stephan Aßmus\n"
84e904ecc9SMatt Madia 		"\tCopyright 2005-2010, Haiku.\n\n"), B_TRANSLATE("OK"));
856ffb6a6eSJérôme Duval 	BTextView *view = alert->TextView();
866ffb6a6eSJérôme Duval 	BFont font;
876ffb6a6eSJérôme Duval 
886ffb6a6eSJérôme Duval 	view->SetStylable(true);
896ffb6a6eSJérôme Duval 
906ffb6a6eSJérôme Duval 	view->GetFont(&font);
916ffb6a6eSJérôme Duval 	font.SetSize(18);
926ffb6a6eSJérôme Duval 	font.SetFace(B_BOLD_FACE);
9337895b5dSJoachim Seemer 	view->SetFontAndColor(0, 9, &font);
946ffb6a6eSJérôme Duval 
956ffb6a6eSJérôme Duval 	alert->Go();
966ffb6a6eSJérôme Duval }
976ffb6a6eSJérôme Duval 
986ffb6a6eSJérôme Duval 
996ffb6a6eSJérôme Duval void
1006ffb6a6eSJérôme Duval InstallerApp::ReadyToRun()
1016ffb6a6eSJérôme Duval {
102a3e6f7e1SJoachim Seemer 	BString infoText;
103a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
104a3e6f7e1SJoachim Seemer 		"Welcome to the Haiku Installer!\n\n");
105a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
106a3e6f7e1SJoachim Seemer 		"IMPORTANT INFORMATION BEFORE INSTALLING HAIKU\n\n");
107a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1084a2da425SStephan Aßmus 		"This is alpha-quality software! It means there is a high risk of "
1094a2da425SStephan Aßmus 		"losing important data. Make frequent backups! You have been "
110a3e6f7e1SJoachim Seemer 		"warned.\n\n\n");
111a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1124a2da425SStephan Aßmus 		"1)   If you are installing Haiku onto real hardware (not inside an "
1134a2da425SStephan Aßmus 		"emulator) it is recommended that you have already prepared a hard "
1144a2da425SStephan Aßmus 		"disk partition. The Installer and the DriveSetup tool offer to "
1154a2da425SStephan Aßmus 		"initialize existing partitions with the Haiku native file system, "
1164a2da425SStephan Aßmus 		"but the options to change the actual partition layout may not have "
1174a2da425SStephan Aßmus 		"been tested on a sufficiently great variety of computer "
118a3e6f7e1SJoachim Seemer 		"configurations so we do not recommend using it.\n");
119a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1204a2da425SStephan Aßmus 		"If you have not created a partition yet, simply reboot, create the "
1214a2da425SStephan Aßmus 		"partition using whatever tool you feel most comfortable with, and "
1224a2da425SStephan Aßmus 		"reboot into Haiku to continue with the installation. You could for "
1234a2da425SStephan Aßmus 		"example use the GParted Live-CD, it can also resize existing "
124a3e6f7e1SJoachim Seemer 		"partitions to make room.\n\n\n");
125a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1263fa60838SJoachim Seemer 		"2)   The Installer will make the Haiku partition itself bootable, "
1273fa60838SJoachim Seemer 		"but takes no steps to integrate Haiku into an existing boot menu. "
1283fa60838SJoachim Seemer 		"If you have GRUB already installed, you can add Haiku to its boot "
1293fa60838SJoachim Seemer 		"menu. Depending on what version of GRUB you use, this is done "
130a3e6f7e1SJoachim Seemer 		"differently.\n\n\n");
131a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
132a3e6f7e1SJoachim Seemer 		"2.1) GRUB 1\n");
133a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1343fa60838SJoachim Seemer 		"Configure your /boot/grub/menu.lst by launching your favorite "
135a3e6f7e1SJoachim Seemer 		"editor from a Terminal like this:\n\n");
136a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
137a3e6f7e1SJoachim Seemer 		"\tsudo <your favorite text editor> /boot/grub/menu.lst\n\n");
138a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1394a2da425SStephan Aßmus 		"You'll note that GRUB uses a different naming strategy for hard "
140a3e6f7e1SJoachim Seemer 		"drives than Linux.\n\n");
141a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
142a3e6f7e1SJoachim Seemer 		"With GRUB it's: (hdN,n)\n\n");
143a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
144a3e6f7e1SJoachim Seemer 		"All hard disks start with \"hd\".\n");
145a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
146a3e6f7e1SJoachim Seemer 		"\"N\" is the hard disk number, starting with \"0\".\n");
147a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
148a3e6f7e1SJoachim Seemer 		"\"n\" is the partition number, also starting with \"0\".\n");
149a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1503fa60838SJoachim Seemer 		"The first logical partition always has the number \"4\", regardless "
151a3e6f7e1SJoachim Seemer 		"of the number of primary partitions.\n\n");
152a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1534a2da425SStephan Aßmus 		"So behind the other menu entries towards the bottom of the file, add "
154a3e6f7e1SJoachim Seemer 		"something similar to these lines:\n\n");
155a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
156a3e6f7e1SJoachim Seemer 		"\t# Haiku on /dev/sda7\n");
157a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
158a3e6f7e1SJoachim Seemer 		"\ttitle\t\t\t\tHaiku\n");
159a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
160a3e6f7e1SJoachim Seemer 		"\trootnoverify\t\t(hd0,6)\n");
161a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
162a3e6f7e1SJoachim Seemer 		"\tchainloader\t\t+1\n\n");
163a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
164a3e6f7e1SJoachim Seemer 		"You can see the correct partition in GParted for example.\n\n\n");
165a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
166a3e6f7e1SJoachim Seemer 		"2.2) GRUB 2\n");
167a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1683fa60838SJoachim Seemer 		"Newer versions of GRUB use an extra configuration file to add "
1693fa60838SJoachim Seemer 		"custom entries to the boot menu. To add them to the top, you have "
1703fa60838SJoachim Seemer 		"to create/edit a file by launching your favorite editor from a "
171a3e6f7e1SJoachim Seemer 		"Terminal like this:\n\n");
172a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
173a3e6f7e1SJoachim Seemer 		"\tsudo <your favorite text editor> /etc/grub.d/40_custom\n\n");
174a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1753fa60838SJoachim Seemer 		"NOTE: While the naming strategy for hard disks is still as described "
176a3e6f7e1SJoachim Seemer 		"under 2.1) the naming scheme for partitions has changed.\n\n");
177a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
178a3e6f7e1SJoachim Seemer 		"GRUB's naming scheme is still: (hdN,n)\n\n");
179a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
180a3e6f7e1SJoachim Seemer 		"All hard disks start with \"hd\".\n");
181a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
182a3e6f7e1SJoachim Seemer 		"\"N\" is the hard disk number, starting with \"0\".\n");
183a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
184a3e6f7e1SJoachim Seemer 		"\"n\" is the partition number, which for GRUB 2 starts with \"1\"\n");
185a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1863fa60838SJoachim Seemer 		"With GRUB 2 the first logical partition always has the number \"5\", "
187a3e6f7e1SJoachim Seemer 		"regardless of the number of primary partitions.\n\n");
188a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
1893fa60838SJoachim Seemer 		"So below the heading that must not be edited, add something similar "
190a3e6f7e1SJoachim Seemer 		"to these lines:\n\n");
191a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
192a3e6f7e1SJoachim Seemer 		"\t# Haiku on /dev/sda7\n");
193a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
194a3e6f7e1SJoachim Seemer 		"\tmenuentry \"Haiku Alpha\" {\n");
195a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
196a3e6f7e1SJoachim Seemer 		"\t\tset root=(hd0,7)\n");
197a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
198a3e6f7e1SJoachim Seemer 		"\t\tchainloader +1\n");
199a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
200a3e6f7e1SJoachim Seemer 		"\t}\n\n");
201a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
2023fa60838SJoachim Seemer 		"Additionally you have to edit another file to actually display the "
203a3e6f7e1SJoachim Seemer 		"boot menu:\n\n");
204a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
205a3e6f7e1SJoachim Seemer 		"\tsudo <your favorite text editor> /etc/default/grub\n\n");
206a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
2073fa60838SJoachim Seemer 		"Here you have to comment out the line \"GRUB_HIDDEN_TIMEOUT=0\" by "
2083fa60838SJoachim Seemer 		"putting a \"#\" in front of it in order to actually display the "
209a3e6f7e1SJoachim Seemer 		"boot menu.\n\n");
210a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
211a3e6f7e1SJoachim Seemer 		"Finally, you have to update the boot menu by entering:\n\n");
212a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
213a3e6f7e1SJoachim Seemer 		"\tsudo update-grub\n\n\n");
214a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
2154a2da425SStephan Aßmus 		"3)   When you successfully boot into Haiku for the first time, make "
2164a2da425SStephan Aßmus 		"sure to read our \"Welcome\" documentation, there is a link on the "
217a3e6f7e1SJoachim Seemer 		"Desktop.\n\n");
218a3e6f7e1SJoachim Seemer 	infoText << B_TRANSLATE(
219a3e6f7e1SJoachim Seemer 		"Have fun and thanks a lot for trying out Haiku! We hope you like it!");
2204a2da425SStephan Aßmus 
2217ff74a7bSStephan Aßmus #if 1
2227ff74a7bSStephan Aßmus 	// Show the EULA first.
2237ff74a7bSStephan Aßmus 	BTextView* textView = new BTextView("eula", be_plain_font, NULL,
2247ff74a7bSStephan Aßmus 		B_WILL_DRAW);
2257ff74a7bSStephan Aßmus 	textView->SetInsets(10, 10, 10, 10);
2267ff74a7bSStephan Aßmus 	textView->MakeEditable(false);
2277ff74a7bSStephan Aßmus 	textView->MakeSelectable(false);
2284a2da425SStephan Aßmus 	textView->SetText(infoText);
2296ffb6a6eSJérôme Duval 
2307ff74a7bSStephan Aßmus 	BScrollView* scrollView = new BScrollView("eulaScroll",
2317ff74a7bSStephan Aßmus 		textView, B_WILL_DRAW, false, true);
2327ff74a7bSStephan Aßmus 
233e904ecc9SMatt Madia 	BButton* cancelButton = new BButton(B_TRANSLATE("Quit"),
2347ff74a7bSStephan Aßmus 		new BMessage(B_QUIT_REQUESTED));
2353ac4a739SStephan Aßmus 	cancelButton->SetTarget(this);
2367ff74a7bSStephan Aßmus 
237e904ecc9SMatt Madia 	BButton* continueButton = new BButton(B_TRANSLATE("Continue"),
2387ff74a7bSStephan Aßmus 		new BMessage(kMsgAgree));
2393ac4a739SStephan Aßmus 	continueButton->SetTarget(this);
2403ac4a739SStephan Aßmus 	continueButton->MakeDefault(true);
2417ff74a7bSStephan Aßmus 
2427ff74a7bSStephan Aßmus 	BRect eulaFrame = BRect(0, 0, 600, 450);
243e904ecc9SMatt Madia 	fEULAWindow = new BWindow(eulaFrame, B_TRANSLATE("README"),
2447ff74a7bSStephan Aßmus 		B_MODAL_WINDOW, B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
2457ff74a7bSStephan Aßmus 			| B_AUTO_UPDATE_SIZE_LIMITS);
2467ff74a7bSStephan Aßmus 
2475dcd3cd1SHannah Boneß 	BLayoutBuilder::Group<>(fEULAWindow, B_VERTICAL, 10)
2485dcd3cd1SHannah Boneß 		.SetInsets(10)
2497ff74a7bSStephan Aßmus 		.Add(scrollView)
2505dcd3cd1SHannah Boneß 		.AddGroup(B_HORIZONTAL, 10)
2517ff74a7bSStephan Aßmus 			.AddGlue()
2523ac4a739SStephan Aßmus 			.Add(cancelButton)
2535dcd3cd1SHannah Boneß 			.Add(continueButton);
2547ff74a7bSStephan Aßmus 
255e9953d08SJonas Sundström 	fEULAWindow->CenterOnScreen();
2567ff74a7bSStephan Aßmus 	fEULAWindow->Show();
2577ff74a7bSStephan Aßmus #else
2587ff74a7bSStephan Aßmus 	// Show the installer window without EULA.
2597ff74a7bSStephan Aßmus 	new InstallerWindow();
2607ff74a7bSStephan Aßmus #endif
2616ffb6a6eSJérôme Duval }
2626ffb6a6eSJérôme Duval 
263