Cleanup code to avoid the use of an infinite while loop, as a pseudo code subblock demarker (which is not very readable).
Signed-off-by: Rob Walker bob.mt.wya@gmail.com --- dlls/shell32/shellpath.c | 91 +++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 42 deletions(-)
diff --git a/dlls/shell32/shellpath.c b/dlls/shell32/shellpath.c index ee5274b5fc..b223bf5212 100644 --- a/dlls/shell32/shellpath.c +++ b/dlls/shell32/shellpath.c @@ -4421,6 +4421,7 @@ static void _SHCreateSymbolicLinks(void) struct stat statFolder; const char *pszHome; HRESULT hr; + BOOL target_ok; char ** xdg_results; char * xdg_desktop_dir;
@@ -4440,31 +4441,34 @@ static void _SHCreateSymbolicLinks(void)
if (pszHome) { - while (1) + target_ok = FALSE; + + /* Try to target a pre-existing '$HOME/My Documents' folder. */ + strcpy(szPersonalTarget, pszHome); + if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) && + !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode)) + { + target_ok = TRUE; + } + /* Try to target the XDG_DOCUMENTS_DIR folder. */ + else if (xdg_results && xdg_results[num-2]) + { + strcpy(szPersonalTarget, xdg_results[num-2]); + target_ok = TRUE; + } + /* Try to target the hardcoded / OS X 'Documents' folder. */ + else { - /* Try to target a pre-existing '$HOME/My Documents' folder. */ strcpy(szPersonalTarget, pszHome); - if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) && - !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode)) - break; - - /* Try to target the XDG_DOCUMENTS_DIR folder. */ - if (xdg_results && xdg_results[num-2]) - { - strcpy(szPersonalTarget, xdg_results[num-2]); - break; - } + target_ok = _SHAppendToUnixPath(szPersonalTarget, DocumentsW) + && !stat(szPersonalTarget, &statFolder) + && S_ISDIR(statFolder.st_mode); + }
- /* Try to target the hardcoded / OS X 'Documents' folder. */ + /* Target the '$HOME' folder directly (fallback). */ + if (!target_ok) strcpy(szPersonalTarget, pszHome); - if (_SHAppendToUnixPath(szPersonalTarget, DocumentsW) && - !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode)) - break;
- /* Target the '$HOME' folder directly (fallback). */ - strcpy(szPersonalTarget, pszHome); - break; - } remove(pszPersonal); symlink(szPersonalTarget, pszPersonal); } @@ -4478,33 +4482,36 @@ static void _SHCreateSymbolicLinks(void) if (FAILED(hr) || !pszHome) continue;
pszMyStuff = wine_get_unix_file_name(wszTempPath); - if (!pszMyStuff) continue; - - while (1) - { - /* Try to target a pre-existing '$HOME/My Documents/My XXX' folder. */ - strcpy(szMyStuffTarget, pszHome); - if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) && - !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode)) - break; + if (!pszMyStuff) continue;
- /* Try to target the XDG_XXX_DIR folder. */ - if (xdg_results && xdg_results[i]) - { - strcpy(szMyStuffTarget, xdg_results[i]); - break; - } + target_ok = FALSE;
- /* Try to target the hardcoded / OS X 'XXX' folder. */ + /* Try to target a pre-existing '$HOME/My Documents/My XXX' folder. */ + strcpy(szMyStuffTarget, pszHome); + if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) && + !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode)) + { + target_ok = TRUE; + } + /* Try to target the XDG_XXX_DIR folder. */ + else if (xdg_results && xdg_results[i]) + { + strcpy(szMyStuffTarget, xdg_results[i]); + target_ok = TRUE; + } + /* Try to target the hardcoded / OS X 'XXX' folder. */ + else + { strcpy(szMyStuffTarget, pszHome); - if (_SHAppendToUnixPath(szMyStuffTarget, MyOSXStuffW[i]) && - !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode)) - break; + target_ok = _SHAppendToUnixPath(szMyStuffTarget, MyOSXStuffW[i]) + && !stat(szMyStuffTarget, &statFolder) + && S_ISDIR(statFolder.st_mode); + }
- /* Use the same target as '%USERPROFILE%\My Documents' (fallback). */ + /* Use the same target as '%USERPROFILE%\My Documents' (fallback). */ + if (!target_ok) strcpy(szMyStuffTarget, szPersonalTarget); - break; - } + remove(pszMyStuff); symlink(szMyStuffTarget, pszMyStuff); heap_free(pszMyStuff);