1
0
mirror of synced 2025-02-20 04:01:01 +01:00

Store environment variables and use on restart (#380)

- Fixes WerWolv/ImHex#373
This commit is contained in:
qxxxb 2021-12-22 07:16:51 -05:00 committed by GitHub
parent 3d32261f16
commit b047fc0063
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 10 deletions

View File

@ -14,7 +14,7 @@ namespace hex::init {
class WindowSplash {
public:
WindowSplash(int &argc, char **&argv);
WindowSplash(int &argc, char **&argv, char **&envp);
~WindowSplash();
bool loop();
@ -40,4 +40,4 @@ namespace hex::init {
std::vector<std::pair<std::string, TaskFunction>> m_tasks;
};
}
}

View File

@ -93,6 +93,7 @@ namespace hex {
static int mainArgc;
static char **mainArgv;
static char **mainEnvp;
static ImFontAtlas *fontAtlas;
static ImFontConfig fontConfig;
@ -106,4 +107,4 @@ namespace hex {
static std::map<std::string, std::any> sharedVariables;
};
}
}

View File

@ -16,7 +16,7 @@ namespace hex {
void ImHexApi::Common::restartImHex() {
EventManager::post<RequestCloseImHex>(false);
std::atexit([]{
execve(SharedData::mainArgv[0], SharedData::mainArgv, nullptr);
execve(SharedData::mainArgv[0], SharedData::mainArgv, SharedData::mainEnvp);
});
}
@ -86,4 +86,4 @@ namespace hex {
return Task(unlocalizedName, maxValue);
}
}
}

View File

@ -43,6 +43,7 @@ namespace hex {
int SharedData::mainArgc;
char **SharedData::mainArgv;
char **SharedData::mainEnvp;
ImFontAtlas *SharedData::fontAtlas;
ImFontConfig SharedData::fontConfig;
@ -53,4 +54,4 @@ namespace hex {
float SharedData::fontScale;
std::map<std::string, std::any> SharedData::sharedVariables;
}
}

View File

@ -25,9 +25,10 @@ using namespace std::literals::chrono_literals;
namespace hex::init {
WindowSplash::WindowSplash(int &argc, char **&argv) : m_window(nullptr) {
WindowSplash::WindowSplash(int &argc, char **&argv, char **&envp) : m_window(nullptr) {
SharedData::mainArgc = argc;
SharedData::mainArgv = argv;
SharedData::mainEnvp = envp;
this->initGLFW();
this->initImGui();
@ -239,4 +240,4 @@ namespace hex::init {
ImGui::DestroyContext();
}
}
}

View File

@ -10,14 +10,14 @@
#include <hex/helpers/file.hpp>
int main(int argc, char **argv) {
int main(int argc, char **argv, char **envp) {
using namespace hex;
// Initialization
{
Window::initNative();
init::WindowSplash splashWindow(argc, argv);
init::WindowSplash splashWindow(argc, argv, envp);
for (const auto &[name, task] : init::getInitTasks())
splashWindow.addStartupTask(name, task);