// Copyright 2019 threeSD Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. #pragma once #include #include #include #include #include "common/common_types.h" #include "common/thread.h" namespace Core { class QuickDecryptor { public: /// (current_size, total_size) using ProgressCallback = std::function; /** * Initializes the decryptor. * @param root_folder Path to the "Nintendo 3DS//" 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, 3> buffers; std::array data_read_event; std::array data_decrypted_event; std::array data_written_event; std::unique_ptr read_thread; std::unique_ptr decrypt_thread; std::unique_ptr write_thread; ProgressCallback callback; Common::Event completion_event; bool is_good{true}; std::atomic_bool is_running{false}; }; } // namespace Core