We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2273

Summary: SDL_GetPrefPath does not fully create a path
Product: SDL Reporter: Boris Bendovsky <bibendovsky>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: critical    
Priority: P2 CC: aldacron
Version: 2.0.1   
Hardware: All   
OS: Windows (All)   
Attachments: A patch for the SDL_GetPrefPath

Description Boris Bendovsky 2013-11-26 09:08:33 UTC
Created attachment 1476 [details]
A patch for the SDL_GetPrefPath

SDL_GetPrefPath creates a path without a name of the organization and a name of the application.
Comment 1 Mike Parker 2014-02-06 15:10:47 UTC
You can take out those two CreateDirectory calls and cut it down to this:

// Build the full path appdata/orgname/appname string as you already do, then:
if( 0xFFFFFFFF == GetFileAttributesW( path )) {
    if( SHCreateDirectoryExW( NULL, path, NULL ) != ERROR_SUCCESS ) {
        Win_SetError( "Couldn't create the pref path." );
    }
}

The call to GetFileAttributes is a test to see if the folder exists. If it doesn't, SHCreateDirectoryEx will create every folder on the path. So you don't have to make separate calls for org name and app name.
Comment 2 Boris Bendovsky 2014-02-10 12:33:18 UTC
(In reply to Mike Parker from comment #1)
> You can take out those two CreateDirectory calls and cut it down to this:
> 
> // Build the full path appdata/orgname/appname string as you already do,
> then:
> if( 0xFFFFFFFF == GetFileAttributesW( path )) {
>     if( SHCreateDirectoryExW( NULL, path, NULL ) != ERROR_SUCCESS ) {
>         Win_SetError( "Couldn't create the pref path." );
>     }
> }
> 
> The call to GetFileAttributes is a test to see if the folder exists. If it
> doesn't, SHCreateDirectoryEx will create every folder on the path. So you
> don't have to make separate calls for org name and app name.

Since I didn't find exact minimum Windows requirements (Windows XP, Windows XP SP1, etc.) I used "CreateDirectoryW" for compatibility. "SHCreateDirectoryExW" requires Windows XP with Service Pack 2 to work. Also "It might be altered or unavailable in subsequent versions of Windows" (http://msdn.microsoft.com/en-us/library/windows/desktop/bb762131%28v=vs.85%29.aspx).
Comment 3 Ryan C. Gordon 2014-02-24 16:57:27 UTC
So the CSIDL_FLAG_CREATE doesn't work (or doesn't do what I thought it did)? That flag is supposed to tell SHGetFolderPath() to create the directory if it's missing.

--ryan.
Comment 4 Mike Parker 2014-02-25 04:11:01 UTC
It will create the path associated with CSIDL_APPDATA (User\AppData\Roaming or whatever) if it doesn't exist, but after that you still have to explicitly create the orgname\appname folders.
Comment 5 Ryan C. Gordon 2014-02-28 03:43:09 UTC
(In reply to Mike Parker from comment #4)
> It will create the path associated with CSIDL_APPDATA (User\AppData\Roaming
> or whatever) if it doesn't exist, but after that you still have to
> explicitly create the orgname\appname folders.

Oh, duh, you're right.

--ryan.
Comment 6 Ryan C. Gordon 2014-03-02 01:29:23 UTC
This is now fixed in https://hg.libsdl.org/SDL/rev/39b104a55d19

Thanks!

--ryan.