Skip to content

Commit 934e7b9

Browse files
GirianSeedtimangus
authored andcommitted
Call SHGetFolderPathA directly
Removing shfolder.h satisfies MSVC, and calling the function directly makes PFNSHGETFOLDERPATHA unnecessary.
1 parent 4303784 commit 934e7b9

2 files changed

Lines changed: 3 additions & 40 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ ifdef MINGW
668668
$(call bin_path, $(TOOLS_MINGW_PREFIX)-gcc))))
669669
endif
670670

671-
LIBS= -lws2_32 -lwinmm -lpsapi
671+
LIBS= -lws2_32 -lwinmm -lpsapi -lshell32
672672
AUTOUPDATER_LIBS += -lwininet
673673

674674
# clang 3.4 doesn't support this

code/sys/sys_win32.c

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3838
#include <io.h>
3939
#include <conio.h>
4040
#include <wincrypt.h>
41-
#include <shfolder.h>
4241
#include <shlobj.h>
4342
#include <psapi.h>
4443
#include <float.h>
@@ -104,30 +103,14 @@ Sys_DefaultHomePath
104103
char *Sys_DefaultHomePath( void )
105104
{
106105
TCHAR szPath[MAX_PATH];
107-
PFNSHGETFOLDERPATHA qSHGetFolderPath;
108-
HMODULE shfolder = LoadLibrary("shfolder.dll");
109-
110-
if(shfolder == NULL)
111-
{
112-
Com_Printf("Unable to load SHFolder.dll\n");
113-
return NULL;
114-
}
115106

116107
if(!*homePath && com_homepath)
117108
{
118-
qSHGetFolderPath = (PFNSHGETFOLDERPATHA)GetProcAddress(shfolder, "SHGetFolderPathA");
119-
if(qSHGetFolderPath == NULL)
120-
{
121-
Com_Printf("Unable to find SHGetFolderPath in SHFolder.dll\n");
122-
FreeLibrary(shfolder);
123-
return NULL;
124-
}
125109

126-
if( !SUCCEEDED( qSHGetFolderPath( NULL, CSIDL_APPDATA,
110+
if( !SUCCEEDED( SHGetFolderPathA( NULL, CSIDL_APPDATA,
127111
NULL, 0, szPath ) ) )
128112
{
129113
Com_Printf("Unable to detect CSIDL_APPDATA\n");
130-
FreeLibrary(shfolder);
131114
return NULL;
132115
}
133116

@@ -139,7 +122,6 @@ char *Sys_DefaultHomePath( void )
139122
Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME_WIN);
140123
}
141124

142-
FreeLibrary(shfolder);
143125
return homePath;
144126
}
145127

@@ -240,33 +222,14 @@ char* Sys_MicrosoftStorePath(void)
240222
if (!microsoftStorePath[0])
241223
{
242224
TCHAR szPath[MAX_PATH];
243-
PFNSHGETFOLDERPATHA qSHGetFolderPath;
244-
HMODULE shfolder = LoadLibrary("shfolder.dll");
245-
246-
if(shfolder == NULL)
247-
{
248-
Com_Printf("Unable to load SHFolder.dll\n");
249-
return microsoftStorePath;
250-
}
251-
252-
qSHGetFolderPath = (PFNSHGETFOLDERPATHA)GetProcAddress(shfolder, "SHGetFolderPathA");
253-
if(qSHGetFolderPath == NULL)
254-
{
255-
Com_Printf("Unable to find SHGetFolderPath in SHFolder.dll\n");
256-
FreeLibrary(shfolder);
257-
return microsoftStorePath;
258-
}
259225

260-
if( !SUCCEEDED( qSHGetFolderPath( NULL, CSIDL_PROGRAM_FILES,
226+
if( !SUCCEEDED( SHGetFolderPathA( NULL, CSIDL_PROGRAM_FILES,
261227
NULL, 0, szPath ) ) )
262228
{
263229
Com_Printf("Unable to detect CSIDL_PROGRAM_FILES\n");
264-
FreeLibrary(shfolder);
265230
return microsoftStorePath;
266231
}
267232

268-
FreeLibrary(shfolder);
269-
270233
// default: C:\Program Files\ModifiableWindowsApps\Quake 3\EN
271234
Com_sprintf(microsoftStorePath, sizeof(microsoftStorePath), "%s%cModifiableWindowsApps%c%s%cEN", szPath, PATH_SEP, PATH_SEP, MSSTORE_PATH, PATH_SEP);
272235
}

0 commit comments

Comments
 (0)