mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-19 18:15:47 +02:00
Remove versions from official plugins and make them only work on one app version
This commit is contained in:
parent
1d78bd2655
commit
4d7c048139
Plugins
Resources
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
namespace TweetDuck.Plugins{
|
namespace TweetDuck.Plugins{
|
||||||
sealed class Plugin{
|
sealed class Plugin{
|
||||||
private const string VersionWildcard = "*";
|
|
||||||
private static readonly Version AppVersion = new Version(Program.VersionTag);
|
private static readonly Version AppVersion = new Version(Program.VersionTag);
|
||||||
|
|
||||||
public string Identifier { get; }
|
public string Identifier { get; }
|
||||||
@ -119,14 +118,14 @@ public override bool Equals(object obj){
|
|||||||
public sealed class Builder{
|
public sealed class Builder{
|
||||||
private static readonly Version DefaultRequiredVersion = new Version(0, 0, 0, 0);
|
private static readonly Version DefaultRequiredVersion = new Version(0, 0, 0, 0);
|
||||||
|
|
||||||
public string Name { get; private set; }
|
public string Name { get; set; }
|
||||||
public string Description { get; private set; } = string.Empty;
|
public string Description { get; set; } = string.Empty;
|
||||||
public string Author { get; private set; } = "(anonymous)";
|
public string Author { get; set; } = "(anonymous)";
|
||||||
public string Version { get; private set; } = "(unknown)";
|
public string Version { get; set; } = string.Empty;
|
||||||
public string Website { get; private set; } = string.Empty;
|
public string Website { get; set; } = string.Empty;
|
||||||
public string ConfigFile { get; private set; } = string.Empty;
|
public string ConfigFile { get; set; } = string.Empty;
|
||||||
public string ConfigDefault { get; private set; } = string.Empty;
|
public string ConfigDefault { get; set; } = string.Empty;
|
||||||
public Version RequiredVersion { get; private set; } = DefaultRequiredVersion;
|
public Version RequiredVersion { get; set; } = DefaultRequiredVersion;
|
||||||
|
|
||||||
public PluginEnvironment Environments { get; private set; } = PluginEnvironment.None;
|
public PluginEnvironment Environments { get; private set; } = PluginEnvironment.None;
|
||||||
|
|
||||||
@ -142,36 +141,10 @@ public Builder(PluginGroup group, string name, string pathRoot, string pathData)
|
|||||||
this.identifier = group.GetIdentifierPrefix()+name;
|
this.identifier = group.GetIdentifierPrefix()+name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetFromTag(string tag, string value){
|
|
||||||
switch(tag){
|
|
||||||
case "NAME": this.Name = value; break;
|
|
||||||
case "DESCRIPTION": this.Description = value; break;
|
|
||||||
case "AUTHOR": this.Author = value; break;
|
|
||||||
case "VERSION": this.Version = value; break;
|
|
||||||
case "WEBSITE": this.Website = value; break;
|
|
||||||
case "CONFIGFILE": this.ConfigFile = value; break;
|
|
||||||
case "CONFIGDEFAULT": this.ConfigDefault = value; break;
|
|
||||||
case "REQUIRES": SetRequiredVersion(value); break;
|
|
||||||
default: throw new FormatException("Invalid metadata tag: "+tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddEnvironment(PluginEnvironment environment){
|
public void AddEnvironment(PluginEnvironment environment){
|
||||||
this.Environments |= environment;
|
this.Environments |= environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetRequiredVersion(string versionStr){
|
|
||||||
if (System.Version.TryParse(versionStr, out Version version)){
|
|
||||||
this.RequiredVersion = version;
|
|
||||||
}
|
|
||||||
else if (versionStr == VersionWildcard){
|
|
||||||
this.RequiredVersion = DefaultRequiredVersion;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
throw new FormatException("Plugin contains invalid minimum version: "+versionStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Plugin BuildAndSetup(){
|
public Plugin BuildAndSetup(){
|
||||||
Plugin plugin = new Plugin(group, identifier, pathRoot, pathData, this);
|
Plugin plugin = new Plugin(group, identifier, pathRoot, pathData, this);
|
||||||
|
|
||||||
@ -183,6 +156,15 @@ public Plugin BuildAndSetup(){
|
|||||||
throw new InvalidOperationException("Plugin has no script files");
|
throw new InvalidOperationException("Plugin has no script files");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (plugin.Group == PluginGroup.Official){
|
||||||
|
if (plugin.RequiredVersion != AppVersion){
|
||||||
|
throw new InvalidOperationException("Plugin is not supported in this version of TweetDuck, this may indicate a failed update or an unsupported plugin that was not removed automatically");
|
||||||
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(plugin.Version)){
|
||||||
|
throw new InvalidOperationException("Official plugins cannot have a version identifier");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// setup
|
// setup
|
||||||
|
|
||||||
string configPath = plugin.ConfigPath, defaultConfigPath = plugin.DefaultConfigPath;
|
string configPath = plugin.ConfigPath, defaultConfigPath = plugin.DefaultConfigPath;
|
||||||
|
@ -32,7 +32,7 @@ public static Plugin FromFolder(string path, PluginGroup group){
|
|||||||
foreach(string line in File.ReadAllLines(metaFile, Encoding.UTF8).Concat(EndTag).Select(line => line.TrimEnd()).Where(line => line.Length > 0)){
|
foreach(string line in File.ReadAllLines(metaFile, Encoding.UTF8).Concat(EndTag).Select(line => line.TrimEnd()).Where(line => line.Length > 0)){
|
||||||
if (line[0] == '[' && line[line.Length-1] == ']'){
|
if (line[0] == '[' && line[line.Length-1] == ']'){
|
||||||
if (currentTag != null){
|
if (currentTag != null){
|
||||||
builder.SetFromTag(currentTag, currentContents);
|
SetProperty(builder, currentTag, currentContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTag = line.Substring(1, line.Length-2).ToUpper();
|
currentTag = line.Substring(1, line.Length-2).ToUpper();
|
||||||
@ -52,5 +52,19 @@ public static Plugin FromFolder(string path, PluginGroup group){
|
|||||||
|
|
||||||
return builder.BuildAndSetup();
|
return builder.BuildAndSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SetProperty(Plugin.Builder builder, string tag, string value){
|
||||||
|
switch(tag){
|
||||||
|
case "NAME": builder.Name = value; break;
|
||||||
|
case "DESCRIPTION": builder.Description = value; break;
|
||||||
|
case "AUTHOR": builder.Author = value; break;
|
||||||
|
case "VERSION": builder.Version = value; break;
|
||||||
|
case "WEBSITE": builder.Website = value; break;
|
||||||
|
case "CONFIGFILE": builder.ConfigFile = value; break;
|
||||||
|
case "CONFIGDEFAULT": builder.ConfigDefault = value; break;
|
||||||
|
case "REQUIRES": builder.RequiredVersion = Version.TryParse(value, out Version version) ? version : throw new FormatException("Invalid required minimum version: "+value); break;
|
||||||
|
default: throw new FormatException("Invalid metadata tag: "+tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,5 @@ Clear columns
|
|||||||
[author]
|
[author]
|
||||||
chylex
|
chylex
|
||||||
|
|
||||||
[version]
|
|
||||||
1.2.1
|
|
||||||
|
|
||||||
[website]
|
|
||||||
https://tweetduck.chylex.com
|
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
1.4.1
|
{version}
|
@ -7,11 +7,5 @@ Edit layout & design
|
|||||||
[author]
|
[author]
|
||||||
chylex
|
chylex
|
||||||
|
|
||||||
[version]
|
|
||||||
1.2.5
|
|
||||||
|
|
||||||
[website]
|
|
||||||
https://tweetduck.chylex.com
|
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
1.10.2
|
{version}
|
@ -8,11 +8,5 @@ Emoji keyboard
|
|||||||
[author]
|
[author]
|
||||||
chylex
|
chylex
|
||||||
|
|
||||||
[version]
|
|
||||||
1.4.4
|
|
||||||
|
|
||||||
[website]
|
|
||||||
https://tweetduck.chylex.com
|
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
1.5.3
|
{version}
|
@ -7,12 +7,6 @@ Custom reply account
|
|||||||
[author]
|
[author]
|
||||||
chylex
|
chylex
|
||||||
|
|
||||||
[version]
|
|
||||||
1.3
|
|
||||||
|
|
||||||
[website]
|
|
||||||
https://tweetduck.chylex.com
|
|
||||||
|
|
||||||
[configfile]
|
[configfile]
|
||||||
configuration.js
|
configuration.js
|
||||||
|
|
||||||
@ -20,4 +14,4 @@ configuration.js
|
|||||||
configuration.default.js
|
configuration.default.js
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
1.10.3
|
{version}
|
@ -7,11 +7,5 @@ Templates
|
|||||||
[author]
|
[author]
|
||||||
chylex
|
chylex
|
||||||
|
|
||||||
[version]
|
|
||||||
1.0.4
|
|
||||||
|
|
||||||
[website]
|
|
||||||
https://tweetduck.chylex.com
|
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
1.5.3
|
{version}
|
@ -7,11 +7,5 @@ Polls in timelines
|
|||||||
[author]
|
[author]
|
||||||
chylex
|
chylex
|
||||||
|
|
||||||
[version]
|
|
||||||
1.1
|
|
||||||
|
|
||||||
[website]
|
|
||||||
https://tweetduck.chylex.com
|
|
||||||
|
|
||||||
[requires]
|
[requires]
|
||||||
1.7
|
{version}
|
@ -93,6 +93,11 @@ try{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "------------------------------"
|
Write-Host "------------------------------"
|
||||||
|
ForEach($file in Get-ChildItem -Path $targetDir -Filter "*.meta" -Recurse){
|
||||||
|
$lines = Get-Content -Path $file.FullName
|
||||||
|
$lines = $lines -Replace '\{version\}', $version
|
||||||
|
,$lines | Rewrite-File $file
|
||||||
|
}
|
||||||
}catch{
|
}catch{
|
||||||
Write-Host "Encountered an error while running PostBuild.ps1 on line" $_.InvocationInfo.ScriptLineNumber
|
Write-Host "Encountered an error while running PostBuild.ps1 on line" $_.InvocationInfo.ScriptLineNumber
|
||||||
Write-Host $_
|
Write-Host $_
|
||||||
|
Loading…
Reference in New Issue
Block a user