diff options
Diffstat (limited to 'src/gui.cpp')
| -rw-r--r-- | src/gui.cpp | 82 |
1 files changed, 79 insertions, 3 deletions
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 @@ | |||
| 11 | #include <ctime> | 11 | #include <ctime> |
| 12 | #include <cstdio> | 12 | #include <cstdio> |
| 13 | #include <sstream> | 13 | #include <sstream> |
| 14 | #ifndef _WIN32 | ||
| 15 | #include <unistd.h> | ||
| 16 | #endif | ||
| 14 | #include <iomanip> | 17 | #include <iomanip> |
| 15 | #include <atomic> | 18 | #include <atomic> |
| 16 | #include <mutex> | 19 | #include <mutex> |
| @@ -1400,6 +1403,67 @@ static void DrawAboutDialog() | |||
| 1400 | static bool g_showBackendWizard = false; | 1403 | static bool g_showBackendWizard = false; |
| 1401 | static std::string g_wizardStatus; | 1404 | static std::string g_wizardStatus; |
| 1402 | static bool g_wizardConverted = false; | 1405 | static bool g_wizardConverted = false; |
| 1406 | static int g_restartArgc = 0; | ||
| 1407 | static char** g_restartArgv = NULL; | ||
| 1408 | |||
| 1409 | // Relaunch Bitflash with the same arguments and datadir, then ask this instance | ||
| 1410 | // to exit. A short delay lets the old process release the network port and the | ||
| 1411 | // block-index files before the new one opens them, so mining resumes cleanly on | ||
| 1412 | // the SQLite wallet instead of both instances fighting over the same files. | ||
| 1413 | static void RestartApplication() | ||
| 1414 | { | ||
| 1415 | #ifdef _WIN32 | ||
| 1416 | char exePath[MAX_PATH]; | ||
| 1417 | if (GetModuleFileNameA(NULL, exePath, MAX_PATH) == 0) | ||
| 1418 | return; | ||
| 1419 | std::string strArgs; | ||
| 1420 | bool fHasDataDir = false; | ||
| 1421 | for (int i = 1; i < g_restartArgc; i++) | ||
| 1422 | { | ||
| 1423 | std::string a = g_restartArgv[i] ? g_restartArgv[i] : ""; | ||
| 1424 | if (a.find("-datadir=") == 0 || a.find("/datadir=") == 0) | ||
| 1425 | fHasDataDir = true; | ||
| 1426 | strArgs += " \"" + a + "\""; | ||
| 1427 | } | ||
| 1428 | if (!fHasDataDir) | ||
| 1429 | strArgs += " \"-datadir=" + GetAppDir() + "\""; | ||
| 1430 | |||
| 1431 | std::string strBat = GetAppDir() + "\\bitflash-restart.bat"; | ||
| 1432 | FILE* pf = fopen(strBat.c_str(), "wb"); | ||
| 1433 | if (pf) | ||
| 1434 | { | ||
| 1435 | // ping is the reliable no-console delay on Windows; timeout needs a tty. | ||
| 1436 | fprintf(pf, | ||
| 1437 | "@echo off\r\n" | ||
| 1438 | "ping 127.0.0.1 -n 3 >nul\r\n" | ||
| 1439 | "start \"\" \"%s\"%s\r\n" | ||
| 1440 | "del \"%%~f0\"\r\n", | ||
| 1441 | exePath, strArgs.c_str()); | ||
| 1442 | fclose(pf); | ||
| 1443 | std::string strCmd = "cmd /c \"" + strBat + "\""; | ||
| 1444 | STARTUPINFOA si; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); | ||
| 1445 | PROCESS_INFORMATION pi; memset(&pi, 0, sizeof(pi)); | ||
| 1446 | if (CreateProcessA(NULL, (char*)strCmd.c_str(), NULL, NULL, FALSE, | ||
| 1447 | CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) | ||
| 1448 | { | ||
| 1449 | CloseHandle(pi.hProcess); | ||
| 1450 | CloseHandle(pi.hThread); | ||
| 1451 | } | ||
| 1452 | } | ||
| 1453 | #else | ||
| 1454 | pid_t pid = fork(); | ||
| 1455 | if (pid == 0) | ||
| 1456 | { | ||
| 1457 | sleep(2); | ||
| 1458 | if (g_restartArgv) | ||
| 1459 | execv(g_restartArgv[0], g_restartArgv); | ||
| 1460 | _exit(127); | ||
| 1461 | } | ||
| 1462 | #endif | ||
| 1463 | fShutdown = true; | ||
| 1464 | if (glfwGetCurrentContext()) | ||
| 1465 | glfwSetWindowShouldClose(glfwGetCurrentContext(), true); | ||
| 1466 | } | ||
| 1403 | 1467 | ||
| 1404 | static void DrawBackendWizardDialog() | 1468 | static void DrawBackendWizardDialog() |
| 1405 | { | 1469 | { |
| @@ -1416,11 +1480,19 @@ static void DrawBackendWizardDialog() | |||
| 1416 | ImGui::TextWrapped("%s", g_wizardStatus.c_str()); | 1480 | ImGui::TextWrapped("%s", g_wizardStatus.c_str()); |
| 1417 | ImGui::Spacing(); | 1481 | ImGui::Spacing(); |
| 1418 | ImGui::TextWrapped( | 1482 | ImGui::TextWrapped( |
| 1419 | "Restart Bitflash to start using the SQLite wallet. Your Berkeley " | 1483 | "The switch takes effect when Bitflash restarts. Until then it is " |
| 1420 | "DB wallet.dat is kept untouched as a fallback."); | 1484 | "still running on the old Berkeley DB wallet. Your wallet.dat is " |
| 1485 | "kept untouched as a fallback."); | ||
| 1421 | ImGui::Spacing(); | 1486 | ImGui::Spacing(); |
| 1422 | if (ImGui::Button("Close", ImVec2(120.0f, 0.0f))) | 1487 | if (ImGui::Button("Restart Now", ImVec2(140.0f, 0.0f))) |
| 1488 | RestartApplication(); | ||
| 1489 | ImGui::SameLine(); | ||
| 1490 | if (ImGui::Button("Later", ImVec2(120.0f, 0.0f))) | ||
| 1423 | g_showBackendWizard = false; | 1491 | g_showBackendWizard = false; |
| 1492 | ImGui::Spacing(); | ||
| 1493 | ImGui::TextDisabled( | ||
| 1494 | "If you keep mining before restarting, new coins go to the old " | ||
| 1495 | "wallet until you switch."); | ||
| 1424 | } | 1496 | } |
| 1425 | else | 1497 | else |
| 1426 | { | 1498 | { |
| @@ -1535,6 +1607,10 @@ int RunGUI(int argc, char* argv[]) | |||
| 1535 | g_mineRadio = nMineMode; | 1607 | g_mineRadio = nMineMode; |
| 1536 | strncpy(g_participantPool, strParticipantPool.c_str(), sizeof(g_participantPool)-1); | 1608 | strncpy(g_participantPool, strParticipantPool.c_str(), sizeof(g_participantPool)-1); |
| 1537 | 1609 | ||
| 1610 | // Kept for the wizard's "Restart Now": relaunch with the same command line. | ||
| 1611 | g_restartArgc = argc; | ||
| 1612 | g_restartArgv = argv; | ||
| 1613 | |||
| 1538 | // First run on a Berkeley DB wallet with no recorded choice yet: offer to | 1614 | // First run on a Berkeley DB wallet with no recorded choice yet: offer to |
| 1539 | // convert to SQLite. Never when already on SQLite, once wallet.sqlite exists, | 1615 | // convert to SQLite. Never when already on SQLite, once wallet.sqlite exists, |
| 1540 | // or once a choice has been recorded in the backend marker. | 1616 | // or once a choice has been recorded in the backend marker. |