| 528 | } |
| 529 | |
| 530 | bool SetStartOnSystemStartup(bool fAutoStart) |
| 531 | { |
| 532 | // If the shortcut exists already, remove it for updating |
| 533 | fs::remove(StartupShortcutPath()); |
| 534 | |
| 535 | if (fAutoStart) |
| 536 | { |
| 537 | CoInitialize(nullptr); |
| 538 | |
| 539 | // Get a pointer to the IShellLink interface. |
| 540 | IShellLinkW* psl = nullptr; |
| 541 | HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr, |
| 542 | CLSCTX_INPROC_SERVER, IID_IShellLinkW, |
| 543 | reinterpret_cast<void**>(&psl)); |
| 544 | |
| 545 | if (SUCCEEDED(hres)) |
| 546 | { |
| 547 | // Get the current executable path |
| 548 | WCHAR pszExePath[MAX_PATH]; |
| 549 | GetModuleFileNameW(nullptr, pszExePath, ARRAYSIZE(pszExePath)); |
| 550 | |
| 551 | // Start client minimized |
| 552 | QString strArgs = "-min"; |
| 553 | // Set -testnet /-regtest options |
| 554 | strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName())); |
| 555 | |
| 556 | // Set the path to the shortcut target |
| 557 | psl->SetPath(pszExePath); |
| 558 | PathRemoveFileSpecW(pszExePath); |
| 559 | psl->SetWorkingDirectory(pszExePath); |
| 560 | psl->SetShowCmd(SW_SHOWMINNOACTIVE); |
| 561 | psl->SetArguments(strArgs.toStdWString().c_str()); |
| 562 | |
| 563 | // Query IShellLink for the IPersistFile interface for |
| 564 | // saving the shortcut in persistent storage. |
| 565 | IPersistFile* ppf = nullptr; |
| 566 | hres = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&ppf)); |
| 567 | if (SUCCEEDED(hres)) |
| 568 | { |
| 569 | // Save the link by calling IPersistFile::Save. |
| 570 | hres = ppf->Save(StartupShortcutPath().wstring().c_str(), TRUE); |
| 571 | ppf->Release(); |
| 572 | psl->Release(); |
| 573 | CoUninitialize(); |
| 574 | return true; |
| 575 | } |
| 576 | psl->Release(); |
| 577 | } |
| 578 | CoUninitialize(); |
| 579 | return false; |
| 580 | } |
| 581 | return true; |
| 582 | } |
| 583 | #elif defined(Q_OS_LINUX) |
| 584 | |
| 585 | // Follow the Desktop Application Autostart Spec: |
no test coverage detected