mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-26 22:03:24 +08:00
Fixed win32 config saving, keyboard mapping, and AltGr bugs.
Made extensive changes to the launcher to provide more control over setting up auto-start and it now saves configuration to the user's documents directory if auto-starting at login and saves to the system directory if auto-starting at boot. Replaced MapVirtualKey() with table lookup to work around that function's lack of support for extended keyboard scan codes. Added first cut at support for AltGr.
This commit is contained in:
@@ -38,14 +38,15 @@ CUnixPlatform::~CUnixPlatform()
|
||||
}
|
||||
|
||||
bool
|
||||
CUnixPlatform::installDaemon(const char*, const char*, const char*, const char*)
|
||||
CUnixPlatform::installDaemon(const char*, const char*,
|
||||
const char*, const char*, bool)
|
||||
{
|
||||
// daemons don't require special installation
|
||||
return true;
|
||||
}
|
||||
|
||||
CUnixPlatform::EResult
|
||||
CUnixPlatform::uninstallDaemon(const char*)
|
||||
CUnixPlatform::uninstallDaemon(const char*, bool)
|
||||
{
|
||||
// daemons don't require special installation
|
||||
return kSuccess;
|
||||
@@ -106,6 +107,18 @@ CUnixPlatform::installDaemonLogger(const char* name)
|
||||
CLog::setOutputter(&CUnixPlatform::deamonLogger);
|
||||
}
|
||||
|
||||
bool
|
||||
CUnixPlatform::canInstallDaemon(const char*, bool) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
CUnixPlatform::isDaemonInstalled(const char*, bool) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const char*
|
||||
CUnixPlatform::getBasename(const char* pathname) const
|
||||
{
|
||||
|
||||
@@ -27,10 +27,15 @@ public:
|
||||
virtual bool installDaemon(const char* name,
|
||||
const char* description,
|
||||
const char* pathname,
|
||||
const char* commandLine);
|
||||
virtual EResult uninstallDaemon(const char* name);
|
||||
const char* commandLine,
|
||||
bool allUsers);
|
||||
virtual EResult uninstallDaemon(const char* name, bool allUsers);
|
||||
virtual int daemonize(const char* name, DaemonFunc);
|
||||
virtual void installDaemonLogger(const char* name);
|
||||
virtual bool canInstallDaemon(const char* name,
|
||||
bool allUsers) const;
|
||||
virtual bool isDaemonInstalled(const char* name,
|
||||
bool allUsers) const;
|
||||
virtual const char* getBasename(const char* pathname) const;
|
||||
virtual CString getUserDirectory() const;
|
||||
virtual CString getSystemDirectory() const;
|
||||
|
||||
@@ -94,14 +94,16 @@ CWin32Platform::setStatusError(SERVICE_STATUS_HANDLE handle, DWORD error)
|
||||
|
||||
bool
|
||||
CWin32Platform::installDaemon(const char* name, const char* description,
|
||||
const char* pathname, const char* commandLine)
|
||||
const char* pathname, const char* commandLine, bool allUsers)
|
||||
{
|
||||
// windows 95 family services
|
||||
if (isWindows95Family()) {
|
||||
// if not for all users then use the user's autostart registry.
|
||||
// key. if windows 95 family then use windows 95 services key.
|
||||
if (!allUsers || isWindows95Family()) {
|
||||
// open registry
|
||||
HKEY key = open95ServicesKey();
|
||||
HKEY key = isWindows95Family() ? open95ServicesKey() :
|
||||
openUserStartupKey();
|
||||
if (key == NULL) {
|
||||
log((CLOG_ERR "cannot open RunServices registry key", GetLastError()));
|
||||
log((CLOG_ERR "cannot open registry key", GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -152,6 +154,8 @@ CWin32Platform::installDaemon(const char* name, const char* description,
|
||||
CloseServiceHandle(mgr);
|
||||
}
|
||||
else {
|
||||
// FIXME -- handle ERROR_SERVICE_EXISTS
|
||||
|
||||
log((CLOG_ERR "CreateService failed with %d", GetLastError()));
|
||||
CloseServiceHandle(mgr);
|
||||
return false;
|
||||
@@ -162,7 +166,7 @@ CWin32Platform::installDaemon(const char* name, const char* description,
|
||||
key = openKey(key, name);
|
||||
if (key == NULL) {
|
||||
// can't open key
|
||||
uninstallDaemon(name);
|
||||
uninstallDaemon(name, allUsers);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -173,7 +177,7 @@ CWin32Platform::installDaemon(const char* name, const char* description,
|
||||
key = openKey(key, "Parameters");
|
||||
if (key == NULL) {
|
||||
// can't open key
|
||||
uninstallDaemon(name);
|
||||
uninstallDaemon(name, allUsers);
|
||||
return false;
|
||||
}
|
||||
setValue(key, "CommandLine", commandLine);
|
||||
@@ -186,14 +190,16 @@ CWin32Platform::installDaemon(const char* name, const char* description,
|
||||
}
|
||||
|
||||
IPlatform::EResult
|
||||
CWin32Platform::uninstallDaemon(const char* name)
|
||||
CWin32Platform::uninstallDaemon(const char* name, bool allUsers)
|
||||
{
|
||||
// windows 95 family services
|
||||
if (isWindows95Family()) {
|
||||
// if not for all users then use the user's autostart registry.
|
||||
// key. if windows 95 family then use windows 95 services key.
|
||||
if (!allUsers || isWindows95Family()) {
|
||||
// open registry
|
||||
HKEY key = open95ServicesKey();
|
||||
HKEY key = isWindows95Family() ? open95ServicesKey() :
|
||||
openUserStartupKey();
|
||||
if (key == NULL) {
|
||||
log((CLOG_ERR "cannot open RunServices registry key", GetLastError()));
|
||||
log((CLOG_ERR "cannot open registry key", GetLastError()));
|
||||
return kAlready;
|
||||
}
|
||||
|
||||
@@ -334,6 +340,91 @@ CWin32Platform::installDaemonLogger(const char* name)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
CWin32Platform::canInstallDaemon(const char* name, bool allUsers) const
|
||||
{
|
||||
// if not for all users then use the user's autostart registry.
|
||||
// key. if windows 95 family then use windows 95 services key.
|
||||
if (!allUsers || isWindows95Family()) {
|
||||
// check if we can open the registry key
|
||||
HKEY key = isWindows95Family() ? open95ServicesKey() :
|
||||
openUserStartupKey();
|
||||
closeKey(key);
|
||||
return (key != NULL);
|
||||
}
|
||||
|
||||
// windows NT family services
|
||||
else {
|
||||
// check if we can open service manager for write
|
||||
SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_WRITE);
|
||||
if (mgr == NULL) {
|
||||
return false;
|
||||
}
|
||||
CloseServiceHandle(mgr);
|
||||
|
||||
// check if we can open the registry key for this service
|
||||
HKEY key = openNTServicesKey();
|
||||
key = openKey(key, name);
|
||||
key = openKey(key, "Parameters");
|
||||
closeKey(key);
|
||||
|
||||
return (key != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
CWin32Platform::isDaemonInstalled(const char* name, bool allUsers) const
|
||||
{
|
||||
// if not for all users then use the user's autostart registry.
|
||||
// key. if windows 95 family then use windows 95 services key.
|
||||
if (!allUsers || isWindows95Family()) {
|
||||
// check if we can open the registry key
|
||||
HKEY key = isWindows95Family() ? open95ServicesKey() :
|
||||
openUserStartupKey();
|
||||
if (key == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check for entry
|
||||
const bool installed = !readValueString(key, name).empty();
|
||||
|
||||
// clean up
|
||||
closeKey(key);
|
||||
|
||||
return installed;
|
||||
}
|
||||
|
||||
// windows NT family services
|
||||
else {
|
||||
// check parameters for this service
|
||||
HKEY key = openNTServicesKey();
|
||||
key = openKey(key, name);
|
||||
key = openKey(key, "Parameters");
|
||||
if (key != NULL) {
|
||||
const bool installed = !readValueString(key, "CommandLine").empty();
|
||||
closeKey(key);
|
||||
if (!installed) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// open service manager
|
||||
SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_READ);
|
||||
if (mgr == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// open the service
|
||||
SC_HANDLE service = OpenService(mgr, name, GENERIC_READ);
|
||||
|
||||
// clean up
|
||||
CloseServiceHandle(service);
|
||||
CloseServiceHandle(mgr);
|
||||
|
||||
return (service != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
CWin32Platform::getBasename(const char* pathname) const
|
||||
{
|
||||
@@ -436,6 +527,11 @@ CWin32Platform::addPathComponent(const CString& prefix,
|
||||
HKEY
|
||||
CWin32Platform::openKey(HKEY key, const char* keyName)
|
||||
{
|
||||
// ignore if parent is NULL
|
||||
if (key == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// open next key
|
||||
HKEY newKey;
|
||||
LONG result = RegOpenKeyEx(key, keyName, 0,
|
||||
@@ -555,6 +651,21 @@ CWin32Platform::open95ServicesKey()
|
||||
return openKey(HKEY_LOCAL_MACHINE, s_keyNames);
|
||||
}
|
||||
|
||||
HKEY
|
||||
CWin32Platform::openUserStartupKey()
|
||||
{
|
||||
static const char* s_keyNames[] = {
|
||||
_T("Software"),
|
||||
_T("Microsoft"),
|
||||
_T("Windows"),
|
||||
_T("CurrentVersion"),
|
||||
_T("Run"),
|
||||
NULL
|
||||
};
|
||||
|
||||
return openKey(HKEY_CURRENT_USER, s_keyNames);
|
||||
}
|
||||
|
||||
int
|
||||
CWin32Platform::runDaemon(RunFunc run, StopFunc stop)
|
||||
{
|
||||
|
||||
@@ -71,10 +71,15 @@ public:
|
||||
virtual bool installDaemon(const char* name,
|
||||
const char* description,
|
||||
const char* pathname,
|
||||
const char* commandLine);
|
||||
virtual EResult uninstallDaemon(const char* name);
|
||||
const char* commandLine,
|
||||
bool allUsers);
|
||||
virtual EResult uninstallDaemon(const char* name, bool allUsers);
|
||||
virtual int daemonize(const char* name, DaemonFunc);
|
||||
virtual void installDaemonLogger(const char* name);
|
||||
virtual bool canInstallDaemon(const char* name,
|
||||
bool allUsers) const;
|
||||
virtual bool isDaemonInstalled(const char* name,
|
||||
bool allUsers) const;
|
||||
virtual const char* getBasename(const char* pathname) const;
|
||||
virtual CString getUserDirectory() const;
|
||||
virtual CString getSystemDirectory() const;
|
||||
@@ -93,6 +98,7 @@ private:
|
||||
static CString readValueString(HKEY, const char* name);
|
||||
static HKEY openNTServicesKey();
|
||||
static HKEY open95ServicesKey();
|
||||
static HKEY openUserStartupKey();
|
||||
|
||||
void serviceMain(DWORD, LPTSTR*);
|
||||
static void WINAPI serviceMainEntry(DWORD, LPTSTR*);
|
||||
|
||||
@@ -43,18 +43,22 @@ public:
|
||||
system and \c description is a short human readable description of
|
||||
the daemon. \c pathname is the path to the daemon executable.
|
||||
\c commandLine should \b not include the name of program as the
|
||||
first argument.
|
||||
first argument. If \c allUsers is true then the daemon will be
|
||||
installed to start at boot time, otherwise it will be installed to
|
||||
start when the current user logs in.
|
||||
*/
|
||||
// FIXME -- throw on error? will get better error messages that way.
|
||||
virtual bool installDaemon(const char* name,
|
||||
const char* description,
|
||||
const char* pathname,
|
||||
const char* commandLine) = 0;
|
||||
const char* commandLine,
|
||||
bool allUsers) = 0;
|
||||
|
||||
//! Uninstall daemon
|
||||
/*!
|
||||
Uninstall a daemon.
|
||||
*/
|
||||
virtual EResult uninstallDaemon(const char* name) = 0;
|
||||
virtual EResult uninstallDaemon(const char* name, bool allUsers) = 0;
|
||||
|
||||
//! Daemonize the process
|
||||
/*!
|
||||
@@ -91,6 +95,24 @@ public:
|
||||
//! @name accessors
|
||||
//@{
|
||||
|
||||
//! Check if user has permission to install the daemon
|
||||
/*!
|
||||
Returns true iff the caller has permission to install or
|
||||
uninstall the daemon. Note that even if this method returns
|
||||
true it's possible that installing/uninstalling the service
|
||||
may still fail. This method ignores whether or not the
|
||||
service is already installed.
|
||||
*/
|
||||
virtual bool canInstallDaemon(const char* name,
|
||||
bool allUsers) const = 0;
|
||||
|
||||
//! Check if the daemon is installed
|
||||
/*!
|
||||
Returns true iff the daemon is installed.
|
||||
*/
|
||||
virtual bool isDaemonInstalled(const char* name,
|
||||
bool allUsers) const = 0;
|
||||
|
||||
//! Extract base name
|
||||
/*!
|
||||
Find the base name in the given \c pathname.
|
||||
|
||||
Reference in New Issue
Block a user