From d7d6975af0971f5a07d489bdef522ca121bb30ec Mon Sep 17 00:00:00 2001 From: wwylele Date: Fri, 21 Oct 2016 22:10:55 +0800 Subject: FileSys: rename SaveDataCheck archive to NCCH archive According to the observation from game and 3dbrew "Used for accessing general NCCH data" --- src/core/CMakeLists.txt | 4 +- src/core/file_sys/archive_ncch.cpp | 62 +++++++++++++++++++++++++++++ src/core/file_sys/archive_ncch.h | 34 ++++++++++++++++ src/core/file_sys/archive_savedatacheck.cpp | 62 ----------------------------- src/core/file_sys/archive_savedatacheck.h | 34 ---------------- src/core/hle/service/fs/archive.cpp | 9 ++--- src/core/hle/service/fs/archive.h | 2 +- 7 files changed, 103 insertions(+), 104 deletions(-) create mode 100644 src/core/file_sys/archive_ncch.cpp create mode 100644 src/core/file_sys/archive_ncch.h delete mode 100644 src/core/file_sys/archive_savedatacheck.cpp delete mode 100644 src/core/file_sys/archive_savedatacheck.h (limited to 'src') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1ecd1c431..299f1f261 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -17,9 +17,9 @@ set(SRCS core_timing.cpp file_sys/archive_backend.cpp file_sys/archive_extsavedata.cpp + file_sys/archive_ncch.cpp file_sys/archive_romfs.cpp file_sys/archive_savedata.cpp - file_sys/archive_savedatacheck.cpp file_sys/archive_sdmc.cpp file_sys/archive_sdmcwriteonly.cpp file_sys/archive_systemsavedata.cpp @@ -162,9 +162,9 @@ set(HEADERS core_timing.h file_sys/archive_backend.h file_sys/archive_extsavedata.h + file_sys/archive_ncch.h file_sys/archive_romfs.h file_sys/archive_savedata.h - file_sys/archive_savedatacheck.h file_sys/archive_sdmc.h file_sys/archive_sdmcwriteonly.h file_sys/archive_systemsavedata.h diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp new file mode 100644 index 000000000..6f1aadfc3 --- /dev/null +++ b/src/core/file_sys/archive_ncch.cpp @@ -0,0 +1,62 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include +#include "common/common_types.h" +#include "common/file_util.h" +#include "common/logging/log.h" +#include "common/string_util.h" +#include "core/file_sys/archive_ncch.h" +#include "core/file_sys/ivfc_archive.h" +#include "core/hle/service/fs/archive.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// FileSys namespace + +namespace FileSys { + +static std::string GetNCCHContainerPath(const std::string& nand_directory) { + return Common::StringFromFormat("%s%s/title/", nand_directory.c_str(), SYSTEM_ID.c_str()); +} + +static std::string GetNCCHPath(const std::string& mount_point, u32 high, u32 low) { + return Common::StringFromFormat("%s%08x/%08x/content/00000000.app.romfs", mount_point.c_str(), + high, low); +} + +ArchiveFactory_NCCH::ArchiveFactory_NCCH(const std::string& nand_directory) + : mount_point(GetNCCHContainerPath(nand_directory)) {} + +ResultVal> ArchiveFactory_NCCH::Open(const Path& path) { + auto vec = path.AsBinary(); + const u32* data = reinterpret_cast(vec.data()); + std::string file_path = GetNCCHPath(mount_point, data[1], data[0]); + auto file = std::make_shared(file_path, "rb"); + + if (!file->IsOpen()) { + return ResultCode(-1); // TODO(Subv): Find the right error code + } + auto size = file->GetSize(); + + auto archive = std::make_unique(file, 0, size); + return MakeResult>(std::move(archive)); +} + +ResultCode ArchiveFactory_NCCH::Format(const Path& path, + const FileSys::ArchiveFormatInfo& format_info) { + LOG_ERROR(Service_FS, "Attempted to format a NCCH archive."); + // TODO: Verify error code + return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, + ErrorLevel::Permanent); +} + +ResultVal ArchiveFactory_NCCH::GetFormatInfo(const Path& path) const { + // TODO(Subv): Implement + LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str()); + return ResultCode(-1); +} + +} // namespace FileSys diff --git a/src/core/file_sys/archive_ncch.h b/src/core/file_sys/archive_ncch.h new file mode 100644 index 000000000..66b8ce75d --- /dev/null +++ b/src/core/file_sys/archive_ncch.h @@ -0,0 +1,34 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "core/file_sys/archive_backend.h" +#include "core/hle/result.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// FileSys namespace + +namespace FileSys { + +/// File system interface to the NCCH archive +class ArchiveFactory_NCCH final : public ArchiveFactory { +public: + ArchiveFactory_NCCH(const std::string& mount_point); + + std::string GetName() const override { + return "NCCH"; + } + + ResultVal> Open(const Path& path) override; + ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; + ResultVal GetFormatInfo(const Path& path) const override; + +private: + std::string mount_point; +}; + +} // namespace FileSys diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp deleted file mode 100644 index 6c4542b7d..000000000 --- a/src/core/file_sys/archive_savedatacheck.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include -#include -#include -#include "common/common_types.h" -#include "common/file_util.h" -#include "common/logging/log.h" -#include "common/string_util.h" -#include "core/file_sys/archive_savedatacheck.h" -#include "core/file_sys/ivfc_archive.h" -#include "core/hle/service/fs/archive.h" - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// FileSys namespace - -namespace FileSys { - -static std::string GetSaveDataCheckContainerPath(const std::string& nand_directory) { - return Common::StringFromFormat("%s%s/title/", nand_directory.c_str(), SYSTEM_ID.c_str()); -} - -static std::string GetSaveDataCheckPath(const std::string& mount_point, u32 high, u32 low) { - return Common::StringFromFormat("%s%08x/%08x/content/00000000.app.romfs", mount_point.c_str(), - high, low); -} - -ArchiveFactory_SaveDataCheck::ArchiveFactory_SaveDataCheck(const std::string& nand_directory) - : mount_point(GetSaveDataCheckContainerPath(nand_directory)) {} - -ResultVal> ArchiveFactory_SaveDataCheck::Open(const Path& path) { - auto vec = path.AsBinary(); - const u32* data = reinterpret_cast(vec.data()); - std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]); - auto file = std::make_shared(file_path, "rb"); - - if (!file->IsOpen()) { - return ResultCode(-1); // TODO(Subv): Find the right error code - } - auto size = file->GetSize(); - - auto archive = std::make_unique(file, 0, size); - return MakeResult>(std::move(archive)); -} - -ResultCode ArchiveFactory_SaveDataCheck::Format(const Path& path, - const FileSys::ArchiveFormatInfo& format_info) { - LOG_ERROR(Service_FS, "Attempted to format a SaveDataCheck archive."); - // TODO: Verify error code - return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, - ErrorLevel::Permanent); -} - -ResultVal ArchiveFactory_SaveDataCheck::GetFormatInfo(const Path& path) const { - // TODO(Subv): Implement - LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str()); - return ResultCode(-1); -} - -} // namespace FileSys diff --git a/src/core/file_sys/archive_savedatacheck.h b/src/core/file_sys/archive_savedatacheck.h deleted file mode 100644 index e9cafbed9..000000000 --- a/src/core/file_sys/archive_savedatacheck.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include "core/file_sys/archive_backend.h" -#include "core/hle/result.h" - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// FileSys namespace - -namespace FileSys { - -/// File system interface to the SaveDataCheck archive -class ArchiveFactory_SaveDataCheck final : public ArchiveFactory { -public: - ArchiveFactory_SaveDataCheck(const std::string& mount_point); - - std::string GetName() const override { - return "SaveDataCheck"; - } - - ResultVal> Open(const Path& path) override; - ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; - ResultVal GetFormatInfo(const Path& path) const override; - -private: - std::string mount_point; -}; - -} // namespace FileSys diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 62cf2c249..4c29784e8 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -15,8 +15,8 @@ #include "common/logging/log.h" #include "core/file_sys/archive_backend.h" #include "core/file_sys/archive_extsavedata.h" +#include "core/file_sys/archive_ncch.h" #include "core/file_sys/archive_savedata.h" -#include "core/file_sys/archive_savedatacheck.h" #include "core/file_sys/archive_sdmc.h" #include "core/file_sys/archive_sdmcwriteonly.h" #include "core/file_sys/archive_systemsavedata.h" @@ -554,10 +554,9 @@ void RegisterArchiveTypes() { LOG_ERROR(Service_FS, "Can't instantiate SharedExtSaveData archive with path %s", sharedextsavedata_factory->GetMountPoint().c_str()); - // Create the SaveDataCheck archive, basically a small variation of the RomFS archive - auto savedatacheck_factory = - std::make_unique(nand_directory); - RegisterArchiveType(std::move(savedatacheck_factory), ArchiveIdCode::SaveDataCheck); + // Create the NCCH archive, basically a small variation of the RomFS archive + auto savedatacheck_factory = std::make_unique(nand_directory); + RegisterArchiveType(std::move(savedatacheck_factory), ArchiveIdCode::NCCH); auto systemsavedata_factory = std::make_unique(nand_directory); diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h index 41a76285c..21ed9717b 100644 --- a/src/core/hle/service/fs/archive.h +++ b/src/core/hle/service/fs/archive.h @@ -33,7 +33,7 @@ enum class ArchiveIdCode : u32 { SystemSaveData = 0x00000008, SDMC = 0x00000009, SDMCWriteOnly = 0x0000000A, - SaveDataCheck = 0x2345678A, + NCCH = 0x2345678A, }; /// Media types for the archives -- cgit v1.2.3