[PATCH v4] shell32: IPersistFile::Save(NULL) should use previously stored file name.

Huw Davies huw at codeweavers.com
Wed Feb 3 06:40:43 CST 2021


From: Dmitry Timoshkov <dmitry at baikal.ru>

Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 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);
-- 
2.23.0




More information about the wine-devel mailing list