Add extended Prism Launcher cat pack support
Some checks failed
Build / build-gentoo (push) Successful in 1m54s
Build / download-system-deps (push) Successful in 43s
Build / get-source-code (push) Successful in 4m4s
Build / build-deb (push) Failing after 2m9s
Build / build-appimage (push) Successful in 1m4s
Build / build-android (push) Failing after 6s
Build / build-windows (push) Has been cancelled

This commit is contained in:
Zachary Hall 2024-12-24 11:24:47 -08:00
parent 286242a126
commit 4e966ba8da
2 changed files with 88 additions and 2 deletions

View file

@ -38,9 +38,9 @@ enum class CatDataType {
class CatData { class CatData {
std::optional<MemoryCat> mem; std::optional<MemoryCat> mem;
fs::path path; fs::path path;
std::string name;
CatDataType type; CatDataType type;
public: public:
std::string name;
inline std::string get_name() { inline std::string get_name() {
return name; return name;
} }

View file

@ -17,6 +17,8 @@
#endif #endif
#include "web_functions.hpp" #include "web_functions.hpp"
#include "cats.hpp" #include "cats.hpp"
#include <json/value.h>
#include <chrono>
using namespace Looper; using namespace Looper;
using namespace Looper::Options; using namespace Looper::Options;
using namespace Looper::Log; using namespace Looper::Log;
@ -191,6 +193,90 @@ extern "C" int looper_run_as_executable(std::vector<std::string> args) {
for (auto const&dir_entry : std::filesystem::directory_iterator(baseDir)) { for (auto const&dir_entry : std::filesystem::directory_iterator(baseDir)) {
if (dir_entry.is_regular_file()) { if (dir_entry.is_regular_file()) {
cat_data.push_back(CatData(dir_entry.path())); 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;
for (auto &variant : variants) {
if (variant.isMember("startTime") && variant.isMember("endTime")) {
Json::Value startTime = variant["startTime"];
Json::Value endTime = variant["endTime"];
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;
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 #endif