mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Plugins - Ported prerequisites UI
Scripting - Ported scripting UI
This commit is contained in:
1 parent
0256a0d625
commit
3b4194cb9d
56 files changed
+1301
-274
No files matched your search
@@ -166,10 +166,13 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public List<PluginPrerequisite> Prerequisites { get; } = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<PluginPrerequisite> PlatformPrerequisites => Prerequisites.Where(p => p.AppliesToPlatform());
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ArePrerequisitesMet()
|
||||
{
|
||||
return Prerequisites.All(p => p.IsMet());
|
||||
return PlatformPrerequisites.All(p => p.IsMet());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,11 +175,14 @@ namespace Artemis.Core
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<PluginPrerequisite> Prerequisites { get; } = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<PluginPrerequisite> PlatformPrerequisites => Prerequisites.Where(p => p.AppliesToPlatform());
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ArePrerequisitesMet()
|
||||
{
|
||||
return Prerequisites.All(p => p.IsMet());
|
||||
return PlatformPrerequisites.All(p => p.IsMet());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies OS platforms a plugin may support.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum PluginPlatform
|
||||
{
|
||||
/// <summary>The Windows platform.</summary>
|
||||
Windows = 0,
|
||||
|
||||
/// <summary>The Linux platform.</summary>
|
||||
Linux = 1,
|
||||
|
||||
/// <summary>The OSX platform.</summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
OSX = 2
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@@ -12,6 +11,11 @@ namespace Artemis.Core
|
||||
/// Gets a list of prerequisites for this plugin
|
||||
/// </summary>
|
||||
List<PluginPrerequisite> Prerequisites { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of prerequisites of the current platform for this plugin
|
||||
/// </summary>
|
||||
IEnumerable<PluginPrerequisite> PlatformPrerequisites { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the prerequisites of this plugin are met
|
||||
|
||||
@@ -22,6 +22,11 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public abstract string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the platform(s) this prerequisite applies to.
|
||||
/// </summary>
|
||||
public PluginPlatform? Platform { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of actions to execute when <see cref="Install" /> is called
|
||||
/// </summary>
|
||||
@@ -91,6 +96,23 @@ namespace Artemis.Core
|
||||
/// <returns><see langword="true" /> if the prerequisite is met; otherwise <see langword="false" /></returns>
|
||||
public abstract bool IsMet();
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this prerequisite applies to the current operating system.
|
||||
/// </summary>
|
||||
public bool AppliesToPlatform()
|
||||
{
|
||||
if (Platform == null)
|
||||
return true;
|
||||
|
||||
if (OperatingSystem.IsWindows())
|
||||
return Platform.Value.HasFlag(PluginPlatform.Windows);
|
||||
if (OperatingSystem.IsLinux())
|
||||
return Platform.Value.HasFlag(PluginPlatform.Linux);
|
||||
if (OperatingSystem.IsMacOS())
|
||||
return Platform.Value.HasFlag(PluginPlatform.OSX);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before installation starts
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -36,6 +38,11 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public string Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an optional list of files to extract, if <see langword="null"/> all files will be extracted.
|
||||
/// </summary>
|
||||
public List<string>? FilesToExtract { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task Execute(CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -50,10 +57,15 @@ namespace Artemis.Core
|
||||
{
|
||||
ZipArchive archive = new(fileStream);
|
||||
long count = 0;
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
|
||||
List<ZipArchiveEntry> entries = new(archive.Entries);
|
||||
if (FilesToExtract != null)
|
||||
entries = entries.Where(e => FilesToExtract.Contains(e.FullName)).ToList();
|
||||
|
||||
foreach (ZipArchiveEntry entry in entries)
|
||||
{
|
||||
await using Stream unzippedEntryStream = entry.Open();
|
||||
Progress.Report((count, archive.Entries.Count));
|
||||
Progress.Report((count, entries.Count));
|
||||
if (entry.Length > 0)
|
||||
{
|
||||
string path = Path.Combine(Target, entry.FullName);
|
||||
|
||||
@@ -18,11 +18,13 @@ namespace Artemis.Core.ScriptingProviders
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ScriptConfiguration" /> class
|
||||
/// </summary>
|
||||
public ScriptConfiguration(ScriptingProvider provider, string name)
|
||||
public ScriptConfiguration(ScriptingProvider provider, string name, ScriptType scriptType)
|
||||
{
|
||||
_scriptingProviderId = provider.Id;
|
||||
_name = name;
|
||||
Entity = new ScriptConfigurationEntity();
|
||||
PendingScriptContent = provider.GetDefaultScriptContent(scriptType);
|
||||
ScriptContent = PendingScriptContent;
|
||||
}
|
||||
|
||||
internal ScriptConfiguration(ScriptConfigurationEntity entity)
|
||||
|
||||
@@ -71,5 +71,11 @@ namespace Artemis.Core.ScriptingProviders
|
||||
/// </summary>
|
||||
/// <param name="scriptType">The type of script the editor will host</param>
|
||||
public abstract IScriptEditorViewModel CreateScriptEditor(ScriptType scriptType);
|
||||
|
||||
/// <summary>
|
||||
/// Called when a script for a certain type needs default content.
|
||||
/// </summary>
|
||||
/// <param name="scriptType">The type of script the default content is for.</param>
|
||||
public abstract string GetDefaultScriptContent(ScriptType scriptType);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ namespace Artemis.Core.ScriptingProviders
|
||||
/// <inheritdoc />
|
||||
internal override void InternalCleanup()
|
||||
{
|
||||
ScriptingService?.InternalGlobalScripts.Remove(this);
|
||||
ScriptingService?.RemoveScript(ScriptConfiguration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -60,10 +60,7 @@ namespace Artemis.Core.ScriptingProviders
|
||||
/// <inheritdoc />
|
||||
internal override void InternalCleanup()
|
||||
{
|
||||
lock (Profile.Scripts)
|
||||
{
|
||||
Profile.Scripts.Remove(this);
|
||||
}
|
||||
Profile.RemoveScript(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Artemis.Core.ScriptingProviders
|
||||
public abstract class Script : CorePropertyChanged, IDisposable
|
||||
{
|
||||
private ScriptingProvider _scriptingProvider = null!;
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>
|
||||
/// The base constructor of any script
|
||||
@@ -71,6 +72,10 @@ namespace Artemis.Core.ScriptingProviders
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
|
||||
_disposed = true;
|
||||
ScriptConfiguration.PropertyChanged -= ScriptConfigurationOnPropertyChanged;
|
||||
ScriptConfiguration.Script = null;
|
||||
ScriptingProvider.InternalScripts.Remove(this);
|
||||
|
||||
Reference in new issue
Block a user