BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / softwareupdater / UpdateAction.cpp
blob259ae6caae48ee78dd0e069963b6d4b0fc7e7d8b
1 /*
2 * Copyright 2017, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Brian Hill <supernova@tycho.email>
7 */
10 #include "UpdateAction.h"
12 #include <Application.h>
13 #include <Catalog.h>
14 #include <package/manager/Exceptions.h>
17 #undef B_TRANSLATION_CONTEXT
18 #define B_TRANSLATION_CONTEXT "UpdateAction"
21 using namespace BPackageKit;
22 //using namespace BPackageKit::BPrivate;
23 using namespace BPackageKit::BManager::BPrivate;
26 UpdateAction::UpdateAction(bool verbose)
28 fVerbose(verbose)
30 fUpdateManager = new(std::nothrow)
31 UpdateManager(B_PACKAGE_INSTALLATION_LOCATION_SYSTEM, verbose);
35 UpdateAction::~UpdateAction()
37 delete fUpdateManager;
41 status_t
42 UpdateAction::Perform(update_type action_request)
44 try {
45 fUpdateManager->CheckNetworkConnection();
47 update_type action = action_request;
48 // Prompt the user if needed
49 if (action == USER_SELECTION_NEEDED)
50 action = fUpdateManager->GetUpdateType();
52 if (action == CANCEL_UPDATE)
53 throw BAbortedByUserException();
54 else if (action <= INVALID_SELECTION || action >= UPDATE_TYPE_END)
55 throw BException(B_TRANSLATE(
56 "Invalid update type, cannot continue with updates"));
58 fUpdateManager->Init(BPackageManager::B_ADD_INSTALLED_REPOSITORIES
59 | BPackageManager::B_ADD_REMOTE_REPOSITORIES
60 | BPackageManager::B_REFRESH_REPOSITORIES);
61 fUpdateManager->CheckRepositories();
63 // fUpdateManager->SetDebugLevel(1);
64 if(action == UPDATE) {
65 // These values indicate that all updates should be installed
66 int packageCount = 0;
67 const char* const packages = "";
68 fUpdateManager->Update(&packages, packageCount);
69 } else if (action == FULLSYNC)
70 fUpdateManager->FullSync();
71 else
72 // Should not happen but just in case
73 throw BException(B_TRANSLATE(
74 "Invalid update type, cannot continue with updates"));
76 } catch (BFatalErrorException ex) {
77 fUpdateManager->FinalUpdate(B_TRANSLATE("Updates did not complete"),
78 ex.Message());
79 return ex.Error();
80 } catch (BAbortedByUserException ex) {
81 if (fVerbose)
82 fprintf(stderr, "Updates aborted by user: %s\n",
83 ex.Message().String());
84 // No need for a final message since user initiated cancel request
85 be_app->PostMessage(kMsgFinalQuit);
86 return B_OK;
87 } catch (BNothingToDoException ex) {
88 if (fVerbose)
89 fprintf(stderr, "Nothing to do while updating packages : %s\n",
90 ex.Message().String());
91 fUpdateManager->FinalUpdate(B_TRANSLATE("No updates available"),
92 B_TRANSLATE("There were no updates found."));
93 return B_OK;
94 } catch (BException ex) {
95 if (fVerbose)
96 fprintf(stderr, B_TRANSLATE(
97 "Exception occurred while updating packages : %s\n"),
98 ex.Message().String());
99 fUpdateManager->FinalUpdate(B_TRANSLATE("Updates did not complete"),
100 ex.Message());
101 return B_ERROR;
104 return B_OK;