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 (!ProjectFile::load(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);
|
||||
@ -118,23 +119,24 @@ namespace hex::plugin::builtin {
|
||||
if (path.extension() == ".hexproj") {
|
||||
if (!ProjectFile::load(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 {
|
||||
EventProviderOpened::post(newProvider);
|
||||
AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.open_file.name");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
} else if (name == "Open Project") {
|
||||
|
@ -219,7 +219,9 @@ namespace hex::plugin::builtin::recent {
|
||||
void loadRecentEntry(const RecentEntry &recentEntry) {
|
||||
if (recentEntry.type == "project") {
|
||||
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;
|
||||
}
|
||||
auto *provider = ImHexApi::Provider::createProvider(recentEntry.type, true);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <hex.hpp>
|
||||
#include <hex/helpers/http_requests.hpp>
|
||||
|
||||
#include <hex/api/workspace_manager.hpp>
|
||||
#include <hex/api/event_manager.hpp>
|
||||
#include <hex/api/content_registry.hpp>
|
||||
#include <hex/api/localization_manager.hpp>
|
||||
@ -7,7 +8,11 @@
|
||||
#include <hex/api/layout_manager.hpp>
|
||||
#include <hex/api/achievement_manager.hpp>
|
||||
#include <hex/api_urls.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/logger.hpp>
|
||||
|
||||
@ -28,8 +33,6 @@
|
||||
|
||||
#include <string>
|
||||
#include <random>
|
||||
#include <popups/popup_question.hpp>
|
||||
#include <hex/api/workspace_manager.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
@ -546,14 +549,17 @@ namespace hex::plugin::builtin {
|
||||
// Restore callback
|
||||
[crashFileData, backupFilePath, hasProject, hasBackupFile] {
|
||||
if (hasBackupFile) {
|
||||
ProjectFile::load(backupFilePath);
|
||||
if (hasProject) {
|
||||
ProjectFile::setPath(crashFileData["project"].get<std::string>());
|
||||
if (ProjectFile::load(backupFilePath)) {
|
||||
if (hasProject) {
|
||||
ProjectFile::setPath(crashFileData["project"].get<std::string>());
|
||||
} else {
|
||||
ProjectFile::setPath("");
|
||||
}
|
||||
RequestUpdateWindowTitle::post();
|
||||
} 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) {
|
||||
ProjectFile::setPath(crashFileData["project"].get<std::string>());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user