mirror of
https://github.com/PabloMK7/citra.git
synced 2025-10-11 20:10:03 +00:00
core: Eliminate more uses of Core::System::GetInstance(). (#7313)
This commit is contained in:
parent
8e2037b3ff
commit
f2ee9baec7
47 changed files with 416 additions and 387 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <cryptopp/modes.h>
|
||||
#include <fmt/format.h>
|
||||
#include "common/alignment.h"
|
||||
#include "common/archives.h"
|
||||
#include "common/common_paths.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/logging/log.h"
|
||||
|
@ -33,6 +34,9 @@
|
|||
#include "core/loader/smdh.h"
|
||||
#include "core/nus_download.h"
|
||||
|
||||
SERIALIZE_EXPORT_IMPL(Service::AM::Module)
|
||||
SERVICE_CONSTRUCT_IMPL(Service::AM::Module)
|
||||
|
||||
namespace Service::AM {
|
||||
|
||||
constexpr u16 PLATFORM_CTR = 0x0004;
|
||||
|
@ -81,8 +85,9 @@ public:
|
|||
std::vector<CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption> content;
|
||||
};
|
||||
|
||||
CIAFile::CIAFile(Service::FS::MediaType media_type)
|
||||
: media_type(media_type), decryption_state(std::make_unique<DecryptionState>()) {}
|
||||
CIAFile::CIAFile(Core::System& system_, Service::FS::MediaType media_type)
|
||||
: system(system_), media_type(media_type),
|
||||
decryption_state(std::make_unique<DecryptionState>()) {}
|
||||
|
||||
CIAFile::~CIAFile() {
|
||||
Close();
|
||||
|
@ -361,8 +366,7 @@ bool CIAFile::Close() const {
|
|||
// are closed.
|
||||
std::string to_delete =
|
||||
GetTitleContentPath(media_type, old_tmd.GetTitleID(), old_index);
|
||||
if (!(Core::System::GetInstance().IsPoweredOn() &&
|
||||
Core::System::GetInstance().SetSelfDelete(to_delete))) {
|
||||
if (!system.IsPoweredOn() || !system.SetSelfDelete(to_delete)) {
|
||||
FileUtil::Delete(to_delete);
|
||||
}
|
||||
}
|
||||
|
@ -425,6 +429,7 @@ InstallStatus InstallCIA(const std::string& path,
|
|||
FileSys::CIAContainer container;
|
||||
if (container.Load(path) == Loader::ResultStatus::Success) {
|
||||
Service::AM::CIAFile installFile(
|
||||
Core::System::GetInstance(),
|
||||
Service::AM::GetTitleMediaType(container.GetTitleMetadata().GetTitleID()));
|
||||
|
||||
bool title_key_available = container.GetTicket().GetTitleKey().has_value();
|
||||
|
@ -502,7 +507,7 @@ InstallStatus InstallCIA(const std::string& path,
|
|||
InstallStatus InstallFromNus(u64 title_id, int version) {
|
||||
LOG_DEBUG(Service_AM, "Downloading {:X}", title_id);
|
||||
|
||||
CIAFile install_file{GetTitleMediaType(title_id)};
|
||||
CIAFile install_file{Core::System::GetInstance(), GetTitleMediaType(title_id)};
|
||||
|
||||
std::string path = fmt::format("/ccs/download/{:016X}/tmd", title_id);
|
||||
if (version != -1) {
|
||||
|
@ -1327,7 +1332,7 @@ void Module::Interface::BeginImportProgram(Kernel::HLERequestContext& ctx) {
|
|||
// Citra will store contents out to sdmc/nand
|
||||
const FileSys::Path cia_path = {};
|
||||
auto file = std::make_shared<Service::FS::File>(
|
||||
am->kernel, std::make_unique<CIAFile>(media_type), cia_path);
|
||||
am->system.Kernel(), std::make_unique<CIAFile>(am->system, media_type), cia_path);
|
||||
|
||||
am->cia_installing = true;
|
||||
|
||||
|
@ -1354,7 +1359,7 @@ void Module::Interface::BeginImportProgramTemporarily(Kernel::HLERequestContext&
|
|||
// contents out to sdmc/nand
|
||||
const FileSys::Path cia_path = {};
|
||||
auto file = std::make_shared<Service::FS::File>(
|
||||
am->kernel, std::make_unique<CIAFile>(FS::MediaType::NAND), cia_path);
|
||||
am->system.Kernel(), std::make_unique<CIAFile>(am->system, FS::MediaType::NAND), cia_path);
|
||||
|
||||
am->cia_installing = true;
|
||||
|
||||
|
@ -1769,8 +1774,8 @@ void Module::Interface::BeginImportTicket(Kernel::HLERequestContext& ctx) {
|
|||
IPC::RequestParser rp(ctx);
|
||||
|
||||
// Create our TicketFile handle for the app to write to
|
||||
auto file = std::make_shared<Service::FS::File>(am->kernel, std::make_unique<TicketFile>(),
|
||||
FileSys::Path{});
|
||||
auto file = std::make_shared<Service::FS::File>(
|
||||
am->system.Kernel(), std::make_unique<TicketFile>(), FileSys::Path{});
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||
rb.Push(ResultSuccess); // No error
|
||||
|
@ -1789,13 +1794,19 @@ void Module::Interface::EndImportTicket(Kernel::HLERequestContext& ctx) {
|
|||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
||||
}
|
||||
|
||||
Module::Module(Core::System& system) : kernel(system.Kernel()) {
|
||||
template <class Archive>
|
||||
void Module::serialize(Archive& ar, const unsigned int) {
|
||||
ar& cia_installing;
|
||||
ar& am_title_list;
|
||||
ar& system_updater_mutex;
|
||||
}
|
||||
SERIALIZE_IMPL(Module)
|
||||
|
||||
Module::Module(Core::System& system) : system(system) {
|
||||
ScanForAllTitles();
|
||||
system_updater_mutex = system.Kernel().CreateMutex(false, "AM::SystemUpdaterMutex");
|
||||
}
|
||||
|
||||
Module::Module(Kernel::KernelSystem& kernel) : kernel(kernel) {}
|
||||
|
||||
Module::~Module() = default;
|
||||
|
||||
void InstallInterfaces(Core::System& system) {
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <vector>
|
||||
#include <boost/serialization/array.hpp>
|
||||
#include <boost/serialization/shared_ptr.hpp>
|
||||
#include <boost/serialization/vector.hpp>
|
||||
#include "common/common_types.h"
|
||||
#include "common/construct.h"
|
||||
#include "common/swap.h"
|
||||
|
@ -80,7 +79,7 @@ using ProgressCallback = void(std::size_t, std::size_t);
|
|||
// A file handled returned for CIAs to be written into and subsequently installed.
|
||||
class CIAFile final : public FileSys::FileBackend {
|
||||
public:
|
||||
explicit CIAFile(Service::FS::MediaType media_type);
|
||||
explicit CIAFile(Core::System& system_, Service::FS::MediaType media_type);
|
||||
~CIAFile();
|
||||
|
||||
ResultVal<std::size_t> Read(u64 offset, std::size_t length, u8* buffer) const override;
|
||||
|
@ -95,6 +94,8 @@ public:
|
|||
void Flush() const override;
|
||||
|
||||
private:
|
||||
Core::System& system;
|
||||
|
||||
// Whether it's installing an update, and what step of installation it is at
|
||||
bool is_update = false;
|
||||
CIAInstallState install_state = CIAInstallState::InstallStarted;
|
||||
|
@ -706,8 +707,6 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
explicit Module(Kernel::KernelSystem& kernel);
|
||||
|
||||
/**
|
||||
* Scans the for titles in a storage medium for listing.
|
||||
* @param media_type the storage medium to scan
|
||||
|
@ -719,27 +718,13 @@ private:
|
|||
*/
|
||||
void ScanForAllTitles();
|
||||
|
||||
Kernel::KernelSystem& kernel;
|
||||
Core::System& system;
|
||||
bool cia_installing = false;
|
||||
std::array<std::vector<u64_le>, 3> am_title_list;
|
||||
std::shared_ptr<Kernel::Mutex> system_updater_mutex;
|
||||
|
||||
template <class Archive>
|
||||
void serialize(Archive& ar, const unsigned int) {
|
||||
ar& cia_installing;
|
||||
ar& am_title_list;
|
||||
ar& system_updater_mutex;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
static void load_construct(Archive& ar, Module* t, const unsigned int file_version) {
|
||||
::new (t) Module(Core::Global<Kernel::KernelSystem>());
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void save_construct(Archive& ar, const unsigned int file_version) const {}
|
||||
|
||||
friend class ::construct_access;
|
||||
void serialize(Archive& ar, const unsigned int);
|
||||
friend class boost::serialization::access;
|
||||
};
|
||||
|
||||
|
@ -747,4 +732,5 @@ void InstallInterfaces(Core::System& system);
|
|||
|
||||
} // namespace Service::AM
|
||||
|
||||
BOOST_SERIALIZATION_CONSTRUCT(Service::AM::Module);
|
||||
BOOST_CLASS_EXPORT_KEY(Service::AM::Module)
|
||||
SERVICE_CONSTRUCT(Service::AM::Module)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue