mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
REFACTOR: Possible 'System.NullReferenceException'.
This commit is contained in:
@@ -65,7 +65,7 @@ namespace DiscImageChef.Core
|
||||
{
|
||||
if(!type.IsSubclassOf(typeof(ImagePlugin))) continue;
|
||||
|
||||
ImagePlugin plugin = (ImagePlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
||||
ImagePlugin plugin = (ImagePlugin)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
RegisterImagePlugin(plugin);
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
@@ -77,7 +77,7 @@ namespace DiscImageChef.Core
|
||||
{
|
||||
if(!type.IsSubclassOf(typeof(PartitionPlugin))) continue;
|
||||
|
||||
PartitionPlugin plugin = (PartitionPlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
||||
PartitionPlugin plugin = (PartitionPlugin)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
RegisterPartPlugin(plugin);
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
@@ -91,9 +91,8 @@ namespace DiscImageChef.Core
|
||||
|
||||
Filesystem plugin;
|
||||
if(encoding != null)
|
||||
plugin = (Filesystem)type.GetConstructor(new[] {encoding.GetType()})
|
||||
.Invoke(new object[] {encoding});
|
||||
else plugin = (Filesystem)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
||||
plugin = (Filesystem)type.GetConstructor(new[] {encoding.GetType()})?.Invoke(new object[] {encoding});
|
||||
else plugin = (Filesystem)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
RegisterPlugin(plugin);
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
|
||||
@@ -259,7 +259,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
// Did we find an InterfaceID of a USB device?
|
||||
if(instanceId.StartsWith("USB\\")) foundDevice = FindDeviceByInstanceId(instanceId);
|
||||
if(instanceId?.StartsWith("USB\\", StringComparison.Ordinal) == true) foundDevice = FindDeviceByInstanceId(instanceId);
|
||||
return foundDevice;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace DiscImageChef.DiscImages
|
||||
|
||||
public override bool IdentifyImage(Filter imageFilter)
|
||||
{
|
||||
extension = Path.GetExtension(imageFilter.GetFilename()).ToLower();
|
||||
extension = Path.GetExtension(imageFilter.GetFilename())?.ToLower();
|
||||
|
||||
if(imageFilter.GetDataForkLength() == 143360 && (extension == ".po" || extension == ".do")) return true;
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace DiscImageChef.DiscImages
|
||||
|
||||
deinterleaved = new byte[tmp.Length];
|
||||
|
||||
extension = Path.GetExtension(imageFilter.GetFilename()).ToLower();
|
||||
extension = Path.GetExtension(imageFilter.GetFilename())?.ToLower();
|
||||
|
||||
int[] offsets;
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace DiscImageChef.DiscImages
|
||||
// Check if file is not multiple of 512
|
||||
if(imageFilter.GetDataForkLength() % 512 == 0) return true;
|
||||
|
||||
extension = Path.GetExtension(imageFilter.GetFilename()).ToLower();
|
||||
extension = Path.GetExtension(imageFilter.GetFilename())?.ToLower();
|
||||
|
||||
if(extension == ".hdf" && ImageInfo.ImageSize % 256 == 0) return true;
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace DiscImageChef.DiscImages
|
||||
Stream stream = imageFilter.GetDataForkStream();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
extension = Path.GetExtension(imageFilter.GetFilename()).ToLower();
|
||||
extension = Path.GetExtension(imageFilter.GetFilename())?.ToLower();
|
||||
switch(extension) {
|
||||
case ".iso" when imageFilter.GetDataForkLength() % 2048 == 0: ImageInfo.SectorSize = 2048;
|
||||
break;
|
||||
|
||||
@@ -51,8 +51,8 @@ namespace DiscImageChef.Filters
|
||||
{
|
||||
if(!type.IsSubclassOf(typeof(Filter))) continue;
|
||||
|
||||
Filter filter = (Filter)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
||||
if(!filtersList.ContainsKey(filter.Name.ToLower())) filtersList.Add(filter.Name.ToLower(), filter);
|
||||
Filter filter = (Filter)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
if(filter != null && !filtersList.ContainsKey(filter.Name.ToLower())) filtersList.Add(filter.Name.ToLower(), filter);
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
}
|
||||
@@ -67,18 +67,17 @@ namespace DiscImageChef.Filters
|
||||
if(!filter.Identify(path)) continue;
|
||||
|
||||
Filter foundFilter =
|
||||
(Filter)filter.GetType().GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
||||
foundFilter.Open(path);
|
||||
(Filter)filter.GetType().GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
|
||||
if(foundFilter.IsOpened()) return foundFilter;
|
||||
foundFilter?.Open(path);
|
||||
|
||||
if(foundFilter?.IsOpened() == true) return foundFilter;
|
||||
}
|
||||
else noFilter = filter;
|
||||
|
||||
if(!noFilter.Identify(path)) return noFilter;
|
||||
if(!noFilter?.Identify(path) == true) return noFilter;
|
||||
|
||||
noFilter.Open(path);
|
||||
|
||||
if(noFilter.IsOpened()) return noFilter;
|
||||
noFilter?.Open(path);
|
||||
|
||||
return noFilter;
|
||||
}
|
||||
|
||||
@@ -131,9 +131,9 @@ namespace DiscImageChef.Interop
|
||||
Marshal.FreeHGlobal(pStr);
|
||||
Marshal.FreeHGlobal(pLen);
|
||||
|
||||
if(machine.StartsWith("iPad", StringComparison.Ordinal) ||
|
||||
if(machine != null && (machine.StartsWith("iPad", StringComparison.Ordinal) ||
|
||||
machine.StartsWith("iPod", StringComparison.Ordinal) ||
|
||||
machine.StartsWith("iPhone", StringComparison.Ordinal)) return PlatformID.iOS;
|
||||
machine.StartsWith("iPhone", StringComparison.Ordinal))) return PlatformID.iOS;
|
||||
|
||||
return PlatformID.MacOSX;
|
||||
}
|
||||
|
||||
@@ -579,6 +579,8 @@ namespace DiscImageChef.Server
|
||||
{
|
||||
_line = tocStream.ReadLine();
|
||||
|
||||
if(_line == null) break;
|
||||
|
||||
if(_line.Length == 0 || _line[0] == '#') continue;
|
||||
|
||||
if(inManufacturer)
|
||||
|
||||
@@ -242,7 +242,7 @@ namespace DiscImageChef.Settings
|
||||
case PlatformID.WinCE:
|
||||
case PlatformID.WindowsPhone:
|
||||
{
|
||||
RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE").OpenSubKey("Claunia.com");
|
||||
RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE")?.OpenSubKey("Claunia.com");
|
||||
if(parentKey == null)
|
||||
{
|
||||
SetDefaultSettings();
|
||||
@@ -358,9 +358,11 @@ namespace DiscImageChef.Settings
|
||||
case PlatformID.WindowsPhone:
|
||||
{
|
||||
RegistryKey parentKey =
|
||||
Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey("Claunia.com");
|
||||
RegistryKey key = parentKey.CreateSubKey("DiscImageChef");
|
||||
Registry.CurrentUser.OpenSubKey("SOFTWARE", true)?.CreateSubKey("Claunia.com");
|
||||
RegistryKey key = parentKey?.CreateSubKey("DiscImageChef");
|
||||
|
||||
if(key != null)
|
||||
{
|
||||
key.SetValue("SaveReportsGlobally", Current.SaveReportsGlobally);
|
||||
key.SetValue("ShareReports", Current.ShareReports);
|
||||
|
||||
@@ -394,6 +396,7 @@ namespace DiscImageChef.Settings
|
||||
key.DeleteValue("VerifyStats", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
|
||||
@@ -183,6 +183,8 @@ namespace DiscImageChef.Commands
|
||||
else
|
||||
{
|
||||
plugins.PluginsList.TryGetValue(idPlugins[0], out plugin);
|
||||
if(plugin != null)
|
||||
{
|
||||
DicConsole.WriteLine(string.Format("Identified by {0}.", plugin.Name));
|
||||
plugin.GetInformation(imageFormat, partitions[i], out information);
|
||||
DicConsole.Write(information);
|
||||
@@ -191,6 +193,7 @@ namespace DiscImageChef.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(checkraw)
|
||||
{
|
||||
@@ -219,6 +222,8 @@ namespace DiscImageChef.Commands
|
||||
else
|
||||
{
|
||||
plugins.PluginsList.TryGetValue(idPlugins[0], out plugin);
|
||||
if(plugin != null)
|
||||
{
|
||||
DicConsole.WriteLine(string.Format("Identified by {0}.", plugin.Name));
|
||||
plugin.GetInformation(imageFormat, wholePart, out information);
|
||||
DicConsole.Write(information);
|
||||
@@ -226,6 +231,7 @@ namespace DiscImageChef.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
DicConsole.ErrorWriteLine(string.Format("Error reading file: {0}", ex.Message));
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace DiscImageChef.Commands
|
||||
|
||||
byte[] hiddenSector = inputFormat.ReadSector(i);
|
||||
|
||||
mediaChecksum.Update(hiddenSector);
|
||||
mediaChecksum?.Update(hiddenSector);
|
||||
}
|
||||
|
||||
DicConsole.DebugWriteLine("Checksum command",
|
||||
@@ -155,14 +155,16 @@ namespace DiscImageChef.Commands
|
||||
doneSectors += sectors - doneSectors;
|
||||
}
|
||||
|
||||
if(options.WholeDisc) mediaChecksum.Update(sector);
|
||||
if(options.WholeDisc)
|
||||
mediaChecksum?.Update(sector);
|
||||
|
||||
if(options.SeparatedTracks) trackChecksum.Update(sector);
|
||||
if(options.SeparatedTracks) trackChecksum?.Update(sector);
|
||||
}
|
||||
|
||||
DicConsole.WriteLine();
|
||||
|
||||
if(options.SeparatedTracks)
|
||||
if(trackChecksum != null)
|
||||
foreach(ChecksumType chk in trackChecksum.End())
|
||||
DicConsole.WriteLine("Track {0}'s {1}: {2}", currentTrack.TrackSequence, chk.type,
|
||||
chk.Value);
|
||||
@@ -176,10 +178,11 @@ namespace DiscImageChef.Commands
|
||||
DicConsole.Write("\rHashing track-less sector {0}", i);
|
||||
|
||||
byte[] hiddenSector = inputFormat.ReadSector(i);
|
||||
mediaChecksum.Update(hiddenSector);
|
||||
mediaChecksum?.Update(hiddenSector);
|
||||
}
|
||||
|
||||
if(options.WholeDisc)
|
||||
if(mediaChecksum != null)
|
||||
foreach(ChecksumType chk in mediaChecksum.End())
|
||||
DicConsole.WriteLine("Disk's {0}: {1}", chk.type, chk.Value);
|
||||
}
|
||||
|
||||
@@ -152,14 +152,18 @@ namespace DiscImageChef.Commands
|
||||
.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);
|
||||
if(error == Errno.NoError)
|
||||
{
|
||||
List<string> rootDir = new List<string>();
|
||||
error = fs.ReadDir("/", ref rootDir);
|
||||
if(error == Errno.NoError) foreach(string entry in rootDir) DicConsole.WriteLine("{0}", entry);
|
||||
if(error == Errno.NoError)
|
||||
foreach(string entry in rootDir) DicConsole.WriteLine("{0}", entry);
|
||||
else
|
||||
DicConsole.ErrorWriteLine("Error {0} reading root directory {0}",
|
||||
error.ToString());
|
||||
@@ -179,15 +183,20 @@ namespace DiscImageChef.Commands
|
||||
.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);
|
||||
if(error == Errno.NoError)
|
||||
{
|
||||
List<string> rootDir = new List<string>();
|
||||
error = fs.ReadDir("/", ref rootDir);
|
||||
if(error == Errno.NoError) foreach(string entry in rootDir) DicConsole.WriteLine("{0}", entry);
|
||||
if(error == Errno.NoError)
|
||||
foreach(string entry in rootDir) DicConsole.WriteLine("{0}", entry);
|
||||
else
|
||||
DicConsole.ErrorWriteLine("Error {0} reading root directory {0}", error.ToString());
|
||||
DicConsole.ErrorWriteLine("Error {0} reading root directory {0}",
|
||||
error.ToString());
|
||||
|
||||
Core.Statistics.AddFilesystem(fs.XmlFSType.Type);
|
||||
}
|
||||
@@ -217,15 +226,20 @@ namespace DiscImageChef.Commands
|
||||
.GetType().GetConstructor(new[]
|
||||
{
|
||||
typeof(ImagePlugin), typeof(Partition), typeof(Encoding)
|
||||
}).Invoke(new object[] {imageFormat, wholePart, null});
|
||||
})
|
||||
?.Invoke(new object[] {imageFormat, wholePart, null});
|
||||
if(fs == null) continue;
|
||||
|
||||
error = fs.Mount(options.Debug);
|
||||
if(error == Errno.NoError)
|
||||
{
|
||||
List<string> rootDir = new List<string>();
|
||||
error = fs.ReadDir("/", ref rootDir);
|
||||
if(error == Errno.NoError) foreach(string entry in rootDir) DicConsole.WriteLine("{0}", entry);
|
||||
if(error == Errno.NoError)
|
||||
foreach(string entry in rootDir) DicConsole.WriteLine("{0}", entry);
|
||||
else
|
||||
DicConsole.ErrorWriteLine("Error {0} reading root directory {0}", error.ToString());
|
||||
DicConsole.ErrorWriteLine("Error {0} reading root directory {0}",
|
||||
error.ToString());
|
||||
|
||||
Core.Statistics.AddFilesystem(fs.XmlFSType.Type);
|
||||
}
|
||||
@@ -235,12 +249,12 @@ namespace DiscImageChef.Commands
|
||||
else
|
||||
{
|
||||
plugins.PluginsList.TryGetValue(idPlugins[0], out plugin);
|
||||
if(plugin != null)
|
||||
{
|
||||
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, wholePart, null});
|
||||
.GetType().GetConstructor(new[] {typeof(ImagePlugin), typeof(Partition), typeof(Encoding)})
|
||||
?.Invoke(new object[] {imageFormat, wholePart, null});
|
||||
error = fs.Mount(options.Debug);
|
||||
if(error == Errno.NoError)
|
||||
{
|
||||
@@ -266,7 +280,8 @@ namespace DiscImageChef.Commands
|
||||
{
|
||||
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);
|
||||
if(error == Errno.NoError)
|
||||
DicConsole.WriteLine("\t\t{0}\t{1} bytes", xattr, xattrBuf.Length);
|
||||
}
|
||||
}
|
||||
else DicConsole.WriteLine("{0}", entry);
|
||||
@@ -279,6 +294,7 @@ namespace DiscImageChef.Commands
|
||||
else DicConsole.ErrorWriteLine("Unable to mount device, error {0}", error.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
DicConsole.ErrorWriteLine(string.Format("Error reading file: {0}", ex.Message));
|
||||
|
||||
Reference in New Issue
Block a user