Add extended Prism Launcher cat pack support
Some checks failed
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 40s
Build / build-gentoo (push) Failing after 1m16s
Build / get-source-code (push) Successful in 3m54s
Build / build-deb (push) Has been cancelled
Some checks failed
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 40s
Build / build-gentoo (push) Failing after 1m16s
Build / get-source-code (push) Successful in 3m54s
Build / build-deb (push) Has been cancelled
This commit is contained in:
parent
286242a126
commit
dc61c0807f
1 changed files with 77 additions and 0 deletions
77
main.cpp
77
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,81 @@ 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 catpack_json;
|
||||
stream >> catpack_json;
|
||||
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")) {
|
||||
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 + 1;
|
||||
auto cur_yday = local_tm.tm_yday;
|
||||
int score = 0;
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
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.yday;
|
||||
}
|
||||
if (endTime.isMember("day") && endTime.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);
|
||||
end = tmp.yday;
|
||||
}
|
||||
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)) cat_data.push_back(CatData(used_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue