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@warpmail.net> 7 */ 8 9 10 #include "UpdateAction.h" 11 12 #include <Application.h> 13 #include <Catalog.h> 14 #include <package/manager/Exceptions.h> 15 16 #include "constants.h" 17 18 19 #undef B_TRANSLATION_CONTEXT 20 #define B_TRANSLATION_CONTEXT "UpdateAction" 21 22 23 using namespace BPackageKit; 24 //using namespace BPackageKit::BPrivate; 25 using namespace BPackageKit::BManager::BPrivate; 26 27 28 UpdateAction::UpdateAction() 29 { 30 fUpdateManager = new(std::nothrow) 31 UpdateManager(B_PACKAGE_INSTALLATION_LOCATION_SYSTEM); 32 } 33 34 35 UpdateAction::~UpdateAction() 36 { 37 delete fUpdateManager; 38 } 39 40 41 status_t 42 UpdateAction::Perform() 43 { 44 try { 45 fUpdateManager->CheckNetworkConnection(); 46 47 fUpdateManager->Init(BPackageManager::B_ADD_INSTALLED_REPOSITORIES 48 | BPackageManager::B_ADD_REMOTE_REPOSITORIES 49 | BPackageManager::B_REFRESH_REPOSITORIES); 50 51 // These values indicate that all updates should be installed 52 int packageCount = 0; 53 const char* const packages = ""; 54 55 // perform the update 56 // fUpdateManager->SetDebugLevel(1); 57 fUpdateManager->Update(&packages, packageCount); 58 } catch (BFatalErrorException ex) { 59 fUpdateManager->FinalUpdate(B_TRANSLATE("Updates did not complete"), 60 ex.Message()); 61 return ex.Error(); 62 } catch (BAbortedByUserException ex) { 63 fprintf(stderr, "Updates aborted by user: %s\n", 64 ex.Message().String()); 65 // No need for a final message since user initiated cancel request 66 be_app->PostMessage(kMsgFinalQuit); 67 return B_OK; 68 } catch (BNothingToDoException ex) { 69 fprintf(stderr, "Nothing to do while updating packages : %s\n", 70 ex.Message().String()); 71 fUpdateManager->FinalUpdate(B_TRANSLATE("No updates available"), 72 B_TRANSLATE("There were no updates found.")); 73 return B_OK; 74 } catch (BException ex) { 75 fprintf(stderr, "Exception occurred while updating packages : %s\n", 76 ex.Message().String()); 77 fUpdateManager->FinalUpdate(B_TRANSLATE("Updates did not complete"), 78 ex.Message()); 79 return B_ERROR; 80 } 81 82 return B_OK; 83 } 84