ux: Handle project loading errors better
This commit is contained in:
parent
e0e2996e25
commit
1d4cbbe418
@ -19,12 +19,14 @@ namespace hex {
|
||||
struct Handler {
|
||||
using Function = std::function<bool(const std::fs::path &, Tar &tar)>;
|
||||
std::fs::path basePath;
|
||||
bool required;
|
||||
Function load, store;
|
||||
};
|
||||
|
||||
struct ProviderHandler {
|
||||
using Function = std::function<bool(prv::Provider *provider, const std::fs::path &, Tar &tar)>;
|
||||
std::fs::path basePath;
|
||||
bool required;
|
||||
Function load, store;
|
||||
};
|
||||
|
||||
|
@ -45,6 +45,10 @@ namespace hex {
|
||||
log::info("{}", e.what());
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (!result && handler.required) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &provider : ImHexApi::Provider::getProviders()) {
|
||||
@ -57,12 +61,16 @@ namespace hex {
|
||||
log::info("{}", e.what());
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (!result && handler.required) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProjectFile::s_currProjectPath = filePath;
|
||||
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectFile::store(std::optional<std::fs::path> filePath) {
|
||||
|
@ -78,7 +78,9 @@ namespace hex::plugin::builtin {
|
||||
} else if (name == "Open Project") {
|
||||
fs::openFileBrowser(fs::DialogMode::Open, { {"Project File", "hexproj"} },
|
||||
[](const auto &path) {
|
||||
ProjectFile::load(path);
|
||||
if (!ProjectFile::load(path)) {
|
||||
View::showErrorPopup("hex.builtin.popup.error.project.load"_lang);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -64,7 +64,9 @@ namespace hex::plugin::builtin {
|
||||
fs::openFileBrowser(fs::DialogMode::Open, { {"Project File", "hexproj"}
|
||||
},
|
||||
[](const auto &path) {
|
||||
ProjectFile::load(path);
|
||||
if (!ProjectFile::load(path)) {
|
||||
View::showErrorPopup("hex.builtin.popup.error.project.load"_lang);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -75,7 +77,9 @@ namespace hex::plugin::builtin {
|
||||
path.replace_extension(".hexproj");
|
||||
}
|
||||
|
||||
ProjectFile::store(path);
|
||||
if (!ProjectFile::load(path)) {
|
||||
View::showErrorPopup("hex.builtin.popup.error.project.load"_lang);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -24,6 +24,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ProjectFile::registerHandler({
|
||||
.basePath = "providers",
|
||||
.required = true,
|
||||
.load = [](const std::fs::path &basePath, Tar &tar) {
|
||||
auto json = nlohmann::json::parse(tar.readString(basePath / "providers.json"));
|
||||
auto providerIds = json["providers"].get<std::vector<int>>();
|
||||
@ -33,13 +34,14 @@ namespace hex::plugin::builtin {
|
||||
auto providerSettings = nlohmann::json::parse(tar.readString(basePath / hex::format("{}.json", id)));
|
||||
|
||||
auto provider = ImHexApi::Provider::createProvider(providerSettings["type"].get<std::string>(), true);
|
||||
ON_SCOPE_EXIT { if (!success) ImHexApi::Provider::remove(provider, true); };
|
||||
if (provider == nullptr) {
|
||||
success = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
provider->loadSettings(providerSettings["settings"]);
|
||||
if (!provider->open())
|
||||
if (!provider->open() || !provider->isAvailable() || !provider->isReadable())
|
||||
success = false;
|
||||
else
|
||||
EventManager::post<EventProviderOpened>(provider);
|
||||
|
@ -103,6 +103,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ProjectFile::registerPerProviderHandler({
|
||||
.basePath = "bookmarks.json",
|
||||
.required = false,
|
||||
.load = [](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) -> bool {
|
||||
auto fileContent = tar.read(basePath);
|
||||
if (fileContent.empty())
|
||||
|
@ -34,6 +34,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ProjectFile::registerPerProviderHandler({
|
||||
.basePath = "data_processor.json",
|
||||
.required = false,
|
||||
.load = [this](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) {
|
||||
auto save = tar.readString(basePath);
|
||||
|
||||
|
@ -15,6 +15,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ProjectFile::registerPerProviderHandler({
|
||||
.basePath = "patches.json",
|
||||
.required = false,
|
||||
.load = [](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) {
|
||||
auto json = nlohmann::json::parse(tar.read(basePath));
|
||||
provider->getPatches() = json["patches"].get<std::map<u64, u8>>();
|
||||
|
@ -302,6 +302,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ProjectFile::registerPerProviderHandler({
|
||||
.basePath = "pattern_source_code.hexpat",
|
||||
.required = false,
|
||||
.load = [this](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) {
|
||||
std::string sourceCode = tar.readString(basePath);
|
||||
|
||||
|
@ -115,6 +115,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.close_provider.desc", "Es wurden ungespeicherte Änderungen an diesem Provider vorgenommen.\nBist du sicher, dass du ihn schliessen willst?" },
|
||||
{ "hex.builtin.popup.error.read_only", "Schreibzugriff konnte nicht erlangt werden. Datei wurde im Lesemodus geöffnet." },
|
||||
{ "hex.builtin.popup.error.open", "Öffnen der Datei fehlgeschlagen!" },
|
||||
{ "hex.builtin.popup.error.project.load", "Laden des Projektes fehlgeschlagen!" },
|
||||
{ "hex.builtin.popup.error.project.save", "Speichern des Projektes fehlgeschlagen!!" },
|
||||
{ "hex.builtin.popup.error.create", "Erstellen der neuen Datei fehlgeschlagen!" },
|
||||
{ "hex.builtin.popup.error.task_exception", "Fehler in Task '{}':\n\n{}" },
|
||||
|
||||
|
@ -117,6 +117,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "Couldn't get write access. File opened in read-only mode." },
|
||||
{ "hex.builtin.popup.error.open", "Failed to open file!" },
|
||||
{ "hex.builtin.popup.error.create", "Failed to create new file!" },
|
||||
{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||
{ "hex.builtin.popup.error.project.save", "Failed to save project!" },
|
||||
{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "File" },
|
||||
|
@ -116,6 +116,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "Impossibile scrivere sul File. File aperto solo in modalità lettura" },
|
||||
{ "hex.builtin.popup.error.open", "Impossibile aprire il File!" },
|
||||
{ "hex.builtin.popup.error.create", "Impossibile creare il nuovo File!" },
|
||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||
//{ "hex.builtin.popup.error.project.save", "Failed to save project!" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "File" },
|
||||
|
@ -116,6 +116,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "書き込み権限を取得できませんでした。ファイルが読み取り専用で開かれました。" },
|
||||
{ "hex.builtin.popup.error.open", "ファイルを開けませんでした。" },
|
||||
{ "hex.builtin.popup.error.create", "新しいファイルを作成できませんでした。" },
|
||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||
//{ "hex.builtin.popup.error.project.save", "Failed to save project!" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "ファイル" },
|
||||
|
@ -116,6 +116,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "쓰기 권한을 가져올 수 없습니다. 파일이 읽기 전용 모드로 열렸습니다." },
|
||||
{ "hex.builtin.popup.error.open", "파일을 여는데 실패했습니다!" },
|
||||
{ "hex.builtin.popup.error.create", "새 파일을 만드는데 실패했습니다!" },
|
||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||
//{ "hex.builtin.popup.error.project.save", "Failed to save project!" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "파일" },
|
||||
|
@ -116,6 +116,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "Não foi possível obter acesso de gravação. Arquivo aberto no modo somente leitura." },
|
||||
{ "hex.builtin.popup.error.open", "Falha ao abrir o arquivo!" },
|
||||
{ "hex.builtin.popup.error.create", "Falha ao criar um novo arquivo!" },
|
||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||
//{ "hex.builtin.popup.error.project.save", "Failed to save project!" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "File" },
|
||||
|
@ -116,6 +116,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "无法获得写权限,文件以只读方式打开。" },
|
||||
{ "hex.builtin.popup.error.open", "打开文件失败!" },
|
||||
{ "hex.builtin.popup.error.create", "创建新文件失败!" },
|
||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||
//{ "hex.builtin.popup.error.project.save", "Failed to save project!" },
|
||||
{ "hex.builtin.popup.error.task_exception", "任务 '{}' 异常:\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "文件" },
|
||||
|
@ -116,6 +116,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.popup.error.read_only", "無法取得寫入權限。檔案已以唯讀模式開啟。" },
|
||||
{ "hex.builtin.popup.error.open", "無法開啟檔案!" },
|
||||
{ "hex.builtin.popup.error.create", "無法建立新檔案!" },
|
||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||
//{ "hex.builtin.popup.error.project.save", "Failed to save project!" },
|
||||
//{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" },
|
||||
|
||||
{ "hex.builtin.menu.file", "檔案" },
|
||||
|
Loading…
x
Reference in New Issue
Block a user