Exemplo n.º 1
0
 public static void Decompress(string compressedFile, string targetFile, bool needToEncrypt)
 {
     try
     {
         string decrFileName = Crypt.DecryptedFilePath(compressedFile, Path.Combine(Path.GetDirectoryName(targetFile), "crypt"));
         using (FileStream sourceStream = new FileStream(compressedFile, FileMode.OpenOrCreate))
         {
             using (FileStream targetStream = File.Create(targetFile))
             {
                 using (FileStream decryptStream = File.Create(decrFileName))
                 {
                     using (GZipStream decompressionStream = new GZipStream(sourceStream, CompressionMode.Decompress))
                     {
                         decompressionStream.CopyTo(decryptStream);
                     }
                 }
                 using (FileStream finaleStream = new FileStream(decrFileName, FileMode.OpenOrCreate))
                 {
                     if (needToEncrypt)
                     {
                         Crypt.Decrypt(finaleStream, targetStream);
                     }
                     else
                     {
                         finaleStream.CopyTo(targetStream);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         using (StreamWriter writer = new StreamWriter(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sourcelog.txt"), true))
         {
             writer.WriteLine("Ошибка деархивации данных:{0}", ex.Message);
             writer.Flush();
         }
     }
 }