Alexander Scott-Johns : wininet: Partially implement FreeUrlCacheSpaceW.

Alexandre Julliard julliard at winehq.org
Fri Mar 11 10:23:39 CST 2011


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

Author: Alexander Scott-Johns <alexander.scott.johns at googlemail.com>
Date:   Wed Mar  2 18:35:27 2011 +0000

wininet: Partially implement FreeUrlCacheSpaceW.

---

 dlls/wininet/urlcache.c |   99 ++++++++++++++++++++++++++++++++++++++++++-----
 include/wininet.h       |   10 +++++
 2 files changed, 99 insertions(+), 10 deletions(-)

diff --git a/dlls/wininet/urlcache.c b/dlls/wininet/urlcache.c
index babf9f7..0c88372 100644
--- a/dlls/wininet/urlcache.c
+++ b/dlls/wininet/urlcache.c
@@ -48,10 +48,12 @@
 #include "wininet.h"
 #include "winineti.h"
 #include "winerror.h"
-#include "internet.h"
 #include "winreg.h"
 #include "shlwapi.h"
 #include "shlobj.h"
+#include "shellapi.h"
+
+#include "internet.h"
 
 #include "wine/unicode.h"
 #include "wine/debug.h"
@@ -1460,28 +1462,105 @@ static BOOL URLCache_EnumHashTableEntries(LPCURLCACHE_HEADER pHeader, const HASH
 }
 
 /***********************************************************************
- *           FreeUrlCacheSpaceA (WININET.@)
+ *           URLCache_DeleteCacheDirectory (Internal)
+ *
+ *  Erase a directory containing an URL cache.
+ *
+ * RETURNS
+ *    TRUE success, FALSE failure/aborted.
  *
  */
-BOOL WINAPI FreeUrlCacheSpaceA(LPCSTR lpszCachePath, DWORD dwSize, DWORD dwFilter)
+static BOOL URLCache_DeleteCacheDirectory(LPCWSTR lpszPath)
 {
-    FIXME("stub!\n");
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
+    DWORD path_len;
+    WCHAR path[MAX_PATH + 1];
+    SHFILEOPSTRUCTW shfos;
+    int ret;
+
+    path_len = strlenW(lpszPath);
+    if (path_len >= MAX_PATH)
+        return FALSE;
+    strcpyW(path, lpszPath);
+    path[path_len + 1] = 0;  /* double-NUL-terminate path */
+
+    shfos.hwnd = NULL;
+    shfos.wFunc = FO_DELETE;
+    shfos.pFrom = path;
+    shfos.pTo = NULL;
+    shfos.fFlags = 0;
+    shfos.fAnyOperationsAborted = FALSE;
+    ret = SHFileOperationW(&shfos);
+    if (ret)
+        ERR("SHFileOperationW on %s returned %i\n", debugstr_w(path), ret);
+    return !(ret || shfos.fAnyOperationsAborted);
 }
 
- /***********************************************************************
+/***********************************************************************
  *           FreeUrlCacheSpaceW (WININET.@)
  *
+ * Frees up some cache.
+ *
+ * PARAMETERS
+ *   lpszCachePath [I] Which volume to free up from, or NULL if you don't care.
+ *   dwSize        [I] How much space to free up.
+ *   dwSizeType    [I] How to interpret dwSize.
+ *
+ * RETURNS
+ *   TRUE success. FALSE failure.
+ *
+ * IMPLEMENTATION
+ *   This implementation just retrieves the path of the cache directory, and
+ *   deletes its contents from the filesystem. The correct approach would
+ *   probably be to implement and use {FindFirst,FindNext,Delete}UrlCacheGroup().
  */
-BOOL WINAPI FreeUrlCacheSpaceW(LPCWSTR lpszCachePath, DWORD dwSize, DWORD dwFilter)
+BOOL WINAPI FreeUrlCacheSpaceW(LPCWSTR lpszCachePath, DWORD dwSize, DWORD dwSizeType)
 {
-    FIXME("stub!\n");
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    URLCACHECONTAINER * pContainer;
+
+    if (lpszCachePath != NULL || dwSize != 100 || dwSizeType != FCS_PERCENT_CACHE_SPACE)
+    {
+        FIXME("(%s, %x, %x): partial stub!\n", debugstr_w(lpszCachePath), dwSize, dwSizeType);
+        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+        return FALSE;
+    }
+
+    LIST_FOR_EACH_ENTRY(pContainer, &UrlContainers, URLCACHECONTAINER, entry)
+    {
+        /* The URL cache has prefix L"" (unlike Cookies and History) */
+        if (pContainer->cache_prefix[0] == 0)
+        {
+            BOOL ret_del;
+            DWORD ret_open;
+            WaitForSingleObject(pContainer->hMutex, INFINITE);
+
+            /* unlock, delete, recreate and lock cache */
+            URLCacheContainer_CloseIndex(pContainer);
+            ret_del = URLCache_DeleteCacheDirectory(pContainer->path);
+            ret_open = URLCacheContainer_OpenIndex(pContainer);
+
+            ReleaseMutex(pContainer->hMutex);
+            return ret_del && (ret_open == ERROR_SUCCESS);
+        }
+    }
     return FALSE;
 }
 
 /***********************************************************************
+ *           FreeUrlCacheSpaceA (WININET.@)
+ *
+ * See FreeUrlCacheSpaceW.
+ */
+BOOL WINAPI FreeUrlCacheSpaceA(LPCSTR lpszCachePath, DWORD dwSize, DWORD dwSizeType)
+{
+    BOOL ret = FALSE;
+    LPWSTR path = heap_strdupAtoW(lpszCachePath);
+    if (lpszCachePath == NULL || path != NULL)
+        ret = FreeUrlCacheSpaceW(path, dwSize, dwSizeType);
+    heap_free(path);
+    return ret;
+}
+
+/***********************************************************************
  *           GetUrlCacheEntryInfoExA (WININET.@)
  *
  */
diff --git a/include/wininet.h b/include/wininet.h
index 0cf453e..ce09821 100644
--- a/include/wininet.h
+++ b/include/wininet.h
@@ -1660,6 +1660,16 @@ BOOLAPI DeleteUrlCacheEntryA(LPCSTR);
 BOOLAPI DeleteUrlCacheEntryW(LPCWSTR);
 #define DeleteUrlCacheEntry  WINELIB_NAME_AW(DeleteUrlCacheEntry)
 
+/* FCS_ flags and FreeUrlCacheSpace are no longer documented */
+#define FCS_PERCENT_CACHE_SPACE  0  /* guessed value */
+#define FCS_PERCENT_DISK_SPACE   1  /* guessed value */
+#define FCS_ABSOLUTE_SIZE        2  /* guessed value */
+
+BOOLAPI FreeUrlCacheSpaceA(LPCSTR ,DWORD ,DWORD);
+BOOLAPI FreeUrlCacheSpaceW(LPCWSTR ,DWORD ,DWORD);
+#define FreeUrlCacheSpace  WINELIB_NAME_AW(FreeUrlCacheSpace)
+
+
 INTERNETAPI DWORD WINAPI InternetDialA(HWND ,LPSTR ,DWORD ,DWORD_PTR* ,DWORD);
 INTERNETAPI DWORD WINAPI InternetDialW(HWND ,LPWSTR ,DWORD ,DWORD_PTR* ,DWORD);
 #define InternetDial WINELIB_NAME_AW(InternetDial)




More information about the wine-cvs mailing list