Beispiel #1
0
 public void extract(Label 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)
     {
         double progress = icp.i * 1.0 / toExtract;
         pb.Width = (int)(progress * 600);
         Application.DoEvents();
         System.Threading.Thread.Sleep(10);
     }
 }
Beispiel #2
0
 public void make(Label 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)
     {
         double progress = (icp.i + bytesCompressed) * 1.0 / bytesToCompress;
         //this.Text = string.Format("{0:0.00}%", Math.Round(progress * 100, 2)).Replace(".", " . ");
         pb.Width = (int)(progress * 600);
         Application.DoEvents();
         System.Threading.Thread.Sleep(10);
     }
     //this.Text = "done";
     MessageBox.Show("new dfc ok");
 }
Beispiel #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);
        }
Beispiel #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(@"..\..\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;
        }
Beispiel #5
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(@"..\..\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;
        }
Beispiel #6
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;
        }
Beispiel #7
0
 public void make(Label 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)
     {
         double progress = (icp.i + bytesCompressed) * 1.0 / bytesToCompress;
         //this.Text = string.Format("{0:0.00}%", Math.Round(progress * 100, 2)).Replace(".", " . ");
         pb.Width = (int)(progress * 600);
         Application.DoEvents();
         System.Threading.Thread.Sleep(10);
     }
     //this.Text = "done";
     MessageBox.Show("new dfc ok");
 }
Beispiel #8
0
 public void extract(Label 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)
     {
         double progress = icp.i * 1.0 / toExtract;
         pb.Width = (int)(progress * 600);
         Application.DoEvents();
         System.Threading.Thread.Sleep(10);
     }
 }