Merge #13734: gui: Drop boost::scoped_array and use wchar_t API explicitly on Windows
bb6ca65f98
gui: get special folder in unicode (Chun Kuan Lee)1c5d225853
Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix #13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454
This commit is contained in:
commit
362518791a
3 changed files with 10 additions and 28 deletions
|
@ -38,8 +38,6 @@
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/scoped_array.hpp>
|
|
||||||
|
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
@ -548,40 +546,28 @@ bool SetStartOnSystemStartup(bool fAutoStart)
|
||||||
CoInitialize(nullptr);
|
CoInitialize(nullptr);
|
||||||
|
|
||||||
// Get a pointer to the IShellLink interface.
|
// Get a pointer to the IShellLink interface.
|
||||||
IShellLink* psl = nullptr;
|
IShellLinkW* psl = nullptr;
|
||||||
HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr,
|
HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr,
|
||||||
CLSCTX_INPROC_SERVER, IID_IShellLink,
|
CLSCTX_INPROC_SERVER, IID_IShellLinkW,
|
||||||
reinterpret_cast<void**>(&psl));
|
reinterpret_cast<void**>(&psl));
|
||||||
|
|
||||||
if (SUCCEEDED(hres))
|
if (SUCCEEDED(hres))
|
||||||
{
|
{
|
||||||
// Get the current executable path
|
// Get the current executable path
|
||||||
TCHAR pszExePath[MAX_PATH];
|
WCHAR pszExePath[MAX_PATH];
|
||||||
GetModuleFileName(nullptr, pszExePath, sizeof(pszExePath));
|
GetModuleFileNameW(nullptr, pszExePath, ARRAYSIZE(pszExePath));
|
||||||
|
|
||||||
// Start client minimized
|
// Start client minimized
|
||||||
QString strArgs = "-min";
|
QString strArgs = "-min";
|
||||||
// Set -testnet /-regtest options
|
// Set -testnet /-regtest options
|
||||||
strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)));
|
strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)));
|
||||||
|
|
||||||
#ifdef UNICODE
|
|
||||||
boost::scoped_array<TCHAR> args(new TCHAR[strArgs.length() + 1]);
|
|
||||||
// Convert the QString to TCHAR*
|
|
||||||
strArgs.toWCharArray(args.get());
|
|
||||||
// Add missing '\0'-termination to string
|
|
||||||
args[strArgs.length()] = '\0';
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Set the path to the shortcut target
|
// Set the path to the shortcut target
|
||||||
psl->SetPath(pszExePath);
|
psl->SetPath(pszExePath);
|
||||||
PathRemoveFileSpec(pszExePath);
|
PathRemoveFileSpecW(pszExePath);
|
||||||
psl->SetWorkingDirectory(pszExePath);
|
psl->SetWorkingDirectory(pszExePath);
|
||||||
psl->SetShowCmd(SW_SHOWMINNOACTIVE);
|
psl->SetShowCmd(SW_SHOWMINNOACTIVE);
|
||||||
#ifndef UNICODE
|
psl->SetArguments(strArgs.toStdWString().c_str());
|
||||||
psl->SetArguments(strArgs.toStdString().c_str());
|
|
||||||
#else
|
|
||||||
psl->SetArguments(args.get());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Query IShellLink for the IPersistFile interface for
|
// Query IShellLink for the IPersistFile interface for
|
||||||
// saving the shortcut in persistent storage.
|
// saving the shortcut in persistent storage.
|
||||||
|
@ -589,11 +575,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
|
||||||
hres = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&ppf));
|
hres = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&ppf));
|
||||||
if (SUCCEEDED(hres))
|
if (SUCCEEDED(hres))
|
||||||
{
|
{
|
||||||
WCHAR pwsz[MAX_PATH];
|
|
||||||
// Ensure that the string is ANSI.
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().string().c_str(), -1, pwsz, MAX_PATH);
|
|
||||||
// Save the link by calling IPersistFile::Save.
|
// Save the link by calling IPersistFile::Save.
|
||||||
hres = ppf->Save(pwsz, TRUE);
|
hres = ppf->Save(StartupShortcutPath().wstring().c_str(), TRUE);
|
||||||
ppf->Release();
|
ppf->Release();
|
||||||
psl->Release();
|
psl->Release();
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
|
|
|
@ -1139,14 +1139,14 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
|
fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
|
||||||
{
|
{
|
||||||
char pszPath[MAX_PATH] = "";
|
WCHAR pszPath[MAX_PATH] = L"";
|
||||||
|
|
||||||
if(SHGetSpecialFolderPathA(nullptr, pszPath, nFolder, fCreate))
|
if(SHGetSpecialFolderPathW(nullptr, pszPath, nFolder, fCreate))
|
||||||
{
|
{
|
||||||
return fs::path(pszPath);
|
return fs::path(pszPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogPrintf("SHGetSpecialFolderPathA() failed, could not obtain requested path.\n");
|
LogPrintf("SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
|
||||||
return fs::path("");
|
return fs::path("");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -63,7 +63,6 @@ EXPECTED_BOOST_INCLUDES=(
|
||||||
boost/optional.hpp
|
boost/optional.hpp
|
||||||
boost/preprocessor/cat.hpp
|
boost/preprocessor/cat.hpp
|
||||||
boost/preprocessor/stringize.hpp
|
boost/preprocessor/stringize.hpp
|
||||||
boost/scoped_array.hpp
|
|
||||||
boost/signals2/connection.hpp
|
boost/signals2/connection.hpp
|
||||||
boost/signals2/last_value.hpp
|
boost/signals2/last_value.hpp
|
||||||
boost/signals2/signal.hpp
|
boost/signals2/signal.hpp
|
||||||
|
|
Loading…
Reference in a new issue