-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPackage.hpp
192 lines (152 loc) · 3.89 KB
/
Package.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#ifndef PACKAGE_H
#define PACKAGE_H
#include "Manifest.hpp"
#include "Utils.hpp"
#include "rapidjson/document.h"
#include "rapidjson/rapidjson.h"
#include <optional>
#include <string>
#if defined(SWITCH) || defined(WII)
#define ROOT_PATH "/"
#elif defined(__WIIU__)
#define ROOT_PATH "fs:/vol/external01/"
#elif defined(_3DS)
#define ROOT_PATH "sdmc:/"
#else
#define ROOT_PATH "sdroot/"
#endif
#ifndef APP_VERSION
#define APP_VERSION "0.0.0"
#endif
#define APP_SHORTNAME "appstore"
class Get;
class Repo;
class GetRepo;
class LocalRepo;
class OSCRepo;
class UniStoreRepo;
/**
* A package is a single application that can be installed. It contains the URL to the zip file and any instructions to install it (like a GET manifest).
*
* The download and install process is handled here, but they will use logic in the parentRepo's class to get the zip URL and installation logic.
*/
class Package
{
public:
explicit Package(int state);
~Package();
Package(const Package& other) = default;
[[nodiscard]] std::string toString() const;
bool downloadZip(std::string_view tmp_path, float* progress = nullptr) const;
bool install(const std::string& pkg_path, const std::string& tmp_path);
bool remove(std::string_view pkg_path);
[[nodiscard]] const char* statusString() const;
void updateStatus(const std::string& pkg_path);
[[nodiscard]] std::string getIconUrl() const;
[[nodiscard]] std::string getBannerUrl() const;
[[nodiscard]] std::string getManifestUrl() const;
[[nodiscard]] std::string getScreenShotUrl(int count) const;
int isPreviouslyInstalled();
[[nodiscard]] std::string getUrlFileExt() const;
Manifest manifest;
[[nodiscard]] const std::string& getPackageName() const
{
return pkg_name;
}
[[nodiscard]] const std::string& getTitle() const
{
return title;
}
[[nodiscard]] const std::string& getAuthor() const
{
return author;
}
[[nodiscard]] const std::string& getShortDescription() const
{
return short_desc;
}
[[nodiscard]] const std::string& getLongDescription() const
{
return long_desc;
}
[[nodiscard]] const std::string& getVersion() const
{
return version;
}
[[nodiscard]] const std::string& getLicense() const
{
return license;
}
[[nodiscard]] const std::string& getChangelog() const
{
return changelog;
}
[[nodiscard]] int getStatus() const
{
return status;
}
[[nodiscard]] int getDownloadCount() const {
return downloads;
}
[[nodiscard]] int getDownloadSize() const {
return download_size;
}
[[nodiscard]] int getExtractedSize() const {
return extracted_size;
}
[[nodiscard]] std::string getHumanDownloadSize() const {
return getHumanReadableBytes(download_size);
}
[[nodiscard]] std::string getHumanExtractedSize() const {
return getHumanReadableBytes(extracted_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;
std::string title;
std::string author;
std::string short_desc;
std::string long_desc;
std::string version;
std::string license;
std::string changelog;
std::string url;
std::string sourceUrl;
std::string iconUrl;
std::string updated;
std::string binary;
int updated_timestamp = 0;
int downloads = 0;
int extracted_size = 0;
int download_size = 0;
int screens = 0;
std::string category;
// Sorting attributes
std::shared_ptr<Repo> mRepo;
int status; // local, update, installed, get
// bitmask for permissions, from left to right:
// unused, iosu, kernel, nand, usb, sd, wifi, sound
char permissions{};
friend Get;
friend Repo;
friend GetRepo;
friend LocalRepo;
friend OSCRepo;
friend UniStoreRepo;
};
#endif