public static FromFile ( string filename, string foldername ) : |
||
filename | string | |
foldername | string | |
Результат |
public static Ctpk Create(string inputPath, string outputPath) { if (!Directory.Exists(inputPath)) { return(null); } Ctpk file = new Ctpk(); // Look for all xml definition files in the folder var files = Directory.GetFiles(inputPath, "*.xml", SearchOption.AllDirectories); foreach (var xmlFilename in files) { CTPKEntry entry = CTPKEntry.FromFile(xmlFilename, inputPath); file._entries.Add(entry); } for (int i = 0; i < file._entries.Count; i++) { file._entries[i].BitmapSizeOffset = (uint)((file._entries.Count + 1) * 8 + i); } using (BinaryWriter writer = new BinaryWriter(File.Open(outputPath, FileMode.Create))) { file.Write(writer); } Console.WriteLine("Finished! Saved to {0}", outputPath); return(file); }
public static Ctpk Create(string inputPath, string outputPath, string _patchPath) { if (!Directory.Exists(inputPath)) { return(null); } string _goodInPath = makePathGood(inputPath); string _goodPatchPath = _patchPath != null?makePathGood(_patchPath) : null; Ctpk file = new Ctpk(); // Look for all xml definition files in the folder string[] _xmlFiles = Directory.GetFiles(_goodInPath, "*.xml", SearchOption.AllDirectories); string[] _xmlOverrides = new string[_xmlFiles.Length]; string[] _pngFiles = new string[_xmlFiles.Length]; Array.Clear(_pngFiles, 0, _pngFiles.Length); Array.Clear(_xmlOverrides, 0, _xmlOverrides.Length); if (_goodPatchPath != null) { string[] patchFiles = Directory.GetFiles(_goodPatchPath, "*", SearchOption.AllDirectories); // Merge patchFiles into files for (int j = 0; j < patchFiles.Length; ++j) { string _choppedName = Path.GetFileNameWithoutExtension(patchFiles[j]); int i; for (i = 0; i < _xmlFiles.Length; ++i) { if (Path.GetFileNameWithoutExtension(_xmlFiles[i]) == _choppedName) { if (Path.GetExtension(patchFiles[j]) == ".xml") { _xmlOverrides[i] = patchFiles[j]; } else { _pngFiles[i] = patchFiles[j]; } break; } } if (i == _xmlFiles.Length) { Console.WriteLine("Base path is " + _goodInPath); for (i = 0; i < _xmlFiles.Length; ++i) { Console.WriteLine(String.Format("{0} ({1})", _xmlFiles[i], Path.GetFileNameWithoutExtension(_xmlFiles[i]))); } throw new Exception(String.Format("Could not find replacement for {0} ({3}) from {1} to put in {2}", patchFiles[j], _goodPatchPath, _goodInPath, _choppedName)); } } } for (int i = 0; i < _xmlFiles.Length; ++i) { CTPKEntry entry; if (_xmlOverrides[i] != null) { entry = CTPKEntry.FromFile(_xmlOverrides[i], _goodInPath, _pngFiles[i]); if (entry == null) { entry = CTPKEntry.FromFile(_xmlFiles[i], _goodInPath, _pngFiles[i]); } } else { entry = CTPKEntry.FromFile(_xmlFiles[i], _goodInPath, _pngFiles[i]); } if (entry == null) { throw new Exception("failed to create ctpkentry"); } file._entries.Add(entry); } for (int i = 0; i < file._entries.Count; i++) { file._entries[i].BitmapSizeOffset = (uint)((file._entries.Count + 1) * 8 + i); } using (BinaryWriter writer = new BinaryWriter(File.Open(outputPath, FileMode.Create))) { file.Write(writer); } Console.WriteLine("Finished! Saved to {0}", outputPath); return(file); }