mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-17 19:13:55 +00:00
Prepare filesystem support
This commit is contained in:
@@ -5,18 +5,7 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
std::filesystem::path canonicalize_module_path(const std::filesystem::path& file)
|
||||
{
|
||||
constexpr std::u16string_view nt_prefix = u"\\??\\";
|
||||
const auto wide_file = file.u16string();
|
||||
|
||||
if (!wide_file.starts_with(nt_prefix))
|
||||
{
|
||||
return canonical(absolute(file));
|
||||
}
|
||||
|
||||
return canonicalize_module_path(wide_file.substr(nt_prefix.size()));
|
||||
}
|
||||
}
|
||||
|
||||
namespace utils
|
||||
@@ -64,26 +53,32 @@ namespace utils
|
||||
}
|
||||
}
|
||||
|
||||
module_manager::module_manager(emulator& emu)
|
||||
: emu_(&emu)
|
||||
module_manager::module_manager(emulator& emu, file_system& file_sys)
|
||||
: emu_(&emu),
|
||||
file_sys_(&file_sys)
|
||||
{
|
||||
}
|
||||
|
||||
mapped_module* module_manager::map_module(const std::filesystem::path& file, logger& logger)
|
||||
mapped_module* module_manager::map_module(const std::filesystem::path& file, const logger& logger)
|
||||
{
|
||||
auto canonical_file = canonicalize_module_path(file);
|
||||
return this->map_local_module(this->file_sys_->translate(file), logger);
|
||||
}
|
||||
|
||||
for (auto& mod : this->modules_)
|
||||
mapped_module* module_manager::map_local_module(const std::filesystem::path& file, const logger& logger)
|
||||
{
|
||||
auto local_file = canonical(absolute(file));
|
||||
|
||||
for (auto& mod : this->modules_ | std::views::values)
|
||||
{
|
||||
if (mod.second.path == canonical_file)
|
||||
if (mod.path == file)
|
||||
{
|
||||
return &mod.second;
|
||||
return &mod;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
auto mod = map_module_from_file(*this->emu_, std::move(canonical_file));
|
||||
auto mod = map_module_from_file(*this->emu_, std::move(local_file));
|
||||
|
||||
logger.log("Mapped %s at 0x%" PRIx64 "\n", mod.path.generic_string().c_str(), mod.image_base);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user