Dmitry Timoshkov : shell32: IPersistFile::Save(NULL) should use previously stored file name.

Alexandre Julliard julliard at winehq.org
Wed Feb 3 15:39:29 CST 2021


Module: wine
Branch: master
Commit: dbb1ed4895079f67ae385afe878e924d3249037b
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=dbb1ed4895079f67ae385afe878e924d3249037b

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Wed Feb  3 12:40:43 2021 +0000

shell32: IPersistFile::Save(NULL) should use previously stored file name.

Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/shell32/shelllink.c       | 16 ++++++++++++----
 dlls/shell32/tests/shelllink.c | 25 ++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/dlls/shell32/shelllink.c b/dlls/shell32/shelllink.c
index 46d9bc994ff..69d610f2503 100644
--- a/dlls/shell32/shelllink.c
+++ b/dlls/shell32/shelllink.c
@@ -367,7 +367,12 @@ static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFile
     TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
 
     if (!pszFileName)
-        return E_FAIL;
+    {
+        if (!This->filepath) return S_OK;
+
+        pszFileName = This->filepath;
+        fRemember = FALSE;
+    }
 
     r = SHCreateStreamOnFileW( pszFileName, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, &stm );
     if( SUCCEEDED( r ) )
@@ -379,9 +384,12 @@ static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFile
 	{
             StartLinkProcessor( pszFileName );
 
-            /* update file path */
-            heap_free(This->filepath);
-            This->filepath = strdupW(pszFileName);
+            if (fRemember)
+            {
+                /* update file path */
+                heap_free(This->filepath);
+                This->filepath = strdupW(pszFileName);
+            }
 
             This->bDirty = FALSE;
         }
diff --git a/dlls/shell32/tests/shelllink.c b/dlls/shell32/tests/shelllink.c
index 20c48814f1d..edd536c3a01 100644
--- a/dlls/shell32/tests/shelllink.c
+++ b/dlls/shell32/tests/shelllink.c
@@ -388,7 +388,7 @@ static void test_get_set(void)
 
 void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc)
 {
-    HRESULT r;
+    HRESULT r, init_dirty;
     IShellLinkA *sl;
     IPersistFile *pf;
 
@@ -451,6 +451,17 @@ void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc)
         IPersistFile_GetCurFile(pf, NULL);
     }
 
+        init_dirty = IPersistFile_IsDirty(pf); /* empty links start off as clean */
+        r = IPersistFile_Save(pf, NULL, FALSE);
+        lok(r == S_OK || r == E_INVALIDARG /* before Windows 7 */, "save failed (0x%08x)\n", r);
+        r = IPersistFile_IsDirty(pf);
+        lok(r == init_dirty, "dirty (0x%08x)\n", r);
+
+        r = IPersistFile_Save(pf, NULL, TRUE);
+        lok(r == S_OK || r == E_INVALIDARG /* before Windows 7 */, "save failed (0x%08x)\n", r);
+        r = IPersistFile_IsDirty(pf);
+        lok(r == init_dirty, "dirty (0x%08x)\n", r);
+
         /* test GetCurFile before ::Save */
         str = (LPWSTR)0xdeadbeef;
         r = IPersistFile_GetCurFile(pf, &str);
@@ -459,6 +470,18 @@ void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc)
 
         r = IPersistFile_Save(pf, path, TRUE);
         lok(r == S_OK, "save failed (0x%08x)\n", r);
+        r = IPersistFile_IsDirty(pf);
+        lok(r == S_FALSE, "dirty (0x%08x)\n", r);
+
+        /* test GetCurFile after ::Save */
+        r = IPersistFile_GetCurFile(pf, &str);
+        lok(r == S_OK, "got 0x%08x\n", r);
+        lok(str != NULL, "Didn't expect NULL\n");
+        lok(!wcscmp(path, str), "Expected %s, got %s\n", wine_dbgstr_w(path), wine_dbgstr_w(str));
+        CoTaskMemFree(str);
+
+        r = IPersistFile_Save(pf, NULL, TRUE);
+        lok(r == S_OK, "save failed (0x%08x)\n", r);
 
         /* test GetCurFile after ::Save */
         r = IPersistFile_GetCurFile(pf, &str);




More information about the wine-cvs mailing list