Add extended Prism Launcher cat pack support
Some checks failed
Build / build-deb (push) Blocked by required conditions
Build / build-appimage (push) Blocked by required conditions
Build / build-android (push) Blocked by required conditions
Build / build-windows (push) Blocked by required conditions
Build / download-system-deps (push) Successful in 47s
Build / build-gentoo (push) Has been cancelled
Build / get-source-code (push) Has been cancelled
Some checks failed
Build / build-deb (push) Blocked by required conditions
Build / build-appimage (push) Blocked by required conditions
Build / build-android (push) Blocked by required conditions
Build / build-windows (push) Blocked by required conditions
Build / download-system-deps (push) Successful in 47s
Build / build-gentoo (push) Has been cancelled
Build / get-source-code (push) Has been cancelled
This commit is contained in:
parent
286242a126
commit
88b5d10e53
2 changed files with 90 additions and 2 deletions
4
cats.hpp
4
cats.hpp
|
@ -38,9 +38,9 @@ enum class CatDataType {
|
|||
class CatData {
|
||||
std::optional<MemoryCat> mem;
|
||||
fs::path path;
|
||||
std::string name;
|
||||
CatDataType type;
|
||||
public:
|
||||
std::string name;
|
||||
inline std::string get_name() {
|
||||
return name;
|
||||
}
|
||||
|
@ -85,4 +85,4 @@ class CatData {
|
|||
this->path = path;
|
||||
}
|
||||
};
|
||||
extern std::vector<CatData> &get_cat_data();
|
||||
extern std::vector<CatData> &get_cat_data();
|
||||
|
|
88
main.cpp
88
main.cpp
|
@ -17,6 +17,8 @@
|
|||
#endif
|
||||
#include "web_functions.hpp"
|
||||
#include "cats.hpp"
|
||||
#include <json/value.h>
|
||||
#include <chrono>
|
||||
using namespace Looper;
|
||||
using namespace Looper::Options;
|
||||
using namespace Looper::Log;
|
||||
|
@ -191,6 +193,92 @@ extern "C" int looper_run_as_executable(std::vector<std::string> args) {
|
|||
for (auto const&dir_entry : std::filesystem::directory_iterator(baseDir)) {
|
||||
if (dir_entry.is_regular_file()) {
|
||||
cat_data.push_back(CatData(dir_entry.path()));
|
||||
} else if (dir_entry.is_directory()) {
|
||||
fs::path json_path = dir_entry.path() / fs::path("catpack.json");
|
||||
if (fs::exists(json_path)) {
|
||||
std::ifstream stream(json_path);
|
||||
Json::Value config;
|
||||
stream >> config;
|
||||
std::string name = dir_entry.path().stem().string();
|
||||
if (config.isMember("name")) {
|
||||
name = config["name"].asString();
|
||||
}
|
||||
if (!config.isMember("default")) {
|
||||
continue;
|
||||
}
|
||||
std::string str = config["default"].asString();
|
||||
if (config.isMember("variants")) {
|
||||
Json::Value variants = config["variants"];
|
||||
int prev_score = INT_MAX;
|
||||
auto now = std::chrono::system_clock::now();
|
||||
time_t now_tt = std::chrono::system_clock::to_time_t(now);
|
||||
tm local_tm = *localtime(&now_tt);
|
||||
auto cur_day = local_tm.tm_mday;
|
||||
auto cur_month = local_tm.tm_mon;
|
||||
auto cur_yday = local_tm.tm_yday;
|
||||
DEBUG.writefln("Current date: %d ([MM/DD] %02d/%02d)", cur_yday, cur_month + 1, cur_day);
|
||||
|
||||
for (auto &variant : variants) {
|
||||
if (variant.isMember("startTime") && variant.isMember("endTime")) {
|
||||
Json::Value startTime = variant["startTime"];
|
||||
Json::Value endTime = variant["endTime"];
|
||||
int score = 0;
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
tm start_tm;
|
||||
tm end_tm;
|
||||
if (startTime.isMember("day") && startTime.isMember("month")) {
|
||||
int day = startTime["day"].asInt();
|
||||
int month = startTime["month"].asInt();
|
||||
tm tmp{};
|
||||
tmp.tm_year = local_tm.tm_year;
|
||||
tmp.tm_mon = month - 1;
|
||||
tmp.tm_mday = day;
|
||||
time_t t = std::mktime(&tmp);
|
||||
tmp = *std::localtime(&t);
|
||||
start = tmp.tm_yday;
|
||||
start_tm = tmp;
|
||||
}
|
||||
if (endTime.isMember("day") && endTime.isMember("month")) {
|
||||
int day = endTime["day"].asInt();
|
||||
int month = endTime["month"].asInt();
|
||||
tm tmp{};
|
||||
tmp.tm_year = local_tm.tm_year;
|
||||
tmp.tm_mon = month - 1;
|
||||
tmp.tm_mday = day;
|
||||
time_t t = std::mktime(&tmp);
|
||||
tmp = *std::localtime(&t);
|
||||
end = tmp.tm_yday;
|
||||
end_tm = tmp;
|
||||
}
|
||||
if (variant.isMember("path")) DEBUG.writefln("Variant %s: %d-%d ([MM/DD] %02d/%02d-%02d/%02d)", variant["path"].asCString(), start, end, start_tm.tm_mon+1, start_tm.tm_mday, end_tm.tm_mon+1, end_tm.tm_mday);
|
||||
if (end < start) {
|
||||
if (cur_yday > end && cur_yday < start) continue;
|
||||
score = end - start + 365;
|
||||
} else {
|
||||
if (cur_yday > end || cur_yday < start) continue;
|
||||
score = end - start;
|
||||
}
|
||||
if (variant.isMember("path")) {
|
||||
if (prev_score > score) {
|
||||
auto newPath = variant["path"].asString();
|
||||
if (!fs::exists(newPath)) {
|
||||
continue;
|
||||
}
|
||||
str = newPath;
|
||||
prev_score = score;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fs::path usedPath = dir_entry.path() / fs::path(str);
|
||||
if (fs::exists(usedPath)) {
|
||||
auto data = CatData(usedPath);
|
||||
data.name = name;
|
||||
cat_data.push_back(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue