2 * Copyright 2017, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Brian Hill <supernova@tycho.email>
10 #include "UpdateAction.h"
12 #include <Application.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
)
30 fUpdateManager
= new(std::nothrow
)
31 UpdateManager(B_PACKAGE_INSTALLATION_LOCATION_SYSTEM
, verbose
);
35 UpdateAction::~UpdateAction()
37 delete fUpdateManager
;
42 UpdateAction::Perform(update_type action_request
)
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
67 const char* const packages
= "";
68 fUpdateManager
->Update(&packages
, packageCount
);
69 } else if (action
== FULLSYNC
)
70 fUpdateManager
->FullSync();
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"),
80 } catch (BAbortedByUserException ex
) {
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
);
87 } catch (BNothingToDoException ex
) {
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."));
94 } catch (BException ex
) {
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"),