Ejemplo n.º 1
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var input        = arc.File.CreateStream(entry.Offset, entry.Size);
            var packed_entry = entry as KogadoEntry;

            if (null == packed_entry || !packed_entry.IsPacked)
            {
                return(input);
            }
            if (packed_entry.CompressionType > 3)
            {
                Trace.WriteLine(string.Format("{1}: Unknown compression type {0}",
                                              packed_entry.CompressionType, packed_entry.Name),
                                "Kogado.PakOpener.OpenEntry");
                return(input);
            }
            if (3 == packed_entry.CompressionType)
            {
                return(new InputCryptoStream(input, new NotTransform()));
            }
            try
            {
                if (2 == packed_entry.CompressionType)
                {
                    var decoded = new MemoryStream((int)packed_entry.UnpackedSize);
                    try
                    {
                        var cocotte = new CocotteEncoder();
                        if (!cocotte.Decode(input, decoded))
                        {
                            throw new InvalidFormatException("Invalid Cocotte-encoded stream");
                        }
                        decoded.Position = 0;
                        return(decoded);
                    }
                    catch
                    {
                        decoded.Dispose();
                        throw;
                    }
                }
                // if (1 == packed_entry.CompressionType)
                var unpacked = new byte[packed_entry.UnpackedSize];
                var mariel   = new MarielEncoder();
                mariel.Unpack(input, unpacked, unpacked.Length);
                return(new BinMemoryStream(unpacked, entry.Name));
            }
            finally
            {
                input.Dispose();
            }
        }
Ejemplo n.º 2
0
 public override Stream OpenEntry(ArcFile arc, Entry entry)
 {
     var input = arc.File.CreateStream (entry.Offset, entry.Size);
     var packed_entry = entry as KogadoEntry;
     if (null == packed_entry || !packed_entry.IsPacked)
         return input;
     if (packed_entry.CompressionType > 3)
     {
         Trace.WriteLine (string.Format ("{1}: Unknown compression type {0}",
                                         packed_entry.CompressionType, packed_entry.Name),
                          "Kogado.PakOpener.OpenEntry");
         return input;
     }
     if (3 == packed_entry.CompressionType)
         return new CryptoStream (input, new NotTransform(), CryptoStreamMode.Read);
     try
     {
         if (2 == packed_entry.CompressionType)
         {
             var decoded = new MemoryStream ((int)packed_entry.UnpackedSize);
             try
             {
                 var cocotte = new CocotteEncoder();
                 if (!cocotte.Decode (input, decoded))
                     throw new InvalidFormatException ("Invalid Cocotte-encoded stream");
                 decoded.Position = 0;
                 return decoded;
             }
             catch
             {
                 decoded.Dispose();
                 throw;
             }
         }
         // if (1 == packed_entry.CompressionType)
         var unpacked = new byte[packed_entry.UnpackedSize];
         var mariel = new MarielEncoder();
         mariel.Unpack (input, unpacked, unpacked.Length);
         return new MemoryStream (unpacked);
     }
     finally
     {
         input.Dispose();
     }
 }