Skip to content

Commit

Permalink
Add implementation for working with FP Proxy
Browse files Browse the repository at this point in the history
Default on Linux
  • Loading branch information
oblivioncth committed Oct 13, 2023
1 parent 73c6184 commit 8e22ee6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 17 deletions.
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 27 additions & 3 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,7 +65,6 @@ set(CLIFP_LINKS
Qx::Network
Qx::Widgets
Fp::Fp
QI-QMP::Qmpi
QuaZip::QuaZip
magic_enum::magic_enum
)
Expand Down Expand Up @@ -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}
Expand Down
8 changes: 8 additions & 0 deletions app/src/task/t-mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion app/src/task/t-mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
// Qx Includes
#include <qx/utility/qx-macros.h>

// Qt Includes
#include <QUuid>

// 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
{
Expand Down
16 changes: 8 additions & 8 deletions app/src/tools/mounter_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QSslError>& 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"}");
});
}

Expand All @@ -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-------------------------

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions app/src/tools/mounter_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8e22ee6

Please sign in to comment.