From af80ed22fdcf0f12eeb65590eb1d33d7f7d6c568 Mon Sep 17 00:00:00 2001 From: Joel Low Date: Sun, 24 Aug 2014 19:10:42 +0800 Subject: [PATCH] Currently only deal with the Program Files folder. Other Known Folders do not seem to be substituted. --- launcher/src/CmderLauncher.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index 78ced72..65e9702 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -97,7 +97,9 @@ std::wstring GetAppId(std::wstring exePath) // Try every single \ in the path to match it against a KNOWNFOLDERID std::wstring::size_type nextBackslash = exePath.find_first_of('\\'); - while (nextBackslash != std::wstring::npos) + for ( ; + nextBackslash != std::wstring::npos; + nextBackslash = exePath.find_first_of('\\', nextBackslash + 1)) { // Try to match the current string against a KNOWNFOLDERID std::wstring subPath = exePath.substr(0, nextBackslash + 1); @@ -112,7 +114,8 @@ std::wstring GetAppId(std::wstring exePath) // We need to specially treat Program Files. We are a 32-bit app, so // if we get Program Files on a 64-bit computer, say we are the 32-bit - // Program Files folder. + // Program Files folder. We currently know that Explorer replaces the + // path for programs in Program Files, but not for other Known Folders. if (IsEqualGUID(id, FOLDERID_ProgramFiles)) { BOOL is64Bit = false; @@ -121,6 +124,11 @@ std::wstring GetAppId(std::wstring exePath) id = FOLDERID_ProgramFilesX86; } } + else if (!IsEqualCLSID(id, FOLDERID_ProgramFilesX86) && + !IsEqualCLSID(id, FOLDERID_ProgramFilesX64)) + { + continue; + } if (StringFromGUID2(id, string, sizeof(string) / sizeof(string[0]))) { @@ -129,9 +137,6 @@ std::wstring GetAppId(std::wstring exePath) return exePath; } } - - // Get the next backslash - nextBackslash = exePath.find_first_of('\\', nextBackslash + 1); } return exePath;