From 8e22ee6f8849c1314033b260ac135ef66af6c247 Mon Sep 17 00:00:00 2001 From: Christian Heimlich Date: Fri, 13 Oct 2023 05:26:10 -0400 Subject: [PATCH] Add implementation for working with FP Proxy Default on Linux --- CMakeLists.txt | 16 +++++++++++++--- app/CMakeLists.txt | 30 +++++++++++++++++++++++++++--- app/src/task/t-mount.cpp | 8 ++++++++ app/src/task/t-mount.h | 9 ++++++++- app/src/tools/mounter_proxy.cpp | 16 ++++++++-------- app/src/tools/mounter_proxy.h | 7 +++++-- 6 files changed, 69 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1120838..9496988 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,14 @@ 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) @@ -81,9 +89,11 @@ ob_fetch_qx( include(OB/Fetchlibfp) ob_fetch_libfp("bca00c48d37e9306a311bc83f74a7692e169afae") -# Fetch QI-QMP (build and import from source) -include(OB/FetchQI-QMP) -ob_fetch_qi_qmp("v0.2.2") +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 QuaZip (build and import from source) include(OB/FetchQuaZip) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index b8c4f87..b926ce3 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -44,8 +44,6 @@ set(CLIFP_SOURCE tools/blockingprocessmanager.cpp tools/deferredprocessmanager.h tools/deferredprocessmanager.cpp - tools/mounter.h - tools/mounter.cpp frontend/statusrelay.h frontend/statusrelay.cpp controller.h @@ -67,7 +65,6 @@ set(CLIFP_LINKS Qx::Network Qx::Widgets Fp::Fp - QI-QMP::Qmpi QuaZip::QuaZip magic_enum::magic_enum ) @@ -101,18 +98,45 @@ 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} NAMESPACE "${PROJECT_NAMESPACE}" ALIAS "${APP_ALIAS_NAME}" SOURCE ${CLIFP_SOURCE} + DEFINITIONS ${CLIFP_DEFINITIONS} RESOURCE "resources.qrc" LINKS ${CLIFP_LINKS} CONFIG STANDARD 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} diff --git a/app/src/task/t-mount.cpp b/app/src/task/t-mount.cpp index aacc602..b8288ce 100644 --- a/app/src/task/t-mount.cpp +++ b/app/src/task/t-mount.cpp @@ -48,14 +48,22 @@ void TMount::perform() QString label = LOG_EVENT_MOUNTING_DATA_PACK.arg(packFileInfo.fileName()); //-Setup Mounter------------------------------------ +#ifdef FP_PROXY + mMounter.setProxyServerPort(22501); +#else mMounter.setWebServerPort(22500); mMounter.setQemuMountPort(22501); mMounter.setQemuProdPort(0); mMounter.setQemuEnabled(!mSkipQemu); +#endif // Start mount emit longTaskStarted(label); +#ifdef FP_PROXY + mMounter.mount(mPath); +#else mMounter.mount(mTitleId, mPath); +#endif } void TMount::stop() diff --git a/app/src/task/t-mount.h b/app/src/task/t-mount.h index e8d0aba..228b2db 100644 --- a/app/src/task/t-mount.h +++ b/app/src/task/t-mount.h @@ -4,9 +4,16 @@ // Qx Includes #include +// Qt Includes +#include + // Project Includes #include "task/task.h" -#include "tools/mounter.h" +#ifdef FP_PROXY + #include "tools/mounter_proxy.h" +#else + #include "tools/mounter.h" +#endif class TMount : public Task { diff --git a/app/src/tools/mounter_proxy.cpp b/app/src/tools/mounter_proxy.cpp index f6a9ca7..f1d2985 100644 --- a/app/src/tools/mounter_proxy.cpp +++ b/app/src/tools/mounter_proxy.cpp @@ -59,18 +59,18 @@ Mounter::Mounter(QObject* parent) : * them to be used as to help make that clear in the logs when the update causes this to stop working). */ connect(&mNam, &QNetworkAccessManager::authenticationRequired, this, [this](){ - emit eventOccured(u"Unexpected use of authentication by PHP server!"_s); + emit eventOccured(NAME, u"Unexpected use of authentication by PHP server!"_s); }); connect(&mNam, &QNetworkAccessManager::preSharedKeyAuthenticationRequired, this, [this](){ - emit eventOccured(u"Unexpected use of PSK authentication by PHP server!"_s); + emit eventOccured(NAME, u"Unexpected use of PSK authentication by PHP server!"_s); }); connect(&mNam, &QNetworkAccessManager::proxyAuthenticationRequired, this, [this](){ - emit eventOccured(u"Unexpected use of proxy by PHP server!"_s); + emit eventOccured(NAME, u"Unexpected use of proxy by PHP server!"_s); }); connect(&mNam, &QNetworkAccessManager::sslErrors, this, [this](QNetworkReply* reply, const QList& errors){ Q_UNUSED(reply); QString errStrList = Qx::String::join(errors, [](const QSslError& err){ return err.errorString(); }, u","_s); - emit eventOccured(u"Unexpected SSL errors from PHP server! {"_s + errStrList + u"}"_s"}"); + emit eventOccured(NAME, u"Unexpected SSL errors from PHP server! {"_s + errStrList + u"}"_s"}"); }); } @@ -84,7 +84,7 @@ void Mounter::finish(const MounterError& errorState) void Mounter::postMountToServer(QStringView filePath) { - emit eventOccured(EVENT_MOUNTING); + emit eventOccured(NAME, EVENT_MOUNTING); //-Create mount request------------------------- @@ -115,12 +115,12 @@ void Mounter::postMountToServer(QStringView filePath) void Mounter::noteProxyRequest(QNetworkAccessManager::Operation op, const QUrl& url, QByteArrayView data) { - emit eventOccured(EVENT_REQUEST_SENT.arg(ENUM_NAME(op), url.toString(), QString::fromLatin1(data))); + emit eventOccured(NAME, EVENT_REQUEST_SENT.arg(ENUM_NAME(op), url.toString(), QString::fromLatin1(data))); } void Mounter::noteProxyResponse(const QString& response) { - emit eventOccured(EVENT_PROXY_RESPONSE.arg(response)); + emit eventOccured(NAME, EVENT_PROXY_RESPONSE.arg(response)); } //Public: @@ -138,7 +138,7 @@ void Mounter::proxyMountFinishedHandler(QNetworkReply* reply) { MounterError err(MounterError::ProxyMount, reply->errorString()); - emit errorOccured(err); + emit errorOccured(NAME, err); finish(err); } else diff --git a/app/src/tools/mounter_proxy.h b/app/src/tools/mounter_proxy.h index f350930..4945c13 100644 --- a/app/src/tools/mounter_proxy.h +++ b/app/src/tools/mounter_proxy.h @@ -56,6 +56,9 @@ class Mounter : public QObject Q_OBJECT //-Class Variables------------------------------------------------------------------------------------------------------ private: + // Meta + static inline const QString NAME = u"Mounter"_s; + // Events - External static inline const QString EVENT_PROXY_RESPONSE = u"Proxy Response: \"%1\""_s; @@ -102,8 +105,8 @@ public slots: void abort(); signals: - void eventOccured(const QString& event); - void errorOccured(MounterError errorMessage); + void eventOccured(QString name, const QString& event); + void errorOccured(QString name, MounterError errorMessage); void mountFinished(MounterError errorState); // For now these just cause a busy state