1 /* 2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2013, Rene Gollent, <rene@gollent.com> 4 * Copyright 2020-2021, Andrew Lindesay <apl@lindesay.co.nz> 5 * 6 * All rights reserved. Distributed under the terms of the MIT License. 7 */ 8 9 10 #include "AbstractPackageProcess.h" 11 12 #include "Model.h" 13 #include "PackageManager.h" 14 15 16 using namespace BPackageKit; 17 18 // #pragma mark - PackageAction 19 20 21 AbstractPackageProcess::AbstractPackageProcess( 22 PackageInfoRef package, Model* model) 23 : 24 fPackage(package), 25 fModel(model), 26 fInstallLocation(AbstractPackageProcess::InstallLocation(package)) 27 { 28 // TODO: ideally if the package is installed at multiple locations, 29 // the user should be able to pick which one to remove. 30 // TODO: allow configuring the installation location 31 fPackageManager = new(std::nothrow) PackageManager( 32 (BPackageInstallationLocation)fInstallLocation); 33 } 34 35 36 AbstractPackageProcess::~AbstractPackageProcess() 37 { 38 delete fPackageManager; 39 } 40 41 42 PackageInfoRef 43 AbstractPackageProcess::FindPackageByName(const BString& name) 44 { 45 return fModel->PackageForName(name); 46 } 47 48 49 /*static*/ int32 50 AbstractPackageProcess::InstallLocation(const PackageInfoRef& package) 51 { 52 const PackageInstallationLocationSet& locations 53 = package->InstallationLocations(); 54 55 // If the package is already installed, return its first installed location 56 if (locations.size() != 0) 57 return *locations.begin(); 58 59 return B_PACKAGE_INSTALLATION_LOCATION_SYSTEM; 60 } 61 62 63