Unify ProgressCallbacks to a Common::ProgressCallback

This commit is contained in:
Pengfei
2021-06-28 22:50:16 +08:00
parent 5a4bf7daff
commit 2575e7fdde
15 changed files with 69 additions and 46 deletions
+5 -6
View File
@@ -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};