mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-23 09:53:10 -06:00
fix
This commit is contained in:
parent
6803515773
commit
c922d6559f
1 changed files with 55 additions and 41 deletions
|
@ -16,61 +16,75 @@
|
|||
|
||||
namespace Core {
|
||||
|
||||
NintendoSwitchLibrary::NintendoSwitchLibrary(Core::System& system) : system(system) {}
|
||||
/**
|
||||
* NintendoSwitchLibrary class manages the operations related to installed games
|
||||
* on the emulated Nintendo Switch, including listing games and launching them.
|
||||
*/
|
||||
class NintendoSwitchLibrary {
|
||||
public:
|
||||
explicit NintendoSwitchLibrary(Core::System& system) : system(system) {}
|
||||
|
||||
std::vector<NintendoSwitchLibrary::GameInfo> NintendoSwitchLibrary::GetInstalledGames() {
|
||||
std::vector<GameInfo> games;
|
||||
const auto& cache = system.GetContentProvider().GetUserNANDCache();
|
||||
struct GameInfo {
|
||||
u64 program_id;
|
||||
std::string title_name;
|
||||
std::string file_path;
|
||||
};
|
||||
|
||||
for (const auto& nca : cache.GetAllEntries()) {
|
||||
if (nca.second == FileSys::ContentRecordType::Program) {
|
||||
const auto program_id = nca.first;
|
||||
const auto title_name = GetGameName(program_id);
|
||||
const auto file_path = cache.GetEntryUnparsed(program_id, FileSys::ContentRecordType::Program);
|
||||
[[nodiscard]] std::vector<GameInfo> GetInstalledGames() {
|
||||
std::vector<GameInfo> games;
|
||||
const auto& cache = system.GetContentProvider().GetUserNANDCache();
|
||||
|
||||
if (title_name.empty() || file_path.empty()) {
|
||||
continue;
|
||||
for (const auto& [program_id, content_type] : cache.GetAllEntries()) {
|
||||
if (content_type == FileSys::ContentRecordType::Program) {
|
||||
const auto title_name = GetGameName(program_id);
|
||||
const auto file_path = cache.GetEntryUnparsed(program_id, FileSys::ContentRecordType::Program);
|
||||
|
||||
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});
|
||||
}
|
||||
|
||||
return games;
|
||||
}
|
||||
|
||||
return games;
|
||||
}
|
||||
[[nodiscard]] std::string GetGameName(u64 program_id) {
|
||||
const auto& patch_manager = system.GetFileSystemController().GetPatchManager(program_id);
|
||||
const auto metadata = patch_manager.GetControlMetadata();
|
||||
|
||||
std::string NintendoSwitchLibrary::GetGameName(u64 program_id) {
|
||||
const auto& patch_manager = system.GetFileSystemController().GetPatchManager(program_id);
|
||||
const auto metadata = patch_manager.GetControlMetadata();
|
||||
if (metadata.first != nullptr) {
|
||||
return metadata.first->GetApplicationName();
|
||||
}
|
||||
|
||||
if (metadata.first != nullptr) {
|
||||
return metadata.first->GetApplicationName();
|
||||
return "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
[[nodiscard]] bool LaunchGame(u64 program_id) {
|
||||
const auto file_path = system.GetContentProvider().GetUserNANDCache().GetEntryUnparsed(program_id, FileSys::ContentRecordType::Program);
|
||||
|
||||
bool NintendoSwitchLibrary::LaunchGame(u64 program_id) {
|
||||
const auto file_path = system.GetContentProvider().GetUserNANDCache().GetEntryUnparsed(program_id, FileSys::ContentRecordType::Program);
|
||||
if (file_path.empty()) {
|
||||
LOG_ERROR(Core, "Failed to launch game. File not found for program_id={:016X}", program_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_path.empty()) {
|
||||
LOG_ERROR(Core, "Failed to launch game. File not found for program_id={:016X}", program_id);
|
||||
return false;
|
||||
const auto loader = Loader::GetLoader(system, file_path);
|
||||
if (!loader) {
|
||||
LOG_ERROR(Core, "Failed to create loader for game. program_id={:016X}", program_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto result = system.Load(*loader);
|
||||
if (result != ResultStatus::Success) {
|
||||
LOG_ERROR(Core, "Failed to load game. Error: {}, program_id={:016X}", result, program_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG_INFO(Core, "Successfully launched game. program_id={:016X}", program_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto loader = Loader::GetLoader(system, file_path);
|
||||
if (!loader) {
|
||||
LOG_ERROR(Core, "Failed to create loader for game. program_id={:016X}", program_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto result = system.Load(*loader);
|
||||
if (result != ResultStatus::Success) {
|
||||
LOG_ERROR(Core, "Failed to load game. Error: {}, program_id={:016X}", result, program_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
const Core::System& system;
|
||||
};
|
||||
|
||||
} // namespace Core
|
Loading…
Reference in a new issue