diff --git a/source/src/dt_app.hpp b/source/src/dt_app.hpp index 94e4009..cd508d0 100644 --- a/source/src/dt_app.hpp +++ b/source/src/dt_app.hpp @@ -29,7 +29,8 @@ namespace dvsku_toolkit { dt_gui_mngr m_gui; friend dt_comp_root; - //friend amo_sys_core; + friend dt_comp_pack; + friend dt_comp_unpack; private: bool prepare() override final; diff --git a/source/src/gui/dt_comp_pack.cpp b/source/src/gui/dt_comp_pack.cpp index 3b4cddb..da06425 100644 --- a/source/src/gui/dt_comp_pack.cpp +++ b/source/src/gui/dt_comp_pack.cpp @@ -1,15 +1,51 @@ #include "gui/dt_comp_pack.hpp" #include "dt_app.hpp" +#include + using namespace dvsku_toolkit; /////////////////////////////////////////////////////////////////////////////// // PUBLIC dt_comp_pack::dt_comp_pack(dt_app& app) - : dt_gui_base(app) {} + : dt_gui_base(app) +{ + m_context.start_callback = [this]() { + std::lock_guard guard(m_mutex); + + m_progress = 0.0f; + m_app.get_systems().core.is_working = true; + + m_app.set_taskbar_status(dvsku::dv_taskbar_status::normal); + m_app.set_taskbar_progress(0U); + }; + m_context.finish_callback = [this](libevp::evp_result result) { + std::lock_guard guard(m_mutex); + + m_progress = 100.0f; + m_app.get_systems().core.is_working = false; + + m_app.set_taskbar_status(dvsku::dv_taskbar_status::no_progress); + m_app.set_taskbar_progress(0U); + + if (result.status == libevp::evp_result_status::ok) + m_app.play_sound(dvsku::dv_sound_type::success); + else if (result.status == libevp::evp_result_status::error) + m_app.play_sound(dvsku::dv_sound_type::warning); + }; + m_context.update_callback = [this](float progress) { + std::lock_guard guard(m_mutex); + + m_progress += progress; + m_app.set_taskbar_progress((uint64_t)m_progress); + }; + m_context.cancel = &m_cancel; +} void dt_comp_pack::render() { + std::lock_guard guard(m_mutex); + ImGui::PushID("Pack"); ImGui::Indent(20.0f); @@ -24,7 +60,10 @@ void dt_comp_pack::render() { ImGui::SameLine(0.0f, 5.0f); if (ImGui::Button("Select##Input", { 125.0f, 21.0f })) { - //file_dialog::select_folder(m_input); + auto result = dvsku::dv_util_dialog::select_dir("Input dir", m_input); + + if (!result.empty()) + m_input = result; } ImGui::Indent(3.0f); @@ -36,7 +75,10 @@ void dt_comp_pack::render() { ImGui::SameLine(0.0f, 5.0f); if (ImGui::Button("Select##Output", { 125.0f, 21.0f })) { - //file_dialog::save_file(m_output); + auto result = dvsku::dv_util_dialog::save_file("Output evp", m_output, true, { "EVP (*.evp)", "*.evp" }); + + if (!result.empty()) + m_output = result; } ImGui::Dummy({ 0.0f, 3.0f }); @@ -91,21 +133,14 @@ void dt_comp_pack::render() { auto avail = ImGui::GetContentRegionMax(); ImGui::SetCursorPosX((avail.x) / 2 - (125 / 2.0f)); - bool cannot_start = m_input.empty() || m_output.empty() || !m_cancel; + bool cannot_start = m_input.empty() || m_output.empty() || m_cancel; if (cannot_start) ImGui::BeginDisabled(); if (!is_working) { if (ImGui::Button("Pack##Pack", { 125.0f, 21.0f })) { - /* m_components.systems.evp.set_start_callback([&]() { handle_on_start(); }); - m_components.systems.evp.set_finish_callback([&](bool success) { handle_on_finish(success); }); - m_components.systems.evp.set_update_callback([&](float value) { handle_on_update(value); }); - m_components.systems.evp.set_error_callback([&](const std::string& msg) { handle_on_error(msg); }); - - m_components.systems.evp.set_cancel_token(&m_cancel); - - m_components.systems.evp.pack(m_input, m_output, m_filter, m_encrypt, m_key, m_iv);*/ + m_app.get_systems().evp.pack(m_input, m_output, m_filter, &m_context); } } else { diff --git a/source/src/gui/dt_comp_pack.hpp b/source/src/gui/dt_comp_pack.hpp index 88c307f..4eb066a 100644 --- a/source/src/gui/dt_comp_pack.hpp +++ b/source/src/gui/dt_comp_pack.hpp @@ -3,6 +3,8 @@ #include "gui/dt_gui_base.hpp" #include +#include +#include namespace dvsku_toolkit { class dt_comp_pack : public dt_gui_base { @@ -25,5 +27,8 @@ namespace dvsku_toolkit { int m_filter = 0U; float m_progress = 0.0f; bool m_cancel = false; + + std::mutex m_mutex; + libevp::evp_context m_context; }; } \ No newline at end of file diff --git a/source/src/gui/dt_comp_unpack.cpp b/source/src/gui/dt_comp_unpack.cpp index ec2af9f..d39fe25 100644 --- a/source/src/gui/dt_comp_unpack.cpp +++ b/source/src/gui/dt_comp_unpack.cpp @@ -1,15 +1,51 @@ #include "gui/dt_comp_unpack.hpp" #include "dt_app.hpp" +#include + using namespace dvsku_toolkit; /////////////////////////////////////////////////////////////////////////////// // PUBLIC dt_comp_unpack::dt_comp_unpack(dt_app& app) - : dt_gui_base(app) {} + : dt_gui_base(app) +{ + m_context.start_callback = [this]() { + std::lock_guard guard(m_mutex); + + m_progress = 0.0f; + m_app.get_systems().core.is_working = true; + + m_app.set_taskbar_status(dvsku::dv_taskbar_status::normal); + m_app.set_taskbar_progress(0U); + }; + m_context.finish_callback = [this](libevp::evp_result result) { + std::lock_guard guard(m_mutex); + + m_progress = 100.0f; + m_app.get_systems().core.is_working = false; + + m_app.set_taskbar_status(dvsku::dv_taskbar_status::no_progress); + m_app.set_taskbar_progress(0U); + + if (result.status == libevp::evp_result_status::ok) + m_app.play_sound(dvsku::dv_sound_type::success); + else if (result.status == libevp::evp_result_status::error) + m_app.play_sound(dvsku::dv_sound_type::warning); + }; + m_context.update_callback = [this](float progress) { + std::lock_guard guard(m_mutex); + + m_progress += progress; + m_app.set_taskbar_progress((uint64_t)m_progress); + }; + m_context.cancel = &m_cancel; +} void dt_comp_unpack::render() { + std::lock_guard guard(m_mutex); + ImGui::PushID("Unpack"); ImGui::Indent(20.0f); @@ -24,7 +60,10 @@ void dt_comp_unpack::render() { ImGui::SameLine(0.0f, 5.0f); if (ImGui::Button("Select##Input", { 125.0f, 21.0f })) { - //file_dialog::open_file(m_input); + auto result = dvsku::dv_util_dialog::open_file("Input evp", m_input, { "EVP (*.evp)", "*.evp" }); + + if (!result.empty()) + m_input = result[0]; } ImGui::Indent(3.0f); @@ -36,7 +75,10 @@ void dt_comp_unpack::render() { ImGui::SameLine(0.0f, 5.0f); if (ImGui::Button("Select##Output", { 125.0f, 21.0f })) { - //file_dialog::select_folder(m_output); + auto result = dvsku::dv_util_dialog::select_dir("Output dir", m_output); + + if (!result.empty()) + m_output = result; } ImGui::Dummy({ 0.0f, 10.0f }); @@ -54,23 +96,18 @@ void dt_comp_unpack::render() { ImVec2 avail = ImGui::GetContentRegionMax(); ImGui::SetCursorPosX((avail.x) / 2 - (125 / 2.0f)); - bool cannot_start = m_input.empty() || m_output.empty() || !m_cancel; + bool cannot_start = m_input.empty() || m_output.empty() || m_cancel; if (cannot_start) ImGui::BeginDisabled(); if (!is_working) { - if (ImGui::Button("Unpack##Unpack", { 125, 20 })) { - //m_components.systems.evp.set_start_callback([&]() { handle_on_start(); }); - //m_components.systems.evp.set_finish_callback([&](bool success) { handle_on_finish(success); }); - //m_components.systems.evp.set_update_callback([&](float value) { handle_on_update(value); }); - //m_components.systems.evp.set_error_callback([&](const std::string& msg) { handle_on_error(msg); }); - - //m_components.systems.evp.unpack(m_input, m_output, m_decrypt, m_key, m_iv); + if (ImGui::Button("Unpack##Unpack", { 125.0f, 21.0f })) { + m_app.get_systems().evp.unpack(m_input, m_output, &m_context); } } else { - if (ImGui::Button("Cancel##Cancel", { 125, 20 })) { + if (ImGui::Button("Cancel##Cancel", { 125.0f, 21.0f })) { m_cancel = true; } } diff --git a/source/src/gui/dt_comp_unpack.hpp b/source/src/gui/dt_comp_unpack.hpp index 00136a8..05f342c 100644 --- a/source/src/gui/dt_comp_unpack.hpp +++ b/source/src/gui/dt_comp_unpack.hpp @@ -2,6 +2,10 @@ #include "gui/dt_gui_base.hpp" +#include +#include +#include + namespace dvsku_toolkit { class dt_comp_unpack : public dt_gui_base { public: @@ -23,5 +27,8 @@ namespace dvsku_toolkit { int m_filter = 0U; float m_progress = 0.0f; bool m_cancel = false; + + std::mutex m_mutex; + libevp::evp_context m_context; }; } \ No newline at end of file diff --git a/source/src/systems/dt_sys_evp.cpp b/source/src/systems/dt_sys_evp.cpp index 3ed3a9f..701f4c1 100644 --- a/source/src/systems/dt_sys_evp.cpp +++ b/source/src/systems/dt_sys_evp.cpp @@ -3,4 +3,12 @@ using namespace dvsku_toolkit; /////////////////////////////////////////////////////////////////////////////// -// PUBLIC \ No newline at end of file +// PUBLIC + +void dt_sys_evp::pack(const std::string& input, const std::string& output, int filter, libevp::evp_context* context) { + m_evp.pack_async(input, output, (libevp::evp_filter)filter, context); +} + +void dt_sys_evp::unpack(const std::string& input, const std::string& output, libevp::evp_context* context) { + m_evp.unpack_async(input, output, context); +} diff --git a/source/src/systems/dt_sys_evp.hpp b/source/src/systems/dt_sys_evp.hpp index ed7bf63..40f9ecd 100644 --- a/source/src/systems/dt_sys_evp.hpp +++ b/source/src/systems/dt_sys_evp.hpp @@ -2,6 +2,8 @@ #include "systems/dt_system_base.hpp" +#include + namespace dvsku_toolkit { class dt_app; @@ -16,5 +18,12 @@ namespace dvsku_toolkit { dt_sys_evp(dt_app& app) : dt_system_base(app) {}; + + public: + void pack(const std::string& input, const std::string& output, int filter, libevp::evp_context* context = nullptr); + void unpack(const std::string& input, const std::string& output, libevp::evp_context* context = nullptr); + + private: + libevp::evp m_evp; }; } \ No newline at end of file