diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2022-04-29 15:02:17 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2022-04-29 21:38:51 +0300 |
commit | 7cdf5f0bb21461fd47fec24e8227d01eef474ad2 (patch) | |
tree | 63dc29ccd5daa4d57317f8b0bff3b10591a746f7 /src/common | |
parent | 2a7bda378e6ccda664ea159dac96aa0b09e13109 (diff) |
Fix potential long path issue
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/utility_win.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp index 5eb5b16c1..d2ec41d53 100644 --- a/src/common/utility_win.cpp +++ b/src/common/utility_win.cpp @@ -16,9 +16,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "asserts.h" #include "utility.h" +#include "asserts.h" +#include "filesystembase.h" + #include <comdef.h> #include <shlguid.h> #include <shlobj.h> @@ -56,22 +58,25 @@ namespace OCC { void Utility::setupFavLink(const QString &folder) { // First create a Desktop.ini so that the folder and favorite link show our application's icon. - QFile desktopIni(folder + QLatin1String("/Desktop.ini")); + QFile desktopIni(folder + QStringLiteral("/Desktop.ini")); if (desktopIni.exists()) { qCWarning(lcUtility) << desktopIni.fileName() << "already exists, not overwriting it to set the folder icon."; } else { qCInfo(lcUtility) << "Creating" << desktopIni.fileName() << "to set a folder icon in Explorer."; - desktopIni.open(QFile::WriteOnly); - desktopIni.write("[.ShellClassInfo]\r\nIconResource="); - desktopIni.write(QDir::toNativeSeparators(qApp->applicationFilePath()).toUtf8()); - desktopIni.write(",0\r\n"); - desktopIni.close(); + if (OC_ENSURE(desktopIni.open(QFile::WriteOnly))) { + desktopIni.write("[.ShellClassInfo]\r\nIconResource="); + desktopIni.write(QDir::toNativeSeparators(qApp->applicationFilePath()).toUtf8()); + desktopIni.write(",0\r\n"); + desktopIni.close(); + } + const QString longFolderPath = FileSystem::longWinPath(folder); + const QString longDesktopIniPath = FileSystem::longWinPath(desktopIni.fileName()); // Set the folder as system and Desktop.ini as hidden+system for explorer to pick it. // https://msdn.microsoft.com/en-us/library/windows/desktop/cc144102 - DWORD folderAttrs = GetFileAttributesW((wchar_t *)folder.utf16()); - SetFileAttributesW((wchar_t *)folder.utf16(), folderAttrs | FILE_ATTRIBUTE_SYSTEM); - SetFileAttributesW((wchar_t *)desktopIni.fileName().utf16(), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM); + const DWORD folderAttrs = GetFileAttributesW(reinterpret_cast<const wchar_t *>(longFolderPath.utf16())); + SetFileAttributesW(reinterpret_cast<const wchar_t *>(longFolderPath.utf16()), folderAttrs | FILE_ATTRIBUTE_SYSTEM); + SetFileAttributesW(reinterpret_cast<const wchar_t *>(longDesktopIniPath.utf16()), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM); } } |