summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfsfileengine_win.cpp
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2021-04-12 14:56:18 +0200
committerKarsten Heimrich <karsten.heimrich@qt.io>2021-05-12 14:53:12 +0200
commit776a969bfd426a697ce95481ab7989f9bb351552 (patch)
treef11e65c3829ed5e9a4d516f9728b07840dcc50bb /src/corelib/io/qfsfileengine_win.cpp
parent37d6fd60a800a0956b41870aca338a30e0bd5768 (diff)
Implement QFileSystemEngine::createLink() on MS-Win
Fixes: QTBUG-74271 Change-Id: I9e414dd16546f65e85b5a1a6c70c40dfa4284a6f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/corelib/io/qfsfileengine_win.cpp')
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp48
1 files changed, 5 insertions, 43 deletions
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index 84ba42f55a..fad9f5e48b 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -494,52 +494,14 @@ bool QFSFileEnginePrivate::doStat(QFileSystemMetaData::MetaDataFlags flags) cons
return metaData.exists();
}
-
+// ### assume that they add .lnk to newName
bool QFSFileEngine::link(const QString &newName)
{
- bool ret = false;
-
- QString linkName = newName;
- //### assume that they add .lnk
-
- IShellLink *psl;
- bool neededCoInit = false;
-
- HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink,
- reinterpret_cast<void **>(&psl));
-
- if (hres == CO_E_NOTINITIALIZED) { // COM was not initialized
- neededCoInit = true;
- CoInitialize(nullptr);
- hres = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink,
- reinterpret_cast<void **>(&psl));
- }
-
- if (SUCCEEDED(hres)) {
- const QString nativeAbsoluteName = fileName(AbsoluteName).replace(QLatin1Char('/'), QLatin1Char('\\'));
- hres = psl->SetPath(reinterpret_cast<const wchar_t *>(nativeAbsoluteName.utf16()));
- if (SUCCEEDED(hres)) {
- const QString nativeAbsolutePathName = fileName(AbsolutePathName).replace(QLatin1Char('/'), QLatin1Char('\\'));
- hres = psl->SetWorkingDirectory(reinterpret_cast<const wchar_t *>(nativeAbsolutePathName.utf16()));
- if (SUCCEEDED(hres)) {
- IPersistFile *ppf;
- hres = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void **>(&ppf));
- if (SUCCEEDED(hres)) {
- hres = ppf->Save(reinterpret_cast<const wchar_t *>(linkName.utf16()), TRUE);
- if (SUCCEEDED(hres))
- ret = true;
- ppf->Release();
- }
- }
- }
- psl->Release();
- }
+ QSystemError error;
+ bool ret = QFileSystemEngine::createLink(QFileSystemEntry(fileName(AbsoluteName)),
+ QFileSystemEntry(newName), error);
if (!ret)
- setError(QFile::RenameError, qt_error_string());
-
- if (neededCoInit)
- CoUninitialize();
-
+ setError(QFile::RenameError, error.toString());
return ret;
}