diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b686e6e4..0f1db8c31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ set(REQUIRED_LIBPORTAL_VERSION 0.9.1) set(REQUIRED_QT_VERSION 6.7.0) if (WIN32) - add_definitions(-DSYSAPI_WIN32 -DWINAPI_MSWINDOWS) + add_definitions(-DWINAPI_MSWINDOWS) # VSCMD_ARG_TGT_ARCH is set on CI if ("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "") # NOT on CI diff --git a/src/apps/deskflow-core/deskflow-core.cpp b/src/apps/deskflow-core/deskflow-core.cpp index f4601b1c0..052b380e8 100644 --- a/src/apps/deskflow-core/deskflow-core.cpp +++ b/src/apps/deskflow-core/deskflow-core.cpp @@ -16,7 +16,7 @@ #include "deskflow/ClientApp.h" #include "deskflow/ServerApp.h" -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) #include "arch/win32/ArchMiscWindows.h" #include #endif @@ -32,7 +32,7 @@ void showHelp(const CoreArgParser &parser) int main(int argc, char **argv) { -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) // HACK to make sure settings gets the correct qApp path QCoreApplication m(argc, argv); m.deleteLater(); diff --git a/src/apps/deskflow-daemon/DaemonApp.cpp b/src/apps/deskflow-daemon/DaemonApp.cpp index a0e392e24..ce317a3cd 100644 --- a/src/apps/deskflow-daemon/DaemonApp.cpp +++ b/src/apps/deskflow-daemon/DaemonApp.cpp @@ -15,8 +15,7 @@ #include "common/Settings.h" #include "deskflow/ipc/DaemonIpcServer.h" -#if SYSAPI_WIN32 - +#if defined(Q_OS_WIN) #include "arch/win32/ArchDaemonWindows.h" #include "deskflow/Screen.h" #include "platform/MSWindowsDebugOutputter.h" @@ -64,7 +63,7 @@ void DaemonApp::applyWatchdogCommand() const { LOG_DEBUG("applying watchdog command"); -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) m_pWatchdog->setProcessConfig(m_command, m_elevate); #else 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. setCommand(""); -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) m_pWatchdog->setProcessConfig("", false); #else LOG_ERR("clearing watchdog command not implemented on this platform"); @@ -137,7 +136,7 @@ void DaemonApp::run(QThread &daemonThread) LOG_DEBUG("daemon thread finished"); }); -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) m_pWatchdog = std::make_unique(m_foreground, *m_pFileLogOutputter); auto command = Settings::value(Settings::Daemon::Command).toString().toStdString(); @@ -154,7 +153,7 @@ void DaemonApp::run(QThread &daemonThread) int DaemonApp::daemonLoop() { -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) // Runs the daemon through the Windows service controller, which controls the program lifecycle. return ArchDaemonWindows::runDaemon([this]() { return mainLoop(); }); #else @@ -164,7 +163,7 @@ int DaemonApp::daemonLoop() int DaemonApp::mainLoop() { -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) if (m_pWatchdog == nullptr) { LOG_ERR("watchdog not initialized"); return s_exitFailed; @@ -173,7 +172,7 @@ int DaemonApp::mainLoop() #endif try { -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) // 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 // 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"); -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) try { LOG_DEBUG("stopping process watchdog"); m_pWatchdog->stop(); @@ -221,7 +220,7 @@ void DaemonApp::setForeground() void DaemonApp::initLogging() { -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) if (!m_foreground) { // 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. @@ -235,7 +234,7 @@ void DaemonApp::initLogging() 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, // 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 diff --git a/src/apps/deskflow-daemon/DaemonApp.h b/src/apps/deskflow-daemon/DaemonApp.h index da18bb416..ca9a250fa 100644 --- a/src/apps/deskflow-daemon/DaemonApp.h +++ b/src/apps/deskflow-daemon/DaemonApp.h @@ -21,7 +21,7 @@ namespace deskflow::core::ipc { class DaemonIpcServer; } -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) class MSWindowsWatchdog; #endif @@ -56,7 +56,7 @@ private: static void showConsole(); -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) std::unique_ptr m_pWatchdog; #endif diff --git a/src/apps/deskflow-daemon/deskflow-daemon.cpp b/src/apps/deskflow-daemon/deskflow-daemon.cpp index 8d03f2084..ac0c0e513 100644 --- a/src/apps/deskflow-daemon/deskflow-daemon.cpp +++ b/src/apps/deskflow-daemon/deskflow-daemon.cpp @@ -15,13 +15,11 @@ #include "common/VersionInfo.h" #include "deskflow/ipc/DaemonIpcServer.h" -#if SYSAPI_WIN32 - +#if defined(Q_OS_WIN) #include "arch/win32/ArchMiscWindows.h" #define WIN32_LEAN_AND_MEAN #include - #endif #include @@ -34,7 +32,7 @@ void handleError(const char *message = "Unrecognized error."); int main(int argc, char **argv) { -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) ArchMiscWindows::guardRuntimeVersion(); // 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 { -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) // Show warning if not running as admin as daemon will behave differently. if (!ArchMiscWindows::isProcessElevated()) { 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). // We need this because using regular main under the Win32 subsystem results in empty args. 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. LOG_ERR("%s", message); -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) // Show a message box for when run from MSI in Win32 subsystem. MessageBoxA(nullptr, message, "Deskflow daemon error", MB_OK | MB_ICONERROR); #endif diff --git a/src/lib/arch/Arch.cpp b/src/lib/arch/Arch.cpp index 47319ce47..6544f9ebf 100644 --- a/src/lib/arch/Arch.cpp +++ b/src/lib/arch/Arch.cpp @@ -10,7 +10,7 @@ #include -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) #include "arch/win32/ArchMiscWindows.h" #endif @@ -26,7 +26,7 @@ Arch::Arch() s_instance = this; } -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) void Arch::init() { ARCH_NETWORK::init(); diff --git a/src/lib/arch/Arch.h b/src/lib/arch/Arch.h index 6c88f177b..ddf24e896 100644 --- a/src/lib/arch/Arch.h +++ b/src/lib/arch/Arch.h @@ -5,7 +5,7 @@ * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception */ - +#include // Consider whether or not to use either encapsulation (as below) // or inheritance (as it is now) for the ARCH stuff. // @@ -25,20 +25,16 @@ #pragma once -#if SYSAPI_WIN32 - +#if defined(Q_OS_WIN) #include "arch/win32/ArchDaemonWindows.h" #include "arch/win32/ArchLogWindows.h" #include "arch/win32/ArchMultithreadWindows.h" #include "arch/win32/ArchNetworkWinsock.h" - #else - #include "arch/ArchDaemonNone.h" #include "arch/unix/ArchLogUnix.h" #include "arch/unix/ArchMultithreadPosix.h" #include "arch/unix/ArchNetworkBSD.h" - #endif /*! @@ -63,7 +59,7 @@ public: Arch(); ~Arch() override = default; -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) //! Call init on other arch classes. /*! Some arch classes depend on others to exist first. When init is called diff --git a/src/lib/deskflow/App.cpp b/src/lib/deskflow/App.cpp index ae430b417..dd5a89c13 100644 --- a/src/lib/deskflow/App.cpp +++ b/src/lib/deskflow/App.cpp @@ -16,7 +16,7 @@ #include "common/Settings.h" #include "deskflow/DeskflowException.h" -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) #include "base/IEventQueue.h" #endif diff --git a/src/lib/deskflow/App.h b/src/lib/deskflow/App.h index 18b138c8b..52baded3f 100644 --- a/src/lib/deskflow/App.h +++ b/src/lib/deskflow/App.h @@ -13,7 +13,7 @@ #include "deskflow/IApp.h" #include "net/SocketMultiplexer.h" -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) #include "deskflow/win32/AppUtilWindows.h" #else #include "deskflow/unix/AppUtilUnix.h" diff --git a/src/lib/deskflow/ServerApp.cpp b/src/lib/deskflow/ServerApp.cpp index c85cb3cea..ed4418ca6 100644 --- a/src/lib/deskflow/ServerApp.cpp +++ b/src/lib/deskflow/ServerApp.cpp @@ -116,7 +116,7 @@ bool ServerApp::loadConfig(const QString &filename) try { // load configuration LOG_DEBUG("opening configuration \"%s\"", path.c_str()); -#ifdef SYSAPI_WIN32 +#if defined(Q_OS_WIN) std::ifstream configStream(filename.toStdWString()); #else std::ifstream configStream(path); diff --git a/src/lib/net/SecureSocket.cpp b/src/lib/net/SecureSocket.cpp index 326074e4f..0b71b7a47 100644 --- a/src/lib/net/SecureSocket.cpp +++ b/src/lib/net/SecureSocket.cpp @@ -658,7 +658,7 @@ ISocketMultiplexerJob *SecureSocket::serviceConnect(ISocketMultiplexerJob *const Lock lock(&getMutex()); int status = 0; -#ifdef SYSAPI_WIN32 +#if defined(Q_OS_WIN) status = secureConnect(static_cast(getSocket()->m_socket)); #else status = secureConnect(getSocket()->m_fd); @@ -686,7 +686,7 @@ ISocketMultiplexerJob *SecureSocket::serviceAccept(ISocketMultiplexerJob *const, Lock lock(&getMutex()); int status = 0; -#ifdef SYSAPI_WIN32 +#if defined(Q_OS_WIN) status = secureAccept(static_cast(getSocket()->m_socket)); #else status = secureAccept(getSocket()->m_fd); diff --git a/src/lib/net/SecureUtils.cpp b/src/lib/net/SecureUtils.cpp index 65aa74803..bc820a723 100644 --- a/src/lib/net/SecureUtils.cpp +++ b/src/lib/net/SecureUtils.cpp @@ -92,7 +92,7 @@ void generatePemSelfSignedCert(const QString &path, int keyLength) X509_sign(cert, privateKey, EVP_sha256()); const std::filesystem::path fsPath = path.toStdString(); -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) auto fp = _wfopen(fsPath.native().c_str(), L"w"); #else auto fp = std::fopen(fsPath.native().c_str(), "w"); diff --git a/src/unittests/legacytests/legacytests/main.cpp b/src/unittests/legacytests/legacytests/main.cpp index e718bd638..cd311b26a 100644 --- a/src/unittests/legacytests/legacytests/main.cpp +++ b/src/unittests/legacytests/legacytests/main.cpp @@ -9,7 +9,7 @@ #include "base/Log.h" #include "unittests/legacytests/shared/ExitTimeout.h" -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) #include "arch/win32/ArchMiscWindows.h" #endif @@ -23,7 +23,7 @@ int main(int argc, char **argv) { ExitTimeout exitTimeout(1, "Unit tests"); -#if SYSAPI_WIN32 +#if defined(Q_OS_WIN) // HACK: shouldn't be needed, but logging fails without this. ArchMiscWindows::setInstanceWin32(GetModuleHandle(nullptr)); #endif