-
Notifications
You must be signed in to change notification settings - Fork 671
/
Copy pathutility_win.h
93 lines (74 loc) · 2.64 KB
/
utility_win.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Copyright (C) by Hannah von Reth <hannah.vonreth@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#pragma once
#include "ocsynclib.h"
#include <QString>
#include <functional>
#include <qt_windows.h>
namespace OCC {
namespace Utility {
class OCSYNC_EXPORT Handle
{
public:
/**
* A RAAI for Windows Handles
*/
Handle() = default;
explicit Handle(HANDLE h);
explicit Handle(HANDLE h, std::function<void(HANDLE)> &&close);
Handle(const Handle &) = delete;
Handle &operator=(const Handle &) = delete;
Handle(Handle &&other)
{
std::swap(_handle, other._handle);
std::swap(_close, other._close);
}
Handle &operator=(Handle &&other)
{
if (this != &other) {
std::swap(_handle, other._handle);
std::swap(_close, other._close);
}
return *this;
}
~Handle();
HANDLE &handle() { return _handle; }
void close();
explicit operator bool() const { return _handle != INVALID_HANDLE_VALUE; }
operator HANDLE() const { return _handle; }
private:
HANDLE _handle = INVALID_HANDLE_VALUE;
std::function<void(HANDLE)> _close;
};
// Possibly refactor to share code with UnixTimevalToFileTime in c_time.c
OCSYNC_EXPORT void UnixTimeToFiletime(time_t t, FILETIME *filetime);
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);
class OCSYNC_EXPORT NtfsPermissionLookupRAII
{
public:
/**
* NTFS permissions lookup is disabled by default for performance reasons
* Enable it and disable it again once we leave the scope
* https://doc.qt.io/Qt-5/qfileinfo.html#ntfs-permissions
*/
NtfsPermissionLookupRAII();
~NtfsPermissionLookupRAII();
private:
Q_DISABLE_COPY(NtfsPermissionLookupRAII);
};
OCSYNC_EXPORT void printWindowsDebugMessage(const QString &s);
}
}