Exemple #1
0
        protected override Logger ProcessFileAndGetLogResults(string inputFilePath, string outputFilePath, string dependencyFilePath, TkItem item)
        {
            // the audio files can be in a subdirectory - make sure it exists before copying there:
            CreateDirectoryIfNotExists(outputFilePath);

            // For the AudioCompilerTask, simply copy input to output without performing any transformations
            // but a future version will introduce this
            File.Copy(inputFilePath, outputFilePath, true);

            // Save the dependency file
            var dependencies = new FileDependencyList();
            dependencies.AddDefaultDependencies();
            dependencies.AddDependencyPath(inputFilePath);
            dependencies.Save(dependencyFilePath);

            return new Logger();
        }
        protected sealed override bool ProcessItem(TkItem item)
        {
            var hasErrors = false;

            var inputFilePath  = item.InputFilePath;
            var outputFilePath = item.OutputFilePath;

            try
            {
                var dependencyFilePath = Path.Combine(Path.Combine(ProjectDirectory.ItemSpec, IntermediateDirectory.ItemSpec),
                                                      FileDependencyList.GetDependencyFileNameFromSourcePath(item.LinkName));

                CreateDirectoryIfNotExists(dependencyFilePath);

                Log.LogMessage(MessageImportance.Low, "Check Toolkit file to compile {0} with dependency file {1}", inputFilePath, dependencyFilePath);
                if (FileDependencyList.CheckForChanges(dependencyFilePath) || !File.Exists(outputFilePath))
                {
                    Log.LogMessage(MessageImportance.Low, "Starting compilation of {0}", inputFilePath);

                    var logger = ProcessFileAndGetLogResults(inputFilePath, outputFilePath, dependencyFilePath, item);

                    LogLogger(logger);

                    if (logger.HasErrors)
                    {
                        hasErrors = true;
                    }
                    else
                    {
                        Log.LogMessage(MessageImportance.High, "Compilation successful of {0} to {1}", inputFilePath, outputFilePath);
                        if (item.OutputCs)
                        {
                            Log.LogWarning("Compilation to CS not yet supported");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.LogError("Cannot process file '{0}' : {1}", inputFilePath, ex.Message);
                hasErrors = true;
            }

            return(!hasErrors);
        }
Exemple #3
0
        protected override Diagnostics.Logger ProcessFileAndGetLogResults(string inputFilePath, string outputFilePath, string dependencyFilePath, TkItem item)
        {
            // the textures can be in a subdirectory - make sure it exists before copying there:
            CreateDirectoryIfNotExists(outputFilePath);

            // For the TextureCompilerTask, simply copy input to output without performing any resize/compression
            // but a future version will introduce this
            File.Copy(inputFilePath, outputFilePath, true);

            // Save the dependency file
            var dependencies = new FileDependencyList();

            dependencies.AddDefaultDependencies();
            dependencies.AddDependencyPath(inputFilePath);
            dependencies.Save(dependencyFilePath);

            return(new Logger());
        }
        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;
        }
Exemple #5
0
        void Run(string[] args)
        {
            // Print the exe header
            PrintHeader();

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

            var options = this;


            bool hasErrors = false;

            // ----------------------------------------------------------------
            // Process model file
            // ----------------------------------------------------------------
            var filePath = Path.Combine(Environment.CurrentDirectory, ModelFile);

            if (!File.Exists(filePath))
            {
                ErrorColor();
                Console.Error.WriteLine("File [{0}] does not exist", filePath);
                ResetColor();
                Environment.Exit(-1);
            }

            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)));
            }

            Console.WriteLine("Compile Model from File [{0}] => {1}", filePath, OutputFile);

            var compilerOptions = new ModelCompilerOptions()
            {
                DependencyFile = dependencyFile,
                Quality        = FastQuality ? ModelRealTimeQuality.Low : ModelRealTimeQuality.Maximum
            };

            var result = ModelCompiler.CompileAndSave(filePath, OutputFile, compilerOptions);

            if (result.HasErrors)
            {
                ErrorColor();
                Console.Error.WriteLine("Compilation has errors. Process aborted.");
                ResetColor();
                Environment.Exit(-1);
            }


            if (result.IsContentGenerated)
            {
                Console.WriteLine("Successfull");
            }
            else
            {
                Console.WriteLine("Nothing to generate. Model and Compiled Model are in sync");
            }
        }
        /// <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;
        }
Exemple #7
0
        /// <summary>Compiles the and save.</summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="outputFile">The output file.</param>
        /// <param name="compilerOptions">The compiler options.</param>
        /// <returns>ContentCompilerResult.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// fileName
        /// or
        /// outputFile
        /// or
        /// compilerOptions
        /// </exception>
        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;
        }
Exemple #8
0
        public static ContentCompilerResult CompileAndSave(string fileName, string outputFile, ModelCompilerOptions compilerOptions)
        {
            Contract.Requires <ArgumentNullException>(fileName != null, "fileName");
            Contract.Requires <ArgumentNullException>(outputFile != null, "outputFile");
            Contract.Requires <ArgumentNullException>(compilerOptions != null, "compilerOptions");

            bool contentToUpdate = true;

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

            var result = new ContentCompilerResult();

            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.HasErrors = true;
                    LogEvent.Tool.Error("Unexpected exception while converting {0} : {1}", fileName, ex.ToString());
                }
            }


            return(result);
        }