Skip to content

Commit

Permalink
Fixed the runtime errors I've run in to so far
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeekman committed Feb 27, 2024
1 parent 6d8572c commit 6882658
Show file tree
Hide file tree
Showing 38 changed files with 333 additions and 148 deletions.
12 changes: 4 additions & 8 deletions src/Artemis.Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ public static class Constants
/// </summary>
public static readonly Plugin CorePlugin = new(CorePluginInfo, new DirectoryInfo(ApplicationFolder), null);

internal static readonly CorePluginFeature CorePluginFeature = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Core")};
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Effect Placeholder")};

internal static JsonSerializerOptions JsonConvertSettings = new()
{
Converters = {new SKColorConverter(), new NumericJsonConverter(), new ForgivingIntConverter()}
};

/// <summary>
/// A read-only collection containing all primitive numeric types
/// </summary>
Expand Down Expand Up @@ -147,4 +139,8 @@ public static class Constants
/// Gets the startup arguments provided to the application
/// </summary>
public static ReadOnlyCollection<string> StartupArguments { get; set; } = null!;

internal static readonly CorePluginFeature CorePluginFeature = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Core")};
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Effect Placeholder")};
internal static readonly JsonSerializerOptions JsonConvertSettings = new() {Converters = {new SKColorConverter(), new NumericJsonConverter()}};
}
34 changes: 0 additions & 34 deletions src/Artemis.Core/JsonConverters/ForgivingIntConverter.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Artemis.Core/Models/Profile/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public Folder CreateCopy()
if (Parent == null)
throw new ArtemisCoreException("Cannot create a copy of a folder without a parent");

FolderEntity entityCopy = CoreJson.DeserializeObject<FolderEntity>(CoreJson.SerializeObject(FolderEntity))!;
FolderEntity entityCopy = CoreJson.Deserialize<FolderEntity>(CoreJson.Serialize(FolderEntity))!;
entityCopy.Id = Guid.NewGuid();
entityCopy.Name += " - Copy";

Expand Down
10 changes: 5 additions & 5 deletions src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ public void ApplyDefaultValue()
// Reference types make a deep clone (ab)using JSON
else
{
string json = CoreJson.SerializeObject(DefaultValue);
SetCurrentValue(CoreJson.DeserializeObject<T>(json)!);
string json = CoreJson.Serialize(DefaultValue);
SetCurrentValue(CoreJson.Deserialize<T>(json)!);
}
}

Expand Down Expand Up @@ -420,7 +420,7 @@ public void AddKeyframe(LayerPropertyKeyframe<T> keyframe)

try
{
T? value = CoreJson.DeserializeObject<T>(keyframeEntity.Value);
T? value = CoreJson.Deserialize<T>(keyframeEntity.Value);
if (value == null)
return null;

Expand Down Expand Up @@ -625,7 +625,7 @@ public void Load()
try
{
if (Entity.Value != null)
BaseValue = CoreJson.DeserializeObject<T>(Entity.Value)!;
BaseValue = CoreJson.Deserialize<T>(Entity.Value)!;
}
catch (JsonException)
{
Expand Down Expand Up @@ -664,7 +664,7 @@ public void Save()
if (!_isInitialized)
throw new ArtemisCoreException("Layer property is not yet initialized");

Entity.Value = CoreJson.SerializeObject(BaseValue);
Entity.Value = CoreJson.Serialize(BaseValue);
Entity.KeyframesEnabled = KeyframesEnabled;
Entity.KeyframeEntities.Clear();
Entity.KeyframeEntities.AddRange(Keyframes.Select(k => k.GetKeyframeEntity()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public KeyframeEntity GetKeyframeEntity()
{
return new KeyframeEntity
{
Value = CoreJson.SerializeObject(Value),
Value = CoreJson.Serialize(Value),
Position = Position,
EasingFunction = (int) EasingFunction
};
Expand Down
12 changes: 12 additions & 0 deletions src/Artemis.Core/Plugins/PluginInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
private Uri? _license;
private string? _licenseName;

[JsonConstructor]
internal PluginInfo()
{
}
Expand All @@ -37,6 +38,7 @@ internal PluginInfo()
/// The plugins GUID
/// </summary>
[JsonRequired]
[JsonInclude]
public Guid Guid
{
get => _guid;
Expand All @@ -47,6 +49,7 @@ public Guid Guid
/// The name of the plugin
/// </summary>
[JsonRequired]
[JsonInclude]
public string Name
{
get => _name;
Expand Down Expand Up @@ -130,6 +133,7 @@ public string? Icon
/// The version of the plugin
/// </summary>
[JsonRequired]
[JsonInclude]
public string Version
{
get => _version;
Expand All @@ -140,6 +144,7 @@ public string Version
/// The main entry DLL, should contain a class implementing Plugin
/// </summary>
[JsonRequired]
[JsonInclude]
public string Main
{
get => _main;
Expand All @@ -159,6 +164,7 @@ public bool AutoEnableFeatures
/// <summary>
/// Gets a boolean indicating whether this plugin requires elevated admin privileges
/// </summary>
[JsonInclude]
public bool RequiresAdmin
{
get => _requiresAdmin;
Expand All @@ -177,6 +183,7 @@ public bool HotReloadSupported
/// <summary>
/// Gets
/// </summary>
[JsonInclude]
public PluginPlatform? Platforms
{
get => _platforms;
Expand All @@ -186,6 +193,7 @@ public PluginPlatform? Platforms
/// <summary>
/// Gets the API version the plugin was built for
/// </summary>
[JsonInclude]
public Version? Api
{
get => _api;
Expand All @@ -195,6 +203,7 @@ public Version? Api
/// <summary>
/// Gets the plugin this info is associated with
/// </summary>
[JsonIgnore]
public Plugin Plugin
{
get => _plugin;
Expand All @@ -204,6 +213,7 @@ public Plugin Plugin
/// <summary>
/// Gets a string representing either a full path pointing to an svg or the markdown icon
/// </summary>
[JsonIgnore]
public string? ResolvedIcon
{
get
Expand All @@ -228,9 +238,11 @@ public override string ToString()
}

/// <inheritdoc />
[JsonIgnore]
public List<PluginPrerequisite> Prerequisites { get; } = new();

/// <inheritdoc />
[JsonIgnore]
public IEnumerable<PluginPrerequisite> PlatformPrerequisites => Prerequisites.Where(p => p.AppliesToPlatform());

/// <inheritdoc />
Expand Down
8 changes: 4 additions & 4 deletions src/Artemis.Core/Plugins/Settings/PluginSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal PluginSetting(IPluginRepository pluginRepository, PluginSettingEntity p
Name = pluginSettingEntity.Name;
try
{
_value = CoreJson.DeserializeObject<T>(pluginSettingEntity.Value)!;
_value = CoreJson.Deserialize<T>(pluginSettingEntity.Value)!;
}
catch (JsonException)
{
Expand Down Expand Up @@ -76,15 +76,15 @@ protected internal virtual void OnSettingSaved()
public string Name { get; }

/// <inheritdoc />
public bool HasChanged => CoreJson.SerializeObject(Value) != _pluginSettingEntity.Value;
public bool HasChanged => CoreJson.Serialize(Value) != _pluginSettingEntity.Value;

/// <inheritdoc />
public bool AutoSave { get; set; }

/// <inheritdoc />
public void RejectChanges()
{
Value = CoreJson.DeserializeObject<T>(_pluginSettingEntity.Value);
Value = CoreJson.Deserialize<T>(_pluginSettingEntity.Value);
}

/// <inheritdoc />
Expand All @@ -93,7 +93,7 @@ public void Save()
if (!HasChanged)
return;

_pluginSettingEntity.Value = CoreJson.SerializeObject(Value);
_pluginSettingEntity.Value = CoreJson.Serialize(Value);
_pluginRepository.SaveSetting(_pluginSettingEntity);
OnSettingSaved();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Artemis.Core/Plugins/Settings/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public PluginSetting<T> GetSetting<T>(string name, T? defaultValue = default)
{
Name = name,
PluginGuid = Plugin.Guid,
Value = CoreJson.SerializeObject(defaultValue)
Value = CoreJson.Serialize(defaultValue)
};
_pluginRepository.AddSetting(settingEntity);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Artemis.Core/Services/NodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public TypeColorRegistration GetTypeColorRegistration(Type type)
public string ExportScript(NodeScript nodeScript)
{
nodeScript.Save();
return CoreJson.SerializeObject(nodeScript.Entity);
return CoreJson.Serialize(nodeScript.Entity);
}

public void ImportScript(string json, NodeScript target)
{
NodeScriptEntity? entity = CoreJson.DeserializeObject<NodeScriptEntity>(json);
NodeScriptEntity? entity = CoreJson.Deserialize<NodeScriptEntity>(json);
if (entity == null)
throw new ArtemisCoreException("Failed to load node script");

Expand Down
6 changes: 3 additions & 3 deletions src/Artemis.Core/Services/PluginManagementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void ExtractBuiltInPlugin(FileInfo zipFile, DirectoryInfo pluginDirector
throw new ArtemisPluginException("Couldn't find a plugin.json in " + zipFile.FullName);

using StreamReader reader = new(metaDataFileEntry.Open());
PluginInfo builtInPluginInfo = CoreJson.DeserializeObject<PluginInfo>(reader.ReadToEnd())!;
PluginInfo builtInPluginInfo = CoreJson.Deserialize<PluginInfo>(reader.ReadToEnd())!;
string preferred = builtInPluginInfo.PreferredPluginDirectory;

// Find the matching plugin in the plugin folder
Expand Down Expand Up @@ -360,7 +360,7 @@ public void UnloadPlugins()
_logger.Warning(new ArtemisPluginException("Couldn't find the plugins metadata file at " + metadataFile), "Plugin exception");

// PluginInfo contains the ID which we need to move on
PluginInfo pluginInfo = CoreJson.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile))!;
PluginInfo pluginInfo = CoreJson.Deserialize<PluginInfo>(File.ReadAllText(metadataFile))!;

if (!pluginInfo.IsCompatible)
return null;
Expand Down Expand Up @@ -610,7 +610,7 @@ public void DisablePlugin(Plugin plugin, bool saveState)
throw new ArtemisPluginException("Couldn't find a plugin.json in " + fileName);

using StreamReader reader = new(metaDataFileEntry.Open());
PluginInfo pluginInfo = CoreJson.DeserializeObject<PluginInfo>(reader.ReadToEnd())!;
PluginInfo pluginInfo = CoreJson.Deserialize<PluginInfo>(reader.ReadToEnd())!;
if (!pluginInfo.Main.EndsWith(".dll"))
throw new ArtemisPluginException("Main entry in plugin.json must point to a .dll file");

Expand Down
8 changes: 4 additions & 4 deletions src/Artemis.Core/Services/Storage/ProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ public async Task<Stream> ExportProfile(ProfileConfiguration profileConfiguratio
if (profileEntity == null)
throw new ArtemisCoreException("Could not locate profile entity");

string configurationJson = CoreJson.SerializeObject(profileConfiguration.Entity);
string profileJson = CoreJson.SerializeObject(profileEntity);
string configurationJson = CoreJson.Serialize(profileConfiguration.Entity);
string profileJson = CoreJson.Serialize(profileEntity);

MemoryStream archiveStream = new();

Expand Down Expand Up @@ -461,11 +461,11 @@ public async Task<ProfileConfiguration> ImportProfile(Stream archiveStream, Prof
// Deserialize profile configuration to JObject
await using Stream configurationStream = configurationEntry.Open();
using StreamReader configurationReader = new(configurationStream);
JsonObject? configurationJson = CoreJson.DeserializeObject<JsonObject>(await configurationReader.ReadToEndAsync());
JsonObject? configurationJson = CoreJson.Deserialize<JsonObject>(await configurationReader.ReadToEndAsync());
// Deserialize profile to JObject
await using Stream profileStream = profileEntry.Open();
using StreamReader profileReader = new(profileStream);
JsonObject? profileJson = CoreJson.DeserializeObject<JsonObject>(await profileReader.ReadToEndAsync());
JsonObject? profileJson = CoreJson.Deserialize<JsonObject>(await profileReader.ReadToEndAsync());

// Before deserializing, apply any pending migrations
MigrateProfile(configurationJson, profileJson);
Expand Down
Loading

0 comments on commit 6882658

Please sign in to comment.