blob: 61521a81cbff40f37c8659ce1b27385417599fc0 (
plain)
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
|
// Copyright 2005-2017 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
#include "mumble_pch.hpp"
#include "UserLockFile.h"
UserLockFile::UserLockFile(const QString &lockFilePath)
: m_handle(0)
, m_path(lockFilePath) {
}
UserLockFile::~UserLockFile() {
release();
}
QString UserLockFile::path() const {
return m_path;
}
bool UserLockFile::acquire() {
if (m_handle != 0) {
return false;
}
m_handle = CreateFile(
reinterpret_cast<const wchar_t *>(m_path.utf16()),
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_HIDDEN,
NULL
);
if (m_handle == INVALID_HANDLE_VALUE && GetLastError() == ERROR_SHARING_VIOLATION) {
return false;
}
return true;
}
void UserLockFile::release() {
if (m_handle != 0) {
CloseHandle(m_handle);
m_handle = 0;
}
}
|