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

Register the flux components so they build #852

Merged
merged 1 commit into from
Oct 20, 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
53 changes: 51 additions & 2 deletions Aaru.Generators/PluginRegisterGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;

Check warning on line 1 in Aaru.Generators/PluginRegisterGenerator.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Build

Correct the spelling of 'Aaru' in assembly name 'Aaru.Generators' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1704)

Check warning on line 1 in Aaru.Generators/PluginRegisterGenerator.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Build

Correct the spelling of 'Aaru' in assembly name 'Aaru.Generators' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1704)
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Aaru.Generators;

Check warning on line 7 in Aaru.Generators/PluginRegisterGenerator.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Build

Correct the spelling of 'Aaru' in namespace name 'Aaru' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1704)

Check warning on line 7 in Aaru.Generators/PluginRegisterGenerator.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Build

Correct the spelling of 'Aaru' in namespace name 'Aaru' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1704)

[Generator]
public class PluginRegisterGenerator : ISourceGenerator
Expand Down Expand Up @@ -44,7 +44,7 @@
string className = pluginRegister.Identifier.Text;

List<string> archives = ((PluginFinder)context.SyntaxReceiver)?.Archives;
List<string> checksums = ((PluginFinder)context.SyntaxReceiver)?.Checksums;

Check warning on line 47 in Aaru.Generators/PluginRegisterGenerator.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Build

Correct the spelling of 'checksums' in variable name 'checksums' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1704)

Check warning on line 47 in Aaru.Generators/PluginRegisterGenerator.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Build

Correct the spelling of 'checksums' in variable name 'checksums' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1704)
List<string> fileSystems = ((PluginFinder)context.SyntaxReceiver)?.FileSystems;
List<string> filters = ((PluginFinder)context.SyntaxReceiver)?.Filters;
List<string> floppyImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.FloppyImagePlugins;
Expand All @@ -54,6 +54,8 @@
List<string> writableFloppyImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.WritableFloppyImagePlugins;
List<string> writableImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.WritableImagePlugins;
List<string> byteAddressableImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.ByteAddressableImagePlugins;
List<string> fluxImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.FluxImagePlugins;
List<string> writableFluxImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.WritableFluxImagePlugins;

StringBuilder sb = new();

Expand Down Expand Up @@ -269,6 +271,32 @@
else
sb.AppendLine(" public void RegisterByteAddressablePlugins(IServiceCollection services) {}");

if(fluxImagePlugins?.Count > 0)
{
sb.AppendLine(" public void RegisterFluxImagePlugins(IServiceCollection services)");
sb.AppendLine(" {");

foreach(string plugin in fluxImagePlugins.Distinct())
sb.AppendLine($" services.AddTransient<IFluxImage, {plugin}>();");

sb.AppendLine(" }");
}
else
sb.AppendLine(" public void RegisterFluxImagePlugins(IServiceCollection services) {}");

if(writableFluxImagePlugins?.Count > 0)
{
sb.AppendLine(" public void RegisterWritableFluxImagePlugins(IServiceCollection services)");
sb.AppendLine(" {");

foreach(string plugin in writableFluxImagePlugins.Distinct())
sb.AppendLine($" services.AddTransient<IWritableFluxImage, {plugin}>();");

sb.AppendLine(" }");
}
else
sb.AppendLine(" public void RegisterWritableFluxImagePlugins(IServiceCollection services) {}");

sb.AppendLine("}");

context.AddSource("Register.g.cs", sb.ToString());
Expand All @@ -281,7 +309,7 @@
sealed class PluginFinder : ISyntaxReceiver
{
public List<string> Archives { get; } = [];
public List<string> Checksums { get; } = [];

Check warning on line 312 in Aaru.Generators/PluginRegisterGenerator.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Build

Correct the spelling of 'Checksums' in member name 'Aaru.Generators.PluginRegisterGenerator.PluginFinder.Checksums' or remove it entirely if it represents any sort of Hungarian notation (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1704)

Check warning on line 312 in Aaru.Generators/PluginRegisterGenerator.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Build

Correct the spelling of 'Checksums' in member name 'Aaru.Generators.PluginRegisterGenerator.PluginFinder.Checksums' or remove it entirely if it represents any sort of Hungarian notation (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1704)
public List<string> FileSystems { get; } = [];
public List<string> Filters { get; } = [];
public List<string> FloppyImagePlugins { get; } = [];
Expand All @@ -291,6 +319,8 @@
public List<string> WritableFloppyImagePlugins { get; } = [];
public List<string> WritableImagePlugins { get; } = [];
public List<string> ByteAddressableImagePlugins { get; } = [];
public List<string> FluxImagePlugins { get; } = [];
public List<string> WritableFluxImagePlugins { get; } = [];
public ClassDeclarationSyntax Register { get; private set; }

#region ISyntaxReceiver Members
Expand Down Expand Up @@ -340,11 +370,20 @@
if(!FloppyImagePlugins.Contains(plugin.Identifier.Text))
FloppyImagePlugins.Add(plugin.Identifier.Text);

if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
.ValueText ==
"IFluxImage") ==
true)
if(!FluxImagePlugins.Contains(plugin.Identifier.Text))
FluxImagePlugins.Add(plugin.Identifier.Text);


if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
.ValueText is "IMediaImage"
or "IOpticalMediaImage"
or "IFloppyImage"
or "ITapeImage") ==
or "ITapeImage"
or "IFluxImage") ==
true)
if(!MediaImagePlugins.Contains(plugin.Identifier.Text))
MediaImagePlugins.Add(plugin.Identifier.Text);
Expand Down Expand Up @@ -374,11 +413,21 @@
WritableFloppyImagePlugins.Add(plugin.Identifier.Text);
}

if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
.ValueText ==
"IWritableFluxImage") ==
true)
{
if(!WritableFluxImagePlugins.Contains(plugin.Identifier.Text))
WritableFluxImagePlugins.Add(plugin.Identifier.Text);
}

if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
.ValueText is "IWritableImage"
or "IWritableOpticalImage"
or "IWritableTapeImage"
or "IByteAddressableImage") ==
or "IByteAddressableImage"
or "IWritableFluxImage") ==
true)
{
if(!WritableImagePlugins.Contains(plugin.Identifier.Text))
Expand Down
4 changes: 3 additions & 1 deletion Aaru.Images/A2R/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public enum A2rDriveType : byte
DS_525_80trk = 0x3,
DS_525_40trk = 0x4,
DS_35_80trk = 0x5,
DS_8 = 0x6
DS_8 = 0x6,
DS_3_80trk = 0x7,
DS_3_40trk = 0x8
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Aaru.Images/A2R/Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public sealed partial class A2R
{
// TODO: A2R supports a lot more formats, please add more whence tested.
MediaType.DOS_35_DS_DD_9, MediaType.DOS_35_HD, MediaType.DOS_525_DS_DD_9, MediaType.DOS_525_HD,
MediaType.Apple32SS, MediaType.Unknown
MediaType.Apple32SS, MediaType.AppleSonyDS, MediaType.Unknown
};

/// <inheritdoc />
Expand Down
10 changes: 10 additions & 0 deletions Aaru.Images/A2R/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ public ErrorNumber Open(IFilter imageFilter)
_imageInfo.Heads = 2;
_imageInfo.Cylinders = 40;

break;
case A2rDriveType.DS_3_80trk:
_imageInfo.Heads = 2;
_imageInfo.Cylinders = 80;

break;
case A2rDriveType.DS_3_40trk:
_imageInfo.Heads = 2;
_imageInfo.Cylinders = 40;

break;
default:
return ErrorNumber.OutOfRange;
Expand Down
3 changes: 3 additions & 0 deletions Aaru.Images/A2R/Write.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ public bool Create(string path, MediaType mediaType, Dictionary<string, string>
_infoChunkV3.driveType = mediaType switch
{
MediaType.DOS_525_DS_DD_9 => A2rDriveType.DS_525_40trk,
MediaType.DOS_35_HD => A2rDriveType.DS_35_80trk,
MediaType.DOS_525_HD => A2rDriveType.DS_525_80trk,
MediaType.AppleSonyDS => A2rDriveType.DS_35_80trk_appleCLV,
MediaType.Apple32SS => A2rDriveType.SS_525_40trk_quarterStep,
MediaType.Unknown => A2rDriveType.DS_35_80trk,
_ => _infoChunkV3.driveType
Expand Down
Loading