@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
* Copyright (C) 2025 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -38,59 +39,25 @@
|
||||
#include <QJsonObject>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <memory>
|
||||
#include "RuntimeContext.h"
|
||||
|
||||
class Library;
|
||||
class Rule;
|
||||
|
||||
enum RuleAction { Allow, Disallow, Defer };
|
||||
struct Rule {
|
||||
enum Action { Allow, Disallow, Defer };
|
||||
|
||||
QList<std::shared_ptr<Rule>> rulesFromJsonV4(const QJsonObject& objectWithRules);
|
||||
struct OS {
|
||||
QString name;
|
||||
// FIXME: unsupported
|
||||
// retained to avoid information being lost from files
|
||||
QString version;
|
||||
};
|
||||
|
||||
class Rule {
|
||||
protected:
|
||||
RuleAction m_result;
|
||||
virtual bool applies(const Library* parent, const RuntimeContext& runtimeContext) = 0;
|
||||
Action action = Defer;
|
||||
std::optional<OS> os;
|
||||
|
||||
public:
|
||||
Rule(RuleAction result) : m_result(result) {}
|
||||
virtual ~Rule() {}
|
||||
virtual QJsonObject toJson() = 0;
|
||||
RuleAction apply(const Library* parent, const RuntimeContext& runtimeContext)
|
||||
{
|
||||
if (applies(parent, runtimeContext))
|
||||
return m_result;
|
||||
else
|
||||
return Defer;
|
||||
}
|
||||
};
|
||||
|
||||
class OsRule : public Rule {
|
||||
private:
|
||||
// the OS
|
||||
QString m_system;
|
||||
// the OS version regexp
|
||||
QString m_version_regexp;
|
||||
|
||||
protected:
|
||||
virtual bool applies(const Library*, const RuntimeContext& runtimeContext) { return runtimeContext.classifierMatches(m_system); }
|
||||
OsRule(RuleAction result, QString system, QString version_regexp) : Rule(result), m_system(system), m_version_regexp(version_regexp) {}
|
||||
|
||||
public:
|
||||
virtual QJsonObject toJson();
|
||||
static std::shared_ptr<OsRule> create(RuleAction result, QString system, QString version_regexp)
|
||||
{
|
||||
return std::shared_ptr<OsRule>(new OsRule(result, system, version_regexp));
|
||||
}
|
||||
};
|
||||
|
||||
class ImplicitRule : public Rule {
|
||||
protected:
|
||||
virtual bool applies(const Library*, [[maybe_unused]] const RuntimeContext& runtimeContext) { return true; }
|
||||
ImplicitRule(RuleAction result) : Rule(result) {}
|
||||
|
||||
public:
|
||||
virtual QJsonObject toJson();
|
||||
static std::shared_ptr<ImplicitRule> create(RuleAction result) { return std::shared_ptr<ImplicitRule>(new ImplicitRule(result)); }
|
||||
static Rule fromJson(const QJsonObject& json);
|
||||
QJsonObject toJson();
|
||||
|
||||
Action apply(const RuntimeContext& runtimeContext);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user