6#include "private/qlockfile_p.h"
7#include "private/qfilesystementry_p.h"
11#include "QtCore/qfileinfo.h"
12#include "QtCore/qdatetime.h"
13#include "QtCore/qdebug.h"
14#include "QtCore/qthread.h"
20 WIN32_FILE_ATTRIBUTE_DATA
data;
21 return GetFileAttributesEx(
fileName, GetFileExInfoStandard, &
data);
32 const DWORD dwShareMode = FILE_SHARE_READ;
33 SECURITY_ATTRIBUTES securityAtts = {
sizeof(SECURITY_ATTRIBUTES), NULL, FALSE };
34 HANDLE fh = CreateFile((
const wchar_t*)fileEntry.nativeFilePath().utf16(),
35 GENERIC_READ | GENERIC_WRITE,
39 FILE_ATTRIBUTE_NORMAL,
41 if (fh == INVALID_HANDLE_VALUE) {
42 const DWORD lastError = GetLastError();
44 case ERROR_SHARING_VIOLATION:
45 case ERROR_ALREADY_EXISTS:
46 case ERROR_FILE_EXISTS:
48 case ERROR_ACCESS_DENIED:
51 return fileExists((
const wchar_t*)fileEntry.nativeFilePath().utf16())
78 HANDLE procHandle = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
84 if (!::GetExitCodeProcess(procHandle, &exitCode))
86 ::CloseHandle(procHandle);
87 if (exitCode != STILL_ACTIVE)
91 if (!processName.
isEmpty() && processName != appname)
99 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, DWORD(pid));
104 const DWORD
length = GetModuleFileNameExW(hProcess, NULL,
buf,
sizeof(
buf) /
sizeof(
wchar_t));
105 CloseHandle(hProcess);
109 int i =
name.lastIndexOf(u
'\\');
111 name.remove(0,
i + 1);
112 i =
name.lastIndexOf(u
'.');
123 CloseHandle(
d->fileHandle);
125 static const int maxAttempts = 500;
130 if (attempts == maxAttempts) {
131 qWarning() <<
"Could not remove our own lock file" <<
d->fileName
132 <<
". Either other users of the lock file are reading it constantly for 500 ms, "
133 "or we (no longer) have permissions to delete the file";
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
bool remove()
Removes the file specified by fileName().
QLockFile::LockError tryLock_sys()
static bool isProcessRunning(qint64 pid, const QString &appname)
static Q_CORE_EXPORT QString processNameByPid(qint64 pid)
QByteArray lockFileContents() const
LockError
This enum describes the result of the last call to lock() or tryLock().
void unlock()
Releases the lock, by deleting the lock file.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
static void msleep(unsigned long)
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
static QT_BEGIN_NAMESPACE bool fileExists(const wchar_t *fileName)
GLenum GLsizei GLuint GLint * bytesWritten
GLenum GLuint GLenum GLsizei length
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
unsigned long long quint64