file_sys: Add functions to manage system archive importing
Provides a couple of functions that simply clearing and adding to imported sysdata.
This commit is contained in:
@@ -86,6 +86,8 @@ add_library(core STATIC
|
||||
file_sys/system_archive/data/font_nintendo_extended.h
|
||||
file_sys/system_archive/data/font_standard.cpp
|
||||
file_sys/system_archive/data/font_standard.h
|
||||
file_sys/system_archive/importer.cpp
|
||||
file_sys/system_archive/importer.h
|
||||
file_sys/system_archive/mii_model.cpp
|
||||
file_sys/system_archive/mii_model.h
|
||||
file_sys/system_archive/ng_word.cpp
|
||||
|
||||
46
src/core/file_sys/system_archive/importer.cpp
Normal file
46
src/core/file_sys/system_archive/importer.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2019 yuzu emulator team
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include "common/file_util.h"
|
||||
#include "core/file_sys/card_image.h"
|
||||
#include "core/file_sys/content_archive.h"
|
||||
#include "core/file_sys/system_archive/importer.h"
|
||||
#include "core/file_sys/vfs.h"
|
||||
#include "core/loader/loader.h"
|
||||
|
||||
namespace FileSys::SystemArchive {
|
||||
|
||||
VirtualFile GetImportedSystemArchive(const VirtualDir& sysdata, u64 title_id) {
|
||||
const auto filename = fmt::format("{:016X}.arc", title_id);
|
||||
return sysdata->GetFile(filename);
|
||||
}
|
||||
|
||||
bool ImportSystemArchive(const VirtualDir& sysdata, u64 title_id, const VirtualFile& data) {
|
||||
const auto filename = fmt::format("{:016X}.arc", title_id);
|
||||
const auto out = sysdata->CreateFile(filename);
|
||||
return out != nullptr && VfsRawCopy(data, out);
|
||||
}
|
||||
|
||||
bool ImportDirectorySystemUpdate(const VirtualDir& sysdata, const VirtualDir& dir) {
|
||||
Core::Crypto::KeyManager keys;
|
||||
|
||||
for (const auto& file : dir->GetFiles()) {
|
||||
NCA nca{file, nullptr, 0, keys};
|
||||
if (nca.GetStatus() == Loader::ResultStatus::Success &&
|
||||
nca.GetType() == NCAContentType::Data && nca.GetRomFS() != nullptr) {
|
||||
if (!ImportSystemArchive(sysdata, nca.GetTitleId(), nca.GetRomFS())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImportXCISystemUpdate(const VirtualDir& sysdata, XCI& xci) {
|
||||
return ImportDirectorySystemUpdate(sysdata, xci.GetUpdatePartition());
|
||||
}
|
||||
|
||||
} // namespace FileSys::SystemArchive
|
||||
31
src/core/file_sys/system_archive/importer.h
Normal file
31
src/core/file_sys/system_archive/importer.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2019 yuzu emulator team
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/file_sys/vfs_types.h"
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
class NSP;
|
||||
class XCI;
|
||||
|
||||
namespace SystemArchive {
|
||||
|
||||
/// Returns the file corresponding to the title_id if it exists in sysdata.
|
||||
VirtualFile GetImportedSystemArchive(const VirtualDir& sysdata, u64 title_id);
|
||||
|
||||
/// Copies the provided file into sysdata, overwriting current data.
|
||||
bool ImportSystemArchive(const VirtualDir& sysdata, u64 title_id, const VirtualFile& data);
|
||||
|
||||
/// Copies all system archives in the directory to sysdata.
|
||||
bool ImportDirectorySystemUpdate(const VirtualDir& sysdata, const VirtualDir& dir);
|
||||
|
||||
/// Calls ImportDirectorySystemUpdate on the update partition of the XCI.
|
||||
bool ImportXCISystemUpdate(const VirtualDir& sysdata, XCI& xci);
|
||||
|
||||
} // namespace SystemArchive
|
||||
|
||||
} // namespace FileSys
|
||||
Reference in New Issue
Block a user