public override TImport Import(string filename, ContentImporterContext context) { FileInfo assemblyFileInfo = new FileInfo(filename); DirectoryInfo fireMLDirInfo = assemblyFileInfo.Directory; DirectoryInfo contentDirInfo = fireMLDirInfo.Parent; /* * DirectoryInfo plotDirInfo = new DirectoryInfo(fireMLDirInfo.FullName + "\\Plot"); * if (!plotDirInfo.Exists) * { * throw new InvalidContentException("剧情脚本文件夹Plot不存在!"); * } * * List<string> plotFileList = new List<string>(); * foreach (FileInfo plotFile in plotDirInfo.GetFiles("*.xml")) * { * plotFileList.Add(plotFile.FullName); * } * * DirectoryInfo assetDirInfo = new DirectoryInfo(fireMLDirInfo.FullName + "\\Asset"); * List<string> assetFileList = new List<string>(); * if (assetDirInfo.Exists) * { * foreach (FileInfo assetFile in assetDirInfo.GetFiles("*.xml")) * { * assetFileList.Add(assetFile.FullName); * } * }*/ List <string> plotFileList = new List <string>(); List <string> assetFileList = new List <string>(); foreach (FileInfo fileInfo in fireMLDirInfo.GetFiles("*.*", SearchOption.AllDirectories)) { string ext = fileInfo.Extension; if (ext == ".fmlplot") { plotFileList.Add(fileInfo.FullName); } else if (ext == ".fmlasset") { assetFileList.Add(fileInfo.FullName); } } string xsdDirPath = fireMLDirInfo.FullName + "\\" + "XSD"; CompilerKernel kernel = new CompilerKernel(plotFileList.ToArray(), assetFileList.ToArray(), xsdDirPath, new FireEngine.XNAContent.ContentManager(contentDirInfo.FullName)); FireMLRoot root = kernel.CompileFireML(); Error[] errors = kernel.CheckPoint(); if (errors.Length > 0) { StringBuilder msg = new StringBuilder(); foreach (Error error in errors) { msg.AppendLine(error.Message + "(" + error.Location.ToString() + ")"); } ContentIdentity ci = new ContentIdentity(errors[0].Location.FileName); ci.FragmentIdentifier = errors[0].Location.Line + ", " + errors[0].Location.Column; throw new InvalidContentException(msg.ToString(), ci); } return(root); }
static void Main(string[] args) { /* * int plotNum = int.Parse(args[0]); * int assetNum = int.Parse(args[1]); * string contentPath = args[2]; * const int BEGIN_ARG = 3; * * List<string> plotList = new List<string>(); * List<string> assetList = new List<string>(); * for (int i = BEGIN_ARG; i < BEGIN_ARG + plotNum; i++) * { * plotList.Add(args[i]); * } * for (int i = BEGIN_ARG + plotNum; i < BEGIN_ARG + plotNum + assetNum; i++) * { * assetList.Add(args[i]); * }*/ FileInfo assemblyFileInfo = new FileInfo(args[0]); DirectoryInfo fireMLDirInfo = assemblyFileInfo.Directory; DirectoryInfo contentDirInfo = fireMLDirInfo.Parent; List <string> plotFileList = new List <string>(); List <string> assetFileList = new List <string>(); foreach (FileInfo fileInfo in fireMLDirInfo.GetFiles("*.*", SearchOption.AllDirectories)) { string ext = fileInfo.Extension; if (ext == ".fmlplot") { plotFileList.Add(fileInfo.FullName); } else if (ext == ".fmlasset") { assetFileList.Add(fileInfo.FullName); } } string xsdDirPath = fireMLDirInfo.FullName + "\\" + "XSD"; ContentManager contentManager = new ContentManager(contentDirInfo.FullName); CompilerKernel kernel = new CompilerKernel(plotFileList.ToArray(), assetFileList.ToArray(), xsdDirPath, contentManager); FireMLRoot result = kernel.CompileFireML(); Error[] errors = kernel.CheckPoint(); foreach (Error e in errors) { Console.WriteLine("{0}\n{1},{2}\n{3}", e.Location.FileName, e.Location.Line, e.Location.Column, e.Message); Console.WriteLine(); } if (errors.Length > 0) { Environment.Exit(-1); return; } BinaryFormatter bf = new BinaryFormatter(); FileStream writeStream = new FileStream("compiled.bin", FileMode.Create); bf.Serialize(writeStream, result); writeStream.Close(); Console.WriteLine("编译完成"); FileStream readStream = new FileStream("compiled.bin", FileMode.Open); FireMLRoot deserialized = bf.Deserialize(readStream) as FireMLRoot; }
static void Main(string[] args) { FileInfo assemblyFileInfo = new FileInfo(args[0]); string savePath = args[1]; DirectoryInfo fireMLDirInfo = assemblyFileInfo.Directory; DirectoryInfo contentDirInfo = fireMLDirInfo.Parent; List <string> plotFileList = new List <string>(); List <string> assetFileList = new List <string>(); foreach (FileInfo fileInfo in fireMLDirInfo.GetFiles("*.*", SearchOption.AllDirectories)) { string ext = fileInfo.Extension; if (ext == ".fmlplot") { plotFileList.Add(fileInfo.FullName); } else if (ext == ".fmlasset") { assetFileList.Add(fileInfo.FullName); } } string xsdDirPath = fireMLDirInfo.FullName + "\\" + "XSD"; //FireEngine.XNAContent.ContentManager contentManager = new FireEngine.XNAContent.ContentManager(contentDirInfo.FullName); CompilerKernel kernel = new CompilerKernel(plotFileList.ToArray(), assetFileList.ToArray(), xsdDirPath, null /*contentManager*/); FireMLRoot result = kernel.CompileFireML(); Error[] errors = kernel.CheckPoint(); foreach (Error e in errors) { Console.WriteLine("{0}\n{1},{2}\n{3}", e.Location.FileName, e.Location.Line, e.Location.Column, e.Message); Console.WriteLine(); } if (errors.Length > 0) { Environment.Exit(-1); return; } Stream bsonStream = new FileStream(savePath, FileMode.Create); BsonBuffer bsonBuffer = new BsonBuffer(); BsonBinaryWriterSettings bsonSettings = new BsonBinaryWriterSettings(); BsonBinaryWriter bsonWriter = new BsonBinaryWriter(bsonStream, bsonBuffer, bsonSettings); BsonSerializer.Serialize <FireMLRoot>(bsonWriter, result); bsonWriter.Close(); JsonWriterSettings jsonSettings = new JsonWriterSettings(); jsonSettings.NewLineChars = "\r\n"; jsonSettings.OutputMode = JsonOutputMode.JavaScript; jsonSettings.Indent = true; jsonSettings.IndentChars = " "; StreamWriter streamWriter = new StreamWriter(new FileStream(savePath + ".json", FileMode.Create)); JsonWriter jsonWriter = new JsonWriter(streamWriter, jsonSettings); BsonSerializer.Serialize <FireMLRoot>(jsonWriter, result); jsonWriter.Close(); }