|
5 | 5 |
|
6 | 6 | #include "flow/core/NodeFactory.hpp" |
7 | 7 |
|
| 8 | +#include <Zipper/Unzipper.hpp> |
8 | 9 | #include <nlohmann/json.hpp> |
9 | | -#include <zip.h> |
10 | 10 |
|
11 | 11 | #include <bit> |
12 | 12 | #include <format> |
|
21 | 21 |
|
22 | 22 | FLOW_NAMESPACE_BEGIN |
23 | 23 |
|
24 | | -const std::string Module::FileExtension = "flowmod"; |
| 24 | +using namespace zipper; |
| 25 | + |
| 26 | +const std::string Module::FileExtension = "fmod"; |
25 | 27 |
|
26 | 28 | #ifdef FLOW_WINDOWS |
27 | 29 | constexpr const char* platform = "windows"; |
@@ -116,55 +118,14 @@ bool Module::Load(const std::filesystem::path& path) |
116 | 118 | throw std::runtime_error(std::format("Path is not a file. (file={})", path.string())); |
117 | 119 | } |
118 | 120 |
|
119 | | - zip_t* archive = zip_open(path.string().c_str(), ZIP_RDONLY, nullptr); |
120 | | - if (!archive) |
| 121 | + Unzipper unzipper(path.string()); |
| 122 | + if (!unzipper.isOpened()) |
121 | 123 | { |
122 | 124 | throw std::runtime_error(std::format("Failed to open module archive. (file={})", path.string())); |
123 | 125 | } |
124 | 126 |
|
125 | | - const zip_int64_t num_entries = zip_get_num_entries(archive, 0); |
126 | | - for (zip_int64_t i = 0; i < num_entries; ++i) |
127 | | - { |
128 | | - zip_stat_t file_info; |
129 | | - zip_stat_init(&file_info); |
130 | | - |
131 | | - if (zip_stat_index(archive, i, 0, &file_info) != 0) |
132 | | - { |
133 | | - zip_close(archive); |
134 | | - throw std::runtime_error( |
135 | | - std::format("Failed to get file info from module archive. (file={})", path.string())); |
136 | | - } |
137 | | - |
138 | | - auto file_path = GetTempModulePath() / file_info.name; |
139 | | - auto file = zip_fopen(archive, file_info.name, 0); |
140 | | - if (!file) |
141 | | - { |
142 | | - zip_close(archive); |
143 | | - throw std::runtime_error( |
144 | | - std::format("Failed to open file in module archive. (file={})", file_path.string())); |
145 | | - } |
146 | | - |
147 | | - std::vector<char> buffer(file_info.size); |
148 | | - zip_fread(file, buffer.data(), file_info.size); |
149 | | - zip_fclose(file); |
150 | | - |
151 | | - std::filesystem::create_directories(file_path.parent_path()); |
152 | | - if (std::filesystem::is_directory(file_path)) |
153 | | - { |
154 | | - continue; |
155 | | - } |
156 | | - |
157 | | - std::ofstream out_file(file_path, std::ios::binary); |
158 | | - if (!out_file) |
159 | | - { |
160 | | - zip_close(archive); |
161 | | - throw std::runtime_error( |
162 | | - std::format("Failed to create file from module archive. (file={})", file_path.string())); |
163 | | - } |
164 | | - |
165 | | - out_file.write(buffer.data(), buffer.size()); |
166 | | - out_file.close(); |
167 | | - } |
| 127 | + unzipper.extractAll(GetTempModulePath().string(), Unzipper::OverwriteMode::Overwrite); |
| 128 | + unzipper.close(); |
168 | 129 |
|
169 | 130 | auto module_metadata_path = GetModuleMetaDataPath(GetTempModulePath() / path.stem()); |
170 | 131 | std::ifstream metadata_fs(module_metadata_path); |
|
0 commit comments