Skip to content

Commit

Permalink
fix: set correct directory for shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Feb 17, 2025
1 parent 79756c6 commit 4ebfeba
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/wintoastlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ namespace Util {
return hr;
}

inline std::wstring parentDirectory(WCHAR* path, DWORD size) {
size_t lastSeparator = 0;
for (size_t i = 0; i < size; i++) {
if (path[i] == L'\\' || path[i] == L'/') {
lastSeparator = i;
}
}
return {path, lastSeparator};
}

inline PCWSTR AsString(_In_ ComPtr<IXmlDocument>& xmlDocument) {
HSTRING xml;
ComPtr<IXmlNodeSerializer> ser;
Expand Down Expand Up @@ -669,14 +679,15 @@ HRESULT WinToast::createShellLinkHelper() {
WCHAR slPath[MAX_PATH]{L'\0'};
Util::defaultShellLinkPath(_appName, slPath);
Util::defaultExecutablePath(exePath);
std::wstring exeDir = Util::parentDirectory(exePath, sizeof(exePath) / sizeof(exePath[0]));
ComPtr<IShellLinkW> shellLink;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
if (SUCCEEDED(hr)) {
hr = shellLink->SetPath(exePath);
if (SUCCEEDED(hr)) {
hr = shellLink->SetArguments(L"");
if (SUCCEEDED(hr)) {
hr = shellLink->SetWorkingDirectory(exePath);
hr = shellLink->SetWorkingDirectory(exeDir.c_str());
if (SUCCEEDED(hr)) {
ComPtr<IPropertyStore> propertyStore;
hr = shellLink.As(&propertyStore);
Expand Down

0 comments on commit 4ebfeba

Please sign in to comment.