Skip to content

Commit

Permalink
Register the flux components so they build
Browse files Browse the repository at this point in the history
  • Loading branch information
FakeShemp authored and claunia committed Oct 20, 2024
1 parent d59012c commit 1c92058
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
53 changes: 51 additions & 2 deletions Aaru.Generators/PluginRegisterGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public void Execute(GeneratorExecutionContext context)
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 @@ public void Execute(GeneratorExecutionContext context)
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 @@ -291,6 +319,8 @@ sealed class PluginFinder : ISyntaxReceiver
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 @@ public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
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 @@ .ValueText is "IMediaImage"
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

0 comments on commit 1c92058

Please sign in to comment.