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