fix: Reset terminate handler directly when being called + some other crashes to crash handling (#1174)

This PR fixes some things about crash handling:
- when the terminate handler is called, immediately set it back to the
original one, so can't make a recursion if the crash-handling code fails
- Only save projects if the crash occured after Imhex finished startup
- do not update the project location when saving the crash backup file:
this will remove problems when `EventAbnormalTermination` is called
before `crashCallback()`

I also added a bit more documentation
This commit is contained in:
iTrooz
2023-07-01 12:32:28 +02:00
committed by GitHub
parent 301418c728
commit c6c3ca4d26
4 changed files with 68 additions and 52 deletions

View File

@@ -47,7 +47,7 @@ namespace hex {
*/
static void setProjectFunctions(
const std::function<bool(const std::fs::path&)> &loadFun,
const std::function<bool(std::optional<std::fs::path>)> &storeFun
const std::function<bool(std::optional<std::fs::path>, bool)> &storeFun
);
/**
@@ -63,10 +63,11 @@ namespace hex {
* @brief Store a project file
*
* @param filePath Path to the project file
* @param updateLocation update the project location so subssequent saves will save there
* @return true if the project file was stored successfully
* @return false if the project file was not stored successfully
*/
static bool store(std::optional<std::fs::path> filePath = std::nullopt);
static bool store(std::optional<std::fs::path> filePath = std::nullopt, bool updateLocation = true);
/**
* @brief Check if a project file is currently loaded
@@ -131,7 +132,7 @@ namespace hex {
ProjectFile() = default;
static std::function<bool(const std::fs::path&)> s_loadProjectFunction;
static std::function<bool(std::optional<std::fs::path>)> s_storeProjectFunction;
static std::function<bool(std::optional<std::fs::path>, bool)> s_storeProjectFunction;
static std::fs::path s_currProjectPath;
static std::vector<Handler> s_handlers;

View File

@@ -17,11 +17,11 @@ namespace hex {
std::fs::path ProjectFile::s_currProjectPath;
std::function<bool(const std::fs::path&)> ProjectFile::s_loadProjectFunction;
std::function<bool(std::optional<std::fs::path>)> ProjectFile::s_storeProjectFunction;
std::function<bool(std::optional<std::fs::path>, bool)> ProjectFile::s_storeProjectFunction;
void ProjectFile::setProjectFunctions(
const std::function<bool(const std::fs::path&)> &loadFun,
const std::function<bool(std::optional<std::fs::path>)> &storeFun
const std::function<bool(std::optional<std::fs::path>, bool)> &storeFun
) {
ProjectFile::s_loadProjectFunction = loadFun;
ProjectFile::s_storeProjectFunction = storeFun;
@@ -31,8 +31,8 @@ namespace hex {
return s_loadProjectFunction(filePath);
}
bool ProjectFile::store(std::optional<std::fs::path> filePath) {
return s_storeProjectFunction(filePath);
bool ProjectFile::store(std::optional<std::fs::path> filePath, bool updateLocation) {
return s_storeProjectFunction(filePath, updateLocation);
}
bool ProjectFile::hasPath() {