io: Remove version checks for versions below Win 10

It's not supported.

Change-Id: Ia17fc7e1d5ae785eca0a6ba530f9b9bc960605d4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Mårten Nordheim 2021-07-15 17:19:43 +02:00
parent c877e9760b
commit 6a51ff3f0d
3 changed files with 36 additions and 76 deletions

View File

@ -694,8 +694,7 @@ QByteArray QFileSystemEngine::id(const QFileSystemEntry &entry)
//static //static
QByteArray QFileSystemEngine::id(HANDLE fHandle) QByteArray QFileSystemEngine::id(HANDLE fHandle)
{ {
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8 ? return fileIdWin8(HANDLE(fHandle));
fileIdWin8(HANDLE(fHandle)) : fileId(HANDLE(fHandle));
} }
//static //static
@ -1420,79 +1419,44 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source,
// we need the "display name" of the file, so can't use nativeAbsoluteFilePath // we need the "display name" of the file, so can't use nativeAbsoluteFilePath
const QString sourcePath = QDir::toNativeSeparators(absoluteName(source).filePath()); const QString sourcePath = QDir::toNativeSeparators(absoluteName(source).filePath());
/*
Windows 7 insists on showing confirmation dialogs and ignores the respective
flags set on IFileOperation. Fall back to SHFileOperation, even if it doesn't
give us the new location of the file.
*/
if (QOperatingSystemVersion::current() > QOperatingSystemVersion::Windows7) {
# if defined(__IFileOperation_INTERFACE_DEFINED__) # if defined(__IFileOperation_INTERFACE_DEFINED__)
CoInitialize(NULL); CoInitialize(NULL);
IFileOperation *pfo = nullptr; IFileOperation *pfo = nullptr;
IShellItem *deleteItem = nullptr; IShellItem *deleteItem = nullptr;
FileOperationProgressSink *sink = nullptr; FileOperationProgressSink *sink = nullptr;
HRESULT hres = E_FAIL; HRESULT hres = E_FAIL;
auto coUninitialize = qScopeGuard([&](){ auto coUninitialize = qScopeGuard([&](){
if (sink) if (sink)
sink->Release(); sink->Release();
if (deleteItem) if (deleteItem)
deleteItem->Release(); deleteItem->Release();
if (pfo) if (pfo)
pfo->Release(); pfo->Release();
CoUninitialize(); CoUninitialize();
if (!SUCCEEDED(hres)) if (!SUCCEEDED(hres))
error = QSystemError(hres, QSystemError::NativeError); error = QSystemError(hres, QSystemError::NativeError);
}); });
hres = CoCreateInstance(CLSID_FileOperation, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&pfo)); hres = CoCreateInstance(CLSID_FileOperation, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&pfo));
if (!pfo) if (!pfo)
return false; return false;
pfo->SetOperationFlags(FOF_ALLOWUNDO | FOFX_RECYCLEONDELETE | FOF_NOCONFIRMATION pfo->SetOperationFlags(FOF_ALLOWUNDO | FOFX_RECYCLEONDELETE | FOF_NOCONFIRMATION
| FOF_SILENT | FOF_NOERRORUI); | FOF_SILENT | FOF_NOERRORUI);
hres = SHCreateItemFromParsingName(reinterpret_cast<const wchar_t*>(sourcePath.utf16()), hres = SHCreateItemFromParsingName(reinterpret_cast<const wchar_t*>(sourcePath.utf16()),
nullptr, IID_PPV_ARGS(&deleteItem)); nullptr, IID_PPV_ARGS(&deleteItem));
if (!deleteItem) if (!deleteItem)
return false; return false;
sink = new FileOperationProgressSink; sink = new FileOperationProgressSink;
hres = pfo->DeleteItem(deleteItem, static_cast<IFileOperationProgressSink*>(sink)); hres = pfo->DeleteItem(deleteItem, static_cast<IFileOperationProgressSink*>(sink));
if (!SUCCEEDED(hres)) if (!SUCCEEDED(hres))
return false; return false;
hres = pfo->PerformOperations(); hres = pfo->PerformOperations();
if (!SUCCEEDED(hres)) if (!SUCCEEDED(hres))
return false; return false;
newLocation = QFileSystemEntry(sink->targetPath); newLocation = QFileSystemEntry(sink->targetPath);
# endif // no IFileOperation in SDK (mingw, likely) - fall back to SHFileOperation # endif // no IFileOperation in SDK (mingw, likely) - fall back to SHFileOperation
} else {
// double null termination needed, so can't use QString::utf16
QVarLengthArray<wchar_t, MAX_PATH + 1> winFile(sourcePath.length() + 2);
sourcePath.toWCharArray(winFile.data());
winFile[sourcePath.length()] = wchar_t{};
winFile[sourcePath.length() + 1] = wchar_t{};
SHFILEOPSTRUCTW operation;
operation.hwnd = nullptr;
operation.wFunc = FO_DELETE;
operation.pFrom = winFile.constData();
operation.pTo = nullptr;
operation.fFlags = FOF_ALLOWUNDO | FOF_NO_UI;
operation.fAnyOperationsAborted = FALSE;
operation.hNameMappings = nullptr;
operation.lpszProgressTitle = nullptr;
int result = SHFileOperation(&operation);
if (result != 0) {
error = QSystemError(result, QSystemError::NativeError);
return false;
}
/*
This implementation doesn't let us know where the file ended up, even if
we would specify FOF_WANTMAPPINGHANDLE | FOF_RENAMEONCOLLISION, as
FOF_RENAMEONCOLLISION has no effect unless files are moved, copied, or renamed.
*/
Q_UNUSED(newLocation);
}
return true; return true;
} }

View File

@ -89,10 +89,8 @@ bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaDa
haveData = true; haveData = true;
int infoLevel = 0 ; // FindExInfoStandard; int infoLevel = 0 ; // FindExInfoStandard;
DWORD dwAdditionalFlags = 0; DWORD dwAdditionalFlags = 0;
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows7) { dwAdditionalFlags = 2; // FIND_FIRST_EX_LARGE_FETCH
dwAdditionalFlags = 2; // FIND_FIRST_EX_LARGE_FETCH infoLevel = 1 ; // FindExInfoBasic;
infoLevel = 1 ; // FindExInfoBasic;
}
int searchOps = 0; // FindExSearchNameMatch int searchOps = 0; // FindExSearchNameMatch
if (onlyDirs) if (onlyDirs)
searchOps = 1 ; // FindExSearchLimitToDirectories searchOps = 1 ; // FindExSearchLimitToDirectories

View File

@ -100,8 +100,6 @@ static bool isProcessLowIntegrity() {
// Disable function until Qt CI is updated // Disable function until Qt CI is updated
return false; return false;
#else #else
if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows8)
return false;
// non-leaking pseudo-handle. Expanded inline function GetCurrentProcessToken() // non-leaking pseudo-handle. Expanded inline function GetCurrentProcessToken()
// (was made an inline function in Windows 8). // (was made an inline function in Windows 8).
const auto process_token = HANDLE(quintptr(-4)); const auto process_token = HANDLE(quintptr(-4));