buid: replace NIH SYSAPI_WIN32 with Q_OS_WIN
This commit is contained in:
committed by
Chris Rizzitello
parent
fce1a37e97
commit
f2a54f4af0
@ -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
|
||||
|
||||
@ -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 <QCoreApplication>
|
||||
#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();
|
||||
|
||||
@ -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<MSWindowsWatchdog>(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
|
||||
|
||||
@ -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<MSWindowsWatchdog> m_pWatchdog;
|
||||
#endif
|
||||
|
||||
|
||||
@ -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 <Windows.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <QCommandLineParser>
|
||||
@ -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
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
#include <thread>
|
||||
|
||||
#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();
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include <QtSystemDetection>
|
||||
// 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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<int>(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<int>(getSocket()->m_socket));
|
||||
#else
|
||||
status = secureAccept(getSocket()->m_fd);
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user