xref: /haiku/src/apps/installer/InstallerApp.cpp (revision b05b0c1c29376ad87549f5692cb81a678cb01e54)
16ffb6a6eSJérôme Duval /*
2058e754bSPanagiotis Vasilopoulos  * Copyright 2020, Panagiotis Vasilopoulos <hello@alwayslivid.com>
376fb7c29SAxel Dörfler  * Copyright 2015, Axel Dörfler <axeld@pinc-software.de>
47ff74a7bSStephan Aßmus  * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>
57ff74a7bSStephan Aßmus  * Copyright 2005, Jérôme DUVAL.
67ff74a7bSStephan Aßmus  * All rights reserved. Distributed under the terms of the MIT License.
76ffb6a6eSJérôme Duval  */
86ffb6a6eSJérôme Duval 
97ff74a7bSStephan Aßmus #include "InstallerApp.h"
107ff74a7bSStephan Aßmus 
1176fb7c29SAxel Dörfler #include <unistd.h>
1276fb7c29SAxel Dörfler 
136ffb6a6eSJérôme Duval #include <Alert.h>
1476fb7c29SAxel Dörfler #include <Roster.h>
156ffb6a6eSJérôme Duval #include <TextView.h>
166ffb6a6eSJérôme Duval 
1776fb7c29SAxel Dörfler #include <syscalls.h>
1876fb7c29SAxel Dörfler 
191565964aSMatt Madia #include "tracker_private.h"
2076fb7c29SAxel Dörfler #include "Utility.h"
211565964aSMatt Madia 
226ffb6a6eSJérôme Duval 
237ff74a7bSStephan Aßmus static const uint32 kMsgAgree = 'agre';
24e13de872SFreeman Lou static const uint32 kMsgNext = 'next';
257ff74a7bSStephan Aßmus 
26546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
27546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "InstallerApp"
287ff74a7bSStephan Aßmus 
2935d3acb2SJérôme Duval 
306ffb6a6eSJérôme Duval int main(int, char **)
316ffb6a6eSJérôme Duval {
326a40fd89SPanagiotis Vasilopoulos 	InstallerApp installer;
336a40fd89SPanagiotis Vasilopoulos 	installer.Run();
346ffb6a6eSJérôme Duval 	return 0;
356ffb6a6eSJérôme Duval }
366ffb6a6eSJérôme Duval 
377ff74a7bSStephan Aßmus 
386ffb6a6eSJérôme Duval InstallerApp::InstallerApp()
394a2da425SStephan Aßmus 	:
404a2da425SStephan Aßmus 	BApplication("application/x-vnd.Haiku-Installer")
416ffb6a6eSJérôme Duval {
4253ad1814SJérôme Duval }
4353ad1814SJérôme Duval 
447ff74a7bSStephan Aßmus 
457ff74a7bSStephan Aßmus void
467ff74a7bSStephan Aßmus InstallerApp::MessageReceived(BMessage* message)
477ff74a7bSStephan Aßmus {
487ff74a7bSStephan Aßmus 	switch (message->what) {
497ff74a7bSStephan Aßmus 		case kMsgAgree:
50dcee1c8cSAdrien Destugues 			fEULAWindow->PostMessage(B_QUIT_REQUESTED);
5153db2fc8SAdrien Destugues 			break;
52e13de872SFreeman Lou 		case kMsgNext:
537ff74a7bSStephan Aßmus 			new InstallerWindow();
547ff74a7bSStephan Aßmus 			break;
557ff74a7bSStephan Aßmus 
567ff74a7bSStephan Aßmus 		default:
577ff74a7bSStephan Aßmus 			BApplication::MessageReceived(message);
586ffb6a6eSJérôme Duval 	}
597ff74a7bSStephan Aßmus }
607ff74a7bSStephan Aßmus 
616ffb6a6eSJérôme Duval 
626ffb6a6eSJérôme Duval void
636ffb6a6eSJérôme Duval InstallerApp::ReadyToRun()
646ffb6a6eSJérôme Duval {
657ff74a7bSStephan Aßmus #if 1
667ff74a7bSStephan Aßmus 	// Show the EULA first.
67e13de872SFreeman Lou 	fEULAWindow = new EULAWindow();
687ff74a7bSStephan Aßmus #else
697ff74a7bSStephan Aßmus 	// Show the installer window without EULA.
707ff74a7bSStephan Aßmus 	new InstallerWindow();
717ff74a7bSStephan Aßmus #endif
726ffb6a6eSJérôme Duval }
7376fb7c29SAxel Dörfler 
7476fb7c29SAxel Dörfler 
7576fb7c29SAxel Dörfler void
7676fb7c29SAxel Dörfler InstallerApp::Quit()
7776fb7c29SAxel Dörfler {
7876fb7c29SAxel Dörfler 	BApplication::Quit();
7976fb7c29SAxel Dörfler 
8076fb7c29SAxel Dörfler 	if (!be_roster->IsRunning(kDeskbarSignature)) {
81*b05b0c1cSPanagiotis Vasilopoulos 		if (CurrentMessage()->GetBool("install_complete")) {
82058e754bSPanagiotis Vasilopoulos 			// Synchronize disks
8376fb7c29SAxel Dörfler 			sync();
8476fb7c29SAxel Dörfler 
8576fb7c29SAxel Dörfler 			if (Utility::IsReadOnlyVolume("/boot")) {
8676fb7c29SAxel Dörfler 				// Unblock CD tray, and eject the CD
8776fb7c29SAxel Dörfler 				Utility::BlockMedia("/boot", false);
8876fb7c29SAxel Dörfler 				Utility::EjectMedia("/boot");
8976fb7c29SAxel Dörfler 			}
9076fb7c29SAxel Dörfler 
91058e754bSPanagiotis Vasilopoulos 			// Quickly reboot without touching anything
92058e754bSPanagiotis Vasilopoulos 			// on disk (which we might just have ejected)
93353af6bfSAxel Dörfler 			_kern_shutdown(true);
94058e754bSPanagiotis Vasilopoulos 		} else {
95058e754bSPanagiotis Vasilopoulos 			// Return to FirstBootPrompt if the user hasn't
96058e754bSPanagiotis Vasilopoulos 			// installed Haiku yet
97*b05b0c1cSPanagiotis Vasilopoulos 			be_roster->Launch("application/x-vnd.Haiku-FirstBootPrompt");
98058e754bSPanagiotis Vasilopoulos 		}
9976fb7c29SAxel Dörfler 	}
10076fb7c29SAxel Dörfler }
101