1 /* 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2008 Collabora, Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15 * its contributors may be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef FileSystem_h 31 #define FileSystem_h 32 33 #if PLATFORM(GTK) 34 #include <gmodule.h> 35 #endif 36 #if PLATFORM(QT) 37 #include <QFile> 38 #include <QLibrary> 39 #if defined(Q_OS_WIN32) 40 #include <windows.h> 41 #endif 42 #endif 43 44 #if PLATFORM(CF) || (PLATFORM(QT) && defined(Q_WS_MAC)) 45 #include <CoreFoundation/CFBundle.h> 46 #endif 47 48 #include <time.h> 49 50 #include <wtf/Platform.h> 51 #include <wtf/Vector.h> 52 53 #include "PlatformString.h" 54 55 typedef const struct __CFData* CFDataRef; 56 57 #if OS(WINDOWS) 58 // These are to avoid including <winbase.h> in a header for Chromium 59 typedef void *HANDLE; 60 // Assuming STRICT 61 typedef struct HINSTANCE__* HINSTANCE; 62 typedef HINSTANCE HMODULE; 63 #endif 64 65 namespace WebCore { 66 67 class CString; 68 69 // PlatformModule 70 #if OS(WINDOWS) 71 typedef HMODULE PlatformModule; 72 #elif PLATFORM(QT) 73 #if defined(Q_WS_MAC) 74 typedef CFBundleRef PlatformModule; 75 #else 76 typedef QLibrary* PlatformModule; 77 #endif // defined(Q_WS_MAC) 78 #elif PLATFORM(GTK) 79 typedef GModule* PlatformModule; 80 #elif PLATFORM(CF) 81 typedef CFBundleRef PlatformModule; 82 #else 83 typedef void* PlatformModule; 84 #endif 85 86 // PlatformModuleVersion 87 #if OS(WINDOWS) 88 struct PlatformModuleVersion { 89 unsigned leastSig; 90 unsigned mostSig; 91 92 PlatformModuleVersion(unsigned) 93 : leastSig(0) 94 , mostSig(0) 95 { 96 } 97 98 PlatformModuleVersion(unsigned lsb, unsigned msb) 99 : leastSig(lsb) 100 , mostSig(msb) 101 { 102 } 103 104 }; 105 #else 106 typedef unsigned PlatformModuleVersion; 107 #endif 108 109 // PlatformFileHandle 110 #if PLATFORM(QT) 111 typedef QFile* PlatformFileHandle; 112 const PlatformFileHandle invalidPlatformFileHandle = 0; 113 #elif OS(WINDOWS) 114 typedef HANDLE PlatformFileHandle; 115 // FIXME: -1 is INVALID_HANDLE_VALUE, defined in <winbase.h>. Chromium tries to 116 // avoid using Windows headers in headers. We'd rather move this into the .cpp. 117 const PlatformFileHandle invalidPlatformFileHandle = reinterpret_cast<HANDLE>(-1); 118 #else 119 typedef int PlatformFileHandle; 120 const PlatformFileHandle invalidPlatformFileHandle = -1; 121 #endif 122 123 bool fileExists(const String&); 124 bool deleteFile(const String&); 125 bool deleteEmptyDirectory(const String&); 126 bool getFileSize(const String&, long long& result); 127 bool getFileModificationTime(const String&, time_t& result); 128 String pathByAppendingComponent(const String& path, const String& component); 129 bool makeAllDirectories(const String& path); 130 String homeDirectoryPath(); 131 String pathGetFileName(const String&); 132 String directoryName(const String&); 133 134 Vector<String> listDirectory(const String& path, const String& filter = String()); 135 136 CString fileSystemRepresentation(const String&); 137 138 inline bool isHandleValid(const PlatformFileHandle& handle) { return handle != invalidPlatformFileHandle; } 139 140 // Prefix is what the filename should be prefixed with, not the full path. 141 CString openTemporaryFile(const char* prefix, PlatformFileHandle&); 142 void closeFile(PlatformFileHandle&); 143 int writeToFile(PlatformFileHandle, const char* data, int length); 144 145 // Methods for dealing with loadable modules 146 bool unloadModule(PlatformModule); 147 148 #if PLATFORM(WIN) 149 String localUserSpecificStorageDirectory(); 150 String roamingUserSpecificStorageDirectory(); 151 152 bool safeCreateFile(const String&, CFDataRef); 153 #endif 154 155 #if PLATFORM(GTK) 156 String filenameToString(const char*); 157 char* filenameFromString(const String&); 158 String filenameForDisplay(const String&); 159 #endif 160 161 #if PLATFORM(CHROMIUM) 162 String pathGetDisplayFileName(const String&); 163 #endif 164 165 } // namespace WebCore 166 167 #endif // FileSystem_h 168