mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-15 22:54:00 +00: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 {
|
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() {
|
struct GameInfo {
|
||||||
std::vector<GameInfo> games;
|
u64 program_id;
|
||||||
const auto& cache = system.GetContentProvider().GetUserNANDCache();
|
std::string title_name;
|
||||||
|
std::string file_path;
|
||||||
|
};
|
||||||
|
|
||||||
for (const auto& nca : cache.GetAllEntries()) {
|
[[nodiscard]] std::vector<GameInfo> GetInstalledGames() {
|
||||||
if (nca.second == FileSys::ContentRecordType::Program) {
|
std::vector<GameInfo> games;
|
||||||
const auto program_id = nca.first;
|
const auto& cache = system.GetContentProvider().GetUserNANDCache();
|
||||||
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()) {
|
for (const auto& [program_id, content_type] : cache.GetAllEntries()) {
|
||||||
continue;
|
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) {
|
if (metadata.first != nullptr) {
|
||||||
const auto& patch_manager = system.GetFileSystemController().GetPatchManager(program_id);
|
return metadata.first->GetApplicationName();
|
||||||
const auto metadata = patch_manager.GetControlMetadata();
|
}
|
||||||
|
|
||||||
if (metadata.first != nullptr) {
|
return "";
|
||||||
return metadata.first->GetApplicationName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if (file_path.empty()) {
|
||||||
const auto file_path = system.GetContentProvider().GetUserNANDCache().GetEntryUnparsed(program_id, FileSys::ContentRecordType::Program);
|
LOG_ERROR(Core, "Failed to launch game. File not found for program_id={:016X}", program_id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (file_path.empty()) {
|
const auto loader = Loader::GetLoader(system, file_path);
|
||||||
LOG_ERROR(Core, "Failed to launch game. File not found for program_id={:016X}", program_id);
|
if (!loader) {
|
||||||
return false;
|
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);
|
private:
|
||||||
if (!loader) {
|
const Core::System& system;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
Loading…
Reference in a new issue