mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Swallow exceptions from bad DDS files
This commit is contained in:
parent
5a501226c3
commit
3703f3f558
@ -34,7 +34,7 @@ namespace Wabbajack.ImageHashing
|
||||
PerceptualHash.Write(bw);
|
||||
}
|
||||
|
||||
public static async Task<ImageState> FromImageStream(Stream stream, Extension ext, bool takeStreamOwnership = true)
|
||||
public static async Task<ImageState?> FromImageStream(Stream stream, Extension ext, bool takeStreamOwnership = true)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
await stream.CopyToAsync(ms);
|
||||
@ -57,6 +57,11 @@ namespace Wabbajack.ImageHashing
|
||||
return img.ImageState();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Log($"Error getting ImageState: {ex}");
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
img?.Dispose();
|
||||
|
@ -86,22 +86,31 @@ namespace Wabbajack.ImageHashing
|
||||
|
||||
public static async Task<PHash> FromStream(Stream stream, Extension ext, bool takeStreamOwnership = true)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
await stream.CopyToAsync(ms);
|
||||
if (takeStreamOwnership) await stream.DisposeAsync();
|
||||
try
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
await stream.CopyToAsync(ms);
|
||||
if (takeStreamOwnership) await stream.DisposeAsync();
|
||||
|
||||
DDSImage img;
|
||||
if (ext == new Extension(".dds"))
|
||||
img = DDSImage.FromDDSMemory(ms.GetBuffer());
|
||||
else if (ext == new Extension(".tga"))
|
||||
{
|
||||
img = DDSImage.FromTGAMemory(ms.GetBuffer());
|
||||
DDSImage img;
|
||||
if (ext == new Extension(".dds"))
|
||||
img = DDSImage.FromDDSMemory(ms.GetBuffer());
|
||||
else if (ext == new Extension(".tga"))
|
||||
{
|
||||
img = DDSImage.FromTGAMemory(ms.GetBuffer());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException("Only DDS and TGA files supported by PHash");
|
||||
}
|
||||
|
||||
return img.PerceptionHash();
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new NotImplementedException("Only DDS and TGA files supported by PHash");
|
||||
Utils.Log($"Error getting PHASH {ex}");
|
||||
return default;
|
||||
}
|
||||
return img.PerceptionHash();
|
||||
}
|
||||
|
||||
public static async Task<PHash> FromFile(AbsolutePath path)
|
||||
|
@ -227,7 +227,7 @@ namespace Wabbajack.VirtualFileSystem
|
||||
};
|
||||
|
||||
if (Consts.TextureExtensions.Contains(relPath.FileName.Extension))
|
||||
self.ImageState = await ImageHashing.ImageState.FromImageStream(stream, relPath.FileName.Extension, false);
|
||||
self.ImageState = await ImageState.FromImageStream(stream, relPath.FileName.Extension, false);
|
||||
|
||||
self.FillFullPath(depth);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user