1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using CommonLang;
- using CommonLang.IO;
- using CommonLang.Xml;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Xml;
- namespace CommonUI.Data
- {
- public class UIEditorConverter
- {
- public delegate bool TryConvertToBin(FileInfo xml, FileInfo bin);
- public TryConvertToBin TryConvert;
- public void ConvertXML(DirectoryInfo dir)
- {
- foreach (FileInfo sub in dir.GetFiles())
- {
- ConvertXML(sub);
- }
- foreach (DirectoryInfo sub in dir.GetDirectories())
- {
- ConvertXML(sub);
- }
- }
- public void ConvertXML(FileInfo xml_file)
- {
- if (xml_file.FullName.EndsWith(".gui.xml"))
- {
- try
- {
- string bin_name = xml_file.FullName.Substring(0, xml_file.FullName.LastIndexOf(".gui.xml")) + ".gui.bin";
- FileInfo bin_file = new FileInfo(bin_name);
- if (TryConvert == null || !TryConvert.Invoke(xml_file, bin_file))
- {
- try
- {
- Console.Write(string.Format("ConvertXML: {0} -> {1}", xml_file.FullName, xml_file.Name + ".bin"));
- var xml = XmlUtil.LoadXML(xml_file.FullName);
- if (xml != null && xml.DocumentElement.Name == UIEditorMeta.UERoot_ClassName)
- {
- var meta = UIEditorMeta.CreateFromXml(xml);
- var bin = UIEditorMeta.SaveToBin(meta);
- File.WriteAllBytes(bin_file.FullName, bin);
- var meta2 = UIEditorMeta.CreateFromBin(bin);
- var bin2 = UIEditorMeta.SaveToBin(meta2);
- if (!CUtils.ArraysEqual<byte>(bin, bin2))
- {
- throw new Exception("Bad IO");
- }
- }
- }
- finally
- {
- Console.WriteLine(" OK!");
- }
- }
- }
- catch (Exception err)
- {
- Console.WriteLine(err.Message);
- Console.WriteLine(err.StackTrace);
- }
- }
- }
- }
- }
|