Esempio n. 1
0
 private void button_ypf_pack_Click(object sender, EventArgs e)
 {
     try
     {
         var ypf      = new YPF();
         var baseName = Path.GetFullPath(textBox_ypf_pack_input.Text).TrimEnd('\\') + "\\";
         HashSet <string> non_compress = new HashSet <string>(textBox_ypf_pack_no_compress.Text.ToLower().Split('/').Where(s => s.Trim() != "")),
                          non_packing  = new HashSet <string>(textBox_ypf_pack_no_packing.Text.ToLower().Split('/').Where(s => s.Trim() != ""));
         foreach (var file in Directory.GetFiles(textBox_ypf_pack_input.Text, "*", SearchOption.AllDirectories).OrderBy(f => f))
         {
             if (non_packing.Contains(Path.GetExtension(file).ToLower()))
             {
                 continue;
             }
             ypf.Entries.Add(new YPFEntry(file.Replace(baseName, ""), File.ReadAllBytes(file))
             {
                 Compressed = !non_compress.Contains(Path.GetExtension(file).ToLower())
             });
         }
         Log("[YPF Pack] Created " + ypf.Entries.Count + " entries.");
         var target = textBox_ypf_pack_output.Text;
         if (Directory.Exists(target))
         {
             target = Path.Combine(target, Path.GetFileName(textBox_ypf_pack_input.Text) + ".ypf");
         }
         using (var writer = new BinaryWriter(File.Open(target, FileMode.Create)))
         {
             Func <byte[], uint> hashName = CheckSum.MurmurHash2, hashData = CheckSum.MurmurHash2;
             if (radioButton_ypf_crc32.Checked)
             {
                 hashName = CheckSum.CRC32;
                 hashData = CheckSum.Adler32;
             }
             ypf.Write(writer, int.Parse(textBox_ypf_engine.Text), hashName, hashData);
             Log("[YPF Pack] Write success, size: " + writer.BaseStream.Position + ", target: " + target);
         }
     }
     catch (Exception ex) { Oops(ex); }
 }