impr: Add better error handling when loading projects
This commit is contained in:
parent
60921031bd
commit
2572e23928
@ -28,8 +28,9 @@ namespace hex::plugin::builtin {
|
|||||||
if (path.extension() == ".hexproj") {
|
if (path.extension() == ".hexproj") {
|
||||||
if (!ProjectFile::load(path)) {
|
if (!ProjectFile::load(path)) {
|
||||||
ui::ToastError::open(hex::format("hex.builtin.popup.error.project.load"_lang, wolv::util::toUTF8String(path)));
|
ui::ToastError::open(hex::format("hex.builtin.popup.error.project.load"_lang, wolv::util::toUTF8String(path)));
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto provider = ImHexApi::Provider::createProvider("hex.builtin.provider.file", true);
|
auto provider = ImHexApi::Provider::createProvider("hex.builtin.provider.file", true);
|
||||||
@ -118,23 +119,24 @@ namespace hex::plugin::builtin {
|
|||||||
if (path.extension() == ".hexproj") {
|
if (path.extension() == ".hexproj") {
|
||||||
if (!ProjectFile::load(path)) {
|
if (!ProjectFile::load(path)) {
|
||||||
ui::ToastError::open(hex::format("hex.builtin.popup.error.project.load"_lang, wolv::util::toUTF8String(path)));
|
ui::ToastError::open(hex::format("hex.builtin.popup.error.project.load"_lang, wolv::util::toUTF8String(path)));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
auto newProvider = static_cast<FileProvider*>(
|
|
||||||
ImHexApi::Provider::createProvider("hex.builtin.provider.file", true)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (newProvider == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
newProvider->setPath(path);
|
|
||||||
if (!newProvider->open()) {
|
|
||||||
hex::ImHexApi::Provider::remove(newProvider);
|
|
||||||
} else {
|
} else {
|
||||||
EventProviderOpened::post(newProvider);
|
return;
|
||||||
AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.open_file.name");
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto newProvider = static_cast<FileProvider*>(
|
||||||
|
ImHexApi::Provider::createProvider("hex.builtin.provider.file", true)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (newProvider == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
newProvider->setPath(path);
|
||||||
|
if (!newProvider->open()) {
|
||||||
|
hex::ImHexApi::Provider::remove(newProvider);
|
||||||
|
} else {
|
||||||
|
EventProviderOpened::post(newProvider);
|
||||||
|
AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.open_file.name");
|
||||||
}
|
}
|
||||||
}, {}, true);
|
}, {}, true);
|
||||||
} else if (name == "Open Project") {
|
} else if (name == "Open Project") {
|
||||||
|
@ -219,7 +219,9 @@ namespace hex::plugin::builtin::recent {
|
|||||||
void loadRecentEntry(const RecentEntry &recentEntry) {
|
void loadRecentEntry(const RecentEntry &recentEntry) {
|
||||||
if (recentEntry.type == "project") {
|
if (recentEntry.type == "project") {
|
||||||
std::fs::path projectPath = recentEntry.data["path"].get<std::string>();
|
std::fs::path projectPath = recentEntry.data["path"].get<std::string>();
|
||||||
ProjectFile::load(projectPath);
|
if (!ProjectFile::load(projectPath)) {
|
||||||
|
ui::ToastError::open(hex::format("hex.builtin.popup.error.project.load"_lang, wolv::util::toUTF8String(projectPath)));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto *provider = ImHexApi::Provider::createProvider(recentEntry.type, true);
|
auto *provider = ImHexApi::Provider::createProvider(recentEntry.type, true);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <hex.hpp>
|
#include <hex.hpp>
|
||||||
#include <hex/helpers/http_requests.hpp>
|
|
||||||
|
#include <hex/api/workspace_manager.hpp>
|
||||||
#include <hex/api/event_manager.hpp>
|
#include <hex/api/event_manager.hpp>
|
||||||
#include <hex/api/content_registry.hpp>
|
#include <hex/api/content_registry.hpp>
|
||||||
#include <hex/api/localization_manager.hpp>
|
#include <hex/api/localization_manager.hpp>
|
||||||
@ -7,7 +8,11 @@
|
|||||||
#include <hex/api/layout_manager.hpp>
|
#include <hex/api/layout_manager.hpp>
|
||||||
#include <hex/api/achievement_manager.hpp>
|
#include <hex/api/achievement_manager.hpp>
|
||||||
#include <hex/api_urls.hpp>
|
#include <hex/api_urls.hpp>
|
||||||
|
|
||||||
#include <hex/ui/view.hpp>
|
#include <hex/ui/view.hpp>
|
||||||
|
#include <toasts/toast_notification.hpp>
|
||||||
|
|
||||||
|
#include <hex/helpers/http_requests.hpp>
|
||||||
#include <hex/helpers/fs.hpp>
|
#include <hex/helpers/fs.hpp>
|
||||||
#include <hex/helpers/logger.hpp>
|
#include <hex/helpers/logger.hpp>
|
||||||
|
|
||||||
@ -28,8 +33,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <popups/popup_question.hpp>
|
|
||||||
#include <hex/api/workspace_manager.hpp>
|
|
||||||
|
|
||||||
namespace hex::plugin::builtin {
|
namespace hex::plugin::builtin {
|
||||||
|
|
||||||
@ -546,14 +549,17 @@ namespace hex::plugin::builtin {
|
|||||||
// Restore callback
|
// Restore callback
|
||||||
[crashFileData, backupFilePath, hasProject, hasBackupFile] {
|
[crashFileData, backupFilePath, hasProject, hasBackupFile] {
|
||||||
if (hasBackupFile) {
|
if (hasBackupFile) {
|
||||||
ProjectFile::load(backupFilePath);
|
if (ProjectFile::load(backupFilePath)) {
|
||||||
if (hasProject) {
|
if (hasProject) {
|
||||||
ProjectFile::setPath(crashFileData["project"].get<std::string>());
|
ProjectFile::setPath(crashFileData["project"].get<std::string>());
|
||||||
|
} else {
|
||||||
|
ProjectFile::setPath("");
|
||||||
|
}
|
||||||
|
RequestUpdateWindowTitle::post();
|
||||||
} else {
|
} else {
|
||||||
ProjectFile::setPath("");
|
ui::ToastError::open(hex::format("hex.builtin.popup.error.project.load"_lang, wolv::util::toUTF8String(backupFilePath)));
|
||||||
}
|
}
|
||||||
RequestUpdateWindowTitle::post();
|
} else {
|
||||||
}else{
|
|
||||||
if (hasProject) {
|
if (hasProject) {
|
||||||
ProjectFile::setPath(crashFileData["project"].get<std::string>());
|
ProjectFile::setPath(crashFileData["project"].get<std::string>());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user