Aric Stewart : shell32: Update shellpaths My Pictures, My Video, My Music to be under

Alexandre Julliard julliard at wine.codeweavers.com
Thu Jan 19 05:46:40 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 265c8a5d7329a1512db900a799bd66013365b295
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=265c8a5d7329a1512db900a799bd66013365b295

Author: Aric Stewart <aric at codeweavers.com>
Date:   Thu Jan 19 12:43:14 2006 +0100

shell32: Update shellpaths My Pictures, My Video, My Music to be under
$HOME, with a number of fallbacks.

---

 dlls/shell32/shellpath.c |   90 +++++++++++++++++++++++++++++++++++-----------
 1 files changed, 68 insertions(+), 22 deletions(-)

diff --git a/dlls/shell32/shellpath.c b/dlls/shell32/shellpath.c
index 215e5ed..29c004f 100644
--- a/dlls/shell32/shellpath.c
+++ b/dlls/shell32/shellpath.c
@@ -1229,6 +1229,66 @@ static HRESULT _SHGetUserShellFolderPath
     return hr;
 }
 
+/* Helper function for _SHGetDefaultValue 
+ *
+ *   handing the directories under $HOME:
+ *   1) try path under $HOME (such as $HOME/My Documents/My Pictures), if it
+ *   exists return it.
+ *   2) if not, but $HOME/My Documents exists return path 1 and have it created
+ *   3) try $HOME if it exists return it
+ *   4) normal fallback to C:/windows/Profiles/...
+ */
+static HRESULT expand_home_path(LPWSTR pszPath, LPCWSTR def_path, UINT resource,
+                                BOOL create_lastdir)
+{
+    HRESULT hr = E_FAIL;
+    const char *home = getenv("HOME");
+
+    if (home)
+    {
+        LPWSTR homeW = wine_get_dos_file_name(home);
+
+        if (homeW)
+        {
+            WCHAR resourcePath[MAX_PATH];
+            lstrcpynW(pszPath, homeW, MAX_PATH);
+
+            if (LoadStringW(shell32_hInstance, resource, resourcePath, MAX_PATH))
+                PathAppendW(pszPath, resourcePath);
+            else
+                PathAppendW(pszPath, def_path);
+
+            if (PathIsDirectoryW(pszPath)) hr = S_OK;
+            else if (create_lastdir)
+            {
+                /* attempt 2, try for My Documents */
+
+                WCHAR* ptr = strrchrW(pszPath, '\\');
+                if (ptr)
+                {
+                    *ptr = 0;
+                    if (PathIsDirectoryW(pszPath))
+                    {
+                        *ptr = '\\';
+                        hr = S_OK;
+                    }
+                }
+            }
+
+            if (hr != S_OK)
+            {
+                /* attempt 3 return HOME */
+                lstrcpyW(pszPath,homeW);
+                hr = S_OK;
+            }
+            HeapFree(GetProcessHeap(), 0, homeW);
+        }
+        else
+            hr = HRESULT_FROM_WIN32(GetLastError());
+    }
+    return hr;
+}
+
 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
  * pszPath, based on the entries in CSIDL_Data.  By semi-expanded, I mean:
  * - The entry's szDefaultPath may be either a string value or an integer
@@ -1260,32 +1320,18 @@ static HRESULT _SHGetDefaultValue(BYTE f
     hr = E_FAIL;
     switch (folder)
     {
+        case CSIDL_MYPICTURES:
+            hr = expand_home_path(pszPath,My_PicturesW,IDS_MYPICTURES,TRUE);
+            break;
         case CSIDL_PERSONAL:
+            hr = expand_home_path(pszPath,PersonalW,IDS_PERSONAL,FALSE);
+            break;
         case CSIDL_MYMUSIC:
-        case CSIDL_MYPICTURES:
+            hr = expand_home_path(pszPath,My_MusicW,IDS_MYMUSIC,TRUE);
+            break;
         case CSIDL_MYVIDEO:
-        {
-            const char *home = getenv("HOME");
-
-            /* special case for "My Documents", map to $HOME */
-            if (home)
-            {
-                LPWSTR homeW = wine_get_dos_file_name(home);
-
-                if (homeW)
-                {
-                    if (PathIsDirectoryW(homeW))
-                    {
-                        lstrcpynW(pszPath, homeW, MAX_PATH);
-                        hr = S_OK;
-                    }
-                    HeapFree(GetProcessHeap(), 0, homeW);
-                }
-                else
-                    hr = HRESULT_FROM_WIN32(GetLastError());
-            }
+            hr = expand_home_path(pszPath,My_VideoW,IDS_MYVIDEO,TRUE);
             break;
-        }
         case CSIDL_DESKTOP:
         case CSIDL_DESKTOPDIRECTORY:
         {




More information about the wine-cvs mailing list