xref: /haiku/src/apps/softwareupdater/CheckAction.cpp (revision 992ae400ec160a3e2ef6ad71c011cd688c9f2476)
173c2c7b4SBrian Hill /*
273c2c7b4SBrian Hill  * Copyright 2017, Haiku, Inc. All Rights Reserved.
373c2c7b4SBrian Hill  * Distributed under the terms of the MIT License.
473c2c7b4SBrian Hill  *
573c2c7b4SBrian Hill  * Authors:
6acfd5c86SBrian Hill  *		Brian Hill <supernova@tycho.email>
773c2c7b4SBrian Hill  */
873c2c7b4SBrian Hill 
973c2c7b4SBrian Hill 
1073c2c7b4SBrian Hill #include "CheckAction.h"
1173c2c7b4SBrian Hill 
1273c2c7b4SBrian Hill #include <Application.h>
1373c2c7b4SBrian Hill #include <Catalog.h>
1473c2c7b4SBrian Hill #include <package/manager/Exceptions.h>
1573c2c7b4SBrian Hill 
1673c2c7b4SBrian Hill 
1773c2c7b4SBrian Hill #undef B_TRANSLATION_CONTEXT
1873c2c7b4SBrian Hill #define B_TRANSLATION_CONTEXT "CheckAction"
1973c2c7b4SBrian Hill 
2073c2c7b4SBrian Hill 
2173c2c7b4SBrian Hill using namespace BPackageKit;
2273c2c7b4SBrian Hill //using namespace BPackageKit::BPrivate;
2373c2c7b4SBrian Hill using namespace BPackageKit::BManager::BPrivate;
2473c2c7b4SBrian Hill 
2573c2c7b4SBrian Hill 
CheckAction(bool verbose)26b35bccc0SBrian Hill CheckAction::CheckAction(bool verbose)
2773c2c7b4SBrian Hill {
2873c2c7b4SBrian Hill 	fCheckManager = new(std::nothrow)
29b35bccc0SBrian Hill 		CheckManager(B_PACKAGE_INSTALLATION_LOCATION_SYSTEM, verbose);
3073c2c7b4SBrian Hill }
3173c2c7b4SBrian Hill 
3273c2c7b4SBrian Hill 
~CheckAction()3373c2c7b4SBrian Hill CheckAction::~CheckAction()
3473c2c7b4SBrian Hill {
3573c2c7b4SBrian Hill 	delete fCheckManager;
3673c2c7b4SBrian Hill }
3773c2c7b4SBrian Hill 
3873c2c7b4SBrian Hill 
3973c2c7b4SBrian Hill status_t
Perform()4073c2c7b4SBrian Hill CheckAction::Perform()
4173c2c7b4SBrian Hill {
4273c2c7b4SBrian Hill 	try {
4373c2c7b4SBrian Hill 		fCheckManager->CheckNetworkConnection();
4473c2c7b4SBrian Hill 
4573c2c7b4SBrian Hill 		fCheckManager->Init(BPackageManager::B_ADD_INSTALLED_REPOSITORIES
4673c2c7b4SBrian Hill 			| BPackageManager::B_ADD_REMOTE_REPOSITORIES
4773c2c7b4SBrian Hill 			| BPackageManager::B_REFRESH_REPOSITORIES);
4873c2c7b4SBrian Hill 
4973c2c7b4SBrian Hill //		fUpdateManager->SetDebugLevel(1);
5073c2c7b4SBrian Hill 		// These values indicate that all updates should be installed
5173c2c7b4SBrian Hill 		int packageCount = 0;
5273c2c7b4SBrian Hill 		const char* const packages = "";
5373c2c7b4SBrian Hill 		fCheckManager->Update(&packages, packageCount);
54*992ae400SMurai Takashi 	} catch (BFatalErrorException& ex) {
5573c2c7b4SBrian Hill 		fprintf(stderr, B_TRANSLATE(
5673c2c7b4SBrian Hill 				"Fatal error while checking for updates: %s\n"),
5773c2c7b4SBrian Hill 			ex.Message().String());
5873c2c7b4SBrian Hill 		be_app->PostMessage(kMsgFinalQuit);
5973c2c7b4SBrian Hill 		return ex.Error();
60*992ae400SMurai Takashi 	} catch (BAbortedByUserException& ex) {
6173c2c7b4SBrian Hill 		be_app->PostMessage(kMsgFinalQuit);
6273c2c7b4SBrian Hill 		return B_OK;
63*992ae400SMurai Takashi 	} catch (BNothingToDoException& ex) {
64b35bccc0SBrian Hill 		puts(B_TRANSLATE("There were no updates found."));
65b35bccc0SBrian Hill 		fCheckManager->NoUpdatesNotification();
6673c2c7b4SBrian Hill 		be_app->PostMessage(kMsgFinalQuit);
6773c2c7b4SBrian Hill 		return B_OK;
68*992ae400SMurai Takashi 	} catch (BException& ex) {
6973c2c7b4SBrian Hill 		fprintf(stderr, B_TRANSLATE(
7073c2c7b4SBrian Hill 				"Exception occurred while checking for updates: %s\n"),
7173c2c7b4SBrian Hill 			ex.Message().String());
7273c2c7b4SBrian Hill 		be_app->PostMessage(kMsgFinalQuit);
7373c2c7b4SBrian Hill 		return B_ERROR;
7473c2c7b4SBrian Hill 	}
7573c2c7b4SBrian Hill 
7673c2c7b4SBrian Hill 	return B_OK;
7773c2c7b4SBrian Hill }
78