diff options
Diffstat (limited to 'src/corelib/io/qfsfileengine_win.cpp')
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 141 |
1 files changed, 19 insertions, 122 deletions
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index c37a690646..70c347978e 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -50,13 +50,9 @@ #include "qdatetime.h" #include "qt_windows.h" -#if !defined(Q_OS_WINCE) -# include <sys/types.h> -# include <direct.h> -# include <winioctl.h> -#else -# include <types.h> -#endif +#include <sys/types.h> +#include <direct.h> +#include <winioctl.h> #include <objbase.h> #ifndef Q_OS_WINRT # include <shlobj.h> @@ -77,14 +73,12 @@ QT_BEGIN_NAMESPACE -#if !defined(Q_OS_WINCE) static inline bool isUncPath(const QString &path) { // Starts with \\, but not \\. return (path.startsWith(QLatin1String("\\\\")) && path.size() > 2 && path.at(2) != QLatin1Char('.')); } -#endif /*! \internal @@ -95,7 +89,7 @@ QString QFSFileEnginePrivate::longFileName(const QString &path) return path; QString absPath = QFileSystemEngine::nativeAbsoluteFilePath(path); -#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if !defined(Q_OS_WINRT) QString prefix = QLatin1String("\\\\?\\"); if (isUncPath(absPath)) { prefix.append(QLatin1String("UNC\\")); // "\\\\?\\UNC\\" @@ -171,7 +165,6 @@ bool QFSFileEnginePrivate::nativeClose() // Windows native mode. bool ok = true; -#ifndef Q_OS_WINCE if (cachedFd != -1) { if (::_close(cachedFd) && !::CloseHandle(fileHandle)) { q->setError(QFile::UnspecifiedError, qt_error_string()); @@ -184,7 +177,6 @@ bool QFSFileEnginePrivate::nativeClose() return ok; } -#endif if ((fileHandle == INVALID_HANDLE_VALUE || !::CloseHandle(fileHandle))) { q->setError(QFile::UnspecifiedError, qt_error_string()); @@ -238,24 +230,6 @@ qint64 QFSFileEnginePrivate::nativeSize() const // Always retrive the current information metaData.clearFlags(QFileSystemMetaData::SizeAttribute); -#if defined(Q_OS_WINCE) - // Buffered stdlib mode. - if (fh) { - QT_OFF_T oldPos = QT_FTELL(fh); - QT_FSEEK(fh, 0, SEEK_END); - qint64 fileSize = (qint64)QT_FTELL(fh); - QT_FSEEK(fh, oldPos, SEEK_SET); - if (fileSize == -1) { - fileSize = 0; - thatQ->setError(QFile::UnspecifiedError, qt_error_string(errno)); - } - return fileSize; - } - if (fd != -1) { - thatQ->setError(QFile::UnspecifiedError, QLatin1String("Not implemented!")); - return 0; - } -#endif bool filled = false; if (fileHandle != INVALID_HANDLE_VALUE && openMode != QIODevice::NotOpen ) filled = QFileSystemEngine::fillMetaData(fileHandle, metaData, @@ -287,7 +261,6 @@ qint64 QFSFileEnginePrivate::nativePos() const if (fileHandle == INVALID_HANDLE_VALUE) return 0; -#if !defined(Q_OS_WINCE) LARGE_INTEGER currentFilePos; LARGE_INTEGER offset; offset.QuadPart = 0; @@ -297,18 +270,6 @@ qint64 QFSFileEnginePrivate::nativePos() const } return qint64(currentFilePos.QuadPart); -#else - LARGE_INTEGER filepos; - filepos.HighPart = 0; - DWORD newFilePointer = SetFilePointer(fileHandle, 0, &filepos.HighPart, FILE_CURRENT); - if (newFilePointer == 0xFFFFFFFF && GetLastError() != NO_ERROR) { - thatQ->setError(QFile::UnspecifiedError, qt_error_string()); - return 0; - } - - filepos.LowPart = newFilePointer; - return filepos.QuadPart; -#endif } /* @@ -323,7 +284,6 @@ bool QFSFileEnginePrivate::nativeSeek(qint64 pos) return seekFdFh(pos); } -#if !defined(Q_OS_WINCE) LARGE_INTEGER currentFilePos; LARGE_INTEGER offset; offset.QuadPart = pos; @@ -333,17 +293,6 @@ bool QFSFileEnginePrivate::nativeSeek(qint64 pos) } return true; -#else - DWORD newFilePointer; - LARGE_INTEGER *li = reinterpret_cast<LARGE_INTEGER*>(&pos); - newFilePointer = SetFilePointer(fileHandle, li->LowPart, &li->HighPart, FILE_BEGIN); - if (newFilePointer == 0xFFFFFFFF && GetLastError() != NO_ERROR) { - q->setError(QFile::PositionError, qt_error_string()); - return false; - } - - return true; -#endif } /* @@ -462,7 +411,6 @@ int QFSFileEnginePrivate::nativeHandle() const { if (fh || fd != -1) return fh ? QT_FILENO(fh) : fd; -#ifndef Q_OS_WINCE if (cachedFd != -1) return cachedFd; @@ -473,9 +421,6 @@ int QFSFileEnginePrivate::nativeHandle() const flags |= _O_RDONLY; cachedFd = _open_osfhandle((intptr_t) fileHandle, flags); return cachedFd; -#else - return -1; -#endif } /* @@ -483,7 +428,7 @@ int QFSFileEnginePrivate::nativeHandle() const */ bool QFSFileEnginePrivate::nativeIsSequential() const { -#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if !defined(Q_OS_WINRT) HANDLE handle = fileHandle; if (fh || fd != -1) handle = (HANDLE)_get_osfhandle(fh ? QT_FILENO(fh) : fd); @@ -531,35 +476,9 @@ bool QFSFileEngine::rename(const QString &newName) bool QFSFileEngine::renameOverwrite(const QString &newName) { Q_D(QFSFileEngine); -#if defined(Q_OS_WINCE) - // Windows Embedded Compact 7 does not have MoveFileEx, simulate it with the following sequence: - // 1. DeleteAndRenameFile (Should work on RAM FS when both files exist) - // 2. DeleteFile/MoveFile (Should work on all file systems) - // - // DeleteFile/MoveFile fallback implementation violates atomicity, but it is more acceptable than - // alternative CopyFile/DeleteFile sequence for the following reasons: - // - // 1. DeleteFile/MoveFile is way faster than CopyFile/DeleteFile and thus more atomic. - // 2. Given the intended use case of this function in QSaveFile, DeleteFile/MoveFile sequence will - // delete the old content, but leave a file "filename.ext.XXXXXX" in the same directory if MoveFile fails. - // With CopyFile/DeleteFile sequence, it can happen that new data is partially copied to target file - // (because CopyFile is not atomic either), thus leaving *some* content to target file. - // This makes the need for application level recovery harder to detect than in DeleteFile/MoveFile - // sequence where target file simply does not exist. - // - bool ret = ::DeleteAndRenameFile((wchar_t*)QFileSystemEntry(newName).nativeFilePath().utf16(), - (wchar_t*)d->fileEntry.nativeFilePath().utf16()) != 0; - if (!ret) { - ret = ::DeleteFile((wchar_t*)QFileSystemEntry(newName).nativeFilePath().utf16()) != 0; - if (ret || ::GetLastError() == ERROR_FILE_NOT_FOUND) - ret = ::MoveFile((wchar_t*)d->fileEntry.nativeFilePath().utf16(), - (wchar_t*)QFileSystemEntry(newName).nativeFilePath().utf16()) != 0; - } -#else bool ret = ::MoveFileEx((wchar_t*)d->fileEntry.nativeFilePath().utf16(), (wchar_t*)QFileSystemEntry(newName).nativeFilePath().utf16(), MOVEFILE_REPLACE_EXISTING) != 0; -#endif if (!ret) setError(QFile::RenameError, QSystemError(::GetLastError(), QSystemError::NativeError).toString()); return ret; @@ -587,7 +506,7 @@ bool QFSFileEngine::setCurrentPath(const QString &path) QString QFSFileEngine::currentPath(const QString &fileName) { -#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if !defined(Q_OS_WINRT) QString ret; //if filename is a drive: then get the pwd of that drive if (fileName.length() >= 2 && @@ -606,10 +525,10 @@ QString QFSFileEngine::currentPath(const QString &fileName) if (ret.length() >= 2 && ret[1] == QLatin1Char(':')) ret[0] = ret.at(0).toUpper(); // Force uppercase drive letters. return ret; -#else // !Q_OS_WINCE && !Q_OS_WINRT +#else // !Q_OS_WINRT Q_UNUSED(fileName); return QFileSystemEngine::currentPath().filePath(); -#endif // Q_OS_WINCE || Q_OS_WINRT +#endif // Q_OS_WINRT } QString QFSFileEngine::homePath() @@ -630,12 +549,12 @@ QString QFSFileEngine::tempPath() QFileInfoList QFSFileEngine::drives() { QFileInfoList ret; -#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) -#if defined(Q_OS_WIN32) +#if !defined(Q_OS_WINRT) +# if defined(Q_OS_WIN32) const UINT oldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); quint32 driveBits = (quint32) GetLogicalDrives() & 0x3ffffff; ::SetErrorMode(oldErrorMode); -#endif +# endif char driveName[] = "A:/"; while (driveBits) { @@ -645,10 +564,10 @@ QFileInfoList QFSFileEngine::drives() driveBits = driveBits >> 1; } return ret; -#else // !Q_OS_WINCE && !Q_OS_WINRT +#else // !Q_OS_WINRT ret.append(QFileInfo(QLatin1String("/"))); return ret; -#endif // Q_OS_WINCE || Q_OS_WINRT +#endif // Q_OS_WINRT } bool QFSFileEnginePrivate::doStat(QFileSystemMetaData::MetaDataFlags flags) const @@ -656,13 +575,11 @@ bool QFSFileEnginePrivate::doStat(QFileSystemMetaData::MetaDataFlags flags) cons if (!tried_stat || !metaData.hasFlags(flags)) { tried_stat = true; -#if !defined(Q_OS_WINCE) int localFd = fd; if (fh && fileEntry.isEmpty()) localFd = QT_FILENO(fh); if (localFd != -1) QFileSystemEngine::fillMetaData(localFd, metaData, flags); -#endif if (metaData.missingFlags(flags) && !fileEntry.isEmpty()) QFileSystemEngine::fillMetaData(fileEntry, metaData, metaData.missingFlags(flags)); } @@ -673,8 +590,8 @@ bool QFSFileEnginePrivate::doStat(QFileSystemMetaData::MetaDataFlags flags) cons bool QFSFileEngine::link(const QString &newName) { -#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) -#if !defined(QT_NO_LIBRARY) +#if !defined(Q_OS_WINRT) +# if !defined(QT_NO_LIBRARY) bool ret = false; QString linkName = newName; @@ -715,24 +632,11 @@ bool QFSFileEngine::link(const QString &newName) CoUninitialize(); return ret; -#else +# else // QT_NO_LIBRARY Q_UNUSED(newName); return false; -#endif // QT_NO_LIBRARY -#elif defined(Q_OS_WINCE) && !defined(QT_NO_WINCE_SHELLSDK) - QString linkName = newName; - linkName.replace(QLatin1Char('/'), QLatin1Char('\\')); - if (!linkName.endsWith(QLatin1String(".lnk"))) - linkName += QLatin1String(".lnk"); - QString orgName = fileName(AbsoluteName).replace(QLatin1Char('/'), QLatin1Char('\\')); - // Need to append on our own - orgName.prepend(QLatin1Char('"')); - orgName.append(QLatin1Char('"')); - bool ret = SUCCEEDED(SHCreateShortcut((wchar_t*)linkName.utf16(), (wchar_t*)orgName.utf16())); - if (!ret) - setError(QFile::RenameError, qt_error_string()); - return ret; -#else // Q_OS_WINCE && !QT_NO_WINCE_SHELLSDK +# endif // QT_NO_LIBRARY +#else // !Q_OS_WINRT Q_UNUSED(newName); Q_UNIMPLEMENTED(); return false; @@ -813,7 +717,6 @@ QString QFSFileEngine::fileName(FileName file) const QString ret; if (!isRelativePath()) { -#if !defined(Q_OS_WINCE) if (d->fileEntry.filePath().startsWith(QLatin1Char('/')) || // It's a absolute path to the current drive, so \a.txt -> Z:\a.txt d->fileEntry.filePath().size() == 2 || // It's a drive letter that needs to get a working dir appended (d->fileEntry.filePath().size() > 2 && d->fileEntry.filePath().at(2) != QLatin1Char('/')) || // It's a drive-relative path, so Z:a.txt -> Z:\currentpath\a.txt @@ -821,9 +724,7 @@ QString QFSFileEngine::fileName(FileName file) const d->fileEntry.filePath().endsWith(QLatin1String("/..")) || d->fileEntry.filePath().endsWith(QLatin1String("/."))) { ret = QDir::fromNativeSeparators(QFileSystemEngine::nativeAbsoluteFilePath(d->fileEntry.filePath())); - } else -#endif - { + } else { ret = d->fileEntry.filePath(); } } else { @@ -905,14 +806,12 @@ bool QFSFileEngine::setSize(qint64 size) if (d->fileHandle != INVALID_HANDLE_VALUE || d->fd != -1 || d->fh) { // resize open file HANDLE fh = d->fileHandle; -#if !defined(Q_OS_WINCE) if (fh == INVALID_HANDLE_VALUE) { if (d->fh) fh = (HANDLE)_get_osfhandle(QT_FILENO(d->fh)); else fh = (HANDLE)_get_osfhandle(d->fd); } -#endif if (fh == INVALID_HANDLE_VALUE) return false; qint64 currentPos = pos(); @@ -984,10 +883,8 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, // get handle to the file HANDLE handle = fileHandle; -#ifndef Q_OS_WINCE if (handle == INVALID_HANDLE_VALUE && fh) handle = (HANDLE)::_get_osfhandle(QT_FILENO(fh)); -#endif #ifdef Q_USE_DEPRECATED_MAP_API nativeClose(); |