Пример #1
0
        public void Run(string[] args)
        {
            // Print the exe header
            PrintHeader();

            // Parse the command line
            if (!ParseCommandLine(args))
            {
                Environment.Exit(-1);
            }

            // Loads the description
            var filePath = Path.Combine(Environment.CurrentDirectory, XmlFontFile);

            var fontDescription = FontDescription.Load(XmlFontFile);

            var defaultOutputFile = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath));

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

            string dependencyFile = null;

            if (CompileOnlyIfNewer)
            {
                dependencyFile = Path.Combine(OutputDependencyDirectory, FileDependencyList.GetDependencyFileNameFromSourcePath(Path.GetFileName(filePath)));
            }

            bool forceCompilation = (DebugOutputSpriteSheet != null && !File.Exists(DebugOutputSpriteSheet));

            var result = FontCompiler.CompileAndSave(filePath, OutputFile, dependencyFile);

            if (result.IsContentGenerated || forceCompilation)
            {
                Console.WriteLine("Writing [{0}] ({1} format)", OutputFile, fontDescription.Format);

                // Save output files.
                if (!string.IsNullOrEmpty(DebugOutputSpriteSheet))
                {
                    Console.WriteLine("Saving debug output spritesheet {0}", DebugOutputSpriteSheet);

                    var spriteFontData = SpriteFontData.Load(OutputFile);

                    if (spriteFontData.Bitmaps.Length > 0 && spriteFontData.Bitmaps[0].Data is SpriteFontData.BitmapData)
                    {
                        var bitmapData = (SpriteFontData.BitmapData)spriteFontData.Bitmaps[0].Data;
                        using (var image = Image.New2D(bitmapData.Width, bitmapData.Height, 1, bitmapData.PixelFormat))
                        {
                            Utilities.Write(image.DataPointer, bitmapData.Data, 0, bitmapData.Data.Length);
                            image.Save(DebugOutputSpriteSheet, ImageFileType.Dds);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("No need to write [{0}]. File is up-to-date from XML description", OutputFile);
            }
        }
Пример #2
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);
        }
Пример #3
0
        public static FileDependencyList FromReader(TextReader textReader)
        {
            var    effectDependency = new FileDependencyList();
            string line;

            while ((line = textReader.ReadLine()) != null)
            {
                var match = MatchLine.Match(line);
                if (match.Success)
                {
                    effectDependency.Add(match.Groups[1].Value, new DateTime(long.Parse(match.Groups[2].Value)));
                }
            }
            return(effectDependency);
        }
Пример #4
0
        private FileDependencyList CalculateDependencies(EffectParserResult parserResult)
        {
            var keys = new List <string>(parserResult.IncludeHandler.FileResolved.Keys);

            keys.Sort(StringComparer.InvariantCultureIgnoreCase);

            var dependency = new FileDependencyList();

            dependency.AddDefaultDependencies();

            foreach (var fileKey in keys)
            {
                var fileItem = parserResult.IncludeHandler.FileResolved[fileKey];
                dependency.AddDependencyPath(fileItem.FilePath);
            }

            return(dependency);
        }
Пример #5
0
        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);
        }
Пример #6
0
 /// <summary>
 /// Checks for changes from a dependency file.
 /// </summary>
 /// <param name="dependencyFilePath">The dependency file path.</param>
 /// <returns><c>true</c> if a file has been updated, <c>false</c> otherwise</returns>
 public bool CheckForChanges(string dependencyFilePath)
 {
     return(FileDependencyList.CheckForChanges(dependencyFilePath));
 }
Пример #7
0
 public List <string> LoadDependency(string dependencyFilePath)
 {
     return(FileDependencyList.FromFileRaw(dependencyFilePath));
 }
Пример #8
0
 public string GetDependencyFileNameFromSourcePath(string pathToFxFile)
 {
     return(FileDependencyList.GetDependencyFileNameFromSourcePath(pathToFxFile));
 }