Migrate all remaining _SHCreateSymbolicLinks() Camel Case variables to snake case. Also rename variables that are currently named in a rather "obtuse" fashion. Remove array size variable, which has no readability or performance advantage over using the ARRAY_SIZE macro. Make all loops pre-increment.
Signed-off-by: Rob Walker bob.mt.wya@gmail.com --- dlls/shell32/shellpath.c | 75 ++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 38 deletions(-)
diff --git a/dlls/shell32/shellpath.c b/dlls/shell32/shellpath.c index ce8af7760c..d7ddfaf26d 100644 --- a/dlls/shell32/shellpath.c +++ b/dlls/shell32/shellpath.c @@ -4409,80 +4409,79 @@ static inline BOOL _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) { */ static void _SHCreateSymbolicLinks(void) { - UINT aidsMyStuff[] = { IDS_PERSONAL, IDS_MYMUSIC, IDS_MYPICTURES, IDS_MYVIDEOS, IDS_DESKTOPDIRECTORY }; - const WCHAR* MyOSXStuffW[] = { DocumentsW, MusicW, PicturesW, MoviesW, DesktopW }; - int acsidlMyStuff[] = { CSIDL_PERSONAL, CSIDL_MYMUSIC, CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_DESKTOPDIRECTORY }; - static const char * const xdg_dirs[] = { "DOCUMENTS", "MUSIC", "PICTURES", "VIDEOS", "DESKTOP" }; - static const unsigned int num = ARRAY_SIZE(xdg_dirs); + UINT ids_dirs[] = { IDS_PERSONAL, IDS_MYMUSIC, IDS_MYPICTURES, IDS_MYVIDEOS, IDS_DESKTOPDIRECTORY }; + const WCHAR* ws_osx_dirs[] = { DocumentsW, MusicW, PicturesW, MoviesW, DesktopW }; + int csidl_dirs[] = { CSIDL_PERSONAL, CSIDL_MYMUSIC, CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_DESKTOPDIRECTORY }; + static const char * const xdg_dirnames[] = { "DOCUMENTS", "MUSIC", "PICTURES", "VIDEOS", "DESKTOP" }; WCHAR wszTempPath[MAX_PATH]; - char szMyStuffTarget[FILENAME_MAX], *pszMyStuff; - struct stat statFolder; - const char *pszHome; + char home_target_dir[FILENAME_MAX], *prefix_profile_dir; + struct stat stat_folder; + const char *env_homedir; HRESULT hr; BOOL target_ok; - char ** xdg_results; + char ** xdg_dirs; int ret; UINT i;
- hr = XDG_UserDirLookup(xdg_dirs, num, &xdg_results); - if (FAILED(hr)) xdg_results = NULL; + hr = XDG_UserDirLookup(xdg_dirnames, ARRAY_SIZE(xdg_dirnames), &xdg_dirs); + if (FAILED(hr)) xdg_dirs = NULL;
- pszHome = getenv("HOME"); - if (!(pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode))) - pszHome = NULL; + env_homedir = getenv("HOME"); + if (!(env_homedir && !stat(env_homedir, &stat_folder) && S_ISDIR(stat_folder.st_mode))) + env_homedir = NULL;
- for (i = 0; i < num; ++i) + for (i = 0; i < ARRAY_SIZE(xdg_dirnames); ++i) { /* Create the '%USERPROFILE%\XXX' directory path. */ - hr = SHGetFolderPathW(NULL, acsidlMyStuff[i]|CSIDL_FLAG_CREATE, NULL, + hr = SHGetFolderPathW(NULL, csidl_dirs[i]|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_DEFAULT, wszTempPath); - if (FAILED(hr) || !pszHome) continue; + if (FAILED(hr) || !env_homedir) continue;
- pszMyStuff = wine_get_unix_file_name(wszTempPath); - if (!pszMyStuff) continue; + prefix_profile_dir = wine_get_unix_file_name(wszTempPath); + if (!prefix_profile_dir) continue;
target_ok = FALSE; /* Try to target a pre-existing '$HOME/My XXX' folder. */ - strcpy(szMyStuffTarget, pszHome); - if ((aidsMyStuff[i] != IDS_DESKTOPDIRECTORY) && - _SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) && - !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode)) + strcpy(home_target_dir, env_homedir); + if ((ids_dirs[i] != IDS_DESKTOPDIRECTORY) && + _SHAppendToUnixPath(home_target_dir, MAKEINTRESOURCEW(ids_dirs[i])) && + !stat(home_target_dir, &stat_folder) && S_ISDIR(stat_folder.st_mode)) { target_ok = TRUE; } /* Try to target the XDG_XXX_DIR folder. */ - else if (xdg_results && xdg_results[i]) + else if (xdg_dirs && xdg_dirs[i]) { - strcpy(szMyStuffTarget, xdg_results[i]); + strcpy(home_target_dir, xdg_dirs[i]); target_ok = TRUE; } /* Try to target the hardcoded / OS X 'XXX' folder. */ else { - strcpy(szMyStuffTarget, pszHome); - target_ok = _SHAppendToUnixPath(szMyStuffTarget, MyOSXStuffW[i]) - && !stat(szMyStuffTarget, &statFolder) - && S_ISDIR(statFolder.st_mode); + strcpy(home_target_dir, env_homedir); + target_ok = _SHAppendToUnixPath(home_target_dir, ws_osx_dirs[i]) + && !stat(home_target_dir, &stat_folder) + && S_ISDIR(stat_folder.st_mode); }
if (target_ok) { - ret = remove(pszMyStuff); + ret = remove(prefix_profile_dir); TRACE("remove directory (%s): %s\n", - (ret ? "soft failed" : "OK"), debugstr_a(pszMyStuff)); - ret = symlink(szMyStuffTarget, pszMyStuff); + (ret ? "soft failed" : "OK"), debugstr_a(prefix_profile_dir)); + ret = symlink(home_target_dir, prefix_profile_dir); TRACE("symlink directory (%s): %s -> %s\n", (ret ? "soft failed" : "OK"), - debugstr_a(pszMyStuff), debugstr_a(szMyStuffTarget)); + debugstr_a(prefix_profile_dir), debugstr_a(home_target_dir)); } - heap_free(pszMyStuff); + heap_free(prefix_profile_dir); }
- if (xdg_results) + if (xdg_dirs) { - for (i = 0; i < num; i++) - heap_free(xdg_results[i]); - heap_free(xdg_results); + for (i = 0; i < ARRAY_SIZE(xdg_dirnames); ++i) + heap_free(xdg_dirs[i]); + heap_free(xdg_dirs); } }