Inventory logic re-write

This commit is contained in:
acidicoala
2023-01-09 03:26:42 +03:00
parent 55ada47bef
commit 6347e3f148
25 changed files with 332 additions and 251 deletions
+10 -18
View File
@@ -3,21 +3,13 @@
#include <koalabox/cache.hpp>
#include <koalabox/logger.hpp>
struct App {
Vector<AppId_t> dlc_ids;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(App, dlc_ids) // NOLINT(misc-const-correctness)
};
using Apps = Map<String, App>;
constexpr auto KEY_APPS = "apps";
Apps get_cached_apps() {
AppDlcNameMap get_cached_apps() noexcept {
try {
const auto cache = koalabox::cache::read_from_cache(KEY_APPS);
return cache.get<Apps>();
return cache.get<AppDlcNameMap>();
} catch (const Exception& e) {
LOG_WARN("Failed to get cached apps: {}", e.what())
@@ -27,31 +19,31 @@ Apps get_cached_apps() {
namespace smoke_api::app_cache {
Vector<AppId_t> get_dlc_ids(AppId_t app_id) {
Vector<DLC> get_dlcs(AppId_t app_id) noexcept {
try {
LOG_DEBUG("Reading cached DLC IDs for the app: {}", app_id)
const auto app = get_cached_apps().at(std::to_string(app_id));
const auto apps = get_cached_apps();
return app.dlc_ids;
return DLC::get_dlcs_from_apps(apps, app_id);
} catch (const Exception& e) {
LOG_ERROR("Error reading DLCs from disk cache: ", e.what())
return {};
}
}
bool save_dlc_ids(AppId_t app_id, const Vector<AppId_t>& dlc_ids) {
bool save_dlcs(AppId_t app_id, const Vector<DLC>& dlcs) noexcept {
try {
LOG_DEBUG("Caching DLC IDs for the app: {}", app_id)
auto apps = get_cached_apps();
apps[std::to_string(app_id)] = {
.dlc_ids = dlc_ids
};
apps[std::to_string(app_id)] = App{.dlcs=DLC::get_dlc_map_from_vector(dlcs)};
return koalabox::cache::save_to_cache(KEY_APPS, Json(apps));
} catch (const Exception& e) {
LOG_ERROR("Failed to cache DLC IDs fro the app: {}", app_id)
LOG_ERROR("Error saving DLCs to disk cache: {}", e.what())
return false;
}
+2 -2
View File
@@ -4,8 +4,8 @@
namespace smoke_api::app_cache {
Vector<AppId_t> get_dlc_ids(AppId_t app_id);
Vector<DLC> get_dlcs(AppId_t app_id) noexcept;
bool save_dlc_ids(AppId_t app_id, const Vector<AppId_t>& dlc_ids);
bool save_dlcs(AppId_t app_id, const Vector<DLC>& dlcs) noexcept;
}
+3 -2
View File
@@ -81,16 +81,17 @@ namespace smoke_api {
globals::smokeapi_handle = module_handle;
koalabox::cache::init_cache(paths::get_cache_path());
config::init();
if (config::instance.logging) {
koalabox::logger::init_file_logger(paths::get_log_path());
}
// FIXME: Dynamic timestamp resolution: https://stackoverflow.com/q/17212518
LOG_INFO("🐨 {} v{} | Compiled at '{}'", PROJECT_NAME, PROJECT_VERSION, __TIMESTAMP__)
koalabox::cache::init_cache(paths::get_cache_path());
const auto exe_path = Path(koalabox::win_util::get_module_file_name_or_throw(nullptr));
const auto exe_name = exe_path.filename().string();