Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Compatibility Code #1094

Merged
merged 4 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/Beutl.Configuration/GlobalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,10 @@ static void Deserialize(ICoreSerializable serializable, JsonObject obj)
if (json["Editor"] is JsonObject editor)
Deserialize(EditorConfig, editor);

if (json["Version"] is JsonValue version)
if (json["Version"] is JsonValue version
&& version.TryGetValue(out string? versionString))
{
if (version.TryGetValue(out string? versionString))
{
LastStartedVersion = versionString;
}
}
else
{
// Todo: 互換性維持のコード
LastStartedVersion = "1.0.0-preview.1";
LastStartedVersion = versionString;
}
}
}
Expand Down
35 changes: 11 additions & 24 deletions src/Beutl.Core/TypeFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public Token(TokenType type, string? text = null)
/*
* 名前空間とアセンブリ名が同じ場合
* [Beutl.Graphics]:Point
*
*
* 型がグローバル空間にある場合
* [Beutl.Graphics]global::Point
*
*
* 名前空間とアセンブリ名が途中まで同じ場合
* [Beutl.Graphics].Shapes:Ellipse
*
*
* 名前空間とアセンブリ名が一致しない場合
* [Beutl.Graphics]Beutl.Audio:Sound
*
*
* ジェネリック引数がある場合
* [System.Collections].Generic:List<[System.Runtime]System:Int32>
*
*
* 入れ子になったクラス
* [System.Net.Mail]System.Net.Mime:MediaTypeNames:Application
*/
Expand Down Expand Up @@ -98,29 +98,16 @@ internal class TypeNameParser

public TypeNameParser(List<Token> tokens, Func<string, Assembly?>? assemblyResolver = null)
{
Assembly? DefaultAssemblyResolver(string s)
{
#if !DEBUG
#warning TypeFormatの互換性コードが残っている
#endif
if (s is "Beutl.Graphics")
{
s = "Beutl.Engine";
}
else if (s is "Beutl.Framework")
{
s = "Beutl.Extensibility";
}


//AssemblyLoadContext.Default.Assemblies
return AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name == s);
}

_tokens = tokens;
_assemblyResolver = assemblyResolver ?? DefaultAssemblyResolver;
}

private static Assembly? DefaultAssemblyResolver(string s)
{
//AssemblyLoadContext.Default.Assemblies
return AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name == s);
}

public Type? Parse()
{
Token[] asmTokens = TakeAssemblyTokens(_tokens).ToArray();
Expand Down
2 changes: 0 additions & 2 deletions src/Beutl.Engine/Animation/Animatable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Nodes;

using Beutl.Media;
using Beutl.Serialization;
Expand Down Expand Up @@ -54,7 +53,6 @@ public override void Deserialize(ICoreSerializationContext context)
base.Deserialize(context);
Dictionary<string, IAnimation>? animations
= context.GetValue<Dictionary<string, IAnimation>>(nameof(Animations));
animations ??= context.GetValue<Dictionary<string, IAnimation>>("animations");

if (animations != null)
{
Expand Down
6 changes: 0 additions & 6 deletions src/Beutl.Engine/Animation/AnimationSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Text.Json.Nodes;

using Beutl.Serialization;
using Beutl.Serialization.Migration;

namespace Beutl.Animation;

Expand All @@ -28,11 +27,6 @@ internal static class AnimationSerializer
{
if (json is JsonObject obj)
{
if (Migration_ChangeSigmaType.ShouldMigrate(property))
{
Migration_ChangeSigmaType.Update(json);
}

if (obj.TryGetDiscriminator(out Type? type)
&& Activator.CreateInstance(type, property) is IAnimation animation)
{
Expand Down
31 changes: 0 additions & 31 deletions src/Beutl.Engine/Graphics/FilterEffects/Blur.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Nodes;

using Beutl.Language;
using Beutl.Serialization;
using Beutl.Serialization.Migration;

using SkiaSharp;

namespace Beutl.Graphics.Effects;

Expand Down Expand Up @@ -41,29 +35,4 @@ public override Rect TransformBounds(Rect bounds)
{
return bounds.Inflate(new Thickness(_sigma.Width * 3, _sigma.Height * 3));
}

public override void Deserialize(ICoreSerializationContext context)
{
// Todo: 互換性処理
if (context is IJsonSerializationContext jsonContext)
{
JsonObject json = jsonContext.GetJsonObject();

try
{
JsonNode? animations = json["Animations"] ?? json["animations"];
JsonNode? sigma = animations?[nameof(Sigma)];

if (sigma != null)
{
Migration_ChangeSigmaType.Update(sigma);
}
}
catch
{
}
}

base.Deserialize(context);
}
}
29 changes: 0 additions & 29 deletions src/Beutl.Engine/Graphics/FilterEffects/DropShadow.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Nodes;

using Beutl.Language;
using Beutl.Media;
using Beutl.Serialization;
using Beutl.Serialization.Migration;

namespace Beutl.Graphics.Effects;

Expand Down Expand Up @@ -89,29 +85,4 @@ public override Rect TransformBounds(Rect bounds)

return _shadowOnly ? shadowBounds : bounds.Union(shadowBounds);
}

public override void Deserialize(ICoreSerializationContext context)
{
// Todo: 互換性処理
if (context is IJsonSerializationContext jsonContext)
{
JsonObject json = jsonContext.GetJsonObject();

try
{
JsonNode? animations = json["Animations"] ?? json["animations"];
JsonNode? sigma = animations?[nameof(Sigma)];

if (sigma != null)
{
Migration_ChangeSigmaType.Update(sigma);
}
}
catch
{
}
}

base.Deserialize(context);
}
}
31 changes: 0 additions & 31 deletions src/Beutl.Engine/Graphics/FilterEffects/InnerShadow.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Nodes;

using Beutl.Language;
using Beutl.Media;
using Beutl.Serialization;
using Beutl.Serialization.Migration;

using OpenCvSharp;

namespace Beutl.Graphics.Effects;

Expand Down Expand Up @@ -82,29 +76,4 @@ public override void ApplyTo(FilterEffectContext context)
else
context.InnerShadow(Position, Sigma, Color);
}

public override void Deserialize(ICoreSerializationContext context)
{
// Todo: 互換性処理
if (context is IJsonSerializationContext jsonContext)
{
JsonObject json = jsonContext.GetJsonObject();

try
{
JsonNode? animations = json["Animations"] ?? json["animations"];
JsonNode? sigma = animations?[nameof(Sigma)];

if (sigma != null)
{
Migration_ChangeSigmaType.Update(sigma);
}
}
catch
{
}
}

base.Deserialize(context);
}
}
30 changes: 0 additions & 30 deletions src/Beutl.Engine/Graphics/FilterEffects/OpenCv/GaussianBlur.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Nodes;

using Beutl.Language;
using Beutl.Media;
using Beutl.Media.Pixel;
using Beutl.Serialization;
using Beutl.Serialization.Migration;

using OpenCvSharp;

using SkiaSharp;
Expand Down Expand Up @@ -140,29 +135,4 @@ public override Rect TransformBounds(Rect rect)
{
return TransformBounds((KernelSize, Sigma, FixImageSize), rect);
}

public override void Deserialize(ICoreSerializationContext context)
{
// Todo: 互換性処理
if (context is IJsonSerializationContext jsonContext)
{
JsonObject json = jsonContext.GetJsonObject();

try
{
JsonNode? animations = json["Animations"] ?? json["animations"];
JsonNode? sigma = animations?[nameof(Sigma)];

if (sigma != null)
{
Migration_ChangeSigmaType.Update(sigma);
}
}
catch
{
}
}

base.Deserialize(context);
}
}
32 changes: 4 additions & 28 deletions src/Beutl.Engine/Media/TextFormatting/FormattedTextTokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,13 @@

namespace Beutl.Media.TextFormatting;

public struct FormattedTextTokenizer(string str)
public readonly struct FormattedTextTokenizer(string str)
{
public bool CompatMode { get; set; } = false;

public int LineCount { get; private set; } = 0;

public List<Token> Result { get; } = [];

public void Tokenize()
{
int lineCount = CompatMode ? 0 : 1;

if (!CompatMode)
{
Tokenize(new StringSpan(str, 0, str.Length));
}
else
{
ReadOnlySpan<char> span = str.AsSpan();
foreach (ReadOnlySpan<char> linesp in span.EnumerateLines())
{
int start = span.IndexOf(linesp, StringComparison.Ordinal);
int len = linesp.Length;

Tokenize(new StringSpan(str, start, len));

Result.Add(new Token(StringSpan.Empty, TokenType.NewLine));
lineCount++;
}
}

LineCount = lineCount;
Tokenize(new StringSpan(str, 0, str.Length));
}

public void WriteTo(StringBuilder sb)
Expand Down Expand Up @@ -90,7 +65,7 @@ private void Tokenize(StringSpan s)
int tagEnd = span.IndexOf(">", StringComparison.Ordinal);

bool isMatch = tagStart >= 0 && tagEnd >= 0 &&
tagStart < tagEnd;
tagStart < tagEnd;

if (isMatch)
{
Expand Down Expand Up @@ -124,6 +99,7 @@ public override string ToString()
{
return "newline";
}

return Text.AsSpan().ToString();
}
}
Expand Down

This file was deleted.

Loading