コード例 #1
0
ファイル: INIFile.Packed.cs プロジェクト: radtek/IntegrateDrv
        public static byte[] Unpack(byte[] fileBytes, string unpackedFileName)
        {
            MemoryStream             packedStream  = new MemoryStream(fileBytes);
            BasicUnpackStreamContext streamContext = new BasicUnpackStreamContext(packedStream);

            Predicate <string> isFileMatch = delegate(string match) { return(String.Compare(match, unpackedFileName, true) == 0); };

            using (CabEngine engine = new CabEngine())
            {
                engine.Unpack(streamContext, isFileMatch);
            }
            Stream unpackedStream = streamContext.FileStream;

            if (unpackedStream != null)
            {
                unpackedStream.Position = 0;

                byte[] unpackedBytes = new byte[unpackedStream.Length];
                unpackedStream.Read(unpackedBytes, 0, unpackedBytes.Length);

                return(unpackedBytes);
            }
            else
            {
                string message = String.Format("Error: File does not contain the expected file ('{1}')", unpackedFileName);
                Console.WriteLine(message);
                Program.Exit();
                return(new byte[0]);
            }
        }
コード例 #2
0
ファイル: INIFile.Packed.cs プロジェクト: mrjrt/IntegrateDrv
        public static byte[] Unpack(byte[] fileBytes, string unpackedFileName)
        {
            var packedStream  = new MemoryStream(fileBytes);
            var streamContext = new BasicUnpackStreamContext(packedStream);

            Predicate <string> isFileMatch =
                match =>
                String.Compare(match, unpackedFileName, StringComparison.OrdinalIgnoreCase) == 0;

            using (var engine = new CabEngine())
            {
                engine.Unpack(streamContext, isFileMatch);
            }
            var unpackedStream = streamContext.FileStream;

            if (unpackedStream != null)
            {
                unpackedStream.Position = 0;

                var unpackedBytes = new byte[unpackedStream.Length];
                unpackedStream.Read(unpackedBytes, 0, unpackedBytes.Length);

                return(unpackedBytes);
            }
            var message = string.Format("Error: File does not contain the expected file ('{1}')", unpackedFileName);

            Console.WriteLine(message);
            Program.Exit();
            return(new byte[0]);
        }