buid: replace NIH SYSAPI_WIN32 with Q_OS_WIN

This commit is contained in:
sithlord48
2026-02-27 22:47:09 -05:00
committed by Chris Rizzitello
parent fce1a37e97
commit f2a54f4af0
13 changed files with 33 additions and 41 deletions

View File

@ -103,7 +103,7 @@ set(REQUIRED_LIBPORTAL_VERSION 0.9.1)
set(REQUIRED_QT_VERSION 6.7.0) set(REQUIRED_QT_VERSION 6.7.0)
if (WIN32) if (WIN32)
add_definitions(-DSYSAPI_WIN32 -DWINAPI_MSWINDOWS) add_definitions(-DWINAPI_MSWINDOWS)
# VSCMD_ARG_TGT_ARCH is set on CI # VSCMD_ARG_TGT_ARCH is set on CI
if ("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "") if ("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "")
# NOT on CI # NOT on CI

View File

@ -16,7 +16,7 @@
#include "deskflow/ClientApp.h" #include "deskflow/ClientApp.h"
#include "deskflow/ServerApp.h" #include "deskflow/ServerApp.h"
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
#include "arch/win32/ArchMiscWindows.h" #include "arch/win32/ArchMiscWindows.h"
#include <QCoreApplication> #include <QCoreApplication>
#endif #endif
@ -32,7 +32,7 @@ void showHelp(const CoreArgParser &parser)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
// HACK to make sure settings gets the correct qApp path // HACK to make sure settings gets the correct qApp path
QCoreApplication m(argc, argv); QCoreApplication m(argc, argv);
m.deleteLater(); m.deleteLater();

View File

@ -15,8 +15,7 @@
#include "common/Settings.h" #include "common/Settings.h"
#include "deskflow/ipc/DaemonIpcServer.h" #include "deskflow/ipc/DaemonIpcServer.h"
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
#include "arch/win32/ArchDaemonWindows.h" #include "arch/win32/ArchDaemonWindows.h"
#include "deskflow/Screen.h" #include "deskflow/Screen.h"
#include "platform/MSWindowsDebugOutputter.h" #include "platform/MSWindowsDebugOutputter.h"
@ -64,7 +63,7 @@ void DaemonApp::applyWatchdogCommand() const
{ {
LOG_DEBUG("applying watchdog command"); LOG_DEBUG("applying watchdog command");
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
m_pWatchdog->setProcessConfig(m_command, m_elevate); m_pWatchdog->setProcessConfig(m_command, m_elevate);
#else #else
LOG_ERR("applying watchdog command not implemented on this platform"); LOG_ERR("applying watchdog command not implemented on this platform");
@ -78,7 +77,7 @@ void DaemonApp::clearWatchdogCommand()
// Clear the setting to prevent it from being next time the daemon starts. // Clear the setting to prevent it from being next time the daemon starts.
setCommand(""); setCommand("");
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
m_pWatchdog->setProcessConfig("", false); m_pWatchdog->setProcessConfig("", false);
#else #else
LOG_ERR("clearing watchdog command not implemented on this platform"); LOG_ERR("clearing watchdog command not implemented on this platform");
@ -137,7 +136,7 @@ void DaemonApp::run(QThread &daemonThread)
LOG_DEBUG("daemon thread finished"); LOG_DEBUG("daemon thread finished");
}); });
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
m_pWatchdog = std::make_unique<MSWindowsWatchdog>(m_foreground, *m_pFileLogOutputter); m_pWatchdog = std::make_unique<MSWindowsWatchdog>(m_foreground, *m_pFileLogOutputter);
auto command = Settings::value(Settings::Daemon::Command).toString().toStdString(); auto command = Settings::value(Settings::Daemon::Command).toString().toStdString();
@ -154,7 +153,7 @@ void DaemonApp::run(QThread &daemonThread)
int DaemonApp::daemonLoop() int DaemonApp::daemonLoop()
{ {
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
// Runs the daemon through the Windows service controller, which controls the program lifecycle. // Runs the daemon through the Windows service controller, which controls the program lifecycle.
return ArchDaemonWindows::runDaemon([this]() { return mainLoop(); }); return ArchDaemonWindows::runDaemon([this]() { return mainLoop(); });
#else #else
@ -164,7 +163,7 @@ int DaemonApp::daemonLoop()
int DaemonApp::mainLoop() int DaemonApp::mainLoop()
{ {
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
if (m_pWatchdog == nullptr) { if (m_pWatchdog == nullptr) {
LOG_ERR("watchdog not initialized"); LOG_ERR("watchdog not initialized");
return s_exitFailed; return s_exitFailed;
@ -173,7 +172,7 @@ int DaemonApp::mainLoop()
#endif #endif
try { try {
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
// Install the platform event queue to handle service stop events. // Install the platform event queue to handle service stop events.
// This must be done on the same thread as the event loop, otherwise the service stop // This must be done on the same thread as the event loop, otherwise the service stop
// request will not add the quit event to the event queue, and the service won't stop. // request will not add the quit event to the event queue, and the service won't stop.
@ -193,7 +192,7 @@ int DaemonApp::mainLoop()
LOG_INFO("daemon is stopping"); LOG_INFO("daemon is stopping");
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
try { try {
LOG_DEBUG("stopping process watchdog"); LOG_DEBUG("stopping process watchdog");
m_pWatchdog->stop(); m_pWatchdog->stop();
@ -221,7 +220,7 @@ void DaemonApp::setForeground()
void DaemonApp::initLogging() void DaemonApp::initLogging()
{ {
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
if (!m_foreground) { if (!m_foreground) {
// Only use MS debug outputter when the process is daemonized, since stdout won't be accessible // Only use MS debug outputter when the process is daemonized, since stdout won't be accessible
// in that case, but is accessible when running in the foreground. // in that case, but is accessible when running in the foreground.
@ -235,7 +234,7 @@ void DaemonApp::initLogging()
void DaemonApp::showConsole() void DaemonApp::showConsole()
{ {
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
// The daemon bin is compiled using the Win32 subsystem which works best for Windows services, // The daemon bin is compiled using the Win32 subsystem which works best for Windows services,
// so when running as a foreground process we need to allocate a console (or we won't see output). // so when running as a foreground process we need to allocate a console (or we won't see output).
// It is important to do this inside the arg check loop so that we can attach console ahead // It is important to do this inside the arg check loop so that we can attach console ahead

View File

@ -21,7 +21,7 @@ namespace deskflow::core::ipc {
class DaemonIpcServer; class DaemonIpcServer;
} }
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
class MSWindowsWatchdog; class MSWindowsWatchdog;
#endif #endif
@ -56,7 +56,7 @@ private:
static void showConsole(); static void showConsole();
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
std::unique_ptr<MSWindowsWatchdog> m_pWatchdog; std::unique_ptr<MSWindowsWatchdog> m_pWatchdog;
#endif #endif

View File

@ -15,13 +15,11 @@
#include "common/VersionInfo.h" #include "common/VersionInfo.h"
#include "deskflow/ipc/DaemonIpcServer.h" #include "deskflow/ipc/DaemonIpcServer.h"
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
#include "arch/win32/ArchMiscWindows.h" #include "arch/win32/ArchMiscWindows.h"
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
#endif #endif
#include <QCommandLineParser> #include <QCommandLineParser>
@ -34,7 +32,7 @@ void handleError(const char *message = "Unrecognized error.");
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
ArchMiscWindows::guardRuntimeVersion(); ArchMiscWindows::guardRuntimeVersion();
// Save window instance for later use, e.g. `GetModuleFileName` which is used when installing the daemon. // Save window instance for later use, e.g. `GetModuleFileName` which is used when installing the daemon.
@ -85,7 +83,7 @@ int main(int argc, char **argv)
try { try {
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
// Show warning if not running as admin as daemon will behave differently. // Show warning if not running as admin as daemon will behave differently.
if (!ArchMiscWindows::isProcessElevated()) { if (!ArchMiscWindows::isProcessElevated()) {
LOG_WARN("not running as admin, some features may not work"); LOG_WARN("not running as admin, some features may not work");
@ -115,8 +113,7 @@ int main(int argc, char **argv)
} }
} }
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
// Win32 subsystem entry point (simply forwards to main). // Win32 subsystem entry point (simply forwards to main).
// We need this because using regular main under the Win32 subsystem results in empty args. // We need this because using regular main under the Win32 subsystem results in empty args.
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
@ -131,7 +128,7 @@ void handleError(const char *message)
// Always print error to stdout in case run as CLI program. // Always print error to stdout in case run as CLI program.
LOG_ERR("%s", message); LOG_ERR("%s", message);
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
// Show a message box for when run from MSI in Win32 subsystem. // Show a message box for when run from MSI in Win32 subsystem.
MessageBoxA(nullptr, message, "Deskflow daemon error", MB_OK | MB_ICONERROR); MessageBoxA(nullptr, message, "Deskflow daemon error", MB_OK | MB_ICONERROR);
#endif #endif

View File

@ -10,7 +10,7 @@
#include <thread> #include <thread>
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
#include "arch/win32/ArchMiscWindows.h" #include "arch/win32/ArchMiscWindows.h"
#endif #endif
@ -26,7 +26,7 @@ Arch::Arch()
s_instance = this; s_instance = this;
} }
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
void Arch::init() void Arch::init()
{ {
ARCH_NETWORK::init(); ARCH_NETWORK::init();

View File

@ -5,7 +5,7 @@
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/ */
#include <QtSystemDetection>
// Consider whether or not to use either encapsulation (as below) // Consider whether or not to use either encapsulation (as below)
// or inheritance (as it is now) for the ARCH stuff. // or inheritance (as it is now) for the ARCH stuff.
// //
@ -25,20 +25,16 @@
#pragma once #pragma once
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
#include "arch/win32/ArchDaemonWindows.h" #include "arch/win32/ArchDaemonWindows.h"
#include "arch/win32/ArchLogWindows.h" #include "arch/win32/ArchLogWindows.h"
#include "arch/win32/ArchMultithreadWindows.h" #include "arch/win32/ArchMultithreadWindows.h"
#include "arch/win32/ArchNetworkWinsock.h" #include "arch/win32/ArchNetworkWinsock.h"
#else #else
#include "arch/ArchDaemonNone.h" #include "arch/ArchDaemonNone.h"
#include "arch/unix/ArchLogUnix.h" #include "arch/unix/ArchLogUnix.h"
#include "arch/unix/ArchMultithreadPosix.h" #include "arch/unix/ArchMultithreadPosix.h"
#include "arch/unix/ArchNetworkBSD.h" #include "arch/unix/ArchNetworkBSD.h"
#endif #endif
/*! /*!
@ -63,7 +59,7 @@ public:
Arch(); Arch();
~Arch() override = default; ~Arch() override = default;
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
//! Call init on other arch classes. //! Call init on other arch classes.
/*! /*!
Some arch classes depend on others to exist first. When init is called Some arch classes depend on others to exist first. When init is called

View File

@ -16,7 +16,7 @@
#include "common/Settings.h" #include "common/Settings.h"
#include "deskflow/DeskflowException.h" #include "deskflow/DeskflowException.h"
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#endif #endif

View File

@ -13,7 +13,7 @@
#include "deskflow/IApp.h" #include "deskflow/IApp.h"
#include "net/SocketMultiplexer.h" #include "net/SocketMultiplexer.h"
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
#include "deskflow/win32/AppUtilWindows.h" #include "deskflow/win32/AppUtilWindows.h"
#else #else
#include "deskflow/unix/AppUtilUnix.h" #include "deskflow/unix/AppUtilUnix.h"

View File

@ -116,7 +116,7 @@ bool ServerApp::loadConfig(const QString &filename)
try { try {
// load configuration // load configuration
LOG_DEBUG("opening configuration \"%s\"", path.c_str()); LOG_DEBUG("opening configuration \"%s\"", path.c_str());
#ifdef SYSAPI_WIN32 #if defined(Q_OS_WIN)
std::ifstream configStream(filename.toStdWString()); std::ifstream configStream(filename.toStdWString());
#else #else
std::ifstream configStream(path); std::ifstream configStream(path);

View File

@ -658,7 +658,7 @@ ISocketMultiplexerJob *SecureSocket::serviceConnect(ISocketMultiplexerJob *const
Lock lock(&getMutex()); Lock lock(&getMutex());
int status = 0; int status = 0;
#ifdef SYSAPI_WIN32 #if defined(Q_OS_WIN)
status = secureConnect(static_cast<int>(getSocket()->m_socket)); status = secureConnect(static_cast<int>(getSocket()->m_socket));
#else #else
status = secureConnect(getSocket()->m_fd); status = secureConnect(getSocket()->m_fd);
@ -686,7 +686,7 @@ ISocketMultiplexerJob *SecureSocket::serviceAccept(ISocketMultiplexerJob *const,
Lock lock(&getMutex()); Lock lock(&getMutex());
int status = 0; int status = 0;
#ifdef SYSAPI_WIN32 #if defined(Q_OS_WIN)
status = secureAccept(static_cast<int>(getSocket()->m_socket)); status = secureAccept(static_cast<int>(getSocket()->m_socket));
#else #else
status = secureAccept(getSocket()->m_fd); status = secureAccept(getSocket()->m_fd);

View File

@ -92,7 +92,7 @@ void generatePemSelfSignedCert(const QString &path, int keyLength)
X509_sign(cert, privateKey, EVP_sha256()); X509_sign(cert, privateKey, EVP_sha256());
const std::filesystem::path fsPath = path.toStdString(); const std::filesystem::path fsPath = path.toStdString();
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
auto fp = _wfopen(fsPath.native().c_str(), L"w"); auto fp = _wfopen(fsPath.native().c_str(), L"w");
#else #else
auto fp = std::fopen(fsPath.native().c_str(), "w"); auto fp = std::fopen(fsPath.native().c_str(), "w");

View File

@ -9,7 +9,7 @@
#include "base/Log.h" #include "base/Log.h"
#include "unittests/legacytests/shared/ExitTimeout.h" #include "unittests/legacytests/shared/ExitTimeout.h"
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
#include "arch/win32/ArchMiscWindows.h" #include "arch/win32/ArchMiscWindows.h"
#endif #endif
@ -23,7 +23,7 @@ int main(int argc, char **argv)
{ {
ExitTimeout exitTimeout(1, "Unit tests"); ExitTimeout exitTimeout(1, "Unit tests");
#if SYSAPI_WIN32 #if defined(Q_OS_WIN)
// HACK: shouldn't be needed, but logging fails without this. // HACK: shouldn't be needed, but logging fails without this.
ArchMiscWindows::setInstanceWin32(GetModuleHandle(nullptr)); ArchMiscWindows::setInstanceWin32(GetModuleHandle(nullptr));
#endif #endif