UIResPacker.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.IO;
  3. namespace ResBuilder
  4. {
  5. class UIResPacker
  6. {
  7. public readonly string inputPath;
  8. public readonly string outputFile;
  9. public UIResPacker(string input , string output)
  10. {
  11. this.inputPath = input;
  12. this.outputFile = Path.Combine(output , "ur.bin");
  13. }
  14. string GetWriteFileName(string fp)
  15. {
  16. if (fp.StartsWith(inputPath))
  17. {
  18. fp = fp.Substring(fp.IndexOf("res"));
  19. fp = fp.Replace('\\', '/');
  20. }
  21. return fp;
  22. }
  23. public void Pack()
  24. {
  25. var files = Directory.GetFiles(inputPath, "*.*", SearchOption.AllDirectories);
  26. files = Array.FindAll<string>(files, (str) => str.EndsWith(".bin") || str.EndsWith(".png") || str.EndsWith(".jpg"));
  27. using (var fs = new FileStream(outputFile, FileMode.Create))
  28. {
  29. var bw = new BinaryWriter(fs);
  30. bw.Write(files.Length);
  31. foreach (var f in files)
  32. {
  33. var bytes = File.ReadAllBytes(f);
  34. bw.Write(GetWriteFileName(f));
  35. bw.Write(bytes.Length);
  36. bw.Write(bytes);
  37. }
  38. }
  39. }
  40. }
  41. }