mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-08-28 05:24:31 -05:00
Add DataContext for data cleanup, add cache invalidation at boot.
This commit is contained in:
80
include/data/DataContext.hpp
Normal file
80
include/data/DataContext.hpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
#include "data/DataCommon.hpp"
|
||||
#include "data/TitleInfo.hpp"
|
||||
#include "data/User.hpp"
|
||||
#include "sys/Task.hpp"
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace data
|
||||
{
|
||||
class DataContext
|
||||
{
|
||||
public:
|
||||
/// @brief Default constructor.
|
||||
DataContext() = default;
|
||||
|
||||
/// @brief Loads the users from the system and creates the accounts for system users.
|
||||
bool load_create_users(sys::Task *task);
|
||||
|
||||
/// @brief Loops and runs the load routine for all users found.
|
||||
void load_user_save_info(sys::Task *task);
|
||||
|
||||
/// @brief Gets a vector of pointers to the users loaded.
|
||||
void get_users(data::UserList &listOut);
|
||||
|
||||
/// @brief Loads the titles from the Switch's application records.
|
||||
void load_application_records(sys::Task *task);
|
||||
|
||||
/// @brief Returns whether a title is loaded with the application ID passed.
|
||||
bool title_is_loaded(uint64_t applicationID);
|
||||
|
||||
/// @brief Attempts to load a title with the application ID passed.
|
||||
void load_title(uint64_t applicationID);
|
||||
|
||||
/// @brief Returns the title info mapped to applicationID. nullptr on not found.
|
||||
data::TitleInfo *get_title_by_id(uint64_t applicationID);
|
||||
|
||||
/// @brief Gets a vector of pointers to all of the current title info instances.
|
||||
void get_title_info_list(data::TitleInfoList &listOut);
|
||||
|
||||
/// @brief Gets a list of title info that has savedata for type.
|
||||
void get_title_info_list_by_type(FsSaveDataType type, data::TitleInfoList &listOut);
|
||||
|
||||
/// @brief Imports the SVI files from the SD card.
|
||||
void import_svi_files(sys::Task *task);
|
||||
|
||||
/// @brief Attempts to read the cache file from the SD card.
|
||||
bool read_cache(sys::Task *task);
|
||||
|
||||
/// @brief Writes the cache to file.
|
||||
bool write_cache(sys::Task *task);
|
||||
|
||||
/// @brief Processes the icon queue.
|
||||
void process_icon_queue();
|
||||
|
||||
private:
|
||||
/// @brief User vector.
|
||||
std::vector<data::User> m_users{};
|
||||
|
||||
/// @brief Map of titles paired with their application ID.
|
||||
std::unordered_map<uint64_t, data::TitleInfo> m_titleInfo{};
|
||||
|
||||
/// @brief Queue of the above to process the icons.
|
||||
std::vector<data::DataCommon *> m_iconQueue{};
|
||||
|
||||
/// @brief Mutex for users.
|
||||
std::mutex m_userMutex{};
|
||||
|
||||
/// @brief Mutex for titles.
|
||||
std::mutex m_titleMutex{};
|
||||
|
||||
/// @brief Mutex to make sure the icon queue doesn't get mutilated.
|
||||
std::mutex m_iconQueueMutex{};
|
||||
|
||||
/// @brief Whether or not the cache is still valid.
|
||||
bool m_cacheIsValid{};
|
||||
};
|
||||
}
|
||||
@@ -5,9 +5,15 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <switch.h>
|
||||
#include <vector>
|
||||
|
||||
namespace data
|
||||
{
|
||||
class TitleInfo;
|
||||
|
||||
/// @brief Vector of pointers to titleinfo instances.
|
||||
using TitleInfoList = std::vector<data::TitleInfo *>;
|
||||
|
||||
/// @brief Class that holds data related to titles loaded from the system.
|
||||
class TitleInfo final : public data::DataCommon
|
||||
{
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace data
|
||||
{
|
||||
class User;
|
||||
|
||||
/// @brief Type used to store save info and play statistics in the vector. Vector is used to preserve the order since I
|
||||
/// can't use a map without having to extra heap allocate it.
|
||||
using UserDataEntry = std::pair<uint64_t, std::pair<FsSaveDataInfo, PdmPlayStatistics>>;
|
||||
@@ -17,6 +19,9 @@ namespace data
|
||||
/// @brief Type definition for the user save info/play stats vector.
|
||||
using UserSaveInfoList = std::vector<UserDataEntry>;
|
||||
|
||||
/// @brief A vector of pointers to User instances.
|
||||
using UserList = std::vector<data::User *>;
|
||||
|
||||
/// @brief Class that stores data for the user.
|
||||
class User final : public data::DataCommon
|
||||
{
|
||||
|
||||
@@ -9,10 +9,6 @@
|
||||
|
||||
namespace data
|
||||
{
|
||||
/// @brief Declaration for user list/user pointer vector.
|
||||
using UserList = std::vector<data::User *>;
|
||||
using TitleInfoList = std::vector<data::TitleInfo *>;
|
||||
|
||||
/// @brief Launches the data loading/initialization state.
|
||||
/// @param clear Whether or not the cache should be cleared.
|
||||
/// @param onDestruction Function that is executed upon destruction of the data loading screen.
|
||||
|
||||
Reference in New Issue
Block a user