1
0
mirror of synced 2024-11-13 18:50:53 +01:00

fix: Crash when trying to load files with invalid paths

This commit is contained in:
WerWolv 2023-07-19 22:35:55 +02:00
parent f930b6e17d
commit 3c97759aa7

View File

@ -249,8 +249,17 @@ namespace hex::plugin::builtin {
auto pathString = settings.at("path").get<std::string>();
std::fs::path path = std::u8string(pathString.begin(), pathString.end());
if (auto projectPath = ProjectFile::getPath(); !projectPath.empty())
this->setPath(std::fs::weakly_canonical(projectPath.parent_path() / path));
if (auto projectPath = ProjectFile::getPath(); !projectPath.empty()) {
try {
this->setPath(std::fs::weakly_canonical(projectPath.parent_path() / path));
} catch (const std::fs::filesystem_error &) {
try {
this->setPath(projectPath.parent_path() / path);
} catch (const std::fs::filesystem_error &e) {
this->setErrorMessage(hex::format("hex.builtin.provider.file.error.open"_lang, this->m_path.string(), e.what()));
}
}
}
else
this->setPath(path);
}