فهرست منبع

switch to using

Luke Pulverenti 8 سال پیش
والد
کامیت
b5b3d8a30c
1فایلهای تغییر یافته به همراه22 افزوده شده و 20 حذف شده
  1. 22 20
      OpenSubtitlesHandler/MovieHasher.cs

+ 22 - 20
OpenSubtitlesHandler/MovieHasher.cs

@@ -8,29 +8,31 @@ namespace OpenSubtitlesHandler
     {
         public static byte[] ComputeMovieHash(Stream input)
         {
-            long lhash, streamsize;
-            streamsize = input.Length;
-            lhash = streamsize;
-
-            long i = 0;
-            byte[] buffer = new byte[sizeof(long)];
-            while (i < 65536 / sizeof(long) && (input.Read(buffer, 0, sizeof(long)) > 0))
+            using (input)
             {
-                i++;
-                lhash += BitConverter.ToInt64(buffer, 0);
-            }
+                long lhash, streamsize;
+                streamsize = input.Length;
+                lhash = streamsize;
 
-            input.Position = Math.Max(0, streamsize - 65536);
-            i = 0;
-            while (i < 65536 / sizeof(long) && (input.Read(buffer, 0, sizeof(long)) > 0))
-            {
-                i++;
-                lhash += BitConverter.ToInt64(buffer, 0);
+                long i = 0;
+                byte[] buffer = new byte[sizeof(long)];
+                while (i < 65536 / sizeof(long) && (input.Read(buffer, 0, sizeof(long)) > 0))
+                {
+                    i++;
+                    lhash += BitConverter.ToInt64(buffer, 0);
+                }
+
+                input.Position = Math.Max(0, streamsize - 65536);
+                i = 0;
+                while (i < 65536 / sizeof(long) && (input.Read(buffer, 0, sizeof(long)) > 0))
+                {
+                    i++;
+                    lhash += BitConverter.ToInt64(buffer, 0);
+                }
+                byte[] result = BitConverter.GetBytes(lhash);
+                Array.Reverse(result);
+                return result;
             }
-            input.Close();
-            byte[] result = BitConverter.GetBytes(lhash);
-            Array.Reverse(result);
-            return result;
         }
 
         public static string ToHexadecimal(byte[] bytes)