diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2023-10-07 21:07:04 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2023-10-07 21:07:04 -0600 |
| commit | dfbf8f15256d929d354b034a9a0db481078b5642 (patch) | |
| tree | 06a05a1f5fa7df00495de3ec5c21fa1a92206442 /src/Companion.cpp | |
| parent | a38f895f8033841c3d7fbea7bcd604ac49dcd03e (diff) | |
Added a command to pack an mpq from a directory
Diffstat (limited to 'src/Companion.cpp')
| -rw-r--r-- | src/Companion.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp index 88f8542..1b98d2d 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -166,3 +166,44 @@ RawFactory *Companion::GetFactory(const std::string &extension) { return this->gFactories[extension]; } + +void Companion::Pack(const std::string& folder, const std::string& output) { + + spdlog::set_level(spdlog::level::debug); + spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v"); + + SPDLOG_INFO("------------------------------------------------"); + + SPDLOG_INFO("Starting CubeOS..."); + SPDLOG_INFO("Scanning {}", folder); + + auto start = duration_cast<milliseconds>(system_clock::now().time_since_epoch()); + std::unordered_map<std::string, std::vector<char>> files; + + for (const auto & entry : fs::recursive_directory_iterator(folder)){ + if(entry.is_directory()) continue; + std::ifstream input( entry.path(), std::ios::binary ); + auto data = std::vector<char>( std::istreambuf_iterator<char>( input ), {} ); + input.close(); + files[entry.path().string()] = data; + } + + auto wrapper = SWrapper(output); + + for(auto& [path, data] : files){ + std::string normalized = path; + std::replace(normalized.begin(), normalized.end(), '\\', '/'); + // Remove parent folder + normalized = normalized.substr(folder.length() + 1); + wrapper.CreateFile(normalized, data); + SPDLOG_INFO("> Added {}", normalized); + } + + auto end = duration_cast<milliseconds>(system_clock::now().time_since_epoch()); + SPDLOG_INFO("Done! Took {}ms", end.count() - start.count()); + SPDLOG_INFO("Exported to {}", output); + spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v"); + SPDLOG_INFO("------------------------------------------------"); + + wrapper.Close(); +}
\ No newline at end of file |
