Cleanup: Use exceptionless Range::* methods rather than ignoring exceptions.
[WebKit-https.git] / Source / WebCore / platform / wince / FileSystemWinCE.cpp
index 49acf12..fb507c0 100644 (file)
 #include "config.h"
 #include "FileSystem.h"
 
+#include "FileMetadata.h"
 #include "NotImplemented.h"
-#include "PlatformString.h"
 #include <wincrypt.h>
 #include <windows.h>
 #include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -68,31 +69,54 @@ static bool getFileInfo(const String& path, BY_HANDLE_FILE_INFORMATION& fileInfo
     return rtn;
 }
 
-bool getFileSize(const String& path, long long& result)
+static void getFileSizeFromFileInfo(const BY_HANDLE_FILE_INFORMATION& fileInfo, long long& size)
+{
+    ULARGE_INTEGER fileSize;
+    fileSize.LowPart = fileInfo.nFileSizeLow;
+    fileSize.HighPart = fileInfo.nFileSizeHigh;
+    size = fileSize.QuadPart;
+}
+
+static void getFileModificationTimeFromFileInfo(const BY_HANDLE_FILE_INFORMATION& fileInfo, time_t& time)
+{
+    ULARGE_INTEGER t;
+    memcpy(&t, &fileInfo.ftLastWriteTime, sizeof(t));
+    time = t.QuadPart * 0.0000001 - 11644473600.0;
+}
+
+bool getFileSize(const String& path, long long& size)
 {
     BY_HANDLE_FILE_INFORMATION fileInformation;
     if (!getFileInfo(path, fileInformation))
         return false;
 
-    ULARGE_INTEGER fileSize;
-    fileSize.LowPart = fileInformation.nFileSizeLow;
-    fileSize.HighPart = fileInformation.nFileSizeHigh;
+    getFileSizeFromFileInfo(fileInformation, size);
+    return true;
+}
 
-    result = fileSize.QuadPart;
+bool getFileModificationTime(const String& path, time_t& time)
+{
+    BY_HANDLE_FILE_INFORMATION fileInformation;
+    if (!getFileInfo(path, fileInformation))
+        return false;
 
+    getFileModificationTimeFromFileInfo(fileInformation, time);
     return true;
 }
 
-bool getFileModificationTime(const String& path, time_t& result)
+bool getFileMetadata(const String& path, FileMetadata& metadata)
 {
     BY_HANDLE_FILE_INFORMATION fileInformation;
     if (!getFileInfo(path, fileInformation))
         return false;
 
-    ULARGE_INTEGER t;
-    memcpy(&t, &fileInformation.ftLastWriteTime, sizeof(t));
-    
-    result = t.QuadPart * 0.0000001 - 11644473600.0;
+    getFileSizeFromFileInfo(fileInformation, metadata.length);
+
+    time_t modificationTime;
+    getFileModificationTimeFromFileInfo(fileInformation, modificationTime);
+    metadata.modificationTime = modificationTime;
+
+    metadata.type = (fileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FileMetadata::TypeDirectory : FileMetadata::TypeFile;
 
     return true;
 }
@@ -187,18 +211,18 @@ String directoryName(const String& path)
     return path.left(pos);
 }
 
-CString openTemporaryFile(const char*, PlatformFileHandle& handle)
+String openTemporaryFile(const String&, PlatformFileHandle& handle)
 {
     handle = INVALID_HANDLE_VALUE;
 
     wchar_t tempPath[MAX_PATH];
     int tempPathLength = ::GetTempPath(WTF_ARRAY_LENGTH(tempPath), tempPath);
     if (tempPathLength <= 0 || tempPathLength > WTF_ARRAY_LENGTH(tempPath))
-        return CString();
+        return String();
 
     HCRYPTPROV hCryptProv = 0;
     if (!CryptAcquireContext(&hCryptProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
-        return CString();
+        return String();
 
     String proposedPath;
     while (1) {
@@ -229,9 +253,28 @@ CString openTemporaryFile(const char*, PlatformFileHandle& handle)
     CryptReleaseContext(hCryptProv, 0);
 
     if (!isHandleValid(handle))
-        return CString();
+        return String();
+
+    return proposedPath;
+}
+
+PlatformFileHandle openFile(const String& path, FileOpenMode mode)
+{
+    DWORD desiredAccess = 0;
+    DWORD creationDisposition = 0;
+    switch (mode) {
+        case OpenForRead:
+            desiredAccess = GENERIC_READ;
+            creationDisposition = OPEN_EXISTING;
+        case OpenForWrite:
+            desiredAccess = GENERIC_WRITE;
+            creationDisposition = CREATE_ALWAYS;
+        default:
+            ASSERT_NOT_REACHED();
+    }
 
-    return proposedPath.latin1();
+    String destination = path;
+    return CreateFile(destination.charactersWithNullTermination(), desiredAccess, 0, 0, creationDisposition, FILE_ATTRIBUTE_NORMAL, 0);
 }
 
 void closeFile(PlatformFileHandle& handle)
@@ -291,7 +334,7 @@ Vector<String> listDirectory(const String& path, const String& filter)
             // is so far only called by PluginDatabase.cpp to list
             // all plugins in a folder, where it's not supposed to list sub-folders.
             if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
-                entries.append(root + findData.cFileName);
+                entries.append(root + String(findData.cFileName));
         } while (FindNextFile(hFind, &findData));
         FindClose(hFind);
     }