Win: Move hresultToQString from vfs plugin to Utility::formatWinError

This commit is contained in:
Hannah von Reth 2020-07-08 12:38:01 +02:00 committed by Kevin Ottens
parent 4589772393
commit 7fa7bc54c4
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
3 changed files with 16 additions and 9 deletions

View file

@ -17,6 +17,7 @@
*/
#include "filesystembase.h"
#include "utility.h"
#include <QDateTime>
#include <QDir>
@ -140,13 +141,7 @@ bool FileSystem::rename(const QString &originFileName,
(wchar_t *)dest.utf16(),
MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH);
if (!success) {
wchar_t *string = 0;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
nullptr, ::GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&string, 0, nullptr);
error = QString::fromWCharArray(string);
LocalFree((HLOCAL)string);
error = Utility::formatWinError();
}
} else
#endif

View file

@ -249,6 +249,8 @@ namespace Utility {
OCSYNC_EXPORT void FiletimeToLargeIntegerFiletime(FILETIME *filetime, LARGE_INTEGER *hundredNSecs);
OCSYNC_EXPORT void UnixTimeToLargeIntegerFiletime(time_t t, LARGE_INTEGER *hundredNSecs);
OCSYNC_EXPORT QString formatWinError(long error = GetLastError());
#endif
}
/** @} */ // \addtogroup

View file

@ -17,12 +17,16 @@
*/
#include "asserts.h"
#include "utility.h"
#include <comdef.h>
#include <shlguid.h>
#include <shlobj.h>
#include <string>
#include <winbase.h>
#include <windows.h>
#include <winerror.h>
#include <shlguid.h>
#include <string>
#include <QLibrary>
static const char systemRunPathC[] = R"(HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run)";
@ -334,4 +338,10 @@ void Utility::UnixTimeToLargeIntegerFiletime(time_t t, LARGE_INTEGER *hundredNSe
hundredNSecs->HighPart = ll >>32;
}
QString Utility::formatWinError(long errorCode)
{
return QStringLiteral("WindowsError: %1: %2").arg(QString::number(errorCode), QString::fromWCharArray(_com_error(errorCode).ErrorMessage()));
}
} // namespace OCC