summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys/archive_ncch.cpp
diff options
context:
space:
mode:
authorSebastian Valle <subv2112@gmail.com>2017-10-06 19:19:20 +0200
committerGitHub <noreply@github.com>2017-10-06 19:19:20 +0200
commit74d4050924e63f98c76570cafb5a6ad95d2ea5b1 (patch)
treeaab85b74fdb13cc49a7427996b2d1cca17c3fbc3 /src/core/file_sys/archive_ncch.cpp
parentMerge pull request #2953 from Subv/applet_launch (diff)
parentfile_sys, loader: add support for reading TMDs to determine app paths (diff)
downloadyuzu-74d4050924e63f98c76570cafb5a6ad95d2ea5b1.tar
yuzu-74d4050924e63f98c76570cafb5a6ad95d2ea5b1.tar.gz
yuzu-74d4050924e63f98c76570cafb5a6ad95d2ea5b1.tar.bz2
yuzu-74d4050924e63f98c76570cafb5a6ad95d2ea5b1.tar.lz
yuzu-74d4050924e63f98c76570cafb5a6ad95d2ea5b1.tar.xz
yuzu-74d4050924e63f98c76570cafb5a6ad95d2ea5b1.tar.zst
yuzu-74d4050924e63f98c76570cafb5a6ad95d2ea5b1.zip
Diffstat (limited to 'src/core/file_sys/archive_ncch.cpp')
-rw-r--r--src/core/file_sys/archive_ncch.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp
index 6d9007731..e8c5be983 100644
--- a/src/core/file_sys/archive_ncch.cpp
+++ b/src/core/file_sys/archive_ncch.cpp
@@ -13,7 +13,10 @@
#include "core/file_sys/archive_ncch.h"
#include "core/file_sys/errors.h"
#include "core/file_sys/ivfc_archive.h"
+#include "core/file_sys/ncch_container.h"
+#include "core/file_sys/title_metadata.h"
#include "core/hle/service/fs/archive.h"
+#include "core/loader/loader.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace
@@ -25,8 +28,18 @@ static std::string GetNCCHContainerPath(const std::string& nand_directory) {
}
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);
+ u32 content_id = 0;
+
+ // TODO(shinyquagsire23): Title database should be doing this path lookup
+ std::string content_path =
+ Common::StringFromFormat("%s%08x/%08x/content/", mount_point.c_str(), high, low);
+ std::string tmd_path = content_path + "00000000.tmd";
+ TitleMetadata tmd(tmd_path);
+ if (tmd.Load() == Loader::ResultStatus::Success) {
+ content_id = tmd.GetBootContentID();
+ }
+
+ return Common::StringFromFormat("%s%08x.app", content_path.c_str(), content_id);
}
ArchiveFactory_NCCH::ArchiveFactory_NCCH(const std::string& nand_directory)
@@ -38,9 +51,14 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path&
u32 high = data[1];
u32 low = data[0];
std::string file_path = GetNCCHPath(mount_point, high, low);
- auto file = std::make_shared<FileUtil::IOFile>(file_path, "rb");
- if (!file->IsOpen()) {
+ std::shared_ptr<FileUtil::IOFile> romfs_file;
+ u64 romfs_offset = 0;
+ u64 romfs_size = 0;
+ auto ncch_container = NCCHContainer(file_path);
+
+ if (ncch_container.ReadRomFS(romfs_file, romfs_offset, romfs_size) !=
+ Loader::ResultStatus::Success) {
// High Title ID of the archive: The category (https://3dbrew.org/wiki/Title_list).
constexpr u32 shared_data_archive = 0x0004009B;
constexpr u32 system_data_archive = 0x000400DB;
@@ -74,9 +92,8 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path&
}
return ERROR_NOT_FOUND;
}
- auto size = file->GetSize();
- auto archive = std::make_unique<IVFCArchive>(file, 0, size);
+ auto archive = std::make_unique<IVFCArchive>(romfs_file, romfs_offset, romfs_size);
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
}