2023-10-29 19:43:40 +01:00
|
|
|
#include <hex/helpers/fs.hpp>
|
|
|
|
|
|
|
|
#include <wolv/io/file.hpp>
|
|
|
|
#include <romfs/romfs.hpp>
|
|
|
|
|
2024-01-30 21:19:43 +01:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2024-06-22 10:44:55 +02:00
|
|
|
#include <hex/helpers/default_paths.hpp>
|
2024-01-30 21:19:43 +01:00
|
|
|
|
2023-10-29 19:43:40 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
void extractBundledFiles() {
|
2023-12-28 19:24:56 +01:00
|
|
|
constexpr static std::array<std::pair<std::string_view, bool>, 2> Paths = {
|
|
|
|
{
|
|
|
|
{ "auto_extract", false },
|
|
|
|
{ "always_auto_extract", true }
|
|
|
|
}
|
|
|
|
};
|
2023-10-29 19:43:40 +01:00
|
|
|
|
2023-12-28 19:25:37 +01:00
|
|
|
for (const auto &[extractFolder, alwaysExtract] : Paths) {
|
2023-12-28 19:24:56 +01:00
|
|
|
for (const auto &romfsPath : romfs::list(extractFolder)) {
|
2024-06-22 10:44:55 +02:00
|
|
|
for (const auto &imhexPath : paths::getDataPaths(false)) {
|
2023-12-28 19:24:56 +01:00
|
|
|
const auto path = imhexPath / std::fs::relative(romfsPath, extractFolder);
|
2024-01-30 21:19:43 +01:00
|
|
|
log::info("Extracting {} to {}", romfsPath.string(), path.string());
|
2023-12-28 19:24:56 +01:00
|
|
|
if (!alwaysExtract && wolv::io::fs::exists(path))
|
|
|
|
continue;
|
2023-10-29 19:43:40 +01:00
|
|
|
|
2023-12-28 19:24:56 +01:00
|
|
|
wolv::io::File file(path, wolv::io::File::Mode::Create);
|
|
|
|
if (!file.isValid())
|
|
|
|
continue;
|
2023-10-29 19:43:40 +01:00
|
|
|
|
2023-12-28 19:24:56 +01:00
|
|
|
auto data = romfs::get(romfsPath).span<u8>();
|
|
|
|
file.writeBuffer(data.data(), data.size());
|
2023-10-29 19:43:40 +01:00
|
|
|
|
2023-12-28 19:24:56 +01:00
|
|
|
if (file.getSize() == data.size())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-10-29 19:43:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|