Beispiel #1
0
        private void _inject(
            string archivePath,
            FileStream fs_archive,
            List <string> fs_list,
            FileInfo fi,
            string filename,
            RedistFile.UpdateDelegate upd)
        {
            IntPtr pContext = IntPtr.Zero;

            if (Compress.My_XMemCreateCompressionContext(1, IntPtr.Zero, (ushort)0, out pContext) != 0)
            {
                throw new Exception("Cannot create compression context. Aborted");
            }
            FileStream fileStream = fi.OpenRead();
            int        length     = (int)fileStream.Length;

            byte[] numArray1 = new byte[length];
            fileStream.Read(numArray1, 0, length);
            fileStream.Close();
            int pDestSize = length * 3;

            byte[] numArray2 = new byte[pDestSize];
            if (Compress.My_XMemCompress(pContext, numArray2, out pDestSize, numArray1, length) != 0)
            {
                throw new Exception("Cannot compress data.");
            }
            BFF bff = new BFF();

            if (pDestSize > length)
            {
                bff.Inject(archivePath, filename, numArray1, length, length, fs_archive, fs_list, upd);
            }
            else
            {
                bff.Inject(archivePath, filename, numArray2, pDestSize, length, fs_archive, fs_list, upd);
            }
        }
Beispiel #2
0
        public void CreateRedist(string sourceFolder, string output, RedistFile.UpdateDelegate upd)
        {
            RedistHeader redistHeader = new RedistHeader(sourceFolder);

            if (upd != null)
            {
                upd("Initializing redist file");
            }
            FileStream fileStream1 = new FileStream(output, FileMode.Create);

            fileStream1.Write(redistHeader.Magic, 0, 4);
            int position1 = (int)fileStream1.Position;

            fileStream1.Write(BitConverter.GetBytes(redistHeader.FileSize), 0, 4);
            int position2 = (int)fileStream1.Position;

            fileStream1.Write(BitConverter.GetBytes(0), 0, 4);
            fileStream1.Write(BitConverter.GetBytes(this.Files.Keys.Count), 0, 4);
            fileStream1.Seek(16L, SeekOrigin.Begin);
            IntPtr pContext = IntPtr.Zero;

            try
            {
                if (Compress.My_XMemCreateCompressionContext(1, IntPtr.Zero, (ushort)0, out pContext) != 0)
                {
                    throw new Exception("Cannot create compression context. Aborted");
                }
            }
            catch (DllNotFoundException ex)
            {
                if (upd != null)
                {
                    upd(string.Format("DLL not found exception ({0})", (object)ex.Message));
                }
                fileStream1.Close();
                return;
            }
            byte[] buffer1 = new byte[4];
            if (upd != null)
            {
                upd("Creating install script");
            }
            StreamWriter streamWriter = new StreamWriter(string.Format("{0}\\Install.bfi", (object)output.Substring(0, output.LastIndexOf("\\"))), false, Encoding.Default);

            streamWriter.WriteLine("BFI");
            streamWriter.WriteLine(output.Substring(output.LastIndexOf("\\") + 1));
            foreach (string key in this.Files.Keys)
            {
                List <string> file = this.Files[key];
                streamWriter.WriteLine(string.Format("{0}={1}", (object)key, (object)file.Count));
                RedistEntry redistEntry = new RedistEntry(key, file.Count);
                fileStream1.Write(redistEntry.ArchiveName, 0, redistEntry.ArchiveName.Length);
                fileStream1.Write(BitConverter.GetBytes(redistEntry.FilesInArchive), 0, 4);
                int position3 = (int)fileStream1.Position;
                fileStream1.Write(buffer1, 0, 4);
                foreach (string str1 in file)
                {
                    string str2 = str1.Substring(sourceFolder.Length + 1);
                    streamWriter.WriteLine(str2);
                    fileStream1.Write(BitConverter.GetBytes(this.AllFiles.IndexOf(str1)), 0, 4);
                }
                int position4 = (int)fileStream1.Position;
                int num       = position4 + (16 - position4 % 16);
                fileStream1.Seek((long)position3, SeekOrigin.Begin);
                fileStream1.Write(BitConverter.GetBytes(num), 0, 4);
                fileStream1.Seek((long)num, SeekOrigin.Begin);
            }
            streamWriter.Close();
            int position5 = (int)fileStream1.Position;
            int num1      = position5 + (16 - position5 % 16);

            fileStream1.Seek((long)position2, SeekOrigin.Begin);
            fileStream1.Write(BitConverter.GetBytes(num1), 0, 4);
            fileStream1.Seek((long)num1, SeekOrigin.Begin);
            fileStream1.Write(BitConverter.GetBytes(this.AllFiles.Count), 0, 4);
            foreach (string allFile in this.AllFiles)
            {
                string s         = allFile.Substring(sourceFolder.Length + 1);
                int    position3 = (int)fileStream1.Position;
                fileStream1.Write(buffer1, 0, 4);
                int position4 = (int)fileStream1.Position;
                fileStream1.Write(buffer1, 0, 4);
                int position6 = (int)fileStream1.Position;
                fileStream1.Write(buffer1, 0, 4);
                byte[] buffer2 = new byte[1] {
                    (byte)s.Length
                };
                fileStream1.Write(buffer2, 0, 1);
                fileStream1.Write(Encoding.Default.GetBytes(s), 0, s.Length);
                int length;
                int pDestSize;
                if (allFile.IndexOf("\\-") == -1)
                {
                    FileStream fileStream2 = new FileStream(allFile, FileMode.Open);
                    length = (int)fileStream2.Length;
                    byte[] numArray1 = new byte[length];
                    this.Assert(fileStream2.Read(numArray1, 0, length), length);
                    fileStream2.Close();
                    pDestSize = length * 3;
                    byte[] numArray2 = new byte[pDestSize];
                    int    num2      = Compress.My_XMemCompress(pContext, numArray2, out pDestSize, numArray1, length);
                    switch (num2)
                    {
                    case -2116149247:
                        fileStream1.Write(numArray1, 0, length);
                        pDestSize = length;
                        break;

                    case 0:
                        if (pDestSize > length)
                        {
                            fileStream1.Write(numArray1, 0, length);
                            pDestSize = length;
                            break;
                        }
                        fileStream1.Write(numArray2, 0, pDestSize);
                        break;

                    default:
                        throw new Exception(string.Format("Cannot compress file. Aborted\r\nHRESULT = {0}", (object)num2.ToString("X8")));
                    }
                }
                else
                {
                    length    = 0;
                    pDestSize = 0;
                }
                int position7 = (int)fileStream1.Position;
                int num3      = position7 + (16 - position7 % 16);
                fileStream1.Seek((long)position3, SeekOrigin.Begin);
                fileStream1.Write(BitConverter.GetBytes(num3), 0, 4);
                fileStream1.Seek((long)position4, SeekOrigin.Begin);
                fileStream1.Write(BitConverter.GetBytes(pDestSize), 0, 4);
                fileStream1.Seek((long)position6, SeekOrigin.Begin);
                fileStream1.Write(BitConverter.GetBytes(length), 0, 4);
                fileStream1.Seek((long)num3, SeekOrigin.Begin);
            }
            int position8 = (int)fileStream1.Position;

            fileStream1.Seek((long)position1, SeekOrigin.Begin);
            fileStream1.Write(BitConverter.GetBytes(position8), 0, 4);
            fileStream1.Close();
            if (upd == null)
            {
                return;
            }
            upd("Finished");
        }