mirror of
https://github.com/Dark98/threeSD.git
synced 2026-07-04 00:38:47 +00:00
core, frontend: Better progress reporter
A new "quick" decryptor is implemented. This is not really much faster (not slower either) but provides the benefit of being able to report progress on a single file. The frontend is updated accordingly to support this feature.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
// Copyright 2019 threeSD Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "common/common_types.h"
|
||||
#include "common/thread.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
class QuickDecryptor {
|
||||
public:
|
||||
/// (current_size, total_size)
|
||||
using ProgressCallback = std::function<void(std::size_t, std::size_t)>;
|
||||
|
||||
/**
|
||||
* Initializes the decryptor.
|
||||
* @param root_folder Path to the "Nintendo 3DS/<ID0>/<ID1>" folder.
|
||||
*/
|
||||
explicit QuickDecryptor(const std::string& root_folder);
|
||||
|
||||
~QuickDecryptor();
|
||||
|
||||
bool DecryptAndWriteFile(const std::string& source, const std::string& destination,
|
||||
const ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
|
||||
void DataReadLoop();
|
||||
void DataDecryptLoop();
|
||||
void DataWriteLoop();
|
||||
|
||||
void Abort();
|
||||
|
||||
private:
|
||||
static constexpr std::size_t BufferSize = 16 * 1024; // 16 KB
|
||||
|
||||
std::string root_folder;
|
||||
std::string source;
|
||||
std::string destination;
|
||||
std::size_t total_size{};
|
||||
|
||||
std::array<std::array<u8, BufferSize>, 3> buffers;
|
||||
std::array<Common::Event, 3> data_read_event;
|
||||
std::array<Common::Event, 3> data_decrypted_event;
|
||||
std::array<Common::Event, 3> data_written_event;
|
||||
|
||||
std::unique_ptr<std::thread> read_thread;
|
||||
std::unique_ptr<std::thread> decrypt_thread;
|
||||
std::unique_ptr<std::thread> write_thread;
|
||||
|
||||
ProgressCallback callback;
|
||||
|
||||
Common::Event completion_event;
|
||||
bool is_good{true};
|
||||
std::atomic_bool is_running{false};
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
Reference in New Issue
Block a user