summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar Sebastian Valle2017-09-25 18:24:12 -0500
committerGravatar GitHub2017-09-25 18:24:12 -0500
commitfd30d48ceb7d513923d01a68e568668b6d4d3e7f (patch)
tree897ebb18a3cff721f402d0be73559f4694d4b1d8 /src/core/file_sys
parentMerge pull request #2952 from MerryMage/page-tables (diff)
parentHLE/Archives: Allow multiple loaded applications to access their SelfNCCH arc... (diff)
downloadyuzu-fd30d48ceb7d513923d01a68e568668b6d4d3e7f.tar.gz
yuzu-fd30d48ceb7d513923d01a68e568668b6d4d3e7f.tar.xz
yuzu-fd30d48ceb7d513923d01a68e568668b6d4d3e7f.zip
Merge pull request #2947 from Subv/selfncch_factory
HLE/Archives: Allow multiple loaded applications to access their SelfNCCH archive independently.
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/archive_selfncch.cpp43
-rw-r--r--src/core/file_sys/archive_selfncch.h9
2 files changed, 39 insertions, 13 deletions
diff --git a/src/core/file_sys/archive_selfncch.cpp b/src/core/file_sys/archive_selfncch.cpp
index 7dc91a405..a16941c70 100644
--- a/src/core/file_sys/archive_selfncch.cpp
+++ b/src/core/file_sys/archive_selfncch.cpp
@@ -3,12 +3,14 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <array> 5#include <array>
6#include <cinttypes>
6#include "common/common_types.h" 7#include "common/common_types.h"
7#include "common/logging/log.h" 8#include "common/logging/log.h"
8#include "common/swap.h" 9#include "common/swap.h"
9#include "core/file_sys/archive_selfncch.h" 10#include "core/file_sys/archive_selfncch.h"
10#include "core/file_sys/errors.h" 11#include "core/file_sys/errors.h"
11#include "core/file_sys/ivfc_archive.h" 12#include "core/file_sys/ivfc_archive.h"
13#include "core/hle/kernel/process.h"
12 14
13//////////////////////////////////////////////////////////////////////////////////////////////////// 15////////////////////////////////////////////////////////////////////////////////////////////////////
14// FileSys namespace 16// FileSys namespace
@@ -227,38 +229,57 @@ private:
227 NCCHData ncch_data; 229 NCCHData ncch_data;
228}; 230};
229 231
230ArchiveFactory_SelfNCCH::ArchiveFactory_SelfNCCH(Loader::AppLoader& app_loader) { 232void ArchiveFactory_SelfNCCH::Register(Loader::AppLoader& app_loader) {
231 std::shared_ptr<FileUtil::IOFile> romfs_file; 233 u64 program_id = 0;
234 if (app_loader.ReadProgramId(program_id) != Loader::ResultStatus::Success) {
235 LOG_WARNING(
236 Service_FS,
237 "Could not read program id when registering with SelfNCCH, this might be a 3dsx file");
238 }
239
240 LOG_DEBUG(Service_FS, "Registering program %016" PRIX64 " with the SelfNCCH archive factory",
241 program_id);
242
243 if (ncch_data.find(program_id) != ncch_data.end()) {
244 LOG_WARNING(Service_FS, "Registering program %016" PRIX64
245 " with SelfNCCH will override existing mapping",
246 program_id);
247 }
248
249 NCCHData& data = ncch_data[program_id];
250
251 std::shared_ptr<FileUtil::IOFile> romfs_file_;
232 if (Loader::ResultStatus::Success == 252 if (Loader::ResultStatus::Success ==
233 app_loader.ReadRomFS(romfs_file, ncch_data.romfs_offset, ncch_data.romfs_size)) { 253 app_loader.ReadRomFS(romfs_file_, data.romfs_offset, data.romfs_size)) {
234 254
235 ncch_data.romfs_file = std::move(romfs_file); 255 data.romfs_file = std::move(romfs_file_);
236 } 256 }
237 257
238 std::shared_ptr<FileUtil::IOFile> update_romfs_file; 258 std::shared_ptr<FileUtil::IOFile> update_romfs_file;
239 if (Loader::ResultStatus::Success == 259 if (Loader::ResultStatus::Success ==
240 app_loader.ReadUpdateRomFS(update_romfs_file, ncch_data.update_romfs_offset, 260 app_loader.ReadUpdateRomFS(update_romfs_file, data.update_romfs_offset,
241 ncch_data.update_romfs_size)) { 261 data.update_romfs_size)) {
242 262
243 ncch_data.update_romfs_file = std::move(update_romfs_file); 263 data.update_romfs_file = std::move(update_romfs_file);
244 } 264 }
245 265
246 std::vector<u8> buffer; 266 std::vector<u8> buffer;
247 267
248 if (Loader::ResultStatus::Success == app_loader.ReadIcon(buffer)) 268 if (Loader::ResultStatus::Success == app_loader.ReadIcon(buffer))
249 ncch_data.icon = std::make_shared<std::vector<u8>>(std::move(buffer)); 269 data.icon = std::make_shared<std::vector<u8>>(std::move(buffer));
250 270
251 buffer.clear(); 271 buffer.clear();
252 if (Loader::ResultStatus::Success == app_loader.ReadLogo(buffer)) 272 if (Loader::ResultStatus::Success == app_loader.ReadLogo(buffer))
253 ncch_data.logo = std::make_shared<std::vector<u8>>(std::move(buffer)); 273 data.logo = std::make_shared<std::vector<u8>>(std::move(buffer));
254 274
255 buffer.clear(); 275 buffer.clear();
256 if (Loader::ResultStatus::Success == app_loader.ReadBanner(buffer)) 276 if (Loader::ResultStatus::Success == app_loader.ReadBanner(buffer))
257 ncch_data.banner = std::make_shared<std::vector<u8>>(std::move(buffer)); 277 data.banner = std::make_shared<std::vector<u8>>(std::move(buffer));
258} 278}
259 279
260ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SelfNCCH::Open(const Path& path) { 280ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SelfNCCH::Open(const Path& path) {
261 auto archive = std::make_unique<SelfNCCHArchive>(ncch_data); 281 auto archive = std::make_unique<SelfNCCHArchive>(
282 ncch_data[Kernel::g_current_process->codeset->program_id]);
262 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); 283 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
263} 284}
264 285
diff --git a/src/core/file_sys/archive_selfncch.h b/src/core/file_sys/archive_selfncch.h
index f1c659948..0d6d6766e 100644
--- a/src/core/file_sys/archive_selfncch.h
+++ b/src/core/file_sys/archive_selfncch.h
@@ -6,6 +6,7 @@
6 6
7#include <memory> 7#include <memory>
8#include <string> 8#include <string>
9#include <unordered_map>
9#include <vector> 10#include <vector>
10#include "common/common_types.h" 11#include "common/common_types.h"
11#include "core/file_sys/archive_backend.h" 12#include "core/file_sys/archive_backend.h"
@@ -33,7 +34,10 @@ struct NCCHData {
33/// File system interface to the SelfNCCH archive 34/// File system interface to the SelfNCCH archive
34class ArchiveFactory_SelfNCCH final : public ArchiveFactory { 35class ArchiveFactory_SelfNCCH final : public ArchiveFactory {
35public: 36public:
36 explicit ArchiveFactory_SelfNCCH(Loader::AppLoader& app_loader); 37 ArchiveFactory_SelfNCCH() = default;
38
39 /// Registers a loaded application so that we can open its SelfNCCH archive when requested.
40 void Register(Loader::AppLoader& app_loader);
37 41
38 std::string GetName() const override { 42 std::string GetName() const override {
39 return "SelfNCCH"; 43 return "SelfNCCH";
@@ -43,7 +47,8 @@ public:
43 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; 47 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
44 48
45private: 49private:
46 NCCHData ncch_data; 50 /// Mapping of ProgramId -> NCCHData
51 std::unordered_map<u64, NCCHData> ncch_data;
47}; 52};
48 53
49} // namespace FileSys 54} // namespace FileSys