Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_GetPrefPath does not fully create a path #1249

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

SDL_GetPrefPath does not fully create a path #1249

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

SDLBugzilla commented Feb 10, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.1
Reported for operating system, platform: Windows (All), All

Comments on the original bug report:

On 2013-11-26 09:08:33 +0000, Boris Bendovsky wrote:

Created attachment 1476
A patch for the SDL_GetPrefPath

SDL_GetPrefPath creates a path without a name of the organization and a name of the application.

On 2014-02-06 15:10:47 +0000, Mike Parker wrote:

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.

On 2014-02-10 12:33:18 +0000, Boris Bendovsky wrote:

(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).

On 2014-02-24 16:57:27 +0000, Ryan C. Gordon wrote:

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.

On 2014-02-25 04:11:01 +0000, Mike Parker wrote:

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.

On 2014-02-28 03:43:09 +0000, Ryan C. Gordon wrote:

(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.

On 2014-03-02 01:29:23 +0000, Ryan C. Gordon wrote:

This is now fixed in https://hg.libsdl.org/SDL/rev/39b104a55d19

Thanks!

--ryan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant