Skip to content

Commit

Permalink
more getters, fix fakeManifest generation
Browse files Browse the repository at this point in the history
  • Loading branch information
vgmoose committed Nov 25, 2023
1 parent 3b8d37a commit 40d47c2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ int Get::validateRepos() const
return 0;
}

std::vector<Package> Get::list()
{
// packages is a vector of shared_ptrs, so we need to dereference them
std::vector<Package> ret;
for (auto& cur : packages) {
if (cur != nullptr)
ret.emplace_back(*cur);
}
return ret;
}

std::vector<Package> Get::search(const std::string& query)
{
// TODO: replace with inverted index for speed
Expand Down
1 change: 1 addition & 0 deletions src/Get.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Get
int toggleRepo(Repo& repo); // enable/disable the specified repo (and write changes)

std::vector<Package> search(const std::string& query); // return a list of packages matching query
std::vector<Package> list(); // return a list of all packages
std::optional<Package> lookup(const std::string& pkg_name);
void addLocalRepo();
void removeDuplicates();
Expand Down
4 changes: 3 additions & 1 deletion src/Manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Manifest::Manifest(const std::vector<std::string>& paths, std::string_view root_

Manifest::Manifest(std::string_view ManifestPath, std::string_view root_path)
{
fakeManifestPossible = true;
struct stat buf = {};
if (stat(ManifestPath.data(), &buf) == 0)
{
Expand Down Expand Up @@ -73,7 +74,8 @@ Manifest::Manifest(std::string_view ManifestPath, std::string_view root_path)
}
}
valid = true;
fakeManifestPossible = true;
} else {
fakeManifestPossible = false;
}
ManifestFile.close();
}
Expand Down
35 changes: 34 additions & 1 deletion src/Package.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Package

int isPreviouslyInstalled();

Manifest manifest;

[[nodiscard]] const std::string& getPackageName() const
{
return pkg_name;
Expand Down Expand Up @@ -99,6 +101,38 @@ class Package
return status;
}

[[nodiscard]] int getDownloadCount() const {
return downloads;
}

[[nodiscard]] int getDownloadSize() const {
return download_size;
}

[[nodiscard]] int getExtractedSize() const {
return download_size;
}

[[nodiscard]] int getScreenshotCount() const {
return screens;
}

[[nodiscard]] int getUpdatedAtTimestamp() const {
return updated_timestamp;
}

[[nodiscard]] const std::string& getUpdatedAt() const {
return updated;
}

[[nodiscard]] const std::string& getCategory() const {
return category;
}

[[nodiscard]] const std::string& getBinary() const {
return binary;
}

private:
// Package attributes
std::string pkg_name;
Expand All @@ -118,7 +152,6 @@ class Package
std::string updated;
std::string binary;

Manifest manifest;
int updated_timestamp = 0;

int downloads = 0;
Expand Down

0 comments on commit 40d47c2

Please sign in to comment.