Skip to content

Commit

Permalink
Merge pull request #32 from oblivioncth/feature/convenience_class
Browse files Browse the repository at this point in the history
Feature/convenience class
  • Loading branch information
oblivioncth authored Nov 10, 2023
2 parents d272763 + bc0013c commit 3dc1dc9
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 137 deletions.
2 changes: 2 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ob_add_standard_library(${LIB_TARGET_NAME}
fp-items.h
fp-macro.h
fp-playlistmanager.h
fp-toolkit.h
settings/fp-config.h
settings/fp-execs.h
settings/fp-preferences.h
Expand All @@ -25,6 +26,7 @@ ob_add_standard_library(${LIB_TARGET_NAME}
fp-macro.cpp
fp-items.cpp
fp-playlistmanager.cpp
fp-toolkit.cpp
settings/fp-config.cpp
settings/fp-execs.cpp
settings/fp-preferences.cpp
Expand Down
92 changes: 55 additions & 37 deletions lib/include/fp/fp-install.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,62 @@
#include "fp/settings/fp-services.h"
#include "fp/fp-macro.h"
#include "fp/fp-db.h"
#include "fp/fp-items.h"
#include "fp/fp-playlistmanager.h"
#include "fp/fp-daemon.h"
#include "fp/fp-toolkit.h"

namespace Fp
{

inline const QString NAME = u"Flashpoint"_s;

class QX_ERROR_TYPE(InstallError, "Fp::InstallError", 1100)
{
friend class Install;
//-Class Enums-------------------------------------------------------------
public:
enum Type
{
NoError,
FileMissing,
DaemonCountMismatch,
DatapackSourceMissing
};

//-Class Variables-------------------------------------------------------------
private:
static inline const QHash<Type, QString> ERR_STRINGS{
{NoError, u""_s},
{FileMissing, u"A required flashpoint install file is missing."_s},
{DaemonCountMismatch, u"The number of configured daemons differs from the expected amount."_s},
{DatapackSourceMissing, u"Expected datapack source missing."_s}
};

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

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

//-Instance Functions-------------------------------------------------------------
public:
bool isValid() const;
Type type() const;
QString specific() const;

private:
Qx::Severity deriveSeverity() const override;
quint32 deriveValue() const override;
QString derivePrimary() const override;
QString deriveSecondary() const override;
};

class FP_FP_EXPORT Install
{
friend class Toolkit;
//-Class Enums---------------------------------------------------------------------------------------------------
enum class Edition {Ultimate, Infinity, Core};

Expand All @@ -51,10 +96,6 @@ enum class Edition {Ultimate, Infinity, Core};
static inline const QString PREFERENCES_JSON_PATH = u"preferences.json"_s;
static inline const QString VER_TXT_PATH = u"version.txt"_s;

// File Info
static inline const QString IMAGE_EXT = u".png"_s;
static inline const QString IMAGE_COMPRESSED_URL_SUFFIX = u"?type=jpg"_s;

// Dynamic path file names
static inline const QString SERVICES_JSON_NAME = u"services.json"_s;
static inline const QString EXECS_JSON_NAME = u"execs.json"_s;
Expand All @@ -66,18 +107,12 @@ enum class Edition {Ultimate, Infinity, Core};
static inline const QString LOGOS_FOLDER_NAME = u"Logos"_s;
static inline const QString SCREENSHOTS_FOLDER_NAME = u"Screenshots"_s;

// Error
static inline const QString ERR_FILE_MISSING = u"A required flashpoint install file is missing."_s;

// Settings
static inline const QString MACRO_FP_PATH = u"<fpPath>"_s;
// Main datapack source
static inline const QString MAIN_DATAPACK_SOURCE = u"Flashpoint Project"_s;

// Regex
static inline const QRegularExpression VERSION_NUMBER_REGEX = QRegularExpression(u"[fF]lashpoint (?<version>.*?) "_s);

public:
static inline const QFileInfo SECURE_PLAYER_INFO = QFileInfo(u"FlashpointSecurePlayer.exe"_s);

//-Instance Variables-----------------------------------------------------------------------------------------------
private:
// Validity
Expand Down Expand Up @@ -106,14 +141,11 @@ enum class Edition {Ultimate, Infinity, Core};
Execs mExecs;
Daemon mDaemon;

// Database
// Facilities
Db* mDatabase = nullptr;

// Playlist Manager
PlaylistManager* mPlaylistManager = nullptr;

// Utilities
MacroResolver* mMacroResolver = nullptr;
Toolkit* mToolkit = nullptr;

//-Constructor-------------------------------------------------------------------------------------------------
public:
Expand All @@ -123,13 +155,6 @@ enum class Edition {Ultimate, Infinity, Core};
public:
~Install();

//-Class Functions------------------------------------------------------------------------------------------------------
private:
static QString standardImageSubPath(QUuid gameId);

public:
static Qx::Error appInvolvesSecurePlayer(bool& involvesBuffer, QFileInfo appInfo);

//-Instance Functions------------------------------------------------------------------------------------------------------
private:
void establishDaemon();
Expand All @@ -146,13 +171,13 @@ enum class Edition {Ultimate, Infinity, Core};
Qx::VersionNumber version() const;
QString launcherChecksum() const;

// Database
// Facilities
Db* database();

// Playlist Manager
PlaylistManager* playlistManager();
const MacroResolver* macroResolver() const;
const Toolkit* toolkit() const;

// Support Application Checks
// Settings
// TODO: At some point create a "Settings" object that wraps all of these, would need to rename existing Fp::Settings
const Config& config() const;
const Preferences& preferences() const;
Expand All @@ -165,14 +190,7 @@ enum class Edition {Ultimate, Infinity, Core};
QDir entryLogosDirectory() const;
QDir entryScreenshotsDirectory() const;
QDir extrasDirectory() const;
QString platformLogoPath(const QString& platform);
QString entryImageLocalPath(ImageType imageType, const QUuid& gameId) const;
QUrl entryImageRemoteUrl(ImageType imageType, const QUuid& gameId) const;
const MacroResolver* macroResolver() const;

// Helper
QString resolveAppPathOverrides(const QString& appPath) const;
QString resolveExecSwaps(const QString& appPath, const QString& platform) const;
QDir platformLogosDirectory() const;
};

}
Expand Down
94 changes: 94 additions & 0 deletions lib/include/fp/fp-toolkit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#ifndef FLASHPOINT_TOOLKIT_H
#define FLASHPOINT_TOOLKIT_H

// Shared Lib Support
#include "fp/fp_export.h"

// Qt Includes
#include <QHash>
#include <QFileInfo>
#include <QDir>

// Qx Includes
#include <qx/core/qx-error.h>

// Project Includes
#include "fp/fp-items.h"

using namespace Qt::Literals::StringLiterals;

namespace Fp
{

class Install;

class FP_FP_EXPORT Toolkit
{
//-Inner Classes----------------------------------------------------------------------------------------------------
public:
class Key
{
friend class Install;
private:
Key() {};
Key(const Key&) = default;
};


//-Class Variables-----------------------------------------------------------------------------------------------
private:
// File Info
static inline const QString IMAGE_EXT = u".png"_s;
static inline const QString IMAGE_COMPRESSED_URL_SUFFIX = u"?type=jpg"_s;

public:
static inline const QFileInfo SECURE_PLAYER_INFO = QFileInfo(u"FlashpointSecurePlayer.exe"_s);

//-Instance Variables-----------------------------------------------------------------------------------------------
private:
const Install& mInstall;

// Implementation Details
QString mEntryLocalLogoTemplate;
QString mEntryLocalScreenshotTemplate;
QString mEntryRemoteLogoTemplate;
QString mEntryRemoteScreenshotTemplate;
QDir mDatapackLocalDir;
QString mDatapackRemoteBase;

//-Constructor-------------------------------------------------------------------------------------------------
public:
Toolkit(const Install& install, const Key&);

//-Class Functions-----------------------------------------------------------------------------------------------
private:
static QString standardImageSubPath(QUuid gameId);

public:
static Qx::Error appInvolvesSecurePlayer(bool& involvesBuffer, QFileInfo appInfo);

//-Instance Functions------------------------------------------------------------------------------------------------------
private:
QString entryLocalLogoPath();

public:
// Images
QString platformLogoPath(const QString& platform) const;
QString entryImageLocalPath(ImageType imageType, const QUuid& gameId) const;
QUrl entryImageRemotePath(ImageType imageType, const QUuid& gameId) const;

// App paths
bool resolveAppPathOverrides(QString& appPath) const;
bool resolveExecSwaps(QString& appPath, const QString& platform) const;
bool resolveTrueAppPath(QString& appPath, const QString& platform, QHash<QString, QString> overrides = {}, bool absolute = false) const;

// Datapacks
QString datapackPath(const Fp::GameData& gameData) const;
QUrl datapackUrl(const Fp::GameData& gameData) const;
bool datapackIsPresent(const Fp::GameData& gameData) const;

};

}

#endif // FLASHPOINT_TOOLKIT_H
Loading

0 comments on commit 3dc1dc9

Please sign in to comment.