Add separation comments to data.

This commit is contained in:
J-D-K 2025-10-30 13:45:46 -04:00
parent ec2417d068
commit 91e348750b
6 changed files with 38 additions and 14 deletions

View File

@ -5,6 +5,7 @@
#include <string_view>
#include <vector>
/// @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.

View File

@ -7,6 +7,7 @@
#include <unordered_map>
#include <vector>
/// @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.

View File

@ -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};

View File

@ -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;

View File

@ -8,6 +8,8 @@
#include <cstring>
// ---- 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); }
}

View File

@ -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.