123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System;
- using System.IO;
- namespace ResBuilder
- {
- class UIResProcessor
- {
- public readonly string inputRoot;
- public readonly string outputRoot;
- public readonly string relativePath;
- public UIResProcessor(string inputRoot , string outputRoot, string relativePath)
- {
- this.inputRoot = inputRoot;
- this.outputRoot = outputRoot;
- this.relativePath = relativePath;
- }
- public void Execute()
- {
- var inputPath = Path.Combine(inputRoot , relativePath);
- var allFiles = Directory.GetFiles(inputPath, "*.*", SearchOption.AllDirectories);
- var binFiles = Array.FindAll<string>(allFiles, (str) => str.EndsWith(".bin"));
- var pngFiles = Array.FindAll<string>(allFiles, (str) => str.EndsWith(".png") || str.EndsWith(".jpg"));
- var xmlFiles = Array.FindAll<string>(allFiles,
- (str) =>
- {
- if (!str.EndsWith(".xml"))
- {
- return false;
- }
- var fileName = Path.ChangeExtension(str , "bin");
- return Array.IndexOf(binFiles, fileName) == -1;
- });
- var outputDir = Path.Combine(outputRoot, relativePath);
- if (Directory.Exists(outputDir))
- {
- Directory.Delete(outputDir, true);
- }
- // -- 1
- foreach (var f in binFiles)
- {
- var relativeFilePath = f.Substring(inputPath.Length + 1);
- var outputFilePath = Path.Combine(outputDir, relativeFilePath);
- var outDirName = Path.GetDirectoryName(outputFilePath);
- if (!Directory.Exists(outDirName))
- {
- Directory.CreateDirectory(outDirName);
- }
- File.Copy(f, outputFilePath, true);
- }
- // -- 2
- foreach (var f in pngFiles)
- {
- var relativeFilePath = f.Substring(inputPath.Length + 1);
- var outputFilePath = Path.Combine(outputDir, relativeFilePath);
- var outDirName = Path.GetDirectoryName(outputFilePath);
- if (!Directory.Exists(outDirName))
- {
- Directory.CreateDirectory(outDirName);
- }
- File.Copy(f, outputFilePath, true);
- }
- foreach (var f in xmlFiles)
- {
- var relativeFilePath = f.Substring(inputPath.Length + 1);
- var outputFilePath = Path.Combine(outputDir, relativeFilePath);
- var outDirName = Path.GetDirectoryName(outputFilePath);
- if (!Directory.Exists(outDirName))
- {
- Directory.CreateDirectory(outDirName);
- }
- File.Copy(f, outputFilePath , true);
- }
- }
- }
- }
|