From 5648dd2ace0fcc176d61a68f12b6d917309cd7fb Mon Sep 17 00:00:00 2001 From: joostverburg Date: Tue, 10 Jul 2007 21:33:06 +0000 Subject: [PATCH] When available, use shfolder.dll to get special folder locations. This allows folders like the application data folder for all users to be used on Windows 95/98 when Internet Explorer 5 is installed. git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5195 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/exehead/util.c | 21 ++++++++++++++++----- Source/exehead/util.h | 3 ++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Source/exehead/util.c b/Source/exehead/util.c index dc5c15ef..68209210 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -16,6 +16,7 @@ #include "../Platform.h" #include +#include #include "util.h" #include "state.h" #include "config.h" @@ -626,6 +627,11 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab) int x = 2; + // Use SHGetFolderPath when shfolder.dll is available + PFNSHGETFOLDERPATHA pSHGetFolderPath = 0; + HMODULE hDLL = LoadLibrary("shfolder"); + if (hDLL) pSHGetFolderPath = (PFNSHGETFOLDERPATHA) myGetProcAddress(MGA_SHGetFolderPathA); + if (g_exec_flags.all_user_var) { x = 4; @@ -651,15 +657,17 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab) while (x--) { + if (pSHGetFolderPath) { + if (!pSHGetFolderPath(g_hwnd, fldrs[x], NULL, SHGFP_TYPE_CURRENT, out)) break; + } + if (!SHGetSpecialFolderLocation(g_hwnd, fldrs[x], &idl)) { BOOL res = SHGetPathFromIDList(idl, out); CoTaskMemFree(idl); - if (res) - { - break; - } + if (res) break; } + *out=0; } @@ -673,6 +681,8 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab) } } + if (hDLL) FreeLibrary(hDLL); + validate_filename(out); } else if (nVarIdx == NS_VAR_CODE) @@ -896,7 +906,8 @@ struct MGA_FUNC MGA_FUNCS[] = { {"ADVAPI32", "LookupPrivilegeValueA"}, {"ADVAPI32", "AdjustTokenPrivileges"}, {"KERNEL32", "GetUserDefaultUILanguage"}, - {"SHLWAPI", "SHAutoComplete"} + {"SHLWAPI", "SHAutoComplete"}, + {"SHFOLDER", "SHGetFolderPathA"} }; void * NSISCALL myGetProcAddress(const enum myGetProcAddressFunctions func) diff --git a/Source/exehead/util.h b/Source/exehead/util.h index 366ad6c1..35a1846f 100644 --- a/Source/exehead/util.h +++ b/Source/exehead/util.h @@ -102,7 +102,8 @@ enum myGetProcAddressFunctions { MGA_LookupPrivilegeValueA, MGA_AdjustTokenPrivileges, MGA_GetUserDefaultUILanguage, - MGA_SHAutoComplete + MGA_SHAutoComplete, + MGA_SHGetFolderPathA }; void * NSISCALL myGetProcAddress(const enum myGetProcAddressFunctions func);