From 6b38069d6ec0e028bc6febb4a095ca5c4b81485e Mon Sep 17 00:00:00 2001 From: Luciano Ciccariello Date: Sat, 16 Nov 2019 19:44:47 +0000 Subject: [PATCH] Add a version of Img.FileOpen that does not throw an exception --- OpenKh.Kh2/Img.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/OpenKh.Kh2/Img.cs b/OpenKh.Kh2/Img.cs index 3d541e92a..365e15d3d 100644 --- a/OpenKh.Kh2/Img.cs +++ b/OpenKh.Kh2/Img.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using Xe.IO; @@ -43,6 +44,14 @@ public Img(Stream stream, Idx idx, bool loadAllIdx) public Idx Idx { get; } + public bool FileOpen(string fileName, Action callback) + { + bool result; + if (result = Idx.TryGetEntry(fileName, out var entry)) + callback(FileOpen(entry)); + return result; + } + public Stream FileOpen(string fileName) { if (Idx.TryGetEntry(fileName, out var entry))