| 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 | ||
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.
(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). 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. 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. (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. This is now fixed in https://hg.libsdl.org/SDL/rev/39b104a55d19 Thanks! --ryan. |
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.