コード例 #1
0
        /// <summary>
        /// Compiles an XML font file description to a file. Optionally output dependency file.
        /// </summary>
        /// <param name="sourceXmlFile">The source XML file.</param>
        /// <param name="outputFile">The output file.</param>
        /// <param name="dependencyFile">The dependency file.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public static ContentCompilerResult CompileAndSave(string sourceXmlFile, string outputFile, string dependencyFile = null)
        {
            var logger = new Logger();
            var result = new ContentCompilerResult {
                Logger = logger
            };

            try
            {
                var fontDescription = FontDescription.Load(sourceXmlFile);

                var defaultOutputFile = Path.GetFileNameWithoutExtension(sourceXmlFile);

                // Compiles to SpriteData
                outputFile = outputFile ?? defaultOutputFile;

                result.IsContentGenerated = true;
                if (dependencyFile != null)
                {
                    if (!FileDependencyList.CheckForChanges(dependencyFile))
                    {
                        result.IsContentGenerated = false;
                    }
                }

                if (result.IsContentGenerated)
                {
                    // Make sure that directory name doesn't collide with filename
                    var directoryName = Path.GetDirectoryName(outputFile + ".tmp");
                    if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName))
                    {
                        Directory.CreateDirectory(directoryName);
                    }

                    using (var stream = new NativeFileStream(outputFile, NativeFileMode.Create, NativeFileAccess.Write))
                    {
                        Compile(fontDescription, stream);

                        if (dependencyFile != null)
                        {
                            var dependencies = new FileDependencyList();
                            dependencies.AddDefaultDependencies();
                            dependencies.AddDependencyPath(sourceXmlFile);
                            dependencies.Save(dependencyFile);
                        }
                    }
                }
            }
            catch (FontException ex)
            {
                logger.Error(ex.Message);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
            }

            return(result);
        }
コード例 #2
0
ファイル: ModelCompiler.cs プロジェクト: falbertp/SharpDX
        public static ContentCompilerResult CompileAndSave(string fileName, string outputFile, ModelCompilerOptions compilerOptions)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            if (outputFile == null)
            {
                throw new ArgumentNullException("outputFile");
            }

            if (compilerOptions == null)
            {
                throw new ArgumentNullException("compilerOptions");
            }


            bool contentToUpdate = true;

            if (compilerOptions.DependencyFile != null)
            {
                if (!FileDependencyList.CheckForChanges(compilerOptions.DependencyFile))
                {
                    contentToUpdate = false;
                }
            }

            var result = new ContentCompilerResult {
                Logger = new Logger()
            };

            if (contentToUpdate)
            {
                try
                {
                    result = CompileFromFile(fileName, compilerOptions);

                    if (result.HasErrors)
                    {
                        return(result);
                    }

                    var modelData = result.ModelData;

                    // Make sure that directory name doesn't collide with filename
                    var directoryName = Path.GetDirectoryName(outputFile + ".tmp");
                    if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName))
                    {
                        Directory.CreateDirectory(directoryName);
                    }

                    // Save the model
                    modelData.Save(outputFile);

                    if (compilerOptions.DependencyFile != null)
                    {
                        // Save the dependency
                        var dependencyList = new FileDependencyList();
                        dependencyList.AddDefaultDependencies();
                        dependencyList.AddDependencyPath(fileName);
                        dependencyList.Save(compilerOptions.DependencyFile);
                    }

                    result.IsContentGenerated = true;
                }
                catch (Exception ex)
                {
                    result.Logger.Error("Unexpected exception while converting {0} : {1}", fileName, ex.ToString());
                }
            }


            return(result);
        }