2 * Copyright (C) 2007 Staikos Computing Services Inc.
3 * Copyright (C) 2007 Holger Hans Peter Freyther
4 * Copyright (C) 2008 Apple, Inc. All rights reserved.
5 * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "FileSystem.h"
36 #include "PlatformString.h"
40 #include <QTemporaryFile>
47 bool fileExists(const String
& path
)
49 return QFile::exists(path
);
53 bool deleteFile(const String
& path
)
55 return QFile::remove(path
);
58 bool deleteEmptyDirectory(const String
& path
)
60 return QDir::root().rmdir(path
);
63 bool getFileSize(const String
& path
, long long& result
)
70 bool getFileModificationTime(const String
& path
, time_t& result
)
73 result
= info
.lastModified().toTime_t();
77 bool makeAllDirectories(const String
& path
)
79 return QDir::root().mkpath(path
);
82 String
pathByAppendingComponent(const String
& path
, const String
& component
)
84 return QDir::toNativeSeparators(QDir(path
).filePath(component
));
87 String
homeDirectoryPath()
89 return QDir::homePath();
92 String
pathGetFileName(const String
& path
)
94 return QFileInfo(path
).fileName();
97 String
directoryName(const String
& path
)
99 return String(QFileInfo(path
).absolutePath());
102 Vector
<String
> listDirectory(const String
& path
, const String
& filter
)
104 Vector
<String
> entries
;
106 QStringList nameFilters
;
107 if (!filter
.isEmpty())
108 nameFilters
.append(filter
);
109 QFileInfoList fileInfoList
= QDir(path
).entryInfoList(nameFilters
, QDir::AllEntries
| QDir::NoDotAndDotDot
);
110 foreach (const QFileInfo fileInfo
, fileInfoList
) {
111 String entry
= String(fileInfo
.canonicalFilePath());
112 entries
.append(entry
);
118 CString
openTemporaryFile(const char* prefix
, PlatformFileHandle
& handle
)
120 QTemporaryFile
* tempFile
= new QTemporaryFile(QLatin1String(prefix
));
121 tempFile
->setAutoRemove(false);
122 QFile
* temp
= tempFile
;
123 if (temp
->open(QIODevice::ReadWrite
)) {
125 return String(temp
->fileName()).utf8();
127 handle
= invalidPlatformFileHandle
;
131 void closeFile(PlatformFileHandle
& handle
)
139 int writeToFile(PlatformFileHandle handle
, const char* data
, int length
)
141 if (handle
&& handle
->exists() && handle
->isWritable())
142 return handle
->write(data
, length
);
147 bool unloadModule(PlatformModule module
)
149 #if defined(Q_WS_MAC)
153 #elif defined(Q_OS_WIN)
154 return ::FreeLibrary(module
);
157 if (module
->unload()) {