From 029ad4a881e54f74384c712aecb142b712c4d6f2 Mon Sep 17 00:00:00 2001 From: pv Date: Sat, 24 Dec 2022 10:04:40 +0300 Subject: [PATCH] Implement version check --- src/App/Facade.cpp | 21 +++++++---- src/App/Facade.hpp | 1 + src/App/Project.hpp | 2 +- src/App/Version.rc | 8 ++--- support/redscript/ScriptableTweak.reds | 3 +- support/redscript/TweakDBInterface.reds | 24 ++++++------- support/redscript/TweakDBManager.reds | 46 ++++++++++++------------- support/redscript/TweakXL.reds | 5 +++ xmake.lua | 2 +- 9 files changed, 62 insertions(+), 50 deletions(-) create mode 100644 support/redscript/TweakXL.reds diff --git a/src/App/Facade.cpp b/src/App/Facade.cpp index 7de4f67..153e142 100644 --- a/src/App/Facade.cpp +++ b/src/App/Facade.cpp @@ -35,6 +35,12 @@ void App::Facade::ExecuteTweak(Red::CName aName) Core::Resolve()->ExecuteTweak(aName); } +bool App::Facade::Require(Red::CString& aVersion) +{ + const auto requirement = semver::from_string_noexcept(aVersion.c_str()); + return requirement.has_value() ? Project::Version >= requirement.value() : false; +} + Red::CString App::Facade::GetVersion() { return Project::Version.to_string().c_str(); @@ -48,11 +54,12 @@ void App::Facade::OnRegister(Descriptor* aType) void App::Facade::OnDescribe(Descriptor* aType) { - aType->AddFunction<&Reload>("Reload", { .isFinal = true }); - aType->AddFunction<&ImportAll>("ImportAll", { .isFinal = true }); - aType->AddFunction<&ImportDir>("ImportDir", { .isFinal = true }); - aType->AddFunction<&ImportTweak>("Import", { .isFinal = true }); - aType->AddFunction<&ExecuteAll>("ExecuteAll", { .isFinal = true }); - aType->AddFunction<&ExecuteTweak>("Execute", { .isFinal = true }); - aType->AddFunction<&GetVersion>("Version", { .isFinal = true }); + aType->AddFunction<&Reload>("Reload"); + aType->AddFunction<&ImportAll>("ImportAll"); + aType->AddFunction<&ImportDir>("ImportDir"); + aType->AddFunction<&ImportTweak>("Import"); + aType->AddFunction<&ExecuteAll>("ExecuteAll"); + aType->AddFunction<&ExecuteTweak>("Execute"); + aType->AddFunction<&Require>("Require"); + aType->AddFunction<&GetVersion>("Version"); } diff --git a/src/App/Facade.hpp b/src/App/Facade.hpp index 90a702a..68b3da7 100644 --- a/src/App/Facade.hpp +++ b/src/App/Facade.hpp @@ -13,6 +13,7 @@ class Facade : public Red::Rtti::Class static void ImportTweak(Red::CString& aPath); static void ExecuteAll(); static void ExecuteTweak(Red::CName aName); + static bool Require(Red::CString& aVersion); static Red::CString GetVersion(); private: diff --git a/src/App/Project.hpp b/src/App/Project.hpp index d08b10e..7c70c78 100644 --- a/src/App/Project.hpp +++ b/src/App/Project.hpp @@ -12,5 +12,5 @@ constexpr auto Author = "psiberx"; constexpr auto NameW = L"TweakXL"; constexpr auto AuthorW = L"psiberx"; -constexpr auto Version = semver::from_string_noexcept("1.1.0").value(); +constexpr auto Version = semver::from_string_noexcept("1.1.1").value(); } diff --git a/src/App/Version.rc b/src/App/Version.rc index 3b414c4..b2bdef0 100644 --- a/src/App/Version.rc +++ b/src/App/Version.rc @@ -1,9 +1,9 @@ -#define VER_PRODUCTVERSION 1,1,0,0 -#define VER_FILEVERSION 1,1,0,2211261928 +#define VER_PRODUCTVERSION 1,1,1,0 +#define VER_FILEVERSION 1,1,1,2212240832 #define VER_PRODUCTNAME_STR "TweakXL\0" -#define VER_PRODUCTVERSION_STR "1.1.0\0" -#define VER_FILEVERSION_STR "1.1.0.2211261928\0" +#define VER_PRODUCTVERSION_STR "1.1.1\0" +#define VER_FILEVERSION_STR "1.1.1.2212240832\0" 1 VERSIONINFO FILEVERSION VER_FILEVERSION diff --git a/support/redscript/ScriptableTweak.reds b/support/redscript/ScriptableTweak.reds index b763dc2..17042d2 100644 --- a/support/redscript/ScriptableTweak.reds +++ b/support/redscript/ScriptableTweak.reds @@ -1,5 +1,4 @@ public abstract native class ScriptableTweak { - - protected cb func OnApply() -> Void + protected cb func OnApply() -> Void } diff --git a/support/redscript/TweakDBInterface.reds b/support/redscript/TweakDBInterface.reds index abf5ab7..8f50cdc 100644 --- a/support/redscript/TweakDBInterface.reds +++ b/support/redscript/TweakDBInterface.reds @@ -16,21 +16,21 @@ public final static native func GetRecordByIndex(type: CName, index: Uint32) -> @addMethod(TweakDBInterface) public final static func GetRecords(keys: array) -> array> { - let records: array>; - for key in keys { - let record = TweakDBInterface.GetRecord(key); - if IsDefined(record) { - ArrayPush(records, record); + let records: array>; + for key in keys { + let record = TweakDBInterface.GetRecord(key); + if IsDefined(record) { + ArrayPush(records, record); + } } - } - return records; + return records; } @addMethod(TweakDBInterface) public final static func GetRecordIDs(type: CName) -> array { - let ids: array; - for record in TweakDBInterface.GetRecords(type) { - ArrayPush(ids, record.GetID()); - } - return ids; + let ids: array; + for record in TweakDBInterface.GetRecords(type) { + ArrayPush(ids, record.GetID()); + } + return ids; } diff --git a/support/redscript/TweakDBManager.reds b/support/redscript/TweakDBManager.reds index 9c26140..34053e2 100644 --- a/support/redscript/TweakDBManager.reds +++ b/support/redscript/TweakDBManager.reds @@ -1,32 +1,32 @@ public abstract native class TweakDBManager { - public final static native func SetFlat(id: TweakDBID, value: Variant) -> Bool - public final static native func CreateRecord(id: TweakDBID, type: CName) -> Bool - public final static native func CloneRecord(id: TweakDBID, base: TweakDBID) -> Bool - public final static native func UpdateRecord(id: TweakDBID) -> Bool - public final static native func RegisterName(name: CName) -> Bool + public final static native func SetFlat(id: TweakDBID, value: Variant) -> Bool + public final static native func CreateRecord(id: TweakDBID, type: CName) -> Bool + public final static native func CloneRecord(id: TweakDBID, base: TweakDBID) -> Bool + public final static native func UpdateRecord(id: TweakDBID) -> Bool + public final static native func RegisterName(name: CName) -> Bool - public final static func SetFlat(name: CName, value: Variant) -> Bool { - if TweakDBManager.SetFlat(TDBID.Create(NameToString(name)), value) { - TweakDBManager.RegisterName(name); - return true; + public final static func SetFlat(name: CName, value: Variant) -> Bool { + if TweakDBManager.SetFlat(TDBID.Create(NameToString(name)), value) { + TweakDBManager.RegisterName(name); + return true; + } + return false; } - return false; - } - public final static func CreateRecord(name: CName, type: CName) -> Bool { - if TweakDBManager.CreateRecord(TDBID.Create(NameToString(name)), type) { - TweakDBManager.RegisterName(name); - return true; + public final static func CreateRecord(name: CName, type: CName) -> Bool { + if TweakDBManager.CreateRecord(TDBID.Create(NameToString(name)), type) { + TweakDBManager.RegisterName(name); + return true; + } + return false; } - return false; - } - public final static func CloneRecord(name: CName, base: TweakDBID) -> Bool { - if TweakDBManager.CloneRecord(TDBID.Create(NameToString(name)), base) { - TweakDBManager.RegisterName(name); - return true; + public final static func CloneRecord(name: CName, base: TweakDBID) -> Bool { + if TweakDBManager.CloneRecord(TDBID.Create(NameToString(name)), base) { + TweakDBManager.RegisterName(name); + return true; + } + return false; } - return false; - } } diff --git a/support/redscript/TweakXL.reds b/support/redscript/TweakXL.reds new file mode 100644 index 0000000..2f4ef98 --- /dev/null +++ b/support/redscript/TweakXL.reds @@ -0,0 +1,5 @@ + +public abstract native class TweakXL { + public static native func Require(version: String) -> Bool + public static native func Version() -> String +} diff --git a/xmake.lua b/xmake.lua index ab77d3a..03a3522 100644 --- a/xmake.lua +++ b/xmake.lua @@ -1,7 +1,7 @@ set_xmakever("2.5.9") set_project("TweakXL") -set_version("1.1.0", {build = "%y%m%d%H%M"}) +set_version("1.1.1", {build = "%y%m%d%H%M"}) set_arch("x64") set_languages("cxx20", "cxx2a")