From 91e348750be4b3db8e0cbd224973dc416562d8e6 Mon Sep 17 00:00:00 2001 From: J-D-K Date: Thu, 30 Oct 2025 13:45:46 -0400 Subject: [PATCH] Add separation comments to data. --- include/config/config.hpp | 1 + include/data/data.hpp | 1 + source/config/ConfigContext.cpp | 4 ++++ source/data/DataContext.cpp | 2 ++ source/data/TitleInfo.cpp | 34 +++++++++++++++++++-------------- source/data/User.cpp | 10 ++++++++++ 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/include/config/config.hpp b/include/config/config.hpp index d7525db..256985a 100644 --- a/include/config/config.hpp +++ b/include/config/config.hpp @@ -5,6 +5,7 @@ #include #include +/// @brief This API acts like a passthrough for the context so the context doesn't need to be global. namespace config { /// @brief Attempts to load config from file. If it fails, loads defaults. diff --git a/include/data/data.hpp b/include/data/data.hpp index d573559..8a307cf 100644 --- a/include/data/data.hpp +++ b/include/data/data.hpp @@ -7,6 +7,7 @@ #include #include +/// @brief The functions in this namespace serve as a passthrough API for the data context so it's not needed globally. namespace data { /// @brief Launches the data loading/initialization state. diff --git a/source/config/ConfigContext.cpp b/source/config/ConfigContext.cpp index 7c31405..b79c105 100644 --- a/source/config/ConfigContext.cpp +++ b/source/config/ConfigContext.cpp @@ -21,6 +21,8 @@ namespace constexpr const char *APP_ID_HEX_FORMAT = "%016llX"; } +// ---- Public functions ---- + void config::ConfigContext::create_directory() { const fslib::Path configDir{PATH_CONFIG_FOLDER}; @@ -176,6 +178,8 @@ void config::ConfigContext::get_custom_path(uint64_t applicationID, char *buffer std::memcpy(buffer, path.c_str(), path.length()); } +// ---- Private functions ---- + bool config::ConfigContext::load_config_file() { const fslib::Path configPath{PATH_CONFIG_FILE}; diff --git a/source/data/DataContext.cpp b/source/data/DataContext.cpp index 8cdd1d7..c35dfe5 100644 --- a/source/data/DataContext.cpp +++ b/source/data/DataContext.cpp @@ -16,6 +16,8 @@ namespace constexpr size_t SIZE_CTRL_DATA = sizeof(NsApplicationControlData); } +// ---- Public functions ---- + bool data::DataContext::load_create_users(sys::Task *task) { static constexpr int32_t MAX_SWITCH_ACCOUNTS = 8; diff --git a/source/data/TitleInfo.cpp b/source/data/TitleInfo.cpp index 8d99e88..29518e2 100644 --- a/source/data/TitleInfo.cpp +++ b/source/data/TitleInfo.cpp @@ -8,6 +8,8 @@ #include +// ---- Construction ---- + data::TitleInfo::TitleInfo(uint64_t applicationID) noexcept : m_applicationID(applicationID) { @@ -54,6 +56,8 @@ data::TitleInfo::TitleInfo(uint64_t applicationID, NsApplicationControlData &con TitleInfo::get_create_path_safe_title(); } +// ---- Public functions ---- + uint64_t data::TitleInfo::get_application_id() const noexcept { return m_applicationID; } const NsApplicationControlData *data::TitleInfo::get_control_data() const noexcept { return &m_data; } @@ -150,20 +154,6 @@ void data::TitleInfo::set_path_safe_title(const char *newPathSafe) noexcept std::memcpy(m_pathSafeTitle, newPathSafe, length); } -void data::TitleInfo::get_create_path_safe_title() noexcept -{ - const bool hasCustom = config::has_custom_path(m_applicationID); - if (hasCustom) - { - config::get_custom_path(m_applicationID, m_pathSafeTitle, TitleInfo::SIZE_PATH_SAFE); - return; - } - - const bool useTitleId = config::get_by_key(config::keys::USE_TITLE_IDS); - const bool sanitized = !useTitleId && stringutil::sanitize_string_for_path(m_entry->name, m_pathSafeTitle, SIZE_PATH_SAFE); - if (useTitleId || !sanitized) { std::snprintf(m_pathSafeTitle, TitleInfo::SIZE_PATH_SAFE, "%016lX", m_applicationID); } -} - void data::TitleInfo::load_icon() { // This is taken from the NacpStruct. @@ -180,3 +170,19 @@ void data::TitleInfo::load_icon() m_icon = gfxutil::create_generic_icon(text, 48, colors::DIALOG_DARK, colors::WHITE); } } + +// ---- Private functions ---- + +void data::TitleInfo::get_create_path_safe_title() noexcept +{ + const bool hasCustom = config::has_custom_path(m_applicationID); + if (hasCustom) + { + config::get_custom_path(m_applicationID, m_pathSafeTitle, TitleInfo::SIZE_PATH_SAFE); + return; + } + + const bool useTitleId = config::get_by_key(config::keys::USE_TITLE_IDS); + const bool sanitized = !useTitleId && stringutil::sanitize_string_for_path(m_entry->name, m_pathSafeTitle, SIZE_PATH_SAFE); + if (useTitleId || !sanitized) { std::snprintf(m_pathSafeTitle, TitleInfo::SIZE_PATH_SAFE, "%016lX", m_applicationID); } +} diff --git a/source/data/User.cpp b/source/data/User.cpp index 30b2096..0a75b6d 100644 --- a/source/data/User.cpp +++ b/source/data/User.cpp @@ -33,6 +33,8 @@ namespace // Function used to sort user data. Definition at the bottom. static bool sort_user_data(const data::UserDataEntry &entryA, const data::UserDataEntry &entryB); +// ---- Construction ---- + data::User::User(AccountUid accountID, FsSaveDataType saveType) noexcept : m_accountID(accountID) , m_saveType(saveType) @@ -58,6 +60,8 @@ data::User::User(AccountUid accountID, std::strncpy(m_pathSafeNickname, pathSafeNickname.data(), pathSafeNickname.length()); } +// ---- Move constructor & operator ---- + data::User::User(data::User &&user) noexcept { *this = std::move(user); } data::User &data::User::operator=(data::User &&user) noexcept @@ -78,6 +82,8 @@ data::User &data::User::operator=(data::User &&user) noexcept return *this; } +// ---- Public functions ---- + void data::User::add_data(uint64_t applicationID, const FsSaveDataInfo &saveInfo, const PdmPlayStatistics &playStats) { auto dataPair = std::make_pair(saveInfo, playStats); @@ -152,6 +158,8 @@ void data::User::erase_save_info_by_id(uint64_t applicationID) m_userData.erase(target); } +// ---- Private functions ---- + void data::User::load_user_data() { if (!m_userData.empty()) { m_userData.clear(); } @@ -262,6 +270,8 @@ data::UserSaveInfoList::iterator data::User::find_title_by_id(uint64_t applicati return std::find_if(m_userData.begin(), m_userData.end(), [&](const auto &entry) { return entry.first == applicationID; }); } +// ---- Static functions ---- + static bool sort_user_data(const data::UserDataEntry &entryA, const data::UserDataEntry &entryB) { // Structured bindings to make this slightly more readable.