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
QByteArray QFileSystemEngine::id(HANDLE fHandle)
{
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8 ?
fileIdWin8(HANDLE(fHandle)) : fileId(HANDLE(fHandle));
return fileIdWin8(HANDLE(fHandle));
}
//static
@ -1420,79 +1419,44 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source,
// we need the "display name" of the file, so can't use nativeAbsoluteFilePath
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__)
CoInitialize(NULL);
IFileOperation *pfo = nullptr;
IShellItem *deleteItem = nullptr;
FileOperationProgressSink *sink = nullptr;
HRESULT hres = E_FAIL;
CoInitialize(NULL);
IFileOperation *pfo = nullptr;
IShellItem *deleteItem = nullptr;
FileOperationProgressSink *sink = nullptr;
HRESULT hres = E_FAIL;
auto coUninitialize = qScopeGuard([&](){
if (sink)
sink->Release();
if (deleteItem)
deleteItem->Release();
if (pfo)
pfo->Release();
CoUninitialize();
if (!SUCCEEDED(hres))
error = QSystemError(hres, QSystemError::NativeError);
});
auto coUninitialize = qScopeGuard([&](){
if (sink)
sink->Release();
if (deleteItem)
deleteItem->Release();
if (pfo)
pfo->Release();
CoUninitialize();
if (!SUCCEEDED(hres))
error = QSystemError(hres, QSystemError::NativeError);
});
hres = CoCreateInstance(CLSID_FileOperation, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&pfo));
if (!pfo)
return false;
pfo->SetOperationFlags(FOF_ALLOWUNDO | FOFX_RECYCLEONDELETE | FOF_NOCONFIRMATION
| FOF_SILENT | FOF_NOERRORUI);
hres = SHCreateItemFromParsingName(reinterpret_cast<const wchar_t*>(sourcePath.utf16()),
nullptr, IID_PPV_ARGS(&deleteItem));
if (!deleteItem)
return false;
sink = new FileOperationProgressSink;
hres = pfo->DeleteItem(deleteItem, static_cast<IFileOperationProgressSink*>(sink));
if (!SUCCEEDED(hres))
return false;
hres = pfo->PerformOperations();
if (!SUCCEEDED(hres))
return false;
newLocation = QFileSystemEntry(sink->targetPath);
hres = CoCreateInstance(CLSID_FileOperation, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&pfo));
if (!pfo)
return false;
pfo->SetOperationFlags(FOF_ALLOWUNDO | FOFX_RECYCLEONDELETE | FOF_NOCONFIRMATION
| FOF_SILENT | FOF_NOERRORUI);
hres = SHCreateItemFromParsingName(reinterpret_cast<const wchar_t*>(sourcePath.utf16()),
nullptr, IID_PPV_ARGS(&deleteItem));
if (!deleteItem)
return false;
sink = new FileOperationProgressSink;
hres = pfo->DeleteItem(deleteItem, static_cast<IFileOperationProgressSink*>(sink));
if (!SUCCEEDED(hres))
return false;
hres = pfo->PerformOperations();
if (!SUCCEEDED(hres))
return false;
newLocation = QFileSystemEntry(sink->targetPath);
# 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;
}

View File

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

View File

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