This commit is contained in:
Crunch (Chaz9) 2024-09-29 22:24:19 +01:00
parent c922d6559f
commit a7822c2ddb

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm> #include <algorithm>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -12,13 +13,15 @@
#include "core/file_sys/registered_cache.h" #include "core/file_sys/registered_cache.h"
#include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/filesystem/filesystem.h"
#include "core/loader/loader.h" #include "core/loader/loader.h"
#include "core/memory.h"
#include "core/nintendo_switch_library.h" #include "core/nintendo_switch_library.h"
namespace Core { namespace Core {
/** /**
* NintendoSwitchLibrary class manages the operations related to installed games * NintendoSwitchLibrary class manages the operations related to installed games
* on the emulated Nintendo Switch, including listing games and launching them. * on the emulated Nintendo Switch, including listing games, launching them,
* and providing additional functionality inspired by multi-system emulation.
*/ */
class NintendoSwitchLibrary { class NintendoSwitchLibrary {
public: public:
@ -28,6 +31,7 @@ public:
u64 program_id; u64 program_id;
std::string title_name; std::string title_name;
std::string file_path; std::string file_path;
u32 version;
}; };
[[nodiscard]] std::vector<GameInfo> GetInstalledGames() { [[nodiscard]] std::vector<GameInfo> GetInstalledGames() {
@ -38,9 +42,10 @@ public:
if (content_type == FileSys::ContentRecordType::Program) { if (content_type == FileSys::ContentRecordType::Program) {
const auto title_name = GetGameName(program_id); const auto title_name = GetGameName(program_id);
const auto file_path = cache.GetEntryUnparsed(program_id, FileSys::ContentRecordType::Program); const auto file_path = cache.GetEntryUnparsed(program_id, FileSys::ContentRecordType::Program);
const auto version = GetGameVersion(program_id);
if (!title_name.empty() && !file_path.empty()) { if (!title_name.empty() && !file_path.empty()) {
games.push_back({program_id, title_name, file_path}); games.push_back({program_id, title_name, file_path, version});
} }
} }
} }
@ -59,6 +64,11 @@ public:
return ""; return "";
} }
[[nodiscard]] u32 GetGameVersion(u64 program_id) {
const auto& patch_manager = system.GetFileSystemController().GetPatchManager(program_id);
return patch_manager.GetGameVersion().value_or(0);
}
[[nodiscard]] bool LaunchGame(u64 program_id) { [[nodiscard]] bool LaunchGame(u64 program_id) {
const auto file_path = system.GetContentProvider().GetUserNANDCache().GetEntryUnparsed(program_id, FileSys::ContentRecordType::Program); const auto file_path = system.GetContentProvider().GetUserNANDCache().GetEntryUnparsed(program_id, FileSys::ContentRecordType::Program);
@ -73,6 +83,12 @@ public:
return false; return false;
} }
// Check firmware compatibility
if (!CheckFirmwareCompatibility(program_id)) {
LOG_ERROR(Core, "Firmware version not compatible with game. program_id={:016X}", program_id);
return false;
}
const auto result = system.Load(*loader); const auto result = system.Load(*loader);
if (result != ResultStatus::Success) { if (result != ResultStatus::Success) {
LOG_ERROR(Core, "Failed to load game. Error: {}, program_id={:016X}", result, program_id); LOG_ERROR(Core, "Failed to load game. Error: {}, program_id={:016X}", result, program_id);
@ -83,8 +99,51 @@ public:
return true; return true;
} }
bool CheckForUpdates(u64 program_id) {
// TODO: Implement update checking logic
return false;
}
bool ApplyUpdate(u64 program_id) {
// TODO: Implement update application logic
return false;
}
bool SetButtonMapping(const std::string& button_config) {
// TODO: Implement button mapping logic
return false;
}
bool CreateSaveState(u64 program_id, const std::string& save_state_name) {
// TODO: Implement save state creation
return false;
}
bool LoadSaveState(u64 program_id, const std::string& save_state_name) {
// TODO: Implement save state loading
return false;
}
void EnableFastForward(bool enable) {
// TODO: Implement fast forward functionality
}
void EnableRewind(bool enable) {
// TODO: Implement rewind functionality
}
private: private:
const Core::System& system; const Core::System& system;
bool CheckFirmwareCompatibility(u64 program_id) {
// TODO: Implement firmware compatibility check
return true;
}
}; };
// Use smart pointer for better memory management
std::unique_ptr<NintendoSwitchLibrary> CreateNintendoSwitchLibrary(Core::System& system) {
return std::make_unique<NintendoSwitchLibrary>(system);
}
} // namespace Core } // namespace Core