Skip to content

Commit

Permalink
Merge pull request #26 from oblivioncth/fp12_linux
Browse files Browse the repository at this point in the history
Restore compatibility with FP 12 on Linux
  • Loading branch information
oblivioncth committed Oct 17, 2023
2 parents b8f75c3 + 239658b commit 24dd593
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 36 deletions.
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ob_add_standard_library(${LIB_TARGET_NAME}
HEADERS_API
COMMON "${PROJECT_NAMESPACE_LC}"
FILES
fp-daemon.h
fp-db.h
fp-install.h
fp-items.h
Expand Down
15 changes: 15 additions & 0 deletions lib/include/fp/fp-daemon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef FLASHPOINT_DAEMON_H
#define FLASHPOINT_DAEMON_H

// Qt Includes
#include <QString>

namespace Fp
{

enum Daemon { Unknown, Docker, Qemu, FpProxy };

Daemon daemonFromString(QStringView name);

}
#endif // FLASHPOINT_DAEMON_H
4 changes: 4 additions & 0 deletions lib/include/fp/fp-install.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "fp/fp-db.h"
#include "fp/fp-items.h"
#include "fp/fp-playlistmanager.h"
#include "fp/fp-daemon.h"

namespace Fp
{
Expand Down Expand Up @@ -104,6 +105,7 @@ enum class Edition {Ultimate, Infinity, Core};
Preferences mPreferences;
Services mServices;
Execs mExecs;
Daemon mDaemon;

// Database
Db* mDatabase = nullptr;
Expand Down Expand Up @@ -131,6 +133,7 @@ enum class Edition {Ultimate, Infinity, Core};

//-Instance Functions------------------------------------------------------------------------------------------------------
private:
void establishDaemon();
void nullify();

public:
Expand All @@ -156,6 +159,7 @@ enum class Edition {Ultimate, Infinity, Core};
const Preferences& preferences() const;
const Services& services() const;
const Execs& execs() const;
Daemon outfittedDaemon() const;

// Data access
QString fullPath() const;
Expand Down
1 change: 0 additions & 1 deletion lib/include/fp/settings/fp-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct FP_FP_EXPORT Config : public Settings
{
QString flashpointPath;
bool startServer;
QString server;
};

class FP_FP_EXPORT ConfigReader : public SettingsReader
Expand Down
4 changes: 2 additions & 2 deletions lib/include/fp/settings/fp-execs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ struct FP_FP_EXPORT Exec
{
QString linux;
QString win32;
QString wine;
std::optional<QString> wine;
};

struct FP_FP_EXPORT Execs : public Settings
{
QList<Exec> list;
QList<Exec> execs;
};

class FP_FP_EXPORT ExecsReader : public SettingsReader
Expand Down
9 changes: 0 additions & 9 deletions lib/include/fp/settings/fp-services.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
namespace Fp
{

enum KnownDaemon{
None = 0x0,
Docker = 0x1,
Qemu = 0x2
};
Q_DECLARE_FLAGS(KnownDaemons, KnownDaemon);
Q_DECLARE_OPERATORS_FOR_FLAGS(KnownDaemons);

struct FP_FP_EXPORT ServerDaemon
{
QString name;
Expand All @@ -45,7 +37,6 @@ struct FP_FP_EXPORT Services : public Settings
QHash<QString, ServerDaemon> daemon;
QSet<StartStop> start;
QSet<StartStop> stop;
KnownDaemons recognizedDaemons; // Non-standard
// TODO: ^If Settings container obj is made (see other todo), move this there
};

Expand Down
37 changes: 34 additions & 3 deletions lib/src/fp-install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ Install::Install(QString installPath, bool preloadPlaylists) :
return;
}

// Note daemon
if(mServices.daemon.size() != 1)
{
mError = Qx::GenericError(Qx::Critical, 11101, "The number of configured daemons differs from the expected amount", "1");
return;
}


establishDaemon();

// Add database
mDatabase = new Db(mDatabaseFile->fileName(), {});

Expand Down Expand Up @@ -150,6 +160,26 @@ Qx::Error Install::appInvolvesSecurePlayer(bool& involvesBuffer, QFileInfo appIn

//-Instance Functions------------------------------------------------------------------------------------------------
//Private:
void Install::establishDaemon()
{
Q_ASSERT(mServices.daemon.size() == 1);

// NOTE: This assumes only one daemon is present!
const ServerDaemon& d = *mServices.daemon.constBegin();

if(d.name.contains(u"qemu"_s, Qt::CaseInsensitive) ||
d.filename.contains(u"qemu"_s, Qt::CaseInsensitive))
mDaemon = Qemu;
else if(d.name.contains(u"docker"_s, Qt::CaseInsensitive) ||
d.filename.contains(u"docker"_s, Qt::CaseInsensitive))
mDaemon = Docker;
else if(d.name.contains(u"proxy"_s, Qt::CaseInsensitive) ||
d.filename.contains(u"proxy"_s, Qt::CaseInsensitive))
mDaemon = FpProxy;
else
mDaemon = Unknown;
}

void Install::nullify()
{
// Files and directories
Expand Down Expand Up @@ -232,6 +262,7 @@ const Config& Install::config() const { return mConfig; }
const Preferences& Install::preferences() const { return mPreferences; }
const Services& Install::services() const { return mServices; }
const Execs& Install::execs() const { return mExecs; }
Daemon Install::outfittedDaemon() const { return mDaemon; }

QString Install::fullPath() const { return mRootDirectory.absolutePath(); }
QDir Install::entryLogosDirectory() const { return mEntryLogosDirectory; }
Expand Down Expand Up @@ -287,14 +318,14 @@ QString Install::resolveExecSwaps(const QString& appPath, const QString& platfor
bool preferNative = mPreferences.nativePlatforms.contains(platform);

// Check if path has an associated swap
for(const Exec& swap : qAsConst(mExecs.list))
for(const Exec& swap : qAsConst(mExecs.execs))
{
if(swap.win32 == appPath)
{
if(preferNative && !swap.linux.isEmpty())
return swap.linux;
else if(!swap.wine.isEmpty())
return swap.wine;
else if(swap.wine.has_value() && !swap.wine->isEmpty())
return swap.wine.value();
}
}

Expand Down
1 change: 0 additions & 1 deletion lib/src/settings/fp-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
QX_JSON_STRUCT_OUTSIDE(Fp::Config,
flashpointPath,
startServer,
server
)

namespace Fp
Expand Down
2 changes: 1 addition & 1 deletion lib/src/settings/fp-execs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ QX_JSON_STRUCT_OUTSIDE(Fp::Exec,
);

QX_JSON_STRUCT_OUTSIDE(Fp::Execs,
list
execs
);

namespace Fp
Expand Down
20 changes: 1 addition & 19 deletions lib/src/settings/fp-services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,7 @@ Qx::JsonError ServicesReader::parseDocument(const QJsonDocument& servicesDoc)
Services* targetServices = static_cast<Services*>(mTargetSettings);

// Parse
Qx::JsonError err = Qx::parseJson(*targetServices, servicesDoc);
if(err.isValid())
return err;

// Check for known daemons
for(const ServerDaemon& d : qAsConst(targetServices->daemon))
{
/* NOTE: If for some reason this list becomes large, use a hash instead
* (e.g. if(hash.contains(u"NAME"_s)){ recognizedDaemons.setFlag(hash["NAME]); } )
*/
if(d.name.contains(u"qemu"_s, Qt::CaseInsensitive) ||
d.filename.contains(u"qemu"_s, Qt::CaseInsensitive))
targetServices->recognizedDaemons.setFlag(KnownDaemon::Qemu);
else if(d.name.contains(u"docker"_s, Qt::CaseInsensitive) ||
d.filename.contains(u"docker"_s, Qt::CaseInsensitive))
targetServices->recognizedDaemons.setFlag(KnownDaemon::Docker);
}

return Qx::JsonError();
return Qx::parseJson(*targetServices, servicesDoc);
}

}

0 comments on commit 24dd593

Please sign in to comment.