Skip to content

Commit 9673c35

Browse files
author
Philip Kaufmann
committed
[Qt, Win] honor current network when creating autostart link
- creates a "Bitcoin (testnet).lnk" when on testnet or a "Bitcoin (regtest).lnk, when on regtest - fixes #5778
1 parent e3a3cd7 commit 9673c35

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/qt/guiutil.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#if BOOST_FILESYSTEM_VERSION >= 3
4141
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
4242
#endif
43+
#include <boost/scoped_array.hpp>
4344

4445
#include <QAbstractItemView>
4546
#include <QApplication>
@@ -567,12 +568,17 @@ TableViewLastColumnResizingFixer::TableViewLastColumnResizingFixer(QTableView* t
567568
#ifdef WIN32
568569
boost::filesystem::path static StartupShortcutPath()
569570
{
571+
if (GetBoolArg("-testnet", false))
572+
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin (testnet).lnk";
573+
else if (GetBoolArg("-regtest", false))
574+
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin (regtest).lnk";
575+
570576
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin.lnk";
571577
}
572578

573579
bool GetStartOnSystemStartup()
574580
{
575-
// check for Bitcoin.lnk
581+
// check for Bitcoin*.lnk
576582
return boost::filesystem::exists(StartupShortcutPath());
577583
}
578584

@@ -588,29 +594,43 @@ bool SetStartOnSystemStartup(bool fAutoStart)
588594
// Get a pointer to the IShellLink interface.
589595
IShellLink* psl = NULL;
590596
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,
591-
CLSCTX_INPROC_SERVER, IID_IShellLink,
592-
reinterpret_cast<void**>(&psl));
597+
CLSCTX_INPROC_SERVER, IID_IShellLink,
598+
reinterpret_cast<void**>(&psl));
593599

594600
if (SUCCEEDED(hres))
595601
{
596602
// Get the current executable path
597603
TCHAR pszExePath[MAX_PATH];
598604
GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));
599605

600-
TCHAR pszArgs[5] = TEXT("-min");
606+
// Start client minimized
607+
QString strArgs = "-min";
608+
// Set -testnet /-regtest options
609+
strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", GetBoolArg("-testnet", false), GetBoolArg("-regtest", false)));
610+
611+
#ifdef UNICODE
612+
boost::scoped_array<TCHAR> args(new TCHAR[strArgs.length() + 1]);
613+
// Convert the QString to TCHAR*
614+
strArgs.toWCharArray(args.get());
615+
// Add missing '\0'-termination to string
616+
args[strArgs.length()] = '\0';
617+
#endif
601618

602619
// Set the path to the shortcut target
603620
psl->SetPath(pszExePath);
604621
PathRemoveFileSpec(pszExePath);
605622
psl->SetWorkingDirectory(pszExePath);
606623
psl->SetShowCmd(SW_SHOWMINNOACTIVE);
607-
psl->SetArguments(pszArgs);
624+
#ifndef UNICODE
625+
psl->SetArguments(strArgs.toStdString().c_str());
626+
#else
627+
psl->SetArguments(args.get());
628+
#endif
608629

609630
// Query IShellLink for the IPersistFile interface for
610631
// saving the shortcut in persistent storage.
611632
IPersistFile* ppf = NULL;
612-
hres = psl->QueryInterface(IID_IPersistFile,
613-
reinterpret_cast<void**>(&ppf));
633+
hres = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&ppf));
614634
if (SUCCEEDED(hres))
615635
{
616636
WCHAR pwsz[MAX_PATH];
@@ -630,7 +650,6 @@ bool SetStartOnSystemStartup(bool fAutoStart)
630650
}
631651
return true;
632652
}
633-
634653
#elif defined(Q_OS_LINUX)
635654

636655
// Follow the Desktop Application Autostart Spec:

0 commit comments

Comments
 (0)