mirror of
https://github.com/Dark98/threeSD.git
synced 2026-07-03 00:38:58 +00:00
Unify ProgressCallbacks to a Common::ProgressCallback
This commit is contained in:
@@ -53,7 +53,7 @@ void SDMCDecryptor::Reset(std::size_t total_size) {
|
||||
}
|
||||
|
||||
bool SDMCDecryptor::DecryptAndWriteFile(const std::string& source, const std::string& destination,
|
||||
const ProgressCallback& callback) {
|
||||
const Common::ProgressCallback& callback) {
|
||||
if (!FileUtil::CreateFullPath(destination)) {
|
||||
LOG_ERROR(Core, "Could not create path {}", destination);
|
||||
return false;
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
*/
|
||||
bool DecryptAndWriteFile(
|
||||
const std::string& source, const std::string& destination,
|
||||
const ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
const Common::ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
|
||||
void Abort();
|
||||
|
||||
|
||||
+17
-11
@@ -69,7 +69,7 @@ void SDMCImporter::AbortImporting() {
|
||||
}
|
||||
|
||||
bool SDMCImporter::ImportContent(const ContentSpecifier& specifier,
|
||||
const ProgressCallback& callback) {
|
||||
const Common::ProgressCallback& callback) {
|
||||
switch (specifier.type) {
|
||||
case ContentType::Application:
|
||||
case ContentType::Update:
|
||||
@@ -130,7 +130,7 @@ bool ImportTitleGeneric(Dec& decryptor, const std::string& base_path,
|
||||
} // namespace
|
||||
|
||||
bool SDMCImporter::ImportTitle(const ContentSpecifier& specifier,
|
||||
const ProgressCallback& callback) {
|
||||
const Common::ProgressCallback& callback) {
|
||||
return ImportTitleGeneric(
|
||||
*decryptor, config.sdmc_path, specifier, [this, &callback](const std::string& filepath) {
|
||||
return decryptor->DecryptAndWriteFile(
|
||||
@@ -144,7 +144,7 @@ bool SDMCImporter::ImportTitle(const ContentSpecifier& specifier,
|
||||
}
|
||||
|
||||
bool SDMCImporter::ImportNandTitle(const ContentSpecifier& specifier,
|
||||
const ProgressCallback& callback) {
|
||||
const Common::ProgressCallback& callback) {
|
||||
|
||||
const auto base_path =
|
||||
config.system_titles_path.substr(0, config.system_titles_path.size() - 6);
|
||||
@@ -167,7 +167,8 @@ bool SDMCImporter::ImportNandTitle(const ContentSpecifier& specifier,
|
||||
});
|
||||
}
|
||||
|
||||
bool SDMCImporter::ImportSavegame(u64 id, [[maybe_unused]] const ProgressCallback& callback) {
|
||||
bool SDMCImporter::ImportSavegame(u64 id,
|
||||
[[maybe_unused]] const Common::ProgressCallback& callback) {
|
||||
const auto path = fmt::format("title/{:08x}/{:08x}/data/", (id >> 32), (id & 0xFFFFFFFF));
|
||||
|
||||
DataContainer container(decryptor->DecryptFile(fmt::format("/{}00000001.sav", path)));
|
||||
@@ -190,7 +191,8 @@ bool SDMCImporter::ImportSavegame(u64 id, [[maybe_unused]] const ProgressCallbac
|
||||
"Nintendo 3DS/00000000000000000000000000000000/00000000000000000000000000000000/" + path);
|
||||
}
|
||||
|
||||
bool SDMCImporter::ImportNandSavegame(u64 id, [[maybe_unused]] const ProgressCallback& callback) {
|
||||
bool SDMCImporter::ImportNandSavegame(u64 id,
|
||||
[[maybe_unused]] const Common::ProgressCallback& callback) {
|
||||
const auto path = fmt::format("sysdata/{:08x}/00000000", (id & 0xFFFFFFFF));
|
||||
|
||||
FileUtil::IOFile file(config.nand_data_path + path, "rb");
|
||||
@@ -216,7 +218,8 @@ bool SDMCImporter::ImportNandSavegame(u64 id, [[maybe_unused]] const ProgressCal
|
||||
1);
|
||||
}
|
||||
|
||||
bool SDMCImporter::ImportExtdata(u64 id, [[maybe_unused]] const ProgressCallback& callback) {
|
||||
bool SDMCImporter::ImportExtdata(u64 id,
|
||||
[[maybe_unused]] const Common::ProgressCallback& callback) {
|
||||
const auto path = fmt::format("extdata/{:08x}/{:08x}/", (id >> 32), (id & 0xFFFFFFFF));
|
||||
SDExtdata extdata("/" + path, *decryptor);
|
||||
if (!extdata.IsGood()) {
|
||||
@@ -228,7 +231,8 @@ bool SDMCImporter::ImportExtdata(u64 id, [[maybe_unused]] const ProgressCallback
|
||||
"Nintendo 3DS/00000000000000000000000000000000/00000000000000000000000000000000/" + path);
|
||||
}
|
||||
|
||||
bool SDMCImporter::ImportNandExtdata(u64 id, [[maybe_unused]] const ProgressCallback& callback) {
|
||||
bool SDMCImporter::ImportNandExtdata(u64 id,
|
||||
[[maybe_unused]] const Common::ProgressCallback& callback) {
|
||||
const auto path = fmt::format("extdata/{:08x}/{:08x}/", (id >> 32), (id & 0xFFFFFFFF));
|
||||
SDExtdata extdata(config.nand_data_path + path);
|
||||
if (!extdata.IsGood()) {
|
||||
@@ -239,7 +243,8 @@ bool SDMCImporter::ImportNandExtdata(u64 id, [[maybe_unused]] const ProgressCall
|
||||
"data/00000000000000000000000000000000/" + path);
|
||||
}
|
||||
|
||||
bool SDMCImporter::ImportSystemArchive(u64 id, [[maybe_unused]] const ProgressCallback& callback) {
|
||||
bool SDMCImporter::ImportSystemArchive(u64 id,
|
||||
[[maybe_unused]] const Common::ProgressCallback& callback) {
|
||||
const auto path = fmt::format("{}{:08x}/{:08x}.app", config.system_archives_path, (id >> 32),
|
||||
(id & 0xFFFFFFFF));
|
||||
FileUtil::IOFile file(path, "rb");
|
||||
@@ -273,7 +278,8 @@ bool SDMCImporter::ImportSystemArchive(u64 id, [[maybe_unused]] const ProgressCa
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SDMCImporter::ImportSysdata(u64 id, [[maybe_unused]] const ProgressCallback& callback) {
|
||||
bool SDMCImporter::ImportSysdata(u64 id,
|
||||
[[maybe_unused]] const Common::ProgressCallback& callback) {
|
||||
switch (id) {
|
||||
case 0: { // boot9.bin
|
||||
const auto target_path = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + BOOTROM9;
|
||||
@@ -500,7 +506,7 @@ TitleData LoadTitleData(NCCHContainer& ncch) {
|
||||
}
|
||||
|
||||
bool SDMCImporter::DumpCXI(const ContentSpecifier& specifier, const std::string& destination,
|
||||
const ProgressCallback& callback) {
|
||||
const Common::ProgressCallback& callback) {
|
||||
|
||||
if (specifier.type != ContentType::Application) {
|
||||
LOG_ERROR(Core, "Unsupported specifier type {}", static_cast<int>(specifier.type));
|
||||
@@ -534,7 +540,7 @@ void SDMCImporter::AbortDumpCXI() {
|
||||
}
|
||||
|
||||
bool SDMCImporter::BuildCIA(const ContentSpecifier& specifier, const std::string& destination,
|
||||
const ProgressCallback& callback) {
|
||||
const Common::ProgressCallback& callback) {
|
||||
|
||||
if (config.certs_db_path.empty()) {
|
||||
LOG_ERROR(Core, "Missing certs.db");
|
||||
|
||||
+13
-14
@@ -9,6 +9,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "common/common_types.h"
|
||||
#include "common/progress_callback.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
@@ -96,9 +97,6 @@ class NCCHContainer;
|
||||
|
||||
class SDMCImporter {
|
||||
public:
|
||||
/// (current_size, total_size)
|
||||
using ProgressCallback = std::function<void(std::size_t, std::size_t)>;
|
||||
|
||||
/**
|
||||
* Initializes the importer.
|
||||
* @param root_folder Path to the "Nintendo 3DS/<ID0>/<ID1>" folder.
|
||||
@@ -114,7 +112,7 @@ public:
|
||||
*/
|
||||
bool ImportContent(
|
||||
const ContentSpecifier& specifier,
|
||||
const ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
const Common::ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
|
||||
/**
|
||||
* Aborts current importing.
|
||||
@@ -128,7 +126,7 @@ public:
|
||||
*/
|
||||
bool DumpCXI(
|
||||
const ContentSpecifier& specifier, const std::string& destination,
|
||||
const ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
const Common::ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
|
||||
/**
|
||||
* Aborts current CXI dumping.
|
||||
@@ -142,7 +140,7 @@ public:
|
||||
*/
|
||||
bool BuildCIA(
|
||||
const ContentSpecifier& specifier, const std::string& destination,
|
||||
const ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
const Common::ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
|
||||
/**
|
||||
* Aborts current CIA building
|
||||
@@ -168,14 +166,15 @@ public:
|
||||
private:
|
||||
bool Init();
|
||||
|
||||
bool ImportTitle(const ContentSpecifier& specifier, const ProgressCallback& callback);
|
||||
bool ImportNandTitle(const ContentSpecifier& specifier, const ProgressCallback& callback);
|
||||
bool ImportSavegame(u64 id, const ProgressCallback& callback);
|
||||
bool ImportNandSavegame(u64 id, const ProgressCallback& callback);
|
||||
bool ImportExtdata(u64 id, const ProgressCallback& callback);
|
||||
bool ImportNandExtdata(u64 id, const ProgressCallback& callback);
|
||||
bool ImportSystemArchive(u64 id, const ProgressCallback& callback);
|
||||
bool ImportSysdata(u64 id, const ProgressCallback& callback);
|
||||
bool ImportTitle(const ContentSpecifier& specifier, const Common::ProgressCallback& callback);
|
||||
bool ImportNandTitle(const ContentSpecifier& specifier,
|
||||
const Common::ProgressCallback& callback);
|
||||
bool ImportSavegame(u64 id, const Common::ProgressCallback& callback);
|
||||
bool ImportNandSavegame(u64 id, const Common::ProgressCallback& callback);
|
||||
bool ImportExtdata(u64 id, const Common::ProgressCallback& callback);
|
||||
bool ImportNandExtdata(u64 id, const Common::ProgressCallback& callback);
|
||||
bool ImportSystemArchive(u64 id, const Common::ProgressCallback& callback);
|
||||
bool ImportSysdata(u64 id, const Common::ProgressCallback& callback);
|
||||
|
||||
void ListTitle(std::vector<ContentSpecifier>& out) const;
|
||||
void ListNandTitle(std::vector<ContentSpecifier>& out) const;
|
||||
|
||||
@@ -45,7 +45,7 @@ CIABuilder::~CIABuilder() = default;
|
||||
|
||||
bool CIABuilder::Init(const std::string& destination, TitleMetadata tmd_,
|
||||
const std::string& certs_db_path, std::size_t total_size_,
|
||||
const ProgressCallback& callback_) {
|
||||
const Common::ProgressCallback& callback_) {
|
||||
|
||||
header = {};
|
||||
meta = {};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include "common/file_util.h"
|
||||
#include "common/progress_callback.h"
|
||||
#include "common/swap.h"
|
||||
#include "core/ncch/ncch_container.h"
|
||||
#include "core/ncch/title_metadata.h"
|
||||
@@ -33,7 +34,7 @@ public:
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool Init(const std::string& destination, TitleMetadata tmd, const std::string& certs_db_path,
|
||||
std::size_t total_size, const ProgressCallback& callback);
|
||||
std::size_t total_size, const Common::ProgressCallback& callback);
|
||||
|
||||
/**
|
||||
* Adds an NCCH content to the CIA.
|
||||
@@ -103,7 +104,7 @@ private:
|
||||
std::shared_ptr<HashedFile> file;
|
||||
std::size_t written{}; // size written (with alignment)
|
||||
std::size_t total_size{};
|
||||
ProgressCallback callback;
|
||||
Common::ProgressCallback callback;
|
||||
|
||||
// The NCCH to abort on
|
||||
std::mutex abort_ncch_mutex;
|
||||
|
||||
@@ -423,7 +423,7 @@ ResultStatus NCCHContainer::ReadSeedCrypto(bool& used) {
|
||||
}
|
||||
|
||||
ResultStatus NCCHContainer::DecryptToFile(std::shared_ptr<FileUtil::IOFile> dest_file,
|
||||
const ProgressCallback& callback) {
|
||||
const Common::ProgressCallback& callback) {
|
||||
ResultStatus result = Load();
|
||||
if (result != ResultStatus::Success)
|
||||
return result;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/progress_callback.h"
|
||||
#include "common/swap.h"
|
||||
#include "core/decryptor.h"
|
||||
#include "core/result_status.h"
|
||||
@@ -274,7 +275,7 @@ public:
|
||||
*/
|
||||
ResultStatus DecryptToFile(
|
||||
std::shared_ptr<FileUtil::IOFile> dest_file,
|
||||
const ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
const Common::ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
|
||||
/**
|
||||
* Aborts DecryptToFile. Simply aborts the decryptor.
|
||||
|
||||
@@ -23,7 +23,7 @@ QuickDecryptor::~QuickDecryptor() = default;
|
||||
bool QuickDecryptor::DecryptAndWriteFile(std::shared_ptr<FileUtil::IOFile> source_,
|
||||
std::size_t size,
|
||||
std::shared_ptr<FileUtil::IOFile> destination_,
|
||||
const ProgressCallback& callback_, bool decrypt_,
|
||||
const Common::ProgressCallback& callback_, bool decrypt_,
|
||||
Core::Key::AESKey key_, Core::Key::AESKey ctr_,
|
||||
std::size_t aes_seek_pos_) {
|
||||
if (is_running) {
|
||||
|
||||
@@ -9,14 +9,12 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "common/common_types.h"
|
||||
#include "common/progress_callback.h"
|
||||
#include "common/thread.h"
|
||||
#include "core/key/key.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
/// (current_size, total_size)
|
||||
using ProgressCallback = std::function<void(std::size_t, std::size_t)>;
|
||||
|
||||
/**
|
||||
* Helper that reads, decrypts and writes data. This uses three threads to process the data
|
||||
* and call progress callbacks occasionally.
|
||||
@@ -41,8 +39,9 @@ public:
|
||||
bool DecryptAndWriteFile(
|
||||
std::shared_ptr<FileUtil::IOFile> source, std::size_t size,
|
||||
std::shared_ptr<FileUtil::IOFile> destination,
|
||||
const ProgressCallback& callback = [](std::size_t, std::size_t) {}, bool decrypt = false,
|
||||
Core::Key::AESKey key = {}, Core::Key::AESKey ctr = {}, std::size_t aes_seek_pos = 0);
|
||||
const Common::ProgressCallback& callback = [](std::size_t, std::size_t) {},
|
||||
bool decrypt = false, Core::Key::AESKey key = {}, Core::Key::AESKey ctr = {},
|
||||
std::size_t aes_seek_pos = 0);
|
||||
|
||||
void DataReadLoop();
|
||||
void DataDecryptLoop();
|
||||
@@ -79,7 +78,7 @@ private:
|
||||
std::unique_ptr<std::thread> decrypt_thread;
|
||||
std::unique_ptr<std::thread> write_thread;
|
||||
|
||||
ProgressCallback callback;
|
||||
Common::ProgressCallback callback;
|
||||
|
||||
Common::Event completion_event;
|
||||
bool is_good{true};
|
||||
|
||||
Reference in New Issue
Block a user