From 8a47568dcfec8869bc08c555f0070be2d7ddddce Mon Sep 17 00:00:00 2001 From: bitflash Date: Wed, 19 Aug 2026 09:23:01 -0300 Subject: gui: add a "Restart Now" button to the conversion wizard After converting to SQLite the wizard said "restart to apply" but offered no way to do it, so a user could close the dialog and keep mining on the old Berkeley DB wallet without realizing the switch had not taken effect -- and coins mined in the meantime land only in wallet.dat, not the SQLite wallet they think they are now on. The post-conversion screen now offers "Restart Now", which relaunches Bitflash with the same command line and datadir (a short delay lets this instance release the network port and block-index files first) and asks this one to exit, so mining resumes on the SQLite wallet. "Later" keeps the old behaviour. A dimmed line warns that mining before the restart still credits the old wallet. wallet.dat is still never touched. The conversion action itself is unchanged (wallet-convert self-test still green); this is GUI wiring only. --- src/gui.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 3 deletions(-) (limited to 'src/gui.cpp') diff --git a/src/gui.cpp b/src/gui.cpp index 89a7ab6..81dd8e0 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -11,6 +11,9 @@ #include #include #include +#ifndef _WIN32 +#include +#endif #include #include #include @@ -1400,6 +1403,67 @@ static void DrawAboutDialog() static bool g_showBackendWizard = false; static std::string g_wizardStatus; static bool g_wizardConverted = false; +static int g_restartArgc = 0; +static char** g_restartArgv = NULL; + +// Relaunch Bitflash with the same arguments and datadir, then ask this instance +// to exit. A short delay lets the old process release the network port and the +// block-index files before the new one opens them, so mining resumes cleanly on +// the SQLite wallet instead of both instances fighting over the same files. +static void RestartApplication() +{ +#ifdef _WIN32 + char exePath[MAX_PATH]; + if (GetModuleFileNameA(NULL, exePath, MAX_PATH) == 0) + return; + std::string strArgs; + bool fHasDataDir = false; + for (int i = 1; i < g_restartArgc; i++) + { + std::string a = g_restartArgv[i] ? g_restartArgv[i] : ""; + if (a.find("-datadir=") == 0 || a.find("/datadir=") == 0) + fHasDataDir = true; + strArgs += " \"" + a + "\""; + } + if (!fHasDataDir) + strArgs += " \"-datadir=" + GetAppDir() + "\""; + + std::string strBat = GetAppDir() + "\\bitflash-restart.bat"; + FILE* pf = fopen(strBat.c_str(), "wb"); + if (pf) + { + // ping is the reliable no-console delay on Windows; timeout needs a tty. + fprintf(pf, + "@echo off\r\n" + "ping 127.0.0.1 -n 3 >nul\r\n" + "start \"\" \"%s\"%s\r\n" + "del \"%%~f0\"\r\n", + exePath, strArgs.c_str()); + fclose(pf); + std::string strCmd = "cmd /c \"" + strBat + "\""; + STARTUPINFOA si; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); + PROCESS_INFORMATION pi; memset(&pi, 0, sizeof(pi)); + if (CreateProcessA(NULL, (char*)strCmd.c_str(), NULL, NULL, FALSE, + CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) + { + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } + } +#else + pid_t pid = fork(); + if (pid == 0) + { + sleep(2); + if (g_restartArgv) + execv(g_restartArgv[0], g_restartArgv); + _exit(127); + } +#endif + fShutdown = true; + if (glfwGetCurrentContext()) + glfwSetWindowShouldClose(glfwGetCurrentContext(), true); +} static void DrawBackendWizardDialog() { @@ -1416,11 +1480,19 @@ static void DrawBackendWizardDialog() ImGui::TextWrapped("%s", g_wizardStatus.c_str()); ImGui::Spacing(); ImGui::TextWrapped( - "Restart Bitflash to start using the SQLite wallet. Your Berkeley " - "DB wallet.dat is kept untouched as a fallback."); + "The switch takes effect when Bitflash restarts. Until then it is " + "still running on the old Berkeley DB wallet. Your wallet.dat is " + "kept untouched as a fallback."); ImGui::Spacing(); - if (ImGui::Button("Close", ImVec2(120.0f, 0.0f))) + if (ImGui::Button("Restart Now", ImVec2(140.0f, 0.0f))) + RestartApplication(); + ImGui::SameLine(); + if (ImGui::Button("Later", ImVec2(120.0f, 0.0f))) g_showBackendWizard = false; + ImGui::Spacing(); + ImGui::TextDisabled( + "If you keep mining before restarting, new coins go to the old " + "wallet until you switch."); } else { @@ -1535,6 +1607,10 @@ int RunGUI(int argc, char* argv[]) g_mineRadio = nMineMode; strncpy(g_participantPool, strParticipantPool.c_str(), sizeof(g_participantPool)-1); + // Kept for the wizard's "Restart Now": relaunch with the same command line. + g_restartArgc = argc; + g_restartArgv = argv; + // First run on a Berkeley DB wallet with no recorded choice yet: offer to // convert to SQLite. Never when already on SQLite, once wallet.sqlite exists, // or once a choice has been recorded in the backend marker. -- cgit v1.2.3