Procházet zdrojové kódy

Use backup when PTC compression is corrupt (#1704)

* Use backup when PTC compression is corrupt

* Apply suggestions from code review

Co-authored-by: LDj3SNuD <35856442+LDj3SNuD@users.noreply.github.com>

Co-authored-by: LDj3SNuD <35856442+LDj3SNuD@users.noreply.github.com>
riperiperi před 5 roky
rodič
revize
9852cb9c9e

+ 10 - 1
ARMeilleure/Translation/PTC/Ptc.cs

@@ -196,7 +196,16 @@ namespace ARMeilleure.Translation.PTC
             {
                 int hashSize = md5.HashSize / 8;
 
-                deflateStream.CopyTo(stream);
+                try
+                {
+                    deflateStream.CopyTo(stream);
+                }
+                catch
+                {
+                    InvalidateCompressedStream(compressedStream);
+
+                    return false;
+                }
 
                 stream.Seek(0L, SeekOrigin.Begin);
 

+ 11 - 2
ARMeilleure/Translation/PTC/PtcProfiler.cs

@@ -120,7 +120,16 @@ namespace ARMeilleure.Translation.PTC
             {
                 int hashSize = md5.HashSize / 8;
 
-                deflateStream.CopyTo(stream);
+                try
+                {
+                    deflateStream.CopyTo(stream);
+                }
+                catch
+                {
+                    InvalidateCompressedStream(compressedStream);
+
+                    return false;
+                }
 
                 stream.Seek(0L, SeekOrigin.Begin);
 
@@ -264,4 +273,4 @@ namespace ARMeilleure.Translation.PTC
             }
         }
     }
-}
+}