UIResProcessor.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.IO;
  3. namespace ResBuilder
  4. {
  5. class UIResProcessor
  6. {
  7. public readonly string inputRoot;
  8. public readonly string outputRoot;
  9. public readonly string relativePath;
  10. public UIResProcessor(string inputRoot , string outputRoot, string relativePath)
  11. {
  12. this.inputRoot = inputRoot;
  13. this.outputRoot = outputRoot;
  14. this.relativePath = relativePath;
  15. }
  16. public void Execute()
  17. {
  18. var inputPath = Path.Combine(inputRoot , relativePath);
  19. var allFiles = Directory.GetFiles(inputPath, "*.*", SearchOption.AllDirectories);
  20. var binFiles = Array.FindAll<string>(allFiles, (str) => str.EndsWith(".bin"));
  21. var pngFiles = Array.FindAll<string>(allFiles, (str) => str.EndsWith(".png") || str.EndsWith(".jpg"));
  22. var xmlFiles = Array.FindAll<string>(allFiles,
  23. (str) =>
  24. {
  25. if (!str.EndsWith(".xml"))
  26. {
  27. return false;
  28. }
  29. var fileName = Path.ChangeExtension(str , "bin");
  30. return Array.IndexOf(binFiles, fileName) == -1;
  31. });
  32. var outputDir = Path.Combine(outputRoot, relativePath);
  33. if (Directory.Exists(outputDir))
  34. {
  35. Directory.Delete(outputDir, true);
  36. }
  37. // -- 1
  38. foreach (var f in binFiles)
  39. {
  40. var relativeFilePath = f.Substring(inputPath.Length + 1);
  41. var outputFilePath = Path.Combine(outputDir, relativeFilePath);
  42. var outDirName = Path.GetDirectoryName(outputFilePath);
  43. if (!Directory.Exists(outDirName))
  44. {
  45. Directory.CreateDirectory(outDirName);
  46. }
  47. File.Copy(f, outputFilePath, true);
  48. }
  49. // -- 2
  50. foreach (var f in pngFiles)
  51. {
  52. var relativeFilePath = f.Substring(inputPath.Length + 1);
  53. var outputFilePath = Path.Combine(outputDir, relativeFilePath);
  54. var outDirName = Path.GetDirectoryName(outputFilePath);
  55. if (!Directory.Exists(outDirName))
  56. {
  57. Directory.CreateDirectory(outDirName);
  58. }
  59. File.Copy(f, outputFilePath, true);
  60. }
  61. foreach (var f in xmlFiles)
  62. {
  63. var relativeFilePath = f.Substring(inputPath.Length + 1);
  64. var outputFilePath = Path.Combine(outputDir, relativeFilePath);
  65. var outDirName = Path.GetDirectoryName(outputFilePath);
  66. if (!Directory.Exists(outDirName))
  67. {
  68. Directory.CreateDirectory(outDirName);
  69. }
  70. File.Copy(f, outputFilePath , true);
  71. }
  72. }
  73. }
  74. }