diff options
| author | 2014-12-29 13:04:37 -0500 | |
|---|---|---|
| committer | 2014-12-29 22:29:55 -0500 | |
| commit | 2c89d4d5cd4e308b04cebb1c9bca48e12f0945da (patch) | |
| tree | ea0a85e43943ba76418f27a68572e8602dbd9839 /src/core/hle/service/fs | |
| parent | Merge pull request #367 from bunnei/usat_ssat (diff) | |
| download | yuzu-2c89d4d5cd4e308b04cebb1c9bca48e12f0945da.tar.gz yuzu-2c89d4d5cd4e308b04cebb1c9bca48e12f0945da.tar.xz yuzu-2c89d4d5cd4e308b04cebb1c9bca48e12f0945da.zip | |
Archives: Implemented ExtSaveData and SharedExtSaveData
They will be stored in /extsavedata/SDMC and /extsavedata/NAND respectively.
Also redirect some APT_A functions to their APT_U equivalents.
Implemented the gamecoin.dat file in SharedExtSaveData in the PTM module.
Implemented formatting the savegame.
Retake a previous savegame if it exists instead of reporting them as not formatted every time a game is loaded.
Diffstat (limited to 'src/core/hle/service/fs')
| -rw-r--r-- | src/core/hle/service/fs/archive.cpp | 59 | ||||
| -rw-r--r-- | src/core/hle/service/fs/archive.h | 3 | ||||
| -rw-r--r-- | src/core/hle/service/fs/fs_user.cpp | 17 |
3 files changed, 36 insertions, 43 deletions
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 487bf3aa7..f19ca3a9f 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include "common/math_util.h" | 11 | #include "common/math_util.h" |
| 12 | 12 | ||
| 13 | #include "core/file_sys/archive_savedata.h" | 13 | #include "core/file_sys/archive_savedata.h" |
| 14 | #include "core/file_sys/archive_extsavedata.h" | ||
| 14 | #include "core/file_sys/archive_backend.h" | 15 | #include "core/file_sys/archive_backend.h" |
| 15 | #include "core/file_sys/archive_sdmc.h" | 16 | #include "core/file_sys/archive_sdmc.h" |
| 16 | #include "core/file_sys/directory_backend.h" | 17 | #include "core/file_sys/directory_backend.h" |
| @@ -224,25 +225,20 @@ static Archive* GetArchive(ArchiveHandle handle) { | |||
| 224 | return (itr == handle_map.end()) ? nullptr : itr->second; | 225 | return (itr == handle_map.end()) ? nullptr : itr->second; |
| 225 | } | 226 | } |
| 226 | 227 | ||
| 227 | ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code) { | 228 | ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path) { |
| 228 | LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code); | 229 | LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code); |
| 229 | 230 | ||
| 230 | auto itr = id_code_map.find(id_code); | 231 | auto itr = id_code_map.find(id_code); |
| 231 | if (itr == id_code_map.end()) { | 232 | if (itr == id_code_map.end()) { |
| 232 | if (id_code == ArchiveIdCode::SaveData) { | ||
| 233 | // When a SaveData archive is created for the first time, it is not yet formatted | ||
| 234 | // and the save file/directory structure expected by the game has not yet been initialized. | ||
| 235 | // Returning the NotFormatted error code will signal the game to provision the SaveData archive | ||
| 236 | // with the files and folders that it expects. | ||
| 237 | // The FormatSaveData service call will create the SaveData archive when it is called. | ||
| 238 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, | ||
| 239 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 240 | } | ||
| 241 | // TODO: Verify error against hardware | 233 | // TODO: Verify error against hardware |
| 242 | return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, | 234 | return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, |
| 243 | ErrorSummary::NotFound, ErrorLevel::Permanent); | 235 | ErrorSummary::NotFound, ErrorLevel::Permanent); |
| 244 | } | 236 | } |
| 245 | 237 | ||
| 238 | ResultCode res = itr->second->backend->Open(archive_path); | ||
| 239 | if (!res.IsSuccess()) | ||
| 240 | return res; | ||
| 241 | |||
| 246 | // This should never even happen in the first place with 64-bit handles, | 242 | // This should never even happen in the first place with 64-bit handles, |
| 247 | while (handle_map.count(next_handle) != 0) { | 243 | while (handle_map.count(next_handle) != 0) { |
| 248 | ++next_handle; | 244 | ++next_handle; |
| @@ -395,25 +391,14 @@ ResultVal<Handle> OpenDirectoryFromArchive(ArchiveHandle archive_handle, const F | |||
| 395 | } | 391 | } |
| 396 | 392 | ||
| 397 | ResultCode FormatSaveData() { | 393 | ResultCode FormatSaveData() { |
| 398 | // TODO(Subv): Actually wipe the savedata folder after creating or opening it | ||
| 399 | |||
| 400 | // Do not create the archive again if it already exists | 394 | // Do not create the archive again if it already exists |
| 401 | if (id_code_map.find(ArchiveIdCode::SaveData) != id_code_map.end()) | 395 | auto archive_itr = id_code_map.find(ArchiveIdCode::SaveData); |
| 402 | return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the correct error code | 396 | if (archive_itr == id_code_map.end()) { |
| 403 | 397 | return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error | |
| 404 | // Create the SaveData archive | ||
| 405 | std::string savedata_directory = FileUtil::GetUserPath(D_SAVEDATA_IDX); | ||
| 406 | auto savedata_archive = Common::make_unique<FileSys::Archive_SaveData>(savedata_directory, | ||
| 407 | Kernel::g_program_id); | ||
| 408 | |||
| 409 | if (savedata_archive->Initialize()) { | ||
| 410 | CreateArchive(std::move(savedata_archive), ArchiveIdCode::SaveData); | ||
| 411 | return RESULT_SUCCESS; | ||
| 412 | } else { | ||
| 413 | LOG_ERROR(Service_FS, "Can't instantiate SaveData archive with path %s", | ||
| 414 | savedata_archive->GetMountPoint().c_str()); | ||
| 415 | return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the proper error code | ||
| 416 | } | 398 | } |
| 399 | |||
| 400 | // Use an empty path, we do not use it when formatting the savedata | ||
| 401 | return archive_itr->second->backend->Format(FileSys::Path()); | ||
| 417 | } | 402 | } |
| 418 | 403 | ||
| 419 | /// Initialize archives | 404 | /// Initialize archives |
| @@ -430,6 +415,26 @@ void ArchiveInit() { | |||
| 430 | CreateArchive(std::move(sdmc_archive), ArchiveIdCode::SDMC); | 415 | CreateArchive(std::move(sdmc_archive), ArchiveIdCode::SDMC); |
| 431 | else | 416 | else |
| 432 | LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str()); | 417 | LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str()); |
| 418 | |||
| 419 | // Create the SaveData archive | ||
| 420 | std::string savedata_directory = FileUtil::GetUserPath(D_SAVEDATA_IDX); | ||
| 421 | auto savedata_archive = Common::make_unique<FileSys::Archive_SaveData>(savedata_directory); | ||
| 422 | CreateArchive(std::move(savedata_archive), ArchiveIdCode::SaveData); | ||
| 423 | |||
| 424 | std::string extsavedata_directory = FileUtil::GetUserPath(D_EXTSAVEDATA); | ||
| 425 | auto extsavedata_archive = Common::make_unique<FileSys::Archive_ExtSaveData>(extsavedata_directory); | ||
| 426 | if (extsavedata_archive->Initialize()) | ||
| 427 | CreateArchive(std::move(extsavedata_archive), ArchiveIdCode::ExtSaveData); | ||
| 428 | else | ||
| 429 | LOG_ERROR(Service_FS, "Can't instantiate ExtSaveData archive with path %s", extsavedata_directory.c_str()); | ||
| 430 | |||
| 431 | std::string sharedextsavedata_directory = FileUtil::GetUserPath(D_EXTSAVEDATA); | ||
| 432 | auto sharedextsavedata_archive = Common::make_unique<FileSys::Archive_ExtSaveData>(sharedextsavedata_directory); | ||
| 433 | if (sharedextsavedata_archive->Initialize()) | ||
| 434 | CreateArchive(std::move(sharedextsavedata_archive), ArchiveIdCode::SharedExtSaveData); | ||
| 435 | else | ||
| 436 | LOG_ERROR(Service_FS, "Can't instantiate SharedExtSaveData archive with path %s", | ||
| 437 | sharedextsavedata_directory.c_str()); | ||
| 433 | } | 438 | } |
| 434 | 439 | ||
| 435 | /// Shutdown archives | 440 | /// Shutdown archives |
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h index b39bc41b6..c23b8cc46 100644 --- a/src/core/hle/service/fs/archive.h +++ b/src/core/hle/service/fs/archive.h | |||
| @@ -29,9 +29,10 @@ typedef u64 ArchiveHandle; | |||
| 29 | /** | 29 | /** |
| 30 | * Opens an archive | 30 | * Opens an archive |
| 31 | * @param id_code IdCode of the archive to open | 31 | * @param id_code IdCode of the archive to open |
| 32 | * @param archive_path Path to the archive, used with Binary paths | ||
| 32 | * @return Handle to the opened archive | 33 | * @return Handle to the opened archive |
| 33 | */ | 34 | */ |
| 34 | ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code); | 35 | ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path); |
| 35 | 36 | ||
| 36 | /** | 37 | /** |
| 37 | * Closes an archive | 38 | * Closes an archive |
diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp index b1a465274..7eb32146d 100644 --- a/src/core/hle/service/fs/fs_user.cpp +++ b/src/core/hle/service/fs/fs_user.cpp | |||
| @@ -107,14 +107,7 @@ static void OpenFileDirectly(Service::Interface* self) { | |||
| 107 | LOG_DEBUG(Service_FS, "archive_path=%s file_path=%s, mode=%u attributes=%d", | 107 | LOG_DEBUG(Service_FS, "archive_path=%s file_path=%s, mode=%u attributes=%d", |
| 108 | archive_path.DebugStr().c_str(), file_path.DebugStr().c_str(), mode.hex, attributes); | 108 | archive_path.DebugStr().c_str(), file_path.DebugStr().c_str(), mode.hex, attributes); |
| 109 | 109 | ||
| 110 | if (archive_path.GetType() != FileSys::Empty) { | 110 | ResultVal<ArchiveHandle> archive_handle = OpenArchive(archive_id, archive_path); |
| 111 | LOG_ERROR(Service_FS, "archive LowPath type other than empty is currently unsupported"); | ||
| 112 | cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw; | ||
| 113 | cmd_buff[3] = 0; | ||
| 114 | return; | ||
| 115 | } | ||
| 116 | |||
| 117 | ResultVal<ArchiveHandle> archive_handle = OpenArchive(archive_id); | ||
| 118 | if (archive_handle.Failed()) { | 111 | if (archive_handle.Failed()) { |
| 119 | LOG_ERROR(Service_FS, "failed to get a handle for archive"); | 112 | LOG_ERROR(Service_FS, "failed to get a handle for archive"); |
| 120 | cmd_buff[1] = archive_handle.Code().raw; | 113 | cmd_buff[1] = archive_handle.Code().raw; |
| @@ -376,13 +369,7 @@ static void OpenArchive(Service::Interface* self) { | |||
| 376 | 369 | ||
| 377 | LOG_DEBUG(Service_FS, "archive_path=%s", archive_path.DebugStr().c_str()); | 370 | LOG_DEBUG(Service_FS, "archive_path=%s", archive_path.DebugStr().c_str()); |
| 378 | 371 | ||
| 379 | if (archive_path.GetType() != FileSys::Empty) { | 372 | ResultVal<ArchiveHandle> handle = OpenArchive(archive_id, archive_path); |
| 380 | LOG_ERROR(Service_FS, "archive LowPath type other than empty is currently unsupported"); | ||
| 381 | cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw; | ||
| 382 | return; | ||
| 383 | } | ||
| 384 | |||
| 385 | ResultVal<ArchiveHandle> handle = OpenArchive(archive_id); | ||
| 386 | cmd_buff[1] = handle.Code().raw; | 373 | cmd_buff[1] = handle.Code().raw; |
| 387 | if (handle.Succeeded()) { | 374 | if (handle.Succeeded()) { |
| 388 | cmd_buff[2] = *handle & 0xFFFFFFFF; | 375 | cmd_buff[2] = *handle & 0xFFFFFFFF; |