Add extended Prism Launcher cat pack support
Some checks failed
Build / download-system-deps (push) Successful in 41s
Build / build-gentoo (push) Successful in 1m40s
Build / get-source-code (push) Successful in 4m0s
Build / build-deb (push) Failing after 2m16s
Build / build-appimage (push) Successful in 1m5s
Build / build-android (push) Failing after 6s
Build / build-windows (push) Failing after 3m48s
Some checks failed
Build / download-system-deps (push) Successful in 41s
Build / build-gentoo (push) Successful in 1m40s
Build / get-source-code (push) Successful in 4m0s
Build / build-deb (push) Failing after 2m16s
Build / build-appimage (push) Successful in 1m5s
Build / build-android (push) Failing after 6s
Build / build-windows (push) Failing after 3m48s
This commit is contained in:
parent
286242a126
commit
62e67d3cd4
2 changed files with 84 additions and 2 deletions
4
cats.hpp
4
cats.hpp
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -85,4 +85,4 @@ class CatData {
|
||||||
this->path = path;
|
this->path = path;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
extern std::vector<CatData> &get_cat_data();
|
extern std::vector<CatData> &get_cat_data();
|
||||||
|
|
82
main.cpp
82
main.cpp
|
@ -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,86 @@ 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 + 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.tm_yday;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
if (variant.isMember("path")) DEBUG.writefln("Variant %s: %d-%d", variant["path"].asCString(), start, end);
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in a new issue