Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion FATX/Analyzers/MetadataAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,20 @@ private void RecoverMetadata(CancellationToken cancellationToken, IProgress<int>
var maxClusters = _length / _interval;
for (uint cluster = 1; cluster < maxClusters; cluster++)
{
var data = _volume.ReadCluster(cluster);
byte[] data;

try
{
data = _volume.ReadCluster(cluster);
}
catch (IOException exception)
{
// Failed to read data
Console.WriteLine(exception.Message);
Console.WriteLine($"Failed to read cluster {cluster}, skipping...");
continue;
}

var clusterOffset = (cluster - 1) * _interval;
for (int i = 0; i < 256; i++)
{
Expand Down
16 changes: 15 additions & 1 deletion FATX/FileSystem/Volume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,20 @@ private List<DirectoryEntry> ReadDirectoryStream(uint cluster)
{
List<DirectoryEntry> stream = new List<DirectoryEntry>();

byte[] data = ReadCluster(cluster);
byte[] data;

try
{
data = ReadCluster(cluster);
}
catch (IOException exception)
{
// Failed to read data, return an empty list
Console.WriteLine(exception.Message);
Console.WriteLine($"Due to exception, returning empty directory stream for cluster {cluster}");
return stream;
}

long clusterOffset = ClusterToPhysicalOffset(cluster);

for (int i = 0; i < 256; i++)
Expand Down Expand Up @@ -364,6 +377,7 @@ public void SeekToCluster(uint cluster)
/// Reads a cluster and returns the data.
/// </summary>
/// <param name="cluster"></param>
/// <exception cref="System.IO.IOException">May be thrown on read errors.</exception>
/// <returns></returns>
public byte[] ReadCluster(uint cluster)
{
Expand Down
15 changes: 14 additions & 1 deletion FATXTools/Controls/FileExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,20 @@ private void WriteFile(string path, DirectoryEntry dirent, List<uint> chainMap)

foreach (uint cluster in chainMap)
{
byte[] clusterData = this.volume.ReadCluster(cluster);
byte[] clusterData;

try
{
clusterData = this.volume.ReadCluster(cluster);
}
catch (IOException exception)
{
// Failed to read cluster, write null bytes instead.
var position = outFile.Position;
Console.WriteLine(exception.Message);
Console.WriteLine($"Due to exception, writing null cluster at {position} to file: {path}");
clusterData = new byte[volume.BytesPerCluster];
}

var writeSize = Math.Min(bytesLeft, this.volume.BytesPerCluster);
outFile.Write(clusterData, 0, (int)writeSize);
Expand Down
15 changes: 14 additions & 1 deletion FATXTools/Controls/RecoveryResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,20 @@ private void WriteFile(string path, DatabaseFile databaseFile)

foreach (uint cluster in databaseFile.ClusterChain)
{
byte[] clusterData = this.volume.ReadCluster(cluster);
byte[] clusterData;

try
{
clusterData = this.volume.ReadCluster(cluster);
}
catch (IOException exception)
{
// Failed to read cluster, write null bytes instead.
var position = outFile.Position;
Console.WriteLine(exception.Message);
Console.WriteLine($"Due to exception, writing null cluster at {position} to file: {path}");
clusterData = new byte[volume.BytesPerCluster];
}

var writeSize = Math.Min(bytesLeft, this.volume.BytesPerCluster);
outFile.Write(clusterData, 0, (int)writeSize);
Expand Down