diff --git a/SabreTools.FileTypes/Compress/ZipFile/Zip.cs b/SabreTools.FileTypes/Compress/ZipFile/Zip.cs index 54e95577..52a69cc6 100644 --- a/SabreTools.FileTypes/Compress/ZipFile/Zip.cs +++ b/SabreTools.FileTypes/Compress/ZipFile/Zip.cs @@ -33,6 +33,11 @@ namespace Compress.ZipFile public ZipStatus ZipStatus { get; set; } + public Zip() + { + ZipUtils.EncodeSetup(); + } + public int LocalFilesCount() { return _localFiles.Count; diff --git a/SabreTools.FileTypes/Compress/ZipFile/ZipUtils.cs b/SabreTools.FileTypes/Compress/ZipFile/ZipUtils.cs index e4078639..30936cf0 100644 --- a/SabreTools.FileTypes/Compress/ZipFile/ZipUtils.cs +++ b/SabreTools.FileTypes/Compress/ZipFile/ZipUtils.cs @@ -7,7 +7,15 @@ namespace Compress.ZipFile { // according to the zip documents, zip filesname are stored as MS-DOS Code Page 437. // (Unless the uncode flag is set, in which case they are stored as UTF-8. - private static Encoding enc = Encoding.GetEncoding(437); + private static Encoding enc = null; + + public static void EncodeSetup() + { + if (enc != null) + return; + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + enc = Encoding.GetEncoding(437); + } public static string GetString(byte[] byteArr) { diff --git a/SabreTools.FileTypes/SabreTools.FileTypes.csproj b/SabreTools.FileTypes/SabreTools.FileTypes.csproj index 27d92c6e..a626bf81 100644 --- a/SabreTools.FileTypes/SabreTools.FileTypes.csproj +++ b/SabreTools.FileTypes/SabreTools.FileTypes.csproj @@ -15,7 +15,8 @@ - + + diff --git a/SabreTools.IO/StreamExtensions.cs b/SabreTools.IO/StreamExtensions.cs index e12d6e83..c6286bea 100644 --- a/SabreTools.IO/StreamExtensions.cs +++ b/SabreTools.IO/StreamExtensions.cs @@ -17,11 +17,19 @@ namespace SabreTools.IO // If the stream is null, don't even try if (input == null) return -1; - + // If the input is not seekable, just return the current position if (!input.CanSeek) - return input.Position; - + { + try + { + return input.Position; + } + catch + { + return -1; + } + } // Attempt to seek to the offset try {