mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Refactor and reformat code
git-svn-id: svn://claunia.com/FileSystemIDandChk@29 17725271-3d32-4980-a8cb-9ff532f270ba
This commit is contained in:
@@ -7,26 +7,26 @@ using FileSystemIDandChk.ImagePlugins;
|
||||
|
||||
namespace FileSystemIDandChk
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
static PluginBase plugins;
|
||||
public static bool chkPartitions;
|
||||
public static bool chkFilesystems;
|
||||
public static bool isDebug;
|
||||
|
||||
public static void Main (string[] args)
|
||||
{
|
||||
plugins = new PluginBase();
|
||||
class MainClass
|
||||
{
|
||||
static PluginBase plugins;
|
||||
public static bool chkPartitions;
|
||||
public static bool chkFilesystems;
|
||||
public static bool isDebug;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
plugins = new PluginBase();
|
||||
|
||||
chkPartitions = true;
|
||||
chkFilesystems = true;
|
||||
chkPartitions = true;
|
||||
chkFilesystems = true;
|
||||
// RELEASE
|
||||
//isDebug = false;
|
||||
// DEBUG
|
||||
isDebug = true;
|
||||
|
||||
Console.WriteLine ("Filesystem Identifier and Checker");
|
||||
Console.WriteLine ("Copyright (C) Natalia Portillo, All Rights Reserved");
|
||||
Console.WriteLine("Filesystem Identifier and Checker");
|
||||
Console.WriteLine("Copyright (C) Natalia Portillo, All Rights Reserved");
|
||||
|
||||
// For debug
|
||||
if (isDebug)
|
||||
@@ -82,32 +82,29 @@ namespace FileSystemIDandChk
|
||||
case "--debug":
|
||||
isDebug = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Runner(args[args.Length - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Runner (string filename)
|
||||
{
|
||||
FileStream stream;
|
||||
List<string> id_plugins;
|
||||
Plugin _plugin;
|
||||
string information;
|
||||
bool checkraw = false;
|
||||
static void Runner(string filename)
|
||||
{
|
||||
List<string> id_plugins;
|
||||
Plugin _plugin;
|
||||
string information;
|
||||
bool checkraw = false;
|
||||
ImagePlugin _imageFormat;
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
_imageFormat = null;
|
||||
|
||||
foreach(ImagePlugin _imageplugin in plugins.ImagePluginsList.Values)
|
||||
foreach (ImagePlugin _imageplugin in plugins.ImagePluginsList.Values)
|
||||
{
|
||||
if(_imageplugin.IdentifyImage(filename))
|
||||
if (_imageplugin.IdentifyImage(filename))
|
||||
{
|
||||
_imageFormat = _imageplugin;
|
||||
Console.WriteLine("Image format identified by {0}.", _imageplugin.Name);
|
||||
@@ -115,7 +112,7 @@ namespace FileSystemIDandChk
|
||||
}
|
||||
}
|
||||
|
||||
if(_imageFormat == null)
|
||||
if (_imageFormat == null)
|
||||
{
|
||||
Console.WriteLine("Image format not identified, not proceeding.");
|
||||
return;
|
||||
@@ -123,21 +120,21 @@ namespace FileSystemIDandChk
|
||||
|
||||
try
|
||||
{
|
||||
if(!_imageFormat.OpenImage(filename))
|
||||
if (!_imageFormat.OpenImage(filename))
|
||||
{
|
||||
Console.WriteLine("Unable to open image format");
|
||||
Console.WriteLine("No error given");
|
||||
return;
|
||||
}
|
||||
|
||||
if(isDebug)
|
||||
if (isDebug)
|
||||
{
|
||||
Console.WriteLine("DEBUG: Correctly opened image file.");
|
||||
Console.WriteLine("DEBUG: Image without headers is {0} bytes.", _imageFormat.GetImageSize());
|
||||
Console.WriteLine("DEBUG: Image has {0} sectors.", _imageFormat.GetSectors());
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Unable to open image format");
|
||||
Console.WriteLine("Error: {0}", ex.Message);
|
||||
@@ -146,152 +143,147 @@ namespace FileSystemIDandChk
|
||||
|
||||
Console.WriteLine("Image identified as {0}.", _imageFormat.GetImageFormat());
|
||||
|
||||
if(chkPartitions)
|
||||
{
|
||||
List<Partition> partitions = new List<Partition>();
|
||||
string partition_scheme = "";
|
||||
if (chkPartitions)
|
||||
{
|
||||
List<Partition> partitions = new List<Partition>();
|
||||
string partition_scheme = "";
|
||||
|
||||
// TODO: Solve possibility of multiple partition schemes (CUE + MBR, MBR + RDB, CUE + APM, etc)
|
||||
foreach (PartPlugin _partplugin in plugins.PartPluginsList.Values)
|
||||
{
|
||||
List<Partition> _partitions;
|
||||
foreach (PartPlugin _partplugin in plugins.PartPluginsList.Values)
|
||||
{
|
||||
List<Partition> _partitions;
|
||||
|
||||
if (_partplugin.GetInformation(_imageFormat, out _partitions))
|
||||
{
|
||||
partition_scheme=_partplugin.Name;
|
||||
partitions = _partitions;
|
||||
break;
|
||||
}
|
||||
}
|
||||
{
|
||||
partition_scheme = _partplugin.Name;
|
||||
partitions = _partitions;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(_imageFormat.ImageHasPartitions())
|
||||
if (_imageFormat.ImageHasPartitions())
|
||||
{
|
||||
partition_scheme = _imageFormat.GetImageFormat();
|
||||
partitions = _imageFormat.GetPartitions();
|
||||
}
|
||||
|
||||
if(partition_scheme=="")
|
||||
{
|
||||
if (partition_scheme == "")
|
||||
{
|
||||
Console.WriteLine("DEBUG: No partitions found");
|
||||
if(!chkFilesystems)
|
||||
{
|
||||
Console.WriteLine("No partitions founds, not searching for filesystems");
|
||||
return;
|
||||
}
|
||||
else
|
||||
checkraw = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Partition scheme identified as {0}", partition_scheme);
|
||||
Console.WriteLine("{0} partitions found.", partitions.Count);
|
||||
if (!chkFilesystems)
|
||||
{
|
||||
Console.WriteLine("No partitions founds, not searching for filesystems");
|
||||
return;
|
||||
}
|
||||
checkraw = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Partition scheme identified as {0}", partition_scheme);
|
||||
Console.WriteLine("{0} partitions found.", partitions.Count);
|
||||
|
||||
for(int i = 0; i< partitions.Count; i++)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Partition {0}:", partitions[i].PartitionSequence);
|
||||
Console.WriteLine("Partition name: {0}", partitions[i].PartitionName);
|
||||
Console.WriteLine("Partition type: {0}", partitions[i].PartitionType);
|
||||
Console.WriteLine("Partition start: {0}", partitions[i].PartitionStart);
|
||||
Console.WriteLine("Partition length: {0}", partitions[i].PartitionLength);
|
||||
Console.WriteLine("Partition description:");
|
||||
Console.WriteLine(partitions[i].PartitionDescription);
|
||||
for (int i = 0; i < partitions.Count; i++)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Partition {0}:", partitions[i].PartitionSequence);
|
||||
Console.WriteLine("Partition name: {0}", partitions[i].PartitionName);
|
||||
Console.WriteLine("Partition type: {0}", partitions[i].PartitionType);
|
||||
Console.WriteLine("Partition start: {0}", partitions[i].PartitionStart);
|
||||
Console.WriteLine("Partition length: {0}", partitions[i].PartitionLength);
|
||||
Console.WriteLine("Partition description:");
|
||||
Console.WriteLine(partitions[i].PartitionDescription);
|
||||
|
||||
if(chkFilesystems)
|
||||
{
|
||||
Console.WriteLine("Identifying filesystem on partition");
|
||||
if (chkFilesystems)
|
||||
{
|
||||
Console.WriteLine("Identifying filesystem on partition");
|
||||
|
||||
Identify(_imageFormat, out id_plugins, partitions[i].PartitionStart);
|
||||
if(id_plugins.Count==0)
|
||||
Console.WriteLine("Filesystem not identified");
|
||||
else if(id_plugins.Count>1)
|
||||
{
|
||||
Console.WriteLine(String.Format("Identified by {0} plugins", id_plugins.Count));
|
||||
if (id_plugins.Count == 0)
|
||||
Console.WriteLine("Filesystem not identified");
|
||||
else if (id_plugins.Count > 1)
|
||||
{
|
||||
Console.WriteLine(String.Format("Identified by {0} plugins", id_plugins.Count));
|
||||
|
||||
foreach(string plugin_name in id_plugins)
|
||||
{
|
||||
if(plugins.PluginsList.TryGetValue(plugin_name, out _plugin))
|
||||
{
|
||||
Console.WriteLine(String.Format("As identified by {0}.", _plugin.Name));
|
||||
foreach (string plugin_name in id_plugins)
|
||||
{
|
||||
if (plugins.PluginsList.TryGetValue(plugin_name, out _plugin))
|
||||
{
|
||||
Console.WriteLine(String.Format("As identified by {0}.", _plugin.Name));
|
||||
_plugin.GetInformation(_imageFormat, partitions[i].PartitionStart, out information);
|
||||
Console.Write(information);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
plugins.PluginsList.TryGetValue(id_plugins[0], out _plugin);
|
||||
Console.WriteLine(String.Format("Identified by {0}.", _plugin.Name));
|
||||
Console.Write(information);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
plugins.PluginsList.TryGetValue(id_plugins[0], out _plugin);
|
||||
Console.WriteLine(String.Format("Identified by {0}.", _plugin.Name));
|
||||
_plugin.GetInformation(_imageFormat, partitions[i].PartitionStart, out information);
|
||||
Console.Write(information);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.Write(information);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(checkraw)
|
||||
{
|
||||
if (checkraw)
|
||||
{
|
||||
Identify(_imageFormat, out id_plugins, 0);
|
||||
if(id_plugins.Count==0)
|
||||
Console.WriteLine("Filesystem not identified");
|
||||
else if(id_plugins.Count>1)
|
||||
{
|
||||
Console.WriteLine(String.Format("Identified by {0} plugins", id_plugins.Count));
|
||||
if (id_plugins.Count == 0)
|
||||
Console.WriteLine("Filesystem not identified");
|
||||
else if (id_plugins.Count > 1)
|
||||
{
|
||||
Console.WriteLine(String.Format("Identified by {0} plugins", id_plugins.Count));
|
||||
|
||||
foreach(string plugin_name in id_plugins)
|
||||
{
|
||||
if(plugins.PluginsList.TryGetValue(plugin_name, out _plugin))
|
||||
{
|
||||
Console.WriteLine(String.Format("As identified by {0}.", _plugin.Name));
|
||||
foreach (string plugin_name in id_plugins)
|
||||
{
|
||||
if (plugins.PluginsList.TryGetValue(plugin_name, out _plugin))
|
||||
{
|
||||
Console.WriteLine(String.Format("As identified by {0}.", _plugin.Name));
|
||||
_plugin.GetInformation(_imageFormat, 0, out information);
|
||||
Console.Write(information);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
plugins.PluginsList.TryGetValue(id_plugins[0], out _plugin);
|
||||
Console.WriteLine(String.Format("Identified by {0}.", _plugin.Name));
|
||||
Console.Write(information);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
plugins.PluginsList.TryGetValue(id_plugins[0], out _plugin);
|
||||
Console.WriteLine(String.Format("Identified by {0}.", _plugin.Name));
|
||||
_plugin.GetInformation(_imageFormat, 0, out information);
|
||||
Console.Write(information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine(String.Format("Error reading file: {0}", ex.Message));
|
||||
if(isDebug)
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
finally
|
||||
{
|
||||
stream = null;
|
||||
}
|
||||
}
|
||||
Console.Write(information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(String.Format("Error reading file: {0}", ex.Message));
|
||||
if (isDebug)
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Identify (ImagePlugins.ImagePlugin imagePlugin, out List<string> id_plugins, ulong partitionOffset)
|
||||
{
|
||||
id_plugins = new List<string>();
|
||||
static void Identify(ImagePlugin imagePlugin, out List<string> id_plugins, ulong partitionOffset)
|
||||
{
|
||||
id_plugins = new List<string>();
|
||||
|
||||
foreach (Plugin _plugin in plugins.PluginsList.Values)
|
||||
foreach (Plugin _plugin in plugins.PluginsList.Values)
|
||||
{
|
||||
if (_plugin.Identify(imagePlugin, partitionOffset))
|
||||
id_plugins.Add(_plugin.Name.ToLower());
|
||||
id_plugins.Add(_plugin.Name.ToLower());
|
||||
}
|
||||
}
|
||||
|
||||
private static void Usage ()
|
||||
{
|
||||
Console.WriteLine("Usage: filesystemidandchk [options] file");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(" --formats List all suported partition and filesystems");
|
||||
Console.WriteLine(" --debug Show debug information");
|
||||
Console.WriteLine(" --partitions Check only for partitions");
|
||||
Console.WriteLine(" --filesystems Check only for filesystems");
|
||||
Console.WriteLine(" --all Check for partitions and filesystems (default)");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Usage()
|
||||
{
|
||||
Console.WriteLine("Usage: filesystemidandchk [options] file");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(" --formats List all suported partition and filesystems");
|
||||
Console.WriteLine(" --debug Show debug information");
|
||||
Console.WriteLine(" --partitions Check only for partitions");
|
||||
Console.WriteLine(" --filesystems Check only for filesystems");
|
||||
Console.WriteLine(" --all Check for partitions and filesystems (default)");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user