Skip to content

Commit

Permalink
Add packing/unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
dvsku committed Apr 22, 2024
1 parent 8119a1a commit f14268c
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 26 deletions.
3 changes: 2 additions & 1 deletion source/src/dt_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
59 changes: 47 additions & 12 deletions source/src/gui/dt_comp_pack.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
#include "gui/dt_comp_pack.hpp"
#include "dt_app.hpp"

#include <dv_gui_opengl/utilities/dv_util_dialog.hpp>

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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> guard(m_mutex);

ImGui::PushID("Pack");
ImGui::Indent(20.0f);

Expand All @@ -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);
Expand All @@ -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 });
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions source/src/gui/dt_comp_pack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "gui/dt_gui_base.hpp"

#include <string>
#include <mutex>
#include <libevp.hpp>

namespace dvsku_toolkit {
class dt_comp_pack : public dt_gui_base {
Expand All @@ -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;
};
}
61 changes: 49 additions & 12 deletions source/src/gui/dt_comp_unpack.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
#include "gui/dt_comp_unpack.hpp"
#include "dt_app.hpp"

#include <dv_gui_opengl/utilities/dv_util_dialog.hpp>

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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> guard(m_mutex);

ImGui::PushID("Unpack");
ImGui::Indent(20.0f);

Expand All @@ -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);
Expand All @@ -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 });
Expand All @@ -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;
}
}
Expand Down
7 changes: 7 additions & 0 deletions source/src/gui/dt_comp_unpack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include "gui/dt_gui_base.hpp"

#include <string>
#include <mutex>
#include <libevp.hpp>

namespace dvsku_toolkit {
class dt_comp_unpack : public dt_gui_base {
public:
Expand All @@ -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;
};
}
10 changes: 9 additions & 1 deletion source/src/systems/dt_sys_evp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
using namespace dvsku_toolkit;

///////////////////////////////////////////////////////////////////////////////
// PUBLIC
// 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);
}
9 changes: 9 additions & 0 deletions source/src/systems/dt_sys_evp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "systems/dt_system_base.hpp"

#include <libevp.hpp>

namespace dvsku_toolkit {
class dt_app;

Expand All @@ -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;
};
}

0 comments on commit f14268c

Please sign in to comment.