Skip to content

Commit

Permalink
Merge pull request #60 from oblivioncth/dev
Browse files Browse the repository at this point in the history
Merge to master for v0.9.4.1
  • Loading branch information
oblivioncth authored May 3, 2023
2 parents 10a6399 + f372a48 commit 8b3af91
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 13 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.24.0...3.25.0)
# Project
# NOTE: DON'T USE TRAILING ZEROS IN VERSIONS
project(CLIFp
VERSION 0.9.4
VERSION 0.9.4.1
LANGUAGES CXX
DESCRIPTION "Command-line Interface for Flashpoint"
)
Expand Down Expand Up @@ -72,14 +72,14 @@ endif()

include(OB/FetchQx)
ob_fetch_qx(
REF "v0.5"
REF "v0.5.0.1"
COMPONENTS
${CLIFP_QX_COMPONENTS}
)

# Fetch libfp (build and import from source)
include(OB/Fetchlibfp)
ob_fetch_libfp("v0.3")
ob_fetch_libfp("v0.3.1")

# Fetch QI-QMP (build and import from source)
include(OB/FetchQI-QMP)
Expand Down
28 changes: 25 additions & 3 deletions app/src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
Controller::Controller(QObject* parent) :
QObject(parent),
mStatusRelay(this),
mExitCode(ErrorCode::NO_ERR)
mExitCode(ErrorCode::NO_ERR),
mReadyToExit(false)
{
// Create driver
Driver* driver = new Driver(QApplication::arguments());
Expand All @@ -38,6 +39,7 @@ Controller::Controller(QObject* parent) :
connect(driver, &Driver::longTaskStarted, &mStatusRelay, &StatusRelay::longTaskStartedHandler);
connect(driver, &Driver::longTaskFinished, &mStatusRelay, &StatusRelay::longTaskFinishedHandler);
connect(&mStatusRelay, &StatusRelay::longTaskCanceled, driver, &Driver::cancelActiveLongTask);
connect(&mStatusRelay, &StatusRelay::longTaskCanceled, this, &Controller::longTaskCanceledHandler);

// Connect driver - Response Requested (BlockingQueuedConnection since response must be waited for)
connect(driver, &Driver::blockingErrorOccured, &mStatusRelay, &StatusRelay::blockingErrorHandler, Qt::BlockingQueuedConnection);
Expand Down Expand Up @@ -92,11 +94,31 @@ void Controller::quitRequestHandler()
qApp->closeAllWindows();
}

void Controller::longTaskCanceledHandler()
{
/* A bit of a bodge. Pressing the Cancel button on a progress dialog
* doesn't count as closing it (it doesn't fire a close event) by the strict definition of
* QWidget, so here when the progress bar is closed we manually check to see if it was
* the last window if the application is ready to exit.
*
* Normally the progress bar should never still be open by that point, but this is here as
* a fail-safe as otherwise the application would deadlock when the progress bar is closed
* via the Cancel button.
*/
if(mReadyToExit && !windowsAreOpen())
exit();
}

void Controller::finisher()
{
// Quit once no windows remain
if(windowsAreOpen())
connect(qApp, &QGuiApplication::lastWindowClosed, this, [this]() { QApplication::exit(mExitCode); });
{
mReadyToExit = true;
connect(qApp, &QGuiApplication::lastWindowClosed, this, &Controller::exit);
}
else
QApplication::exit(mExitCode);
exit();
}

void Controller::exit() { QApplication::exit(mExitCode); }
3 changes: 3 additions & 0 deletions app/src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Controller : public QObject
QThread mWorkerThread;
StatusRelay mStatusRelay;
ErrorCode mExitCode;
bool mReadyToExit;

//-Constructor-------------------------------------------------------------------------------------------------
public:
Expand All @@ -36,7 +37,9 @@ class Controller : public QObject
private slots:
void driverFinishedHandler(ErrorCode code);
void quitRequestHandler();
void longTaskCanceledHandler();
void finisher();
void exit();

signals:
void quit();
Expand Down
7 changes: 5 additions & 2 deletions app/src/frontend/statusrelay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ void StatusRelay::longTaskStartedHandler(QString task)

void StatusRelay::longTaskFinishedHandler()
{
if(mLongTaskProgressDialog.isVisible()) // Is already closed if canceled
mLongTaskProgressDialog.reset();
/* Always reset the dialog regardless of whether it is visible or not as it may not be currently visible,
* but queued to be visible on the next event loop iteration and therefore still needs to be hidden
* immediately after.
*/
mLongTaskProgressDialog.reset();
}
4 changes: 4 additions & 0 deletions app/src/kernel/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ void Core::attachFlashpoint(std::unique_ptr<Fp::Install> flashpointInstall)
// Capture install
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));

// Initialize child process env var
mChildTitleProcEnv = QProcessEnvironment::systemEnvironment();

Expand Down
1 change: 1 addition & 0 deletions app/src/kernel/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Core : public QObject
static inline const QString LOG_EVENT_G_HELP_SHOWN = QSL("Displayed general help information");
static inline const QString LOG_EVENT_VER_SHOWN = QSL("Displayed version information");
static inline const QString LOG_EVENT_NOTIFCATION_LEVEL = QSL("Notification Level is: %1");
static inline const QString LOG_EVENT_RECOGNIZED_DAEMONS = QSL("Recognized service daemons: %1");
static inline const QString LOG_EVENT_ENQ_START = QSL("Enqueuing startup tasks...");
static inline const QString LOG_EVENT_ENQ_STOP = QSL("Enqueuing shutdown tasks...");
static inline const QString LOG_EVENT_ENQ_DATA_PACK = QSL("Enqueuing Data Pack tasks...");
Expand Down
5 changes: 3 additions & 2 deletions app/src/task/t-download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ void TDownload::postDownload(Qx::DownloadManagerReport downloadReport)
}
else
{
downloadReport.errorInfo().setErrorLevel(Qx::GenericError::Critical);
emit errorOccurred(NAME, downloadReport.errorInfo());
Qx::GenericError err = downloadReport.errorInfo();
err.setErrorLevel(Qx::GenericError::Critical);
emit errorOccurred(NAME, err);
errorStatus = ErrorCode::CANT_OBTAIN_DATA_PACK;
}

Expand Down
16 changes: 14 additions & 2 deletions app/src/tools/mounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ void Mounter::setMountOnServer()
// GET request
mPhpMountReply = mNam.get(mountReq);

// Log request
emit eventOccured(EVENT_REQUEST_SENT.arg(ENUM_NAME(mPhpMountReply->operation()), mountUrl.toString()));

// Await finished() signal...
}

Expand All @@ -157,6 +160,11 @@ void Mounter::notePhpMountResponse(const QString& response)
finish();
}

void Mounter::logMountInfo(const MountInfo& info)
{
emit eventOccured(EVENT_MOUNT_INFO_DETERMINED.arg(info.filePath, info.driveId, info.driveSerial));
}

//Public:
bool Mounter::isMounting() { return mMounting; }

Expand Down Expand Up @@ -191,7 +199,7 @@ void Mounter::qmpiFinishedHandler()

void Mounter::qmpiReadyForCommandsHandler() { createMountPoint(); }

void Mounter::phpMountFinishedHandler(QNetworkReply *reply)
void Mounter::phpMountFinishedHandler(QNetworkReply* reply)
{
assert(reply == mPhpMountReply.get());

Expand Down Expand Up @@ -281,8 +289,12 @@ void Mounter::mount(QUuid titleId, QString filePath)
Qx::Base85 driveSerial = Qx::Base85::encode(rawTitleId, &encoding);
mCurrentMountInfo.driveSerial = driveSerial.toString();

// Log info
logMountInfo(mCurrentMountInfo);
emit eventOccured(EVENT_QEMU_DETECTION.arg(mQemuEnabled ? "is" : "isn't"));

// Connect to QEMU instance, or go straight to web server portion if bypassing
if(mQemuMounter.port() != 0)
if(mQemuEnabled)
{
emit eventOccured(EVENT_CONNECTING_TO_QEMU);
mQemuMounter.connectToHost();
Expand Down
6 changes: 5 additions & 1 deletion app/src/tools/mounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ class Mounter : public QObject

// Events - Internal
static inline const QString EVENT_CONNECTING_TO_QEMU = QSL("Connecting to FP QEMU instance...");
static inline const QString EVENT_MOUNT_INFO_DETERMINED = QSL("Mount Info: {.filePath = \"%1\", .driveId = \"%2\", .driveSerial = \"%3\"}");
static inline const QString EVENT_QEMU_DETECTION = QSL("QEMU %1 in use.");
static inline const QString EVENT_CREATING_MOUNT_POINT = QSL("Creating data pack mount point on QEMU instance...");
static inline const QString EVENT_MOUNTING_THROUGH_SERVER = QSL("Mounting data pack via PHP server...");
static inline const QString EVENT_REQUEST_SENT = QSL("Sent request (%1): %2}");

// Connections
static const int QMP_TRANSACTION_TIMEOUT = 5000; // ms
Expand Down Expand Up @@ -80,6 +83,7 @@ class Mounter : public QObject
void createMountPoint();
void setMountOnServer();
void notePhpMountResponse(const QString& response);
void logMountInfo(const MountInfo& info);

public:
bool isMounting();
Expand All @@ -99,7 +103,7 @@ private slots:
void qmpiConnectedHandler(QJsonObject version, QJsonArray capabilities);
void qmpiFinishedHandler();
void qmpiReadyForCommandsHandler();
void phpMountFinishedHandler(QNetworkReply *reply);
void phpMountFinishedHandler(QNetworkReply* reply);

void qmpiConnectionErrorHandler(QAbstractSocket::SocketError error);
void qmpiCommunicationErrorHandler(Qmpi::CommunicationError error);
Expand Down

0 comments on commit 8b3af91

Please sign in to comment.