xref: /haiku/src/apps/installer/InstallerApp.cpp (revision 6011ce6c7495e4e707bd33b12a7e22d66c710aad)
1 /*
2  * Copyright 2020, Panagiotis Vasilopoulos <hello@alwayslivid.com>
3  * Copyright 2015, Axel Dörfler <axeld@pinc-software.de>
4  * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>
5  * Copyright 2005, Jérôme DUVAL.
6  * All rights reserved. Distributed under the terms of the MIT License.
7  */
8 
9 #include "InstallerApp.h"
10 
11 #include <unistd.h>
12 
13 #include <Alert.h>
14 #include <Roster.h>
15 #include <TextView.h>
16 
17 #include <syscalls.h>
18 
19 #include "tracker_private.h"
20 #include "Utility.h"
21 
22 
23 static const uint32 kMsgAgree = 'agre';
24 static const uint32 kMsgNext = 'next';
25 
26 #undef B_TRANSLATION_CONTEXT
27 #define B_TRANSLATION_CONTEXT "InstallerApp"
28 
29 
30 int main(int, char **)
31 {
32 	InstallerApp installer;
33 	installer.Run();
34 	return 0;
35 }
36 
37 
38 InstallerApp::InstallerApp()
39 	:
40 	BApplication("application/x-vnd.Haiku-Installer")
41 {
42 }
43 
44 
45 void
46 InstallerApp::MessageReceived(BMessage* message)
47 {
48 	switch (message->what) {
49 		case kMsgAgree:
50 			fEULAWindow->PostMessage(B_QUIT_REQUESTED);
51 			break;
52 		case kMsgNext:
53 			new InstallerWindow();
54 			break;
55 
56 		default:
57 			BApplication::MessageReceived(message);
58 	}
59 }
60 
61 
62 void
63 InstallerApp::ReadyToRun()
64 {
65 #if 1
66 	// Show the EULA first.
67 	fEULAWindow = new EULAWindow();
68 #else
69 	// Show the installer window without EULA.
70 	new InstallerWindow();
71 #endif
72 }
73 
74 
75 void
76 InstallerApp::Quit()
77 {
78 	BApplication::Quit();
79 
80 	if (!be_roster->IsRunning(kDeskbarSignature)) {
81 		if (CurrentMessage()->GetBool("install_complete")) {
82 			// Synchronize disks
83 			sync();
84 
85 			if (Utility::IsReadOnlyVolume("/boot")) {
86 				// Unblock CD tray, and eject the CD
87 				Utility::BlockMedia("/boot", false);
88 				Utility::EjectMedia("/boot");
89 			}
90 
91 			// Quickly reboot without touching anything
92 			// on disk (which we might just have ejected)
93 			_kern_shutdown(true);
94 		} else {
95 			// Return to FirstBootPrompt if the user hasn't
96 			// installed Haiku yet
97 			be_roster->Launch("application/x-vnd.Haiku-FirstBootPrompt");
98 		}
99 	}
100 }
101