From 074b209ca886519d761b33733026c6f09615ff52 Mon Sep 17 00:00:00 2001 From: nshaheed Date: Sat, 16 Mar 2024 10:48:33 -0700 Subject: [PATCH 1/4] maded logo tinier --- src/exec.h | 113 ++++++++++++++++++----------------------------------- 1 file changed, 39 insertions(+), 74 deletions(-) diff --git a/src/exec.h b/src/exec.h index fffc0fa..86a6bb6 100644 --- a/src/exec.h +++ b/src/exec.h @@ -44,78 +44,43 @@ void execCommand(std::string cmd, std::vector args, Manager* manage void printLogo() { - std::cout << " AAA " << std::endl; -std::cout << " AAA " << std::endl; -std::cout << " A A AAA " << std::endl; -std::cout << " AAAA AAAA " << std::endl; -std::cout << " AAAA AAAAA " << std::endl; -std::cout << " AAAA AAAAA " << std::endl; -std::cout << " AAAAAAAA OAAAAAG A A AAAAA " << std::endl; -std::cout << " AAK AAAAAAAAA AAAAAAAAAAA Y A AAAA AA AA " << std::endl; -std::cout << " AAAAAAAAAA AAAAAAAA AAAAAAA AAA AAAAAG AAAAA AAAA " << std::endl; -std::cout << " AAAAAAAAA AAAAAAAAA AAAAAAAAAAAAAAAAAAAAA AAAA AAAAA " << std::endl; -std::cout << " AAAAAAAA AAA AAA AAAAAAA AAAA AAAA " << std::endl; -std::cout << " AAAAAAAA AAAAAAA AAAA AAAA " << std::endl; -std::cout << " AAAA AAAAA " << std::endl; -std::cout << " AAAAA AAAA " << std::endl; -std::cout << " AAAAAAAAAAA AAAAA AAAA " << std::endl; -std::cout << " AAAAAAAAA AAAAAA AAAAAA AAAA AAAA " << std::endl; -std::cout << " AAAAAAA AA AA AAAAAAAAAAAA AAAAA AAAAA " << std::endl; -std::cout << " AAAAAAA AAAAAAAAAA AAAAA AAAA AAAA " << std::endl; -std::cout << " AAAAAAAEAAAAAA AAAAA A AA " << std::endl; -std::cout << " AAAAAAAAAAAA AAAAA AAAA " << std::endl; -std::cout << " AAAAAAAAAAAAAAAA AAAAAAAAAAA UAAAA AAAA " << std::endl; -std::cout << " AAA OAAA AAAAAAAA AAAAAAA AA " << std::endl; -std::cout << " AAAAAAAAAAAAAAAA AAAAAA AAAAAAAA " << std::endl; -std::cout << " AAAAAAA " << std::endl; -std::cout << " AAAKAAA " << std::endl; -std::cout << " AAAAAA " << std::endl; -std::cout << " AAAAA " << std::endl; -std::cout << " " << std::endl; -std::cout << " " << std::endl; -std::cout << " " << std::endl; -std::cout << " " << std::endl; -std::cout << " " << std::endl; -std::cout << " " << std::endl; -std::cout << " " << std::endl; -std::cout << " " << std::endl; -std::cout << " " << std::endl; -std::cout << " " << std::endl; -std::cout << " " << std::endl; -std::cout << " AAAA " << std::endl; -std::cout << " AAAAA A AAAA " << std::endl; -std::cout << " AAAA AA AAA " << std::endl; -std::cout << " AAAAA A FAAAAAC AAA AAA " << std::endl; -std::cout << " AAAW AAAAAAA A H AAAAA PAAA A AAA " << std::endl; -std::cout << " AAAAAA AAAA AA AA AAAAAP AAA A AA " << std::endl; -std::cout << " AAAAAAAAA AA CA A AAAAAAA AAA AA " << std::endl; -std::cout << " AAAAA AAAAAAAA AAAA AA A AA A " << std::endl; -std::cout << " AAAAAAAAAAAAA AA A A AA A A " << std::endl; -std::cout << " AAAAAAAA A A AA A A A " << std::endl; -std::cout << " AA AAAA A A A AA A A " << std::endl; -std::cout << " AAAAAA A A AA A A A " << std::endl; -std::cout << " AAAAA A AH AAF A AA A A " << std::endl; -std::cout << " AAAAAA AAAA A AM AAAA AA A " << std::endl; -std::cout << " AAAAA A A GA AV A A AA AA " << std::endl; -std::cout << " AAAAA A A LA A AAM AAAAAA AAAA DAA AA " << std::endl; -std::cout << " AAAA A A A AA AAAAAA AA AAAAAAP A A AAAAAAAAAAAAAAVA AA " << std::endl; -std::cout << " A AF A A AA A AS AA A AAAA AG AA AA AAAAAAAAAAAAAAANAA AA AAA " << std::endl; -std::cout << " A A A A AAA AAAA NA AT AA AAAH AAAA A AAAAAAA AA A A AANAAAAAAAAAAAAA " << std::endl; -std::cout << " AAAA AAAA AAAA AA AA LA A AA AA ZA AAAAA CAA AAA AAAAAAAAAAAAAAAA " << std::endl; -std::cout << " AAAA AA A AAAAA A OAT A AA AA A A AA A AAAAAA A A " << std::endl; -std::cout << " AAAA A A AA AOAA AJ QA A A A A AAUSAA A A A A " << std::endl; -std::cout << " AAAAAAAAAAAAAAAAAX AAAA A AAAAA AA A A A A A AAAAA AA A A A " << std::endl; -std::cout << " AAA AAV AA A AAAASA A A A A A A A AAAA AAAA A A " << std::endl; -std::cout << " AAAAAAAAAAAAAAAAX AAAA AA AN A A KA MAV A A A A AA A AA A A " << std::endl; -std::cout << " AAAA A AA AAAA A YA AA A A A A AA A A A " << std::endl; -std::cout << " A A AAAA AA AA A A AA ZAR AA A A A AAAA AAAA " << std::endl; -std::cout << " AAAA AA AA AA A A A OAK AA AI AX A A AAAA NA A " << std::endl; -std::cout << " AA A AAAA AAAAAD A AU AA QAA BA A A A AAAA A A " << std::endl; -std::cout << " AAAAA A AAA AA A A GAQ A A YA AAA A AU AAAA " << std::endl; -std::cout << " AA AAAA AAAD RAA AAA AAA AAA AAA A A " << std::endl; -std::cout << " AAAAA AAA A A " << std::endl; -std::cout << " AAAAA A A " << std::endl; -std::cout << " A AA " << std::endl; -std::cout << " AA A " << std::endl; -std::cout << " AAA " << std::endl; + std::cout << std::endl; + std::cout << " ss " << std::endl; + std::cout << " rox zop " << std::endl; + std::cout << " xor ony " << std::endl; + std::cout << " tkjiimtz yrljjjjjjox oo qnx " << std::endl; + std::cout << " zsliiiilrwzzxsliiimty sov wor " << std::endl; + std::cout << " xrmjjjjmsz oo poz " << std::endl; + std::cout << " row yoq " << std::endl; + std::cout << " xqnrutlhiihmv oo tov " << std::endl; + std::cout << " zskiijnpmklry uot oo " << std::endl; + std::cout << " yohhmu pnyzop " << std::endl; + std::cout << " uljjjjjjjihpy znopoy " << std::endl; + std::cout << " vnfo " << std::endl; + std::cout << " vmr " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " zxwvx " << std::endl; + std::cout << " zxxwwwy ywwz " << std::endl; + std::cout << " xx yy ywwwxxz zxvx " << std::endl; + std::cout << " ysoooopuz xw xx ww " << std::endl; + std::cout << " womsz ywy zwx xx " << std::endl; + std::cout << " tmt wx ww ww " << std::endl; + std::cout << " xnq ww zz zwx ww " << std::endl; + std::cout << " zno ww yz zz zyz ww xvz " << std::endl; + std::cout << " poy ww zyz xvuvvv vx ywxyxyzywwxxxxwwxz " << std::endl; + std::cout << " oo xw zxy yxz zyz xtv wwwwzwvz zuuxyxxy " << std::endl; + std::cout << " oo zwx wtw zwx yz ywx xtvy wwz xx " << std::endl; + std::cout << " tmnooooooopv ww wwww yxz zzz zvw zww ww xx " << std::endl; + std::cout << " tmoooxxywxy ywz xwzxwz zxyz zzz zvw zwx ww " << std::endl; + std::cout << " zwx wx ww zz yyz yy ww ywy xw " << std::endl; + std::cout << " xwvw wvy yy zyyzyz xx xwz zwy " << std::endl; + std::cout << " vtx z zyz xx " << std::endl; + std::cout << " xw " << std::endl; + std::cout << " xy " << std::endl; + std::cout << " " << std::endl; } From 56273011fc056b4d47020d26617a3b7e04b1d9ad Mon Sep 17 00:00:00 2001 From: nshaheed Date: Sat, 16 Mar 2024 17:31:28 -0700 Subject: [PATCH 2/4] added uninstaller --- CMakeLists.txt | 4 ++++ src/exec.h | 2 ++ src/fetch.cpp | 7 +++++-- src/fetch.h | 4 ++-- src/manager.cpp | 12 +++++++++++- src/manager.h | 3 +++ src/uninstaller.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/uninstaller.h | 30 ++++++++++++++++++++++++++++++ src/util.cpp | 10 ++++++++++ src/util.h | 10 ++++++++++ 10 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 src/uninstaller.cpp create mode 100644 src/uninstaller.h create mode 100644 src/util.cpp create mode 100644 src/util.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 986fad0..dcda5da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,10 @@ set(SOURCES src/exec.h src/fetch.h src/fetch.cpp + src/uninstaller.h + src/uninstaller.cpp + src/util.h + src/util.cpp ) find_package(Curses REQUIRED) diff --git a/src/exec.h b/src/exec.h index 86a6bb6..82aa6e8 100644 --- a/src/exec.h +++ b/src/exec.h @@ -35,6 +35,8 @@ void execCommand(std::string cmd, std::vector args, Manager* manage // manager->fetch->fetch("https://ccrma.stanford.edu/~nshaheed/220a/hw4/hw4.wav"); // manager->fetch->fetch("https://ccrma.stanford.edu/~nshaheed/rave_models/chafe_cello.ts"); manager->install(args[0]); + } else if (cmd == "uninstall") { + manager->uninstall(args[0]); } else if (cmd == "help") { printLogo(); } else { diff --git a/src/fetch.cpp b/src/fetch.cpp index ea06906..cf198e2 100644 --- a/src/fetch.cpp +++ b/src/fetch.cpp @@ -5,6 +5,7 @@ #include #include "fetch.h" +#include "util.h" // Callback function to update progress int progressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { @@ -66,12 +67,14 @@ int progressCallback(void *clientp, double dltotal, double dlnow, double ultotal - chump info www.package.com/ABSaturator.zip # the path is a url to be downloaded - chump info pkg-name # search pre-defined directories for the pkg name (or online pkg list) */ -optional Fetch::fetch(std::string url, std::string package_name) { +optional Fetch::fetch(std::string url, Package package) { if (!isURL(url)) { std::cerr << "Not a URL!" << std::endl; return {}; } + std::string package_name = package.name; + // struct progress data; CURL *curl; FILE *fp; @@ -129,7 +132,7 @@ optional Fetch::fetch(std::string url, std::string package_name) { // get home environment variable const char* env_p = std::getenv("HOME"); fs::path home = fs::path(env_p); - fs::path install_dir = home / ".chuck/lib" / package_name; + fs::path install_dir = packagePath(package); fs::path install_path = install_dir / filename; // create dir if needed diff --git a/src/fetch.h b/src/fetch.h index 200354e..2dec865 100644 --- a/src/fetch.h +++ b/src/fetch.h @@ -24,13 +24,13 @@ namespace fs = std::filesystem; class FetchBase { public: virtual ~FetchBase() = default; - virtual optional fetch(std::string data, std::string package_name) = 0; + virtual optional fetch(std::string data, Package package) = 0; }; class Fetch : public FetchBase { public: - optional fetch(std::string data, std::string package_name); + optional fetch(std::string data, Package package); public: bool isJSONFile(std::string path); diff --git a/src/manager.cpp b/src/manager.cpp index edc6411..88a780f 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -9,6 +9,7 @@ Manager::Manager() { Manager::Manager(std::string package_list_path) { fetch = new Fetch(); package_list = new PackageList(package_list_path); + uninstaller = new Uninstaller(package_list); } optional Manager::getPackage(string name) { @@ -29,7 +30,7 @@ bool Manager::install(std::string packageName) { // fetch for (auto file: package.files) { - fetch->fetch(file, package.name); + fetch->fetch(file, package); } // validate @@ -39,4 +40,13 @@ bool Manager::install(std::string packageName) { return true; } +bool Manager::uninstall(std::string packageName) { + if(!uninstaller->uninstall(packageName)) { + std::cerr << "Failed to uninstall " << packageName << std::endl; + return false; + } else { + std::cout << "Successfully uninstalled " << packageName << std::endl; + } + return true; +} diff --git a/src/manager.h b/src/manager.h index e444ba3..d1134eb 100644 --- a/src/manager.h +++ b/src/manager.h @@ -9,6 +9,7 @@ #include "package.h" #include "package_list.h" #include "fetch.h" +#include "uninstaller.h" using std::optional; using std::string; @@ -28,6 +29,7 @@ class Manager { optional getPackage(string name); bool install(string packageName); + bool uninstall(string packageName); public: @@ -36,6 +38,7 @@ class Manager { private: PackageList* package_list; + UninstallerBase* uninstaller; }; diff --git a/src/uninstaller.cpp b/src/uninstaller.cpp new file mode 100644 index 0000000..b1bbea7 --- /dev/null +++ b/src/uninstaller.cpp @@ -0,0 +1,45 @@ +#include "uninstaller.h" +#include "util.h" + +Uninstaller::Uninstaller(PackageList* pkg_list) { + package_list = pkg_list; +} + +bool Uninstaller::uninstall(std::string package_name) { + // lookup package name (default to latest version) + auto pkg = package_list->lookup(package_name); + + if (!pkg) { + std::cerr << "BADBADBAD" << std::endl; + return false; + } + + auto package = pkg.value(); + + fs::path package_dir = packagePath(package); + + // validate that it's actually a directory + if (!fs::exists(package_dir) || !fs::is_directory(package_dir)) { + std::cerr << "Package " << package.name << " was not found." << std::endl; + return false; + } + + + // only delete files that chump knows about + for (auto file: package.files) { + fs::path filename = fs::path(file).filename(); + + fs::path filepath = package_dir / filename; + + if (!fs::remove(filepath)) { + std::cerr << "File " << filepath << " not found." << std::endl; + } + } + + // If the package directory still has files, don't remove it. + if (!fs::remove(package_dir)) { + std::cerr << "Directory " << package_dir << " not removed." << std::endl; + } + + return true; +} diff --git a/src/uninstaller.h b/src/uninstaller.h new file mode 100644 index 0000000..02977a8 --- /dev/null +++ b/src/uninstaller.h @@ -0,0 +1,30 @@ +#ifndef __UNINSTALLER_H__ +#define __UNINSTALLER_H__ + +#include "package.h" +#include "package_list.h" + +using std::optional; + +namespace fs = std::filesystem; + +// Abstract base class +class UninstallerBase { +public: + virtual ~UninstallerBase() = default; + virtual bool uninstall(std::string package_name) = 0; +}; + + +class Uninstaller : public UninstallerBase { + public: + Uninstaller(PackageList* package_list); + + public: + bool uninstall(std::string package_name); + + private: + PackageList* package_list; +}; + +#endif diff --git a/src/util.cpp b/src/util.cpp new file mode 100644 index 0000000..2d75b8e --- /dev/null +++ b/src/util.cpp @@ -0,0 +1,10 @@ +#include "util.h" + +// Returns the path to the directory where a package will be installed +fs::path packagePath(Package p) { + const char* env_p = std::getenv("HOME"); + fs::path home = fs::path(env_p); + fs::path package_dir = home / ".chuck/lib" / p.name; + + return package_dir; +} diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..655c6f3 --- /dev/null +++ b/src/util.h @@ -0,0 +1,10 @@ +#ifndef __UTIL_H__ +#define __UTIL_H__ + +#include "package.h" + +namespace fs = std::filesystem; + +fs::path packagePath(Package p); + +#endif From a7be681f1a1fbf29b389a55adcc25950e88ac7f3 Mon Sep 17 00:00:00 2001 From: nshaheed Date: Sat, 16 Mar 2024 17:58:30 -0700 Subject: [PATCH 3/4] made file list os-level --- data/packages.json | 8 ++-- src/manager.cpp | 4 +- src/package.cpp | 63 +++++++++++++++------------- src/package.h | 27 ++++++------ src/test/data/test-package-list.json | 4 +- src/test/package_list_test.cpp | 2 +- src/uninstaller.cpp | 3 +- 7 files changed, 63 insertions(+), 48 deletions(-) diff --git a/data/packages.json b/data/packages.json index 6b1f79b..57d2ba7 100644 --- a/data/packages.json +++ b/data/packages.json @@ -7,9 +7,11 @@ "api_version": "10.1", "homepage": "https://github.com/nshaheed/hydra-chugin", "repository": "https://github.com/nshaheed/hydra-chugin", - "files": [ - "https://ccrma.stanford.edu/~nshaheed/chugins/Hydra/linux/Hydra.chug" - ], + "files": { + "linux": [ + "https://ccrma.stanford.edu/~nshaheed/chugins/Hydra/linux/Hydra.chug" + ] + }, "spec_file": "specA", "authors": ["Nick Shaheed"], "license": "tbd", diff --git a/src/manager.cpp b/src/manager.cpp index 88a780f..0f477c4 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -28,8 +28,10 @@ bool Manager::install(std::string packageName) { auto package = pkg.value(); + // TODO actually fetch operating system + std::string os = "linux"; // fetch - for (auto file: package.files) { + for (auto file: package.files[os]) { fetch->fetch(file, package); } diff --git a/src/package.cpp b/src/package.cpp index 822b190..30d2341 100644 --- a/src/package.cpp +++ b/src/package.cpp @@ -20,45 +20,50 @@ bool Package::operator==(const Package& other) const { // Output stream operator overload std::ostream& operator<<(std::ostream& os, const Package& pkg) { - os << "Owner: " << pkg.owner << "\n" - << "Name: " << pkg.name << "\n" - << "Version: " << pkg.version << "\n" - << "API Version: " << pkg.api_version << "\n" - << "Homepage: " << pkg.homepage << "\n" - << "Repository: " << pkg.repository << "\n" - << "Spec File: " << pkg.specFile << "\n" - << "Authors: ["; + os << "Owner: " << pkg.owner << "\n" + << "Name: " << pkg.name << "\n" + << "Version: " << pkg.version << "\n" + << "API Version: " << pkg.api_version << "\n" + << "Homepage: " << pkg.homepage << "\n" + << "Repository: " << pkg.repository << "\n" + << "Spec File: " << pkg.specFile << "\n" + << "Authors: ["; - if (!pkg.authors.empty()) { - os << pkg.authors[0]; + if (!pkg.authors.empty()) { + os << pkg.authors[0]; - for (size_t i = 1; i < pkg.authors.size(); ++i) { - os << ", " << pkg.authors[i]; - } + for (size_t i = 1; i < pkg.authors.size(); ++i) { + os << ", " << pkg.authors[i]; } + } - os << "]\nLicense: " << pkg.license << "\n" - << "Description: " << pkg.description << "\n" - << "Keywords: ["; + os << "]\nLicense: " << pkg.license << "\n" + << "Description: " << pkg.description << "\n" + << "Keywords: ["; - if (!pkg.keywords.empty()) { - os << pkg.keywords[0]; + if (!pkg.keywords.empty()) { + os << pkg.keywords[0]; - for (size_t i = 1; i < pkg.keywords.size(); ++i) { - os << ", " << pkg.keywords[i]; - } + for (size_t i = 1; i < pkg.keywords.size(); ++i) { + os << ", " << pkg.keywords[i]; } + } - os << "]\nFiles: ["; - if (!pkg.files.empty()) { - os << pkg.files[0]; + os << "]\nFiles: ["; + if (!pkg.files.empty()) { - for (size_t i = 1; i < pkg.files.size(); ++i) { - os << ", " << pkg.files[i]; - } + for (const auto& pair : pkg.files) { + os << pair.first << ":" << std::endl; + + // os << pkg.files[0]; + + for (size_t i = 1; i < pair.second.size(); ++i) { + os << ", " << pair.second[i]; + } } - os << "]\n"; - return os; + } + os << "]\n"; + return os; } void to_json(json& j, const Package& p) { diff --git a/src/package.h b/src/package.h index 2489f57..d5784dd 100644 --- a/src/package.h +++ b/src/package.h @@ -8,21 +8,24 @@ #include using json = nlohmann::json; +using std::string; +using std::map; +using std::vector; // A Package describes the package spec. struct Package { - std::string owner; - std::string name; - std::string version; - std::string api_version; - std::vector files; // download urls - std::string homepage; - std::string repository; - std::string specFile; - std::vector authors; - std::string license; - std::string description; - std::vector keywords; + string owner; + string name; + string version; + string api_version; + map> files; // map of operating system to list of files to download + string homepage; + string repository; + string specFile; + vector authors; + string license; + string description; + vector keywords; // Equality operator overload bool operator==(const Package& other) const; diff --git a/src/test/data/test-package-list.json b/src/test/data/test-package-list.json index 6b3f4b3..4f107ba 100644 --- a/src/test/data/test-package-list.json +++ b/src/test/data/test-package-list.json @@ -7,7 +7,9 @@ "api_version": "9.0", "homepage": "http://example.com", "repository": "http://repo.com", - "files": ["https://ccrma.stanford.edu/~nshaheed/chugins/Hydra/linux/butt.chug"], + "files": { + "linux": ["https://ccrma.stanford.edu/~nshaheed/chugins/Hydra/linux/butt.chug"] + }, "spec_file": "specA", "authors": ["AuthorA", "AuthorB"], "license": "MIT", diff --git a/src/test/package_list_test.cpp b/src/test/package_list_test.cpp index 207f7f5..ab0db88 100644 --- a/src/test/package_list_test.cpp +++ b/src/test/package_list_test.cpp @@ -7,7 +7,7 @@ TEST_CASE("Load db file", "[PackageList]") { std::string path = "./data/test-package-list.json"; PackageList pkglist = PackageList(path); - Package want = {"John", "Butt", "1.0", "9.0", {"https://ccrma.stanford.edu/~nshaheed/chugins/Hydra/linux/butt.chug"}, "http://example.com", "http://repo.com", "specA", {"AuthorA", "AuthorB"}, "MIT", "DescriptionA", {"KeywordA", "KeywordB"}}; + Package want = {"John", "Butt", "1.0", "9.0", {{"linux", {"https://ccrma.stanford.edu/~nshaheed/chugins/Hydra/linux/butt.chug"}}}, "http://example.com", "http://repo.com", "specA", {"AuthorA", "AuthorB"}, "MIT", "DescriptionA", {"KeywordA", "KeywordB"}}; optional got = pkglist.lookup("Butt"); diff --git a/src/uninstaller.cpp b/src/uninstaller.cpp index b1bbea7..de28b1c 100644 --- a/src/uninstaller.cpp +++ b/src/uninstaller.cpp @@ -24,9 +24,10 @@ bool Uninstaller::uninstall(std::string package_name) { return false; } + std::string os = "linux"; // only delete files that chump knows about - for (auto file: package.files) { + for (auto file: package.files[os]) { fs::path filename = fs::path(file).filename(); fs::path filepath = package_dir / filename; From ada77a63c352c60ccff66ae714668dce0e3e8ee9 Mon Sep 17 00:00:00 2001 From: nshaheed Date: Mon, 8 Apr 2024 15:37:45 -0700 Subject: [PATCH 4/4] added whichOS functionality --- src/manager.cpp | 3 ++- src/uninstaller.cpp | 2 +- src/util.cpp | 13 +++++++++++++ src/util.h | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/manager.cpp b/src/manager.cpp index 0f477c4..cc5c53f 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -1,5 +1,6 @@ #include "manager.h" +#include "util.h" Manager::Manager() { fetch = new Fetch(); @@ -29,7 +30,7 @@ bool Manager::install(std::string packageName) { auto package = pkg.value(); // TODO actually fetch operating system - std::string os = "linux"; + std::string os = whichOS(); // fetch for (auto file: package.files[os]) { fetch->fetch(file, package); diff --git a/src/uninstaller.cpp b/src/uninstaller.cpp index de28b1c..b7805e1 100644 --- a/src/uninstaller.cpp +++ b/src/uninstaller.cpp @@ -24,7 +24,7 @@ bool Uninstaller::uninstall(std::string package_name) { return false; } - std::string os = "linux"; + std::string os = whichOS(); // only delete files that chump knows about for (auto file: package.files[os]) { diff --git a/src/util.cpp b/src/util.cpp index 2d75b8e..caf0fe4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -8,3 +8,16 @@ fs::path packagePath(Package p) { return package_dir; } + +std::string whichOS() { +#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) + return "windows"; +#elif defined(__APPLE__) + return "mac"; +#elif defined(__linux__) + return "linux"; +#else + std::cerr << "Unknown operating system" << std::endl; + return ""; +#endif +} diff --git a/src/util.h b/src/util.h index 655c6f3..dcea006 100644 --- a/src/util.h +++ b/src/util.h @@ -7,4 +7,6 @@ namespace fs = std::filesystem; fs::path packagePath(Package p); +std::string whichOS(); + #endif