Skip to content

Commit 1c841d3

Browse files
authored
Merge pull request #112 from Nerixyz/fix/shortcut-dir
fix: set correct directory for shortcut
2 parents b39e783 + 4ebfeba commit 1c841d3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/wintoastlib.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@ namespace Util {
248248
return hr;
249249
}
250250

251+
inline std::wstring parentDirectory(WCHAR* path, DWORD size) {
252+
size_t lastSeparator = 0;
253+
for (size_t i = 0; i < size; i++) {
254+
if (path[i] == L'\\' || path[i] == L'/') {
255+
lastSeparator = i;
256+
}
257+
}
258+
return {path, lastSeparator};
259+
}
260+
251261
inline PCWSTR AsString(_In_ ComPtr<IXmlDocument>& xmlDocument) {
252262
HSTRING xml;
253263
ComPtr<IXmlNodeSerializer> ser;
@@ -669,14 +679,15 @@ HRESULT WinToast::createShellLinkHelper() {
669679
WCHAR slPath[MAX_PATH]{L'\0'};
670680
Util::defaultShellLinkPath(_appName, slPath);
671681
Util::defaultExecutablePath(exePath);
682+
std::wstring exeDir = Util::parentDirectory(exePath, sizeof(exePath) / sizeof(exePath[0]));
672683
ComPtr<IShellLinkW> shellLink;
673684
HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
674685
if (SUCCEEDED(hr)) {
675686
hr = shellLink->SetPath(exePath);
676687
if (SUCCEEDED(hr)) {
677688
hr = shellLink->SetArguments(L"");
678689
if (SUCCEEDED(hr)) {
679-
hr = shellLink->SetWorkingDirectory(exePath);
690+
hr = shellLink->SetWorkingDirectory(exeDir.c_str());
680691
if (SUCCEEDED(hr)) {
681692
ComPtr<IPropertyStore> propertyStore;
682693
hr = shellLink.As(&propertyStore);

0 commit comments

Comments
 (0)