xref: /haiku/src/apps/softwareupdater/CheckAction.cpp (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 /*
2  * Copyright 2017, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Brian Hill <supernova@tycho.email>
7  */
8 
9 
10 #include "CheckAction.h"
11 
12 #include <Application.h>
13 #include <Catalog.h>
14 #include <package/manager/Exceptions.h>
15 
16 
17 #undef B_TRANSLATION_CONTEXT
18 #define B_TRANSLATION_CONTEXT "CheckAction"
19 
20 
21 using namespace BPackageKit;
22 //using namespace BPackageKit::BPrivate;
23 using namespace BPackageKit::BManager::BPrivate;
24 
25 
26 CheckAction::CheckAction(bool verbose)
27 {
28 	fCheckManager = new(std::nothrow)
29 		CheckManager(B_PACKAGE_INSTALLATION_LOCATION_SYSTEM, verbose);
30 }
31 
32 
33 CheckAction::~CheckAction()
34 {
35 	delete fCheckManager;
36 }
37 
38 
39 status_t
40 CheckAction::Perform()
41 {
42 	try {
43 		fCheckManager->CheckNetworkConnection();
44 
45 		fCheckManager->Init(BPackageManager::B_ADD_INSTALLED_REPOSITORIES
46 			| BPackageManager::B_ADD_REMOTE_REPOSITORIES
47 			| BPackageManager::B_REFRESH_REPOSITORIES);
48 
49 //		fUpdateManager->SetDebugLevel(1);
50 		// These values indicate that all updates should be installed
51 		int packageCount = 0;
52 		const char* const packages = "";
53 		fCheckManager->Update(&packages, packageCount);
54 	} catch (BFatalErrorException& ex) {
55 		fprintf(stderr, B_TRANSLATE(
56 				"Fatal error while checking for updates: %s\n"),
57 			ex.Message().String());
58 		be_app->PostMessage(kMsgFinalQuit);
59 		return ex.Error();
60 	} catch (BAbortedByUserException& ex) {
61 		be_app->PostMessage(kMsgFinalQuit);
62 		return B_OK;
63 	} catch (BNothingToDoException& ex) {
64 		puts(B_TRANSLATE("There were no updates found."));
65 		fCheckManager->NoUpdatesNotification();
66 		be_app->PostMessage(kMsgFinalQuit);
67 		return B_OK;
68 	} catch (BException& ex) {
69 		fprintf(stderr, B_TRANSLATE(
70 				"Exception occurred while checking for updates: %s\n"),
71 			ex.Message().String());
72 		be_app->PostMessage(kMsgFinalQuit);
73 		return B_ERROR;
74 	}
75 
76 	return B_OK;
77 }
78