xref: /haiku/src/apps/installer/InstallerApp.cpp (revision 76fb7c29e06b74e23ca1e32953c7869de36a506e)
16ffb6a6eSJérôme Duval /*
2*76fb7c29SAxel Dörfler  * Copyright 2015, Axel Dörfler <axeld@pinc-software.de>
37ff74a7bSStephan Aßmus  * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>
47ff74a7bSStephan Aßmus  * Copyright 2005, Jérôme DUVAL.
57ff74a7bSStephan Aßmus  * All rights reserved. Distributed under the terms of the MIT License.
66ffb6a6eSJérôme Duval  */
76ffb6a6eSJérôme Duval 
87ff74a7bSStephan Aßmus #include "InstallerApp.h"
97ff74a7bSStephan Aßmus 
10*76fb7c29SAxel Dörfler #include <unistd.h>
11*76fb7c29SAxel Dörfler 
126ffb6a6eSJérôme Duval #include <Alert.h>
13*76fb7c29SAxel Dörfler #include <Roster.h>
146ffb6a6eSJérôme Duval #include <TextView.h>
156ffb6a6eSJérôme Duval 
16*76fb7c29SAxel Dörfler #include <syscalls.h>
17*76fb7c29SAxel Dörfler 
181565964aSMatt Madia #include "tracker_private.h"
19*76fb7c29SAxel Dörfler #include "Utility.h"
201565964aSMatt Madia 
216ffb6a6eSJérôme Duval 
227ff74a7bSStephan Aßmus static const uint32 kMsgAgree = 'agre';
23e13de872SFreeman Lou static const uint32 kMsgNext = 'next';
247ff74a7bSStephan Aßmus 
253ac4a739SStephan Aßmus //static const char* kEULAText =
263ac4a739SStephan Aßmus //"NOTICE: READ THIS BEFORE INSTALLING OR USING HAIKU\n\n"
273ac4a739SStephan Aßmus //
283ac4a739SStephan Aßmus //"Copyright " B_UTF8_COPYRIGHT " 2001-2009 The Haiku Project. All rights "
293ac4a739SStephan Aßmus //"reserved. The copyright to the Haiku code is property of Haiku, Inc. or of "
303ac4a739SStephan Aßmus //"the respective authors where expressly noted in the source.\n\n"
313ac4a739SStephan Aßmus //
323ac4a739SStephan Aßmus //"Permission is hereby granted, free of charge, to any person obtaining a "
333ac4a739SStephan Aßmus //"copy of this software and associated documentation files (the \"Software\"), "
343ac4a739SStephan Aßmus //"to deal in the Software without restriction, including without limitation "
353ac4a739SStephan Aßmus //"the rights to use, copy, modify, merge, publish, distribute, sublicense, "
363ac4a739SStephan Aßmus //"and/or sell copies of the Software, and to permit persons to whom the "
373ac4a739SStephan Aßmus //"Software is furnished to do so, subject to the following conditions:\n\n"
383ac4a739SStephan Aßmus //"The above copyright notice and this permission notice shall be included in "
393ac4a739SStephan Aßmus //"all copies or substantial portions of the Software.\n\n"
403ac4a739SStephan Aßmus //
413ac4a739SStephan Aßmus //"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS "
423ac4a739SStephan Aßmus //"OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
433ac4a739SStephan Aßmus //"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
443ac4a739SStephan Aßmus //"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
453ac4a739SStephan Aßmus //"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING "
463ac4a739SStephan Aßmus //"FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS "
473ac4a739SStephan Aßmus //"IN THE SOFTWARE.";
487ff74a7bSStephan Aßmus 
497ff74a7bSStephan Aßmus 
50546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
51546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "InstallerApp"
527ff74a7bSStephan Aßmus 
5335d3acb2SJérôme Duval 
546ffb6a6eSJérôme Duval int main(int, char **)
556ffb6a6eSJérôme Duval {
566ffb6a6eSJérôme Duval 	InstallerApp theApp;
576ffb6a6eSJérôme Duval 	theApp.Run();
586ffb6a6eSJérôme Duval 	return 0;
596ffb6a6eSJérôme Duval }
606ffb6a6eSJérôme Duval 
617ff74a7bSStephan Aßmus 
626ffb6a6eSJérôme Duval InstallerApp::InstallerApp()
634a2da425SStephan Aßmus 	:
644a2da425SStephan Aßmus 	BApplication("application/x-vnd.Haiku-Installer")
656ffb6a6eSJérôme Duval {
6653ad1814SJérôme Duval }
6753ad1814SJérôme Duval 
687ff74a7bSStephan Aßmus 
697ff74a7bSStephan Aßmus void
707ff74a7bSStephan Aßmus InstallerApp::MessageReceived(BMessage* message)
717ff74a7bSStephan Aßmus {
727ff74a7bSStephan Aßmus 	switch (message->what) {
737ff74a7bSStephan Aßmus 		case kMsgAgree:
747ff74a7bSStephan Aßmus 			fEULAWindow->Lock();
757ff74a7bSStephan Aßmus 			fEULAWindow->Quit();
76e13de872SFreeman Lou 		case kMsgNext:
777ff74a7bSStephan Aßmus 			new InstallerWindow();
787ff74a7bSStephan Aßmus 			break;
797ff74a7bSStephan Aßmus 
807ff74a7bSStephan Aßmus 		default:
817ff74a7bSStephan Aßmus 			BApplication::MessageReceived(message);
826ffb6a6eSJérôme Duval 	}
837ff74a7bSStephan Aßmus }
847ff74a7bSStephan Aßmus 
856ffb6a6eSJérôme Duval 
866ffb6a6eSJérôme Duval void
876ffb6a6eSJérôme Duval InstallerApp::AboutRequested()
886ffb6a6eSJérôme Duval {
89e904ecc9SMatt Madia 	BAlert *alert = new BAlert("about", B_TRANSLATE("Installer\n"
904a2da425SStephan Aßmus 		"\twritten by Jérôme Duval and Stephan Aßmus\n"
91e904ecc9SMatt Madia 		"\tCopyright 2005-2010, Haiku.\n\n"), B_TRANSLATE("OK"));
92aed35104SHumdinger 	alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
936ffb6a6eSJérôme Duval 	BTextView *view = alert->TextView();
946ffb6a6eSJérôme Duval 	BFont font;
956ffb6a6eSJérôme Duval 
966ffb6a6eSJérôme Duval 	view->SetStylable(true);
976ffb6a6eSJérôme Duval 
986ffb6a6eSJérôme Duval 	view->GetFont(&font);
996ffb6a6eSJérôme Duval 	font.SetSize(18);
1006ffb6a6eSJérôme Duval 	font.SetFace(B_BOLD_FACE);
10137895b5dSJoachim Seemer 	view->SetFontAndColor(0, 9, &font);
1026ffb6a6eSJérôme Duval 
1036ffb6a6eSJérôme Duval 	alert->Go();
1046ffb6a6eSJérôme Duval }
1056ffb6a6eSJérôme Duval 
1066ffb6a6eSJérôme Duval 
1076ffb6a6eSJérôme Duval void
1086ffb6a6eSJérôme Duval InstallerApp::ReadyToRun()
1096ffb6a6eSJérôme Duval {
1107ff74a7bSStephan Aßmus #if 1
1117ff74a7bSStephan Aßmus 	// Show the EULA first.
112e13de872SFreeman Lou 	fEULAWindow = new EULAWindow();
1137ff74a7bSStephan Aßmus #else
1147ff74a7bSStephan Aßmus 	// Show the installer window without EULA.
1157ff74a7bSStephan Aßmus 	new InstallerWindow();
1167ff74a7bSStephan Aßmus #endif
1176ffb6a6eSJérôme Duval }
118*76fb7c29SAxel Dörfler 
119*76fb7c29SAxel Dörfler 
120*76fb7c29SAxel Dörfler void
121*76fb7c29SAxel Dörfler InstallerApp::Quit()
122*76fb7c29SAxel Dörfler {
123*76fb7c29SAxel Dörfler 	BApplication::Quit();
124*76fb7c29SAxel Dörfler 
125*76fb7c29SAxel Dörfler 	if (!be_roster->IsRunning(kDeskbarSignature)) {
126*76fb7c29SAxel Dörfler 		// Synchronize disks, and reboot the system
127*76fb7c29SAxel Dörfler 		sync();
128*76fb7c29SAxel Dörfler 
129*76fb7c29SAxel Dörfler 		if (Utility::IsReadOnlyVolume("/boot")) {
130*76fb7c29SAxel Dörfler 			// Unblock CD tray, and eject the CD
131*76fb7c29SAxel Dörfler 			Utility::BlockMedia("/boot", false);
132*76fb7c29SAxel Dörfler 			Utility::EjectMedia("/boot");
133*76fb7c29SAxel Dörfler 		}
134*76fb7c29SAxel Dörfler 
135*76fb7c29SAxel Dörfler 		// Quickly shutdown without possibly touching anything on disk
136*76fb7c29SAxel Dörfler 		// (which we might just have ejected)
137*76fb7c29SAxel Dörfler 		_kern_shutdown(false);
138*76fb7c29SAxel Dörfler 	}
139*76fb7c29SAxel Dörfler }
140