1
0
mirror of synced 2025-01-18 00:56:49 +01:00

sys: Added "Restore auto backup" popup on first launch after crash

This commit is contained in:
WerWolv 2021-08-17 22:54:09 +02:00
parent f9f67d3bcd
commit 48f27c2174
6 changed files with 63 additions and 2 deletions

View File

@ -36,6 +36,10 @@ namespace hex {
return ProjectFile::s_currProjectFilePath;
}
static void clearProjectFilePath() {
ProjectFile::s_currProjectFilePath.clear();
}
[[nodiscard]] static std::string getFilePath() {
return ProjectFile::s_filePath;

View File

@ -26,6 +26,7 @@ namespace hex {
friend void ImHexSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler *handler, ImGuiTextBuffer *buf);
bool setFont(const std::filesystem::path &font_path);
private:
void frameBegin();
void frame();
@ -54,6 +55,8 @@ namespace hex {
u32 m_bannerWidth = 0, m_bannerHeight = 0;
void *m_bannerTexture = nullptr;
std::filesystem::path m_safetyBackupPath;
};
}

View File

@ -48,6 +48,11 @@ namespace hex::plugin::builtin {
{ "hex.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" },
{ "hex.welcome.header.various", "Verschiedenes" },
{ "hex.safety_backup.title", "Verlorene Daten wiederherstellen" },
{ "hex.safety_backup.desc", "Oh nein, ImHex ist letztes mal abgestürtzt.\nWillst du das verherige Projekt wiederherstellen?"},
{ "hex.safety_backup.restore", "Ja, Wiederherstellen" },
{ "hex.safety_backup.delete", "Nein, Entfernen" },
{ "hex.common.little_endian", "Little Endian" },
{ "hex.common.big_endian", "Big Endian" },
{ "hex.common.decimal", "Dezimal" },

View File

@ -48,6 +48,12 @@ namespace hex::plugin::builtin {
{ "hex.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" },
{ "hex.welcome.header.various", "Various" },
{ "hex.safety_backup.title", "Restore lost data" },
{ "hex.safety_backup.desc", "Oh no, ImHex crashed last time.\nDo you want to restore your past work?"},
{ "hex.safety_backup.restore", "Yes, Restore" },
{ "hex.safety_backup.delete", "No, Delete" },
{ "hex.common.little_endian", "Little Endian" },
{ "hex.common.big_endian", "Big Endian" },
{ "hex.common.decimal", "Decimal" },

View File

@ -48,6 +48,11 @@ namespace hex::plugin::builtin {
{ "hex.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" },
{ "hex.welcome.header.various", "Varie" },
//{ "hex.safety_backup.title", "Restore lost data" },
//{ "hex.safety_backup.desc", "Oh no, ImHex crashed last time.\nDo you want to restore your past work?"},
//{ "hex.safety_backup.restore", "Yes, Restore" },
//{ "hex.safety_backup.delete", "No, Delete" },
{ "hex.common.little_endian", "Little Endian" },
{ "hex.common.big_endian", "Big Endian" },
{ "hex.common.decimal", "Decimale" },

View File

@ -184,13 +184,22 @@ namespace hex {
glfwSetWindowTitle(this->m_window, title.c_str());
});
EventManager::subscribe<EventAbnormalTermination>(this, [](int signal) {
constexpr auto CrashBackupFileName = "crash_backup.hexproj";
EventManager::subscribe<EventAbnormalTermination>(this, [CrashBackupFileName](int signal) {
for (const auto &path : hex::getPath(ImHexPath::Config)) {
if (ProjectFile::store((std::filesystem::path(path) / "crash_backup.hexproj").string()))
if (ProjectFile::store((std::filesystem::path(path) / CrashBackupFileName).string()))
break;
}
});
for (const auto &path : hex::getPath(ImHexPath::Config)) {
if (auto filePath = std::filesystem::path(path) / CrashBackupFileName; std::filesystem::exists(filePath)) {
this->m_safetyBackupPath = filePath;
View::doLater([]{ ImGui::OpenPopup("hex.safety_backup.title"_lang); });
}
}
EventManager::post<EventSettingsChanged>();
for (const auto &path : ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files"))
@ -399,6 +408,35 @@ namespace hex {
ImGui::TextUnformatted("To find out where your plugin folder is, check ImHex' Readme.");
ImGui::EndPopup();
}
// Popup for if there is a safety backup present because ImHex crashed
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F));
if (ImGui::BeginPopupModal("hex.safety_backup.title"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) {
ImGui::TextUnformatted("hex.safety_backup.desc"_lang);
ImGui::NewLine();
auto width = ImGui::GetWindowWidth();
ImGui::SetCursorPosX(width / 9);
if (ImGui::Button("hex.safety_backup.restore"_lang, ImVec2(width / 3, 0))) {
ProjectFile::load(this->m_safetyBackupPath.string());
EventManager::post<EventProjectFileLoad>();
ProjectFile::markDirty();
ProjectFile::clearProjectFilePath();
std::filesystem::remove(this->m_safetyBackupPath);
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
ImGui::SetCursorPosX(width / 9 * 5);
if (ImGui::Button("hex.safety_backup.delete"_lang, ImVec2(width / 3, 0))) {
std::filesystem::remove(this->m_safetyBackupPath);
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
void Window::frame() {