Пример #1
0
 public void extract(Progress pb)
 {
     icp = new ICP();
     System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(exthread));
     t.Name = "DFC_Extracter";
     t.Start();
     while (!extracting)
     {
         System.Threading.Thread.Sleep(1);
         Application.DoEvents();
     }
     while (extracting)
     {
         pb.prog(icp.i, toExtract);
         System.Threading.Thread.Sleep(10);
     }
 }
Пример #2
0
 public void make(Progress pb)
 {
     icp = new ICP();
     new System.Threading.Thread(new System.Threading.ThreadStart(makeDFC)).Start();
     while (!encoding)
     {
         System.Threading.Thread.Sleep(1);
         Application.DoEvents();
     }
     while (encoding)
     {
         pb.prog(icp.i + bytesCompressed, bytesToCompress);
         System.Threading.Thread.Sleep(10);
     }
     //this.Text = "done";
     MessageBox.Show(
         "restart Loopstream from visual studio to embed the new dfc\r\n\r\n" +
         "then run Loopstream.exe with the command line argument 'sign'\r\n" +
         "to create Loopstream.exe.exe for publication");
 }
Пример #3
0
        bool extract(Stream si, long end, string filename, ICP icp)
        {
            SevenZip.Compression.LZMA.Decoder dec = new SevenZip.Compression.LZMA.Decoder();
            //using (MemoryStream msi = new MemoryStream(GamePatcher.Properties.Resources.kengeki1))
            using (FileStream fso = new FileStream(filename, FileMode.Create))
            {
                byte[] props = new byte[5];
                si.Read(props, 0, 5);

                byte[] length = new byte[8];
                si.Read(length, 0, 8);

                long len = BitConverter.ToInt64(length, 0);

                dec.SetDecoderProperties(props);
                //dec.Code(si, fso, si.Length, len, null);
                dec.Code(si, fso, end, len, icp);
            }
            //si.Close();
            return(true);
        }
Пример #4
0
        void makeDFC()
        {
            archivequeue = new List<string>();
            string src = Path.GetFullPath(@"..\..\tools\");
            recurse(src, archivequeue);
            string[] files = archivequeue.ToArray();
            for (int a = 0; a < files.Length; a++)
            {
                files[a] = files[a].Substring(src.Length).Replace('\\', '/');
            }

            int filenameslength = 0;
            long[] cLen = new long[files.Length];
            long[] eLen = new long[files.Length];
            byte[][] filename = new byte[files.Length][];
            for (int a = 0; a < files.Length; a++)
            {
                eLen[a] = new FileInfo(src + files[a]).Length;
                filename[a] = Encoding.UTF8.GetBytes(files[a]);
                filenameslength += filename[a].Length;
                bytesToCompress += eLen[a];
            }

            byte[] buffer = new byte[8192];
            byte[] header = new byte[
                              4 + // header     length
                              4 + // file       count
               files.Length * 4 + // filename   length
               files.Length * 8 + // compressed length
               files.Length * 8 + // extracted  length
               filenameslength
            ];
            for (int a = 0; a < header.Length; a++)
            {
                header[a] = 0xFF;
            }

            using (FileStream fso = new FileStream(@"..\..\res\tools.dfc", FileMode.Create))
            {
                encoding = true;
                fso.Write(header, 0, header.Length);
                for (int a = 0; a < files.Length; a++)
                {
                    using (FileStream fsi = new FileStream(src + files[a], FileMode.Open, FileAccess.Read))
                    {
                        long pre = fso.Position;
                        SevenZip.Compression.LZMA.Encoder enc = new SevenZip.Compression.LZMA.Encoder();
                        enc.WriteCoderProperties(fso);
                        fso.Write(BitConverter.GetBytes(fsi.Length), 0, 8);
                        enc.Code(fsi, fso, fsi.Length, -1, icp);
                        cLen[a] = fso.Position - pre;
                        bytesCompressed += icp.i;
                        icp = new ICP();

                    }
                }
                using (MemoryStream msh = new MemoryStream(header.Length))
                {
                    msh.Write(BitConverter.GetBytes((Int32)header.Length), 0, 4);
                    msh.Write(BitConverter.GetBytes((Int32)files.Length), 0, 4);
                    foreach (byte[] fn in filename)
                    {
                        msh.Write(BitConverter.GetBytes((Int32)fn.Length), 0, 4);
                    }
                    foreach (long cLn in cLen)
                    {
                        msh.Write(BitConverter.GetBytes((Int64)cLn), 0, 8);
                    }
                    foreach (long eLn in eLen)
                    {
                        msh.Write(BitConverter.GetBytes((Int64)eLn), 0, 8);
                    }
                    foreach (byte[] fn in filename)
                    {
                        msh.Write(fn, 0, fn.Length);
                    }
                    fso.Seek(0, SeekOrigin.Begin);
                    msh.Seek(0, SeekOrigin.Begin);
                    msh.WriteTo(fso);
                }
            }
            encoding = false;
        }
Пример #5
0
        bool extract(Stream si, long end, string filename, ICP icp)
        {
            SevenZip.Compression.LZMA.Decoder dec = new SevenZip.Compression.LZMA.Decoder();
            //using (MemoryStream msi = new MemoryStream(GamePatcher.Properties.Resources.kengeki1))
            using (FileStream fso = new FileStream(filename, FileMode.Create))
            {
                byte[] props = new byte[5];
                si.Read(props, 0, 5);

                byte[] length = new byte[8];
                si.Read(length, 0, 8);

                long len = BitConverter.ToInt64(length, 0);

                dec.SetDecoderProperties(props);
                //dec.Code(si, fso, si.Length, len, null);
                dec.Code(si, fso, end, len, icp);
            }
            //si.Close();
            return true;
        }
Пример #6
0
 public void make(Progress pb)
 {
     icp = new ICP();
     new System.Threading.Thread(new System.Threading.ThreadStart(makeDFC)).Start();
     while (!encoding)
     {
         System.Threading.Thread.Sleep(1);
         Application.DoEvents();
     }
     while (encoding)
     {
         pb.prog(icp.i + bytesCompressed, bytesToCompress);
         System.Threading.Thread.Sleep(10);
     }
     //this.Text = "done";
     MessageBox.Show(
         "restart Loopstream from visual studio to embed the new dfc\r\n\r\n" +
         "then run Loopstream.exe with the command line argument 'sign'\r\n" +
         "to create Loopstream.exe.exe for publication");
 }
Пример #7
0
 public void extract(Progress pb)
 {
     icp = new ICP();
     System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(exthread));
     t.Name = "DFC_Extracter";
     t.Start();
     while (!extracting)
     {
         System.Threading.Thread.Sleep(1);
         Application.DoEvents();
     }
     while (extracting)
     {
         pb.prog(icp.i, toExtract);
         System.Threading.Thread.Sleep(10);
     }
 }
Пример #8
0
        void makeDFC()
        {
            archivequeue = new List <string>();
            string src = Path.GetFullPath(@"..\..\tools\");

            recurse(src, archivequeue);
            string[] files = archivequeue.ToArray();
            for (int a = 0; a < files.Length; a++)
            {
                files[a] = files[a].Substring(src.Length).Replace('\\', '/');
            }

            int filenameslength = 0;

            long[]   cLen     = new long[files.Length];
            long[]   eLen     = new long[files.Length];
            byte[][] filename = new byte[files.Length][];
            for (int a = 0; a < files.Length; a++)
            {
                eLen[a]          = new FileInfo(src + files[a]).Length;
                filename[a]      = Encoding.UTF8.GetBytes(files[a]);
                filenameslength += filename[a].Length;
                bytesToCompress += eLen[a];
            }

            byte[] buffer = new byte[8192];
            byte[] header = new byte[
                4 +                // header     length
                4 +                // file       count
                files.Length * 4 + // filename   length
                files.Length * 8 + // compressed length
                files.Length * 8 + // extracted  length
                filenameslength
                            ];
            for (int a = 0; a < header.Length; a++)
            {
                header[a] = 0xFF;
            }

            using (FileStream fso = new FileStream(@"..\..\res\tools.dfc", FileMode.Create))
            {
                encoding = true;
                fso.Write(header, 0, header.Length);
                for (int a = 0; a < files.Length; a++)
                {
                    using (FileStream fsi = new FileStream(src + files[a], FileMode.Open, FileAccess.Read))
                    {
                        long pre = fso.Position;
                        SevenZip.Compression.LZMA.Encoder enc = new SevenZip.Compression.LZMA.Encoder();
                        enc.WriteCoderProperties(fso);
                        fso.Write(BitConverter.GetBytes(fsi.Length), 0, 8);
                        enc.Code(fsi, fso, fsi.Length, -1, icp);
                        cLen[a]          = fso.Position - pre;
                        bytesCompressed += icp.i;
                        icp              = new ICP();
                    }
                }
                using (MemoryStream msh = new MemoryStream(header.Length))
                {
                    msh.Write(BitConverter.GetBytes((Int32)header.Length), 0, 4);
                    msh.Write(BitConverter.GetBytes((Int32)files.Length), 0, 4);
                    foreach (byte[] fn in filename)
                    {
                        msh.Write(BitConverter.GetBytes((Int32)fn.Length), 0, 4);
                    }
                    foreach (long cLn in cLen)
                    {
                        msh.Write(BitConverter.GetBytes((Int64)cLn), 0, 8);
                    }
                    foreach (long eLn in eLen)
                    {
                        msh.Write(BitConverter.GetBytes((Int64)eLn), 0, 8);
                    }
                    foreach (byte[] fn in filename)
                    {
                        msh.Write(fn, 0, fn.Length);
                    }
                    fso.Seek(0, SeekOrigin.Begin);
                    msh.Seek(0, SeekOrigin.Begin);
                    msh.WriteTo(fso);
                }
            }
            encoding = false;
        }