示例#1
0
        private void button_ypf_unpack_Click(object sender, EventArgs e)
        {
            var files = new List <string>();

            if (Directory.Exists(textBox_ypf_unpack_input.Text))
            {
                files.AddRange(Directory.GetFiles(textBox_ypf_unpack_input.Text, "*.ypf"));
            }
            else
            {
                files.Add(textBox_ypf_unpack_input.Text);
            }
            groupBox1.Enabled = false;
            Func <byte[], uint> hashName = null, hashData = null;

            if (checkBox_ypf_verify.Checked)
            {
                if (radioButton_ypf_crc32.Checked)
                {
                    hashName = CheckSum.CRC32;
                    hashData = CheckSum.Adler32;
                }
                else
                {
                    hashData = hashName = CheckSum.MurmurHash2;
                }
            }
            var output = textBox_ypf_unpack_output.Text;

            ThreadPool.QueueUserWorkItem(s =>
            {
                int success = 0;
                foreach (var file in files)
                {
                    try
                    {
                        Log("[YPF Unpack] Unpacking " + Path.GetFileName(file) + " ...");
                        using (var reader = new BinaryReader(File.OpenRead(file)))
                        {
                            var ypf = YPF.ReadFile(reader, hashName, hashData);
                            Log("[YPF Unpack] Found " + ypf.Entries.Count + " entries.");
                            foreach (var entry in ypf.Entries)
                            {
                                Log("[YPF Unpack] Unpacking " + entry.Name + "(" + entry.Size + ") ...");
                                var path = Path.Combine(output, Path.GetFileNameWithoutExtension(file), entry.Name);
                                Directory.CreateDirectory(Path.GetDirectoryName(path));
                                File.WriteAllBytes(path, entry.Data);
                            }
                        }
                        success++;
                    }
                    catch (Exception ex) { Oops(ex); }
                }
                Log("[YPF Unpack] Complete, unpacked " + success + "/" + files.Count + " files.");
                Invoke(new Action(() => groupBox1.Enabled = true));
            });
        }