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 - SDL_GetPrefPath does not fully create a path
Summary: SDL_GetPrefPath does not fully create a path
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.1
Hardware: All Windows (All)
: P2 critical
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-26 09:08 UTC by Boris Bendovsky
Modified: 2014-03-02 01:29 UTC (History)
1 user (show)

See Also:


Attachments
A patch for the SDL_GetPrefPath (2.35 KB, patch)
2013-11-26 09:08 UTC, Boris Bendovsky
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.