diff --git a/CMakeLists.txt b/CMakeLists.txt index 278ec5c..60c98f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,8 @@ add_library(solanaceae_sha1_ngcft1 # hacky deps ./solanaceae/ngc_ft1_sha1/mio.hpp ./solanaceae/ngc_ft1_sha1/file_rw_mapped.hpp + ./solanaceae/ngc_ft1_sha1/file_constructor.hpp + ./solanaceae/ngc_ft1_sha1/file_constructor.cpp ./solanaceae/ngc_ft1_sha1/hash_utils.hpp ./solanaceae/ngc_ft1_sha1/hash_utils.cpp diff --git a/solanaceae/ngc_ft1_sha1/file_constructor.cpp b/solanaceae/ngc_ft1_sha1/file_constructor.cpp new file mode 100644 index 0000000..d6bec6f --- /dev/null +++ b/solanaceae/ngc_ft1_sha1/file_constructor.cpp @@ -0,0 +1,8 @@ +#include "./file_constructor.hpp" + +#include "./file_rw_mapped.hpp" + +std::unique_ptr construct_file2_rw_mapped(std::string_view file_path, int64_t file_size) { + return std::make_unique(file_path, file_size); +} + diff --git a/solanaceae/ngc_ft1_sha1/file_constructor.hpp b/solanaceae/ngc_ft1_sha1/file_constructor.hpp new file mode 100644 index 0000000..9d18a0f --- /dev/null +++ b/solanaceae/ngc_ft1_sha1/file_constructor.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +#include +#include + +std::unique_ptr construct_file2_rw_mapped(std::string_view file_path, int64_t file_size = -1); + diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp index f6e347d..1a170b6 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp @@ -16,7 +16,7 @@ #include -#include "./file_rw_mapped.hpp" +#include "./file_constructor.hpp" #include "./components.hpp" #include "./contact_components.hpp" @@ -473,7 +473,7 @@ bool SHA1_NGCFT1::onEvent(const Message::Events::MessageUpdated& e) { ce.emplace(std::vector{full_file_path}); const bool file_exists = std::filesystem::exists(full_file_path); - std::unique_ptr file_impl = std::make_unique(full_file_path, info.file_size); + std::unique_ptr file_impl = construct_file2_rw_mapped(full_file_path, info.file_size); if (!file_impl->isGood()) { std::cerr << "SHA1_NGCFT1 error: failed opening file '" << full_file_path << "'!\n"; @@ -953,7 +953,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_done& e) { // HACK: remap file, to clear ram // TODO: error checking - o.get() = std::make_unique( + o.get() = construct_file2_rw_mapped( o.get().file_list.front(), info.file_size ); @@ -1185,7 +1185,7 @@ bool SHA1_NGCFT1::sendFilePath(const Contact3 c, std::string_view file_name, std file_name_ = std::string(file_name), file_path_ = std::string(file_path) ]() mutable { - auto file_impl = std::make_unique(file_path_, -1); + std::unique_ptr file_impl = construct_file2_rw_mapped(file_path_, -1); if (!file_impl->isGood()) { { std::lock_guard l{self->_info_builder_queue_mutex}; @@ -1235,7 +1235,7 @@ bool SHA1_NGCFT1::sendFilePath(const Contact3 c, std::string_view file_name, std ]() mutable { // // back on iterate thread - auto file_impl = std::make_unique(file_path_, sha1_info.file_size); + std::unique_ptr file_impl = construct_file2_rw_mapped(file_path_, sha1_info.file_size); if (!file_impl->isGood()) { std::cerr << "SHA1_NGCFT1 error: failed opening file '" << file_path_ << "'!\n"; return;