mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
🎨Add interface for writable media images.
This commit is contained in:
1
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
1
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
@@ -422,6 +422,7 @@
|
||||
<e p="HDCopy.cs" t="Include" />
|
||||
<e p="IMD.cs" t="Include" />
|
||||
<e p="IMediaImage.cs" t="Include" />
|
||||
<e p="IWritableImage.cs" t="Include" />
|
||||
<e p="KryoFlux.cs" t="Include" />
|
||||
<e p="MaxiDisk.cs" t="Include" />
|
||||
<e p="NDIF.cs" t="Include" />
|
||||
|
||||
@@ -34,7 +34,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.DiscImages;
|
||||
using DiscImageChef.Filesystems;
|
||||
@@ -60,9 +59,13 @@ namespace DiscImageChef.Core
|
||||
/// </summary>
|
||||
public readonly SortedDictionary<string, IFilesystem> PluginsList;
|
||||
/// <summary>
|
||||
/// List of all filesystem plugins
|
||||
/// List of read-only filesystem plugins
|
||||
/// </summary>
|
||||
public readonly SortedDictionary<string, IReadOnlyFilesystem> ReadOnlyFilesystems;
|
||||
/// <summary>
|
||||
/// List of writable media image plugins
|
||||
/// </summary>
|
||||
public readonly SortedDictionary<string, IWritableImage> WritableImages;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the plugins lists
|
||||
@@ -73,10 +76,12 @@ namespace DiscImageChef.Core
|
||||
ReadOnlyFilesystems = new SortedDictionary<string, IReadOnlyFilesystem>();
|
||||
PartPluginsList = new SortedDictionary<string, IPartition>();
|
||||
ImagePluginsList = new SortedDictionary<string, IMediaImage>();
|
||||
WritableImages = new SortedDictionary<string, IWritableImage>();
|
||||
|
||||
Assembly assembly = Assembly.GetAssembly(typeof(IMediaImage));
|
||||
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IMediaImage))).Where(t=>t.IsClass))
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IMediaImage)))
|
||||
.Where(t => t.IsClass))
|
||||
try
|
||||
{
|
||||
IMediaImage plugin = (IMediaImage)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
@@ -86,18 +91,19 @@ namespace DiscImageChef.Core
|
||||
|
||||
assembly = Assembly.GetAssembly(typeof(IPartition));
|
||||
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IPartition))).Where(t=>t.IsClass))
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IPartition)))
|
||||
.Where(t => t.IsClass))
|
||||
try
|
||||
{
|
||||
IPartition plugin =
|
||||
(IPartition)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
IPartition plugin = (IPartition)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
RegisterPartPlugin(plugin);
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
|
||||
assembly = Assembly.GetAssembly(typeof(IFilesystem));
|
||||
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IFilesystem))).Where(t=>t.IsClass))
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IFilesystem)))
|
||||
.Where(t => t.IsClass))
|
||||
try
|
||||
{
|
||||
IFilesystem plugin = (IFilesystem)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
@@ -105,16 +111,29 @@ namespace DiscImageChef.Core
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
|
||||
|
||||
assembly = Assembly.GetAssembly(typeof(IReadOnlyFilesystem));
|
||||
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IReadOnlyFilesystem))).Where(t=>t.IsClass))
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IReadOnlyFilesystem)))
|
||||
.Where(t => t.IsClass))
|
||||
try
|
||||
{
|
||||
IReadOnlyFilesystem plugin = (IReadOnlyFilesystem)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
IReadOnlyFilesystem plugin =
|
||||
(IReadOnlyFilesystem)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
RegisterReadOnlyFilesystem(plugin);
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
|
||||
assembly = Assembly.GetAssembly(typeof(IWritableImage));
|
||||
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IWritableImage)))
|
||||
.Where(t => t.IsClass))
|
||||
try
|
||||
{
|
||||
IWritableImage plugin =
|
||||
(IWritableImage)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
RegisterWritableMedia(plugin);
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
}
|
||||
|
||||
void RegisterImagePlugin(IMediaImage plugin)
|
||||
@@ -130,7 +149,13 @@ namespace DiscImageChef.Core
|
||||
|
||||
void RegisterReadOnlyFilesystem(IReadOnlyFilesystem plugin)
|
||||
{
|
||||
if(!ReadOnlyFilesystems.ContainsKey(plugin.Name.ToLower())) ReadOnlyFilesystems.Add(plugin.Name.ToLower(), plugin);
|
||||
if(!ReadOnlyFilesystems.ContainsKey(plugin.Name.ToLower()))
|
||||
ReadOnlyFilesystems.Add(plugin.Name.ToLower(), plugin);
|
||||
}
|
||||
|
||||
void RegisterWritableMedia(IWritableImage plugin)
|
||||
{
|
||||
if(!WritableImages.ContainsKey(plugin.Name.ToLower())) WritableImages.Add(plugin.Name.ToLower(), plugin);
|
||||
}
|
||||
|
||||
void RegisterPartPlugin(IPartition partplugin)
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
<Compile Include="Enums.cs" />
|
||||
<Compile Include="Exceptions.cs" />
|
||||
<Compile Include="HDCopy.cs" />
|
||||
<Compile Include="IWritableImage.cs" />
|
||||
<Compile Include="KryoFlux.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Apple2MG.cs" />
|
||||
|
||||
134
DiscImageChef.DiscImages/IWritableImage.cs
Normal file
134
DiscImageChef.DiscImages/IWritableImage.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : IWritableImage.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Disc image plugins.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Defines interface to be implemented by writable image plugins.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DiscImageChef.CommonTypes;
|
||||
|
||||
namespace DiscImageChef.DiscImages
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract class to implement disk image writing plugins.
|
||||
/// TODO: This interface is subject to change until notice.
|
||||
/// </summary>
|
||||
public interface IWritableImage : IMediaImage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="MediaTagType" /> that are supported by the media image format
|
||||
/// </summary>
|
||||
List<MediaTagType> SupportedMediaTags { get; }
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="SectorTagType" /> that are supported by the media image format
|
||||
/// </summary>
|
||||
List<SectorTagType> SupportedSectorTags { get; }
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="MediaType" /> that are supported by the media image format
|
||||
/// </summary>
|
||||
List<MediaType> SupportedMediaTypes { get; }
|
||||
/// <summary>
|
||||
/// Retrieves a list of options supported by the filesystem, with name, type and description
|
||||
/// </summary>
|
||||
IEnumerable<(string name, Type type, string description)> SupportedOptions { get; }
|
||||
/// <summary>
|
||||
/// Gets a list of known extensions for format auto-chosing
|
||||
/// </summary>
|
||||
List<string> KnownExtensions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new image in the specified path, for the specified <see cref="MediaType" />, with the
|
||||
/// specified options to hold a media with the specified number of sectors
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the new image, with extension</param>
|
||||
/// <param name="mediaType"><see cref="MediaType" /> that will be written in the image</param>
|
||||
/// <param name="options">Options to be used when creating new image</param>
|
||||
/// <param name="sectors">How many sectors the media has.</param>
|
||||
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
|
||||
bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a media tag to the image
|
||||
/// </summary>
|
||||
/// <param name="data">Media tag</param>
|
||||
/// <param name="tag">
|
||||
/// <see cref="MediaTagType" />
|
||||
/// </param>
|
||||
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
|
||||
bool WriteMediaTag(byte[] data, MediaTagType tag);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a sector to the image
|
||||
/// </summary>
|
||||
/// <param name="data">Sector data</param>
|
||||
/// <param name="sectorAddress">Sector address</param>
|
||||
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
|
||||
bool WriteSector(byte[] data, ulong sectorAddress);
|
||||
|
||||
/// <summary>
|
||||
/// Writes several sectors to the image
|
||||
/// </summary>
|
||||
/// <param name="data">Sectors data</param>
|
||||
/// <param name="sectorAddress">Sector starting address</param>
|
||||
/// <param name="length">How many sectors to write</param>
|
||||
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
|
||||
bool WriteSectors(byte[] data, ulong sectorAddress, uint length);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a sector to the image with tags attached
|
||||
/// </summary>
|
||||
/// <param name="data">Sector data with its tags attached</param>
|
||||
/// <param name="sectorAddress">Sector address</param>
|
||||
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
|
||||
bool WriteSectorLong(byte[] data, ulong sectorAddress);
|
||||
|
||||
/// <summary>
|
||||
/// Writes several sectors to the image
|
||||
/// </summary>
|
||||
/// <param name="data">Sector data with their tags attached</param>
|
||||
/// <param name="sectorAddress">Sector starting address</param>
|
||||
/// <param name="length">How many sectors to write</param>
|
||||
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
|
||||
bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length);
|
||||
|
||||
/// <summary>
|
||||
/// Sets tracks for optical media
|
||||
/// </summary>
|
||||
/// <param name="tracks">List of tracks</param>
|
||||
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
|
||||
bool SetTracks(List<Track> tracks);
|
||||
|
||||
/// <summary>
|
||||
/// Closes and flushes to disk the image
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
|
||||
bool Close();
|
||||
}
|
||||
}
|
||||
@@ -51,32 +51,55 @@ namespace DiscImageChef.Commands
|
||||
DicConsole.WriteLine("Supported filters ({0}):", filtersList.Filters.Count);
|
||||
if(formatsOptions.Verbose) DicConsole.VerboseWriteLine("GUID\t\t\t\t\tFilter");
|
||||
foreach(KeyValuePair<string, IFilter> kvp in filtersList.Filters)
|
||||
if(formatsOptions.Verbose) DicConsole.VerboseWriteLine("{0}\t{1}", kvp.Value.Id, kvp.Value.Name);
|
||||
else DicConsole.WriteLine(kvp.Value.Name);
|
||||
if(formatsOptions.Verbose)
|
||||
DicConsole.VerboseWriteLine("{0}\t{1}", kvp.Value.Id, kvp.Value.Name);
|
||||
else
|
||||
DicConsole.WriteLine(kvp.Value.Name);
|
||||
|
||||
DicConsole.WriteLine();
|
||||
DicConsole.WriteLine("Supported disc image formats ({0}):", plugins.ImagePluginsList.Count);
|
||||
DicConsole.WriteLine("Read-only media image formats ({0}):",
|
||||
plugins.ImagePluginsList.Count(t => !t.Value.GetType().GetInterfaces()
|
||||
.Contains(typeof(IWritableImage))));
|
||||
if(formatsOptions.Verbose) DicConsole.VerboseWriteLine("GUID\t\t\t\t\tPlugin");
|
||||
foreach(KeyValuePair<string, IMediaImage> kvp in plugins.ImagePluginsList)
|
||||
if(formatsOptions.Verbose)
|
||||
DicConsole.VerboseWriteLine("{0}\t{1}", kvp.Value.Id, kvp.Value.Name);
|
||||
else DicConsole.WriteLine(kvp.Value.Name);
|
||||
else
|
||||
DicConsole.WriteLine(kvp.Value.Name);
|
||||
|
||||
DicConsole.WriteLine();
|
||||
DicConsole.WriteLine("Supported filesystems for identification and information only ({0}):", plugins.PluginsList.Count(t => !t.Value.GetType().GetInterfaces().Contains(typeof(IReadOnlyFilesystem))));
|
||||
DicConsole.WriteLine("Read/write media image formats ({0}):", plugins.WritableImages.Count);
|
||||
if(formatsOptions.Verbose) DicConsole.VerboseWriteLine("GUID\t\t\t\t\tPlugin");
|
||||
foreach(KeyValuePair<string, IFilesystem> kvp in plugins.PluginsList.Where(t => !t.Value.GetType().GetInterfaces().Contains(typeof(IReadOnlyFilesystem))))
|
||||
foreach(KeyValuePair<string, IWritableImage> kvp in plugins.WritableImages)
|
||||
if(formatsOptions.Verbose)
|
||||
DicConsole.VerboseWriteLine("{0}\t{1}", kvp.Value.Id, kvp.Value.Name);
|
||||
else DicConsole.WriteLine(kvp.Value.Name);
|
||||
else
|
||||
DicConsole.WriteLine(kvp.Value.Name);
|
||||
|
||||
DicConsole.WriteLine();
|
||||
DicConsole.WriteLine("Supported filesystems that can read their contents ({0}):", plugins.ReadOnlyFilesystems.Count);
|
||||
DicConsole.WriteLine("Supported filesystems for identification and information only ({0}):",
|
||||
plugins.PluginsList.Count(t => !t.Value.GetType().GetInterfaces()
|
||||
.Contains(typeof(IReadOnlyFilesystem))));
|
||||
if(formatsOptions.Verbose) DicConsole.VerboseWriteLine("GUID\t\t\t\t\tPlugin");
|
||||
foreach(KeyValuePair<string, IFilesystem> kvp in plugins.PluginsList.Where(t => !t.Value.GetType()
|
||||
.GetInterfaces()
|
||||
.Contains(typeof(
|
||||
IReadOnlyFilesystem
|
||||
))))
|
||||
if(formatsOptions.Verbose)
|
||||
DicConsole.VerboseWriteLine("{0}\t{1}", kvp.Value.Id, kvp.Value.Name);
|
||||
else
|
||||
DicConsole.WriteLine(kvp.Value.Name);
|
||||
|
||||
DicConsole.WriteLine();
|
||||
DicConsole.WriteLine("Supported filesystems that can read their contents ({0}):",
|
||||
plugins.ReadOnlyFilesystems.Count);
|
||||
if(formatsOptions.Verbose) DicConsole.VerboseWriteLine("GUID\t\t\t\t\tPlugin");
|
||||
foreach(KeyValuePair<string, IReadOnlyFilesystem> kvp in plugins.ReadOnlyFilesystems)
|
||||
if(formatsOptions.Verbose)
|
||||
DicConsole.VerboseWriteLine("{0}\t{1}", kvp.Value.Id, kvp.Value.Name);
|
||||
else DicConsole.WriteLine(kvp.Value.Name);
|
||||
else
|
||||
DicConsole.WriteLine(kvp.Value.Name);
|
||||
|
||||
DicConsole.WriteLine();
|
||||
DicConsole.WriteLine("Supported partitioning schemes ({0}):", plugins.PartPluginsList.Count);
|
||||
@@ -84,7 +107,8 @@ namespace DiscImageChef.Commands
|
||||
foreach(KeyValuePair<string, IPartition> kvp in plugins.PartPluginsList)
|
||||
if(formatsOptions.Verbose)
|
||||
DicConsole.VerboseWriteLine("{0}\t{1}", kvp.Value.Id, kvp.Value.Name);
|
||||
else DicConsole.WriteLine(kvp.Value.Name);
|
||||
else
|
||||
DicConsole.WriteLine(kvp.Value.Name);
|
||||
|
||||
Core.Statistics.AddCommand("formats");
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Core;
|
||||
using DiscImageChef.DiscImages;
|
||||
using DiscImageChef.Filesystems;
|
||||
|
||||
namespace DiscImageChef.Commands
|
||||
@@ -45,15 +46,28 @@ namespace DiscImageChef.Commands
|
||||
{
|
||||
PluginBase plugins = new PluginBase();
|
||||
|
||||
DicConsole.WriteLine("Read-only filesystems options:");
|
||||
foreach(KeyValuePair<string, IReadOnlyFilesystem> kvp in plugins.ReadOnlyFilesystems)
|
||||
{
|
||||
List<(string name, Type type, string description)> options = kvp.Value.SupportedOptions.ToList();
|
||||
options.Add(("debug", typeof(bool), "Enables debug features if available"));
|
||||
|
||||
DicConsole.WriteLine("Options for {0}:", kvp.Value.Name);
|
||||
DicConsole.WriteLine("{0,-16} {1,-16} {2,-8}", "Name", "Type", "Description");
|
||||
DicConsole.WriteLine("\tOptions for {0}:", kvp.Value.Name);
|
||||
DicConsole.WriteLine("\t\t{0,-16} {1,-16} {2,-8}", "Name", "Type", "Description");
|
||||
foreach((string name, Type type, string description) option in options.OrderBy(t => t.name))
|
||||
DicConsole.WriteLine("{0,-16} {1,-16} {2,-8}", option.name, option.type, option.description);
|
||||
DicConsole.WriteLine("\t\t{0,-16} {1,-16} {2,-8}", option.name, option.type, option.description);
|
||||
DicConsole.WriteLine();
|
||||
}
|
||||
|
||||
DicConsole.WriteLine("Read/Write media images options:");
|
||||
foreach(KeyValuePair<string, IWritableImage> kvp in plugins.WritableImages)
|
||||
{
|
||||
List<(string name, Type type, string description)> options = kvp.Value.SupportedOptions.ToList();
|
||||
|
||||
DicConsole.WriteLine("\tOptions for {0}:", kvp.Value.Name);
|
||||
DicConsole.WriteLine("\t\t{0,-16} {1,-16} {2,-8}", "Name", "Type", "Description");
|
||||
foreach((string name, Type type, string description) option in options.OrderBy(t => t.name))
|
||||
DicConsole.WriteLine("\t\t{0,-16} {1,-16} {2,-8}", option.name, option.type, option.description);
|
||||
DicConsole.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,6 +351,6 @@ namespace DiscImageChef
|
||||
[Verb("list-encodings", HelpText = "Lists all supported text encodings and code pages.")]
|
||||
public class ListEncodingsOptions : CommonOptions { }
|
||||
|
||||
[Verb("list-options", HelpText = "Lists all options supported by read-only filesystems.")]
|
||||
[Verb("list-options", HelpText = "Lists all options supported by read-only filesystems and writable media images.")]
|
||||
public class ListOptionsOptions : CommonOptions { }
|
||||
}
|
||||
Reference in New Issue
Block a user