From b9ec685b4e03fffa6dc137aeca5d0236cd31438b Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 21 Dec 2017 17:14:49 +0000 Subject: [PATCH] REFACTOR: Minor refactors. --- DiscImageChef.Devices/Windows/ListDevices.cs | 2 +- DiscImageChef.Filesystems/FAT.cs | 2 +- DiscImageChef/Commands/Ls.cs | 64 +++++++++++--------- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/DiscImageChef.Devices/Windows/ListDevices.cs b/DiscImageChef.Devices/Windows/ListDevices.cs index 7c6a73bd..98bbf8b3 100644 --- a/DiscImageChef.Devices/Windows/ListDevices.cs +++ b/DiscImageChef.Devices/Windows/ListDevices.cs @@ -77,7 +77,7 @@ namespace DiscImageChef.Devices.Windows catch(Exception ex) { #if DEBUG - throw ex; + throw; #else return null; #endif diff --git a/DiscImageChef.Filesystems/FAT.cs b/DiscImageChef.Filesystems/FAT.cs index a5ba3400..bcb7a3b3 100644 --- a/DiscImageChef.Filesystems/FAT.cs +++ b/DiscImageChef.Filesystems/FAT.cs @@ -1340,7 +1340,7 @@ namespace DiscImageChef.Filesystems if(entry.ctime > 0 && entry.cdate > 0) { xmlFSType.CreationDate = DateHandlers.DOSToDateTime(entry.cdate, entry.ctime); - if(entry.ctime_ms > 0) xmlFSType.CreationDate.AddMilliseconds(entry.ctime_ms * 10); + if(entry.ctime_ms > 0) xmlFSType.CreationDate = xmlFSType.CreationDate.AddMilliseconds(entry.ctime_ms * 10); xmlFSType.CreationDateSpecified = true; sb.AppendFormat("Volume created on {0}", xmlFSType.CreationDate).AppendLine(); } diff --git a/DiscImageChef/Commands/Ls.cs b/DiscImageChef/Commands/Ls.cs index 67df2ae8..b01fea51 100644 --- a/DiscImageChef/Commands/Ls.cs +++ b/DiscImageChef/Commands/Ls.cs @@ -178,13 +178,14 @@ namespace DiscImageChef.Commands else { plugins.PluginsList.TryGetValue(idPlugins[0], out plugin); + if(plugin == null) continue; + DicConsole.WriteLine(string.Format("Identified by {0}.", plugin.Name)); Filesystem fs = (Filesystem)plugin .GetType().GetConstructor(new[] { typeof(ImagePlugin), typeof(Partition), typeof(Encoding) - }) - ?.Invoke(new object[] {imageFormat, partitions[i], null}); + })?.Invoke(new object[] {imageFormat, partitions[i], null}); if(fs == null) continue; error = fs.Mount(options.Debug); @@ -255,43 +256,48 @@ namespace DiscImageChef.Commands Filesystem fs = (Filesystem)plugin .GetType().GetConstructor(new[] {typeof(ImagePlugin), typeof(Partition), typeof(Encoding)}) ?.Invoke(new object[] {imageFormat, wholePart, null}); - error = fs.Mount(options.Debug); - if(error == Errno.NoError) + if(fs != null) { - List rootDir = new List(); - error = fs.ReadDir("/", ref rootDir); + error = fs.Mount(options.Debug); if(error == Errno.NoError) - foreach(string entry in rootDir) - if(options.Long) - { - FileEntryInfo stat = new FileEntryInfo(); - List xattrs = new List(); - - error = fs.Stat(entry, ref stat); - if(error == Errno.NoError) + { + List rootDir = new List(); + error = fs.ReadDir("/", ref rootDir); + if(error == Errno.NoError) + foreach(string entry in rootDir) + if(options.Long) { - DicConsole.WriteLine("{0}\t{1}\t{2} bytes\t{3}", stat.CreationTimeUtc, - stat.Inode, stat.Length, entry); + FileEntryInfo stat = new FileEntryInfo(); + List xattrs = new List(); - error = fs.ListXAttr(entry, ref xattrs); - if(error != Errno.NoError) continue; - - foreach(string xattr in xattrs) + error = fs.Stat(entry, ref stat); + if(error == Errno.NoError) { - byte[] xattrBuf = new byte[0]; - error = fs.GetXattr(entry, xattr, ref xattrBuf); - if(error == Errno.NoError) - DicConsole.WriteLine("\t\t{0}\t{1} bytes", xattr, xattrBuf.Length); + DicConsole.WriteLine("{0}\t{1}\t{2} bytes\t{3}", stat.CreationTimeUtc, + stat.Inode, stat.Length, entry); + + error = fs.ListXAttr(entry, ref xattrs); + if(error != Errno.NoError) continue; + + foreach(string xattr in xattrs) + { + byte[] xattrBuf = new byte[0]; + error = fs.GetXattr(entry, xattr, ref xattrBuf); + if(error == Errno.NoError) + DicConsole.WriteLine("\t\t{0}\t{1} bytes", xattr, + xattrBuf.Length); + } } + else DicConsole.WriteLine("{0}", entry); } else DicConsole.WriteLine("{0}", entry); - } - else DicConsole.WriteLine("{0}", entry); - else DicConsole.ErrorWriteLine("Error {0} reading root directory {0}", error.ToString()); + else + DicConsole.ErrorWriteLine("Error {0} reading root directory {0}", error.ToString()); - Core.Statistics.AddFilesystem(fs.XmlFSType.Type); + Core.Statistics.AddFilesystem(fs.XmlFSType.Type); + } + else DicConsole.ErrorWriteLine("Unable to mount device, error {0}", error.ToString()); } - else DicConsole.ErrorWriteLine("Unable to mount device, error {0}", error.ToString()); } } }