2020-07-28 00:53:29 +08:00
|
|
|
#pragma once
|
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "wil/resource.h"
|
|
|
|
#include <lmcons.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2021-04-09 01:42:46 +08:00
|
|
|
constexpr inline wchar_t POWERTOYS_MSI_MUTEX_NAME[] = L"Local\\PowerToys_Runner_MSI_InstanceMutex";
|
|
|
|
constexpr inline wchar_t POWERTOYS_BOOTSTRAPPER_MUTEX_NAME[] = L"Local\\PowerToys_Bootstrapper_InstanceMutex";
|
2020-07-28 00:53:29 +08:00
|
|
|
}
|
|
|
|
|
2021-04-09 01:42:46 +08:00
|
|
|
inline wil::unique_mutex_nothrow createAppMutex(const std::wstring& mutexName)
|
2020-07-28 00:53:29 +08:00
|
|
|
{
|
|
|
|
wil::unique_mutex_nothrow result{ CreateMutexW(nullptr, TRUE, mutexName.c_str()) };
|
|
|
|
|
|
|
|
return GetLastError() == ERROR_ALREADY_EXISTS ? wil::unique_mutex_nothrow{} : std::move(result);
|
|
|
|
}
|