Skip to content

Commit

Permalink
Allow for handling different daemon's dynamically at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Oct 15, 2023
1 parent 8e22ee6 commit 3f5a5ab
Show file tree
Hide file tree
Showing 16 changed files with 792 additions and 605 deletions.
18 changes: 4 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ set(TARGET_FP_VERSION_PREFIX 12.0)
# Handled by fetched libs, but set this here formally since they aren't part of the main project
option(BUILD_SHARED_LIBS "Build CLIFp with shared libraries" OFF)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(FP_PROXY_DEFAULT ON)
else()
set(FP_PROXY_DEFAULT OFF)
endif()

option(FP_PROXY "Configure CLIFp to work with an install that uses an FP Proxy Server" ${FP_PROXY_DEFAULT})

# C++
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -87,13 +79,11 @@ ob_fetch_qx(

# Fetch libfp (build and import from source)
include(OB/Fetchlibfp)
ob_fetch_libfp("bca00c48d37e9306a311bc83f74a7692e169afae")
ob_fetch_libfp("239658b41b43c700adc612a390d4602683df334b")

if(NOT FP_PROXY)
# Fetch QI-QMP (build and import from source)
include(OB/FetchQI-QMP)
ob_fetch_qi_qmp("v0.2.2")
endif()
# Fetch QI-QMP (build and import from source)
include(OB/FetchQI-QMP)
ob_fetch_qi_qmp("v0.2.2")

# Fetch QuaZip (build and import from source)
include(OB/FetchQuaZip)
Expand Down
33 changes: 7 additions & 26 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ set(CLIFP_SOURCE
tools/blockingprocessmanager.cpp
tools/deferredprocessmanager.h
tools/deferredprocessmanager.cpp
tools/mounter_proxy.h
tools/mounter_proxy.cpp
tools/mounter_qmp.h
tools/mounter_qmp.cpp
tools/mounter_router.h
tools/mounter_router.cpp
frontend/statusrelay.h
frontend/statusrelay.cpp
controller.h
Expand All @@ -67,6 +73,7 @@ set(CLIFP_LINKS
Fp::Fp
QuaZip::QuaZip
magic_enum::magic_enum
QI-QMP::Qmpi
)

if(CMAKE_SYSTEM_NAME STREQUAL Windows)
Expand Down Expand Up @@ -98,27 +105,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
)
endif()

# FP Proxy specific changes
if(FP_PROXY)
list(APPEND CLIFP_SOURCE
tools/mounter_proxy.h
tools/mounter_proxy.cpp
)
list(APPEND CLIFP_DEFINITIONS
PRIVATE
"FP_PROXY"
)
else()
list(APPEND CLIFP_SOURCE
tools/mounter.h
tools/mounter.cpp
)
list(APPEND CLIFP_LINKS
PRIVATE
QI-QMP::Qmpi
)
endif()

# Add via ob standard executable
include(OB/Executable)
ob_add_standard_executable(${APP_TARGET_NAME}
Expand All @@ -132,11 +118,6 @@ ob_add_standard_executable(${APP_TARGET_NAME}
WIN32
)

# Add environment specific defines
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
target_compile_definitions(${APP_TARGET_NAME} PRIVATE "FP_PROXY_MOUNTER")
endif()

## Forward select project variables to C++ code
include(OB/CppVars)
ob_add_cpp_vars(${APP_TARGET_NAME}
Expand Down
65 changes: 33 additions & 32 deletions app/src/kernel/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ void Core::attachFlashpoint(std::unique_ptr<Fp::Install> flashpointInstall)
mFlashpointInstall = std::move(flashpointInstall);

// Note install details
QString dmns = QString(magic_enum::enum_flags_name(static_cast<Fp::KnownDaemon>(mFlashpointInstall->services().recognizedDaemons.toInt())).data());
logEvent(NAME, LOG_EVENT_RECOGNIZED_DAEMONS.arg(dmns));
logEvent(NAME, LOG_EVENT_OUTFITTED_DAEMON.arg(ENUM_NAME(mFlashpointInstall->outfittedDaemon())));

// Initialize child process env vars
QProcessEnvironment de = QProcessEnvironment::systemEnvironment();
Expand Down Expand Up @@ -425,21 +424,23 @@ CoreError Core::enqueueStartupTasks()
logEvent(NAME, LOG_EVENT_ENQ_START);

#ifdef __linux__
/* On Linux X11 Server needs to be temporarily be set to allow connections from root for docker
*
* TODO: It should be OK to skip this (and the corresponding shutdown task that reverses it),
* if docker isn't used, but leaving for now.
/* On Linux X11 Server needs to be temporarily be set to allow connections from root for docker,
* if it's in use
*/
TExec* xhostSet = new TExec(this);
xhostSet->setIdentifier(u"xhost Set"_s);
xhostSet->setStage(Task::Stage::Startup);
xhostSet->setExecutable(u"xhost"_s);
xhostSet->setDirectory(mFlashpointInstall->fullPath());
xhostSet->setParameters({u"+SI:localuser:root"_s});
xhostSet->setProcessType(TExec::ProcessType::Blocking);

mTaskQueue.push(xhostSet);
logTask(NAME, xhostSet);

if(mFlashpointInstall->outfittedDaemon() == Fp::Daemon::Docker)
{
TExec* xhostSet = new TExec(this);
xhostSet->setIdentifier(u"xhost Set"_s);
xhostSet->setStage(Task::Stage::Startup);
xhostSet->setExecutable(u"xhost"_s);
xhostSet->setDirectory(mFlashpointInstall->fullPath());
xhostSet->setParameters({u"+SI:localuser:root"_s});
xhostSet->setProcessType(TExec::ProcessType::Blocking);

mTaskQueue.push(xhostSet);
logTask(NAME, xhostSet);
}
#endif

// Get settings
Expand Down Expand Up @@ -503,7 +504,7 @@ CoreError Core::enqueueStartupTasks()

#ifdef __linux__
// On Linux the startup tasks take a while so make sure the docker image is actually running before proceeding
if(mFlashpointInstall->services().recognizedDaemons.testFlag(Fp::KnownDaemon::Docker))
if(mFlashpointInstall->outfittedDaemon() == Fp::Daemon::Docker)
{
TAwaitDocker* dockerWait = new TAwaitDocker(this);
dockerWait->setStage(Task::Stage::Startup);
Expand Down Expand Up @@ -551,17 +552,20 @@ void Core::enqueueShutdownTasks()
}

#ifdef __linux__
// Undo xhost permissions modifications
TExec* xhostClear = new TExec(this);
xhostClear->setIdentifier(u"xhost Clear"_s);
xhostClear->setStage(Task::Stage::Shutdown);
xhostClear->setExecutable(u"xhost"_s);
xhostClear->setDirectory(mFlashpointInstall->fullPath());
xhostClear->setParameters({"-SI:localuser:root"});
xhostClear->setProcessType(TExec::ProcessType::Blocking);

mTaskQueue.push(xhostClear);
logTask(NAME, xhostClear);
// Undo xhost permissions modifications related to docker
if(mFlashpointInstall->outfittedDaemon() == Fp::Daemon::Docker)
{
TExec* xhostClear = new TExec(this);
xhostClear->setIdentifier(u"xhost Clear"_s);
xhostClear->setStage(Task::Stage::Shutdown);
xhostClear->setExecutable(u"xhost"_s);
xhostClear->setDirectory(mFlashpointInstall->fullPath());
xhostClear->setParameters({"-SI:localuser:root"});
xhostClear->setProcessType(TExec::ProcessType::Blocking);

mTaskQueue.push(xhostClear);
logTask(NAME, xhostClear);
}
#endif
}

Expand Down Expand Up @@ -679,15 +683,12 @@ Qx::Error Core::enqueueDataPackTasks(const Fp::GameData& gameData)
{
logEvent(NAME, LOG_EVENT_DATA_PACK_NEEDS_MOUNT);

// Determine if QEMU is involved
bool qemuUsed = mFlashpointInstall->services().recognizedDaemons.testFlag(Fp::KnownDaemon::Qemu);

// Create task
TMount* mountTask = new TMount(this);
mountTask->setStage(Task::Stage::Auxiliary);
mountTask->setTitleId(gameData.gameId());
mountTask->setPath(packDestFolderPath + '/' + packFileName);
mountTask->setSkipQemu(!qemuUsed);
mountTask->setDaemon(mFlashpointInstall->outfittedDaemon());

mTaskQueue.push(mountTask);
logTask(NAME, mountTask);
Expand Down
2 changes: 1 addition & 1 deletion app/src/kernel/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Core : public QObject
static inline const QString LOG_EVENT_G_HELP_SHOWN = u"Displayed general help information"_s;
static inline const QString LOG_EVENT_VER_SHOWN = u"Displayed version information"_s;
static inline const QString LOG_EVENT_NOTIFCATION_LEVEL = u"Notification Level is: %1"_s;
static inline const QString LOG_EVENT_RECOGNIZED_DAEMONS = u"Recognized service daemons: %1"_s;
static inline const QString LOG_EVENT_OUTFITTED_DAEMON = u"Recognized daemon: %1"_s;
static inline const QString LOG_EVENT_ENQ_START = u"Enqueuing startup tasks..."_s;
static inline const QString LOG_EVENT_ENQ_STOP = u"Enqueuing shutdown tasks..."_s;
static inline const QString LOG_EVENT_ENQ_DATA_PACK = u"Enqueuing Data Pack tasks..."_s;
Expand Down
10 changes: 9 additions & 1 deletion app/src/kernel/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,15 @@ std::unique_ptr<Fp::Install> Driver::findFlashpointInstall()
// Attempt to instantiate
fpInstall = std::make_unique<Fp::Install>(currentDir.absolutePath());
if(fpInstall->isValid())
break;
{
if(fpInstall->outfittedDaemon() == Fp::Daemon::Unknown)
{
mCore->logError(NAME, Qx::GenericError(Qx::Warning, 12011, LOG_WARN_FP_UNRECOGNIZED_DAEMON));
fpInstall.reset();
}
else
break;
}
else
{
mCore->logError(NAME, fpInstall->error().setSeverity(Qx::Warning));
Expand Down
11 changes: 6 additions & 5 deletions app/src/kernel/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class QX_ERROR_TYPE(DriverError, "DriverError", 1201)
{
friend class Driver;
//-Class Enums-------------------------------------------------------------
//-Class Enums-------------------------------------------------------------
public:
enum Type
{
Expand All @@ -25,7 +25,7 @@ class QX_ERROR_TYPE(DriverError, "DriverError", 1201)
InvalidInstall = 3,
};

//-Class Variables-------------------------------------------------------------
//-Class Variables-------------------------------------------------------------
private:
static inline const QHash<Type, QString> ERR_STRINGS{
{NoError, u""_s},
Expand All @@ -34,16 +34,16 @@ class QX_ERROR_TYPE(DriverError, "DriverError", 1201)
{InvalidInstall, u"CLIFp does not appear to be deployed in a valid Flashpoint install"_s}
};

//-Instance Variables-------------------------------------------------------------
//-Instance Variables-------------------------------------------------------------
private:
Type mType;
QString mSpecific;

//-Constructor-------------------------------------------------------------
//-Constructor-------------------------------------------------------------
private:
DriverError(Type t = NoError, const QString& s = {});

//-Instance Functions-------------------------------------------------------------
//-Instance Functions-------------------------------------------------------------
public:
bool isValid() const;
Type type() const;
Expand Down Expand Up @@ -71,6 +71,7 @@ class Driver : public QObject
// Logging
static inline const QString LOG_EVENT_FLASHPOINT_SEARCH = u"Searching for Flashpoint root..."_s;
static inline const QString LOG_EVENT_FLASHPOINT_ROOT_CHECK = uR"(Checking if "%1" is flashpoint root)"_s;
static inline const QString LOG_WARN_FP_UNRECOGNIZED_DAEMON = "Flashpoint install does not contain a recognized daemon!";
static inline const QString LOG_EVENT_FLASHPOINT_LINK = uR"(Linked to Flashpoint install at: "%1")"_s;
static inline const QString LOG_EVENT_TASK_COUNT = u"%1 task(s) to perform"_s;
static inline const QString LOG_EVENT_QUEUE_START = u"Processing Task queue"_s;
Expand Down
Loading

0 comments on commit 3f5a5ab

Please sign in to comment.