Skip to content

Commit e2fee5c

Browse files
committed
[GUI] Use wchar_t API explicitly on Windows
1 parent 6143f80 commit e2fee5c

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

src/qt/guiutil.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,17 @@ bool DHMSTableWidgetItem::operator<(QTableWidgetItem const& item) const
630630
#ifdef WIN32
631631
fs::path static StartupShortcutPath()
632632
{
633+
if (gArgs.GetBoolArg("-testnet", false))
634+
return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX (testnet).lnk";
635+
else if (gArgs.GetBoolArg("-regtest", false))
636+
return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX (regtest).lnk";
637+
633638
return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX.lnk";
634639
}
635640

636641
bool GetStartOnSystemStartup()
637642
{
638-
// check for PIVX.lnk
643+
// check for PIVX*.lnk
639644
return fs::exists(StartupShortcutPath());
640645
}
641646

@@ -648,36 +653,35 @@ bool SetStartOnSystemStartup(bool fAutoStart)
648653
CoInitialize(NULL);
649654

650655
// Get a pointer to the IShellLink interface.
651-
IShellLink* psl = NULL;
652-
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,
653-
CLSCTX_INPROC_SERVER, IID_IShellLink,
656+
IShellLinkW* psl = nullptr;
657+
HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr,
658+
CLSCTX_INPROC_SERVER, IID_IShellLinkW,
654659
reinterpret_cast<void**>(&psl));
655660

656661
if (SUCCEEDED(hres)) {
657662
// Get the current executable path
658-
TCHAR pszExePath[MAX_PATH];
659-
GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));
663+
WCHAR pszExePath[MAX_PATH];
664+
GetModuleFileNameW(nullptr, pszExePath, ARRAYSIZE(pszExePath));
660665

661-
TCHAR pszArgs[5] = TEXT("-min");
666+
// Start client minimized
667+
QString strArgs = "-min";
668+
// Set -testnet /-regtest options
669+
strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)));
662670

663671
// Set the path to the shortcut target
664672
psl->SetPath(pszExePath);
665-
PathRemoveFileSpec(pszExePath);
673+
PathRemoveFileSpecW(pszExePath);
666674
psl->SetWorkingDirectory(pszExePath);
667675
psl->SetShowCmd(SW_SHOWMINNOACTIVE);
668-
psl->SetArguments(pszArgs);
676+
psl->SetArguments(strArgs.toStdWString().c_str());
669677

670678
// Query IShellLink for the IPersistFile interface for
671679
// saving the shortcut in persistent storage.
672-
IPersistFile* ppf = NULL;
673-
hres = psl->QueryInterface(IID_IPersistFile,
674-
reinterpret_cast<void**>(&ppf));
680+
IPersistFile* ppf = nullptr;
681+
hres = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&ppf));
675682
if (SUCCEEDED(hres)) {
676-
WCHAR pwsz[MAX_PATH];
677-
// Ensure that the string is ANSI.
678-
MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().string().c_str(), -1, pwsz, MAX_PATH);
679683
// Save the link by calling IPersistFile::Save.
680-
hres = ppf->Save(pwsz, TRUE);
684+
hres = ppf->Save(StartupShortcutPath().wstring().c_str(), TRUE);
681685
ppf->Release();
682686
psl->Release();
683687
CoUninitialize();
@@ -694,7 +698,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
694698
#elif defined(Q_OS_LINUX)
695699

696700
// Follow the Desktop Application Autostart Spec:
697-
// http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html
701+
// http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html
698702

699703
fs::path static GetAutostartDir()
700704
{
@@ -746,8 +750,13 @@ bool SetStartOnSystemStartup(bool fAutoStart)
746750
// Write a pivx.desktop file to the autostart directory:
747751
optionFile << "[Desktop Entry]\n";
748752
optionFile << "Type=Application\n";
749-
optionFile << "Name=PIVX\n";
750-
optionFile << "Exec=" << pszExePath << " -min\n";
753+
if (gArgs.GetBoolArg("-testnet", false))
754+
optionFile << "Name=PIVX (testnet)\n";
755+
else if (gArgs.GetBoolArg("-regtest", false))
756+
optionFile << "Name=PIVX (regtest)\n";
757+
else
758+
optionFile << "Name=PIVX\n";
759+
optionFile << "Exec=" << pszExePath << strprintf(" -min -testnet=%d -regtest=%d\n", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false));
751760
optionFile << "Terminal=false\n";
752761
optionFile << "Hidden=false\n";
753762
optionFile.close();

src/util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,13 +737,13 @@ void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length)
737737
#ifdef WIN32
738738
fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
739739
{
740-
char pszPath[MAX_PATH] = "";
740+
WCHAR pszPath[MAX_PATH] = L"";
741741

742-
if (SHGetSpecialFolderPathA(NULL, pszPath, nFolder, fCreate)) {
742+
if (SHGetSpecialFolderPathW(nullptr, pszPath, nFolder, fCreate)) {
743743
return fs::path(pszPath);
744744
}
745745

746-
LogPrintf("SHGetSpecialFolderPathA() failed, could not obtain requested path.\n");
746+
LogPrintf("SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
747747
return fs::path("");
748748
}
749749
#endif

0 commit comments

Comments
 (0)