Exemple #1
0
 public override bool IsAppropriateForSolution(SolutionBuilder.SolutionBuildResult buildResult)
 {
     // Normally we'd return true so that this profile is always selected, but this is our fallback profile.
     return(false);
 }
Exemple #2
0
        public override SolutionBuilder.SolutionBuildResult ProcessBuildResult(Configuration configuration, SolutionBuilder.SolutionBuildResult buildResult)
        {
            Common.ProcessContentProjects(configuration, buildResult, ContentProjectsProcessed);

            return(base.ProcessBuildResult(configuration, buildResult));
        }
Exemple #3
0
 public override bool IsAppropriateForSolution(SolutionBuilder.SolutionBuildResult buildResult)
 {
     return(buildResult.TargetFilesUsed.Any(
                (targetFile) => targetFile.Contains(@"XNA Game Studio\v4.0")
                ));
 }
Exemple #4
0
 public abstract bool IsAppropriateForSolution(SolutionBuilder.SolutionBuildResult buildResult);
Exemple #5
0
 public virtual SolutionBuilder.SolutionBuildResult ProcessBuildResult(Configuration defaultConfiguration, SolutionBuilder.SolutionBuildResult buildResult)
 {
     return(buildResult);
 }
Exemple #6
0
    public static void ProcessContentProjects(Configuration configuration, SolutionBuilder.SolutionBuildResult buildResult, HashSet <string> contentProjectsProcessed)
    {
        var contentOutputDirectory =
            configuration.ProfileSettings.GetValueOrDefault("ContentOutputDirectory", null) as string;

        if (contentOutputDirectory == null)
        {
            return;
        }

        contentOutputDirectory = contentOutputDirectory
                                 .Replace("%configpath%", configuration.Path)
                                 .Replace("%outputpath%", configuration.OutputDirectory);

        var projectCollection = new ProjectCollection();
        var contentProjects   = buildResult.ProjectsBuilt.Where(
            (project) => project.File.EndsWith(".contentproj")
            ).ToArray();

        var builtXNBs =
            (from bi in buildResult.AllItemsBuilt
             where bi.OutputPath.EndsWith(".xnb", StringComparison.OrdinalIgnoreCase)
             select bi).Distinct().ToArray();

        var forceCopyImporters = new HashSet <string>(
            ((IEnumerable)configuration.ProfileSettings["ForceCopyXNBImporters"]).Cast <string>()
            );

        var forceCopyProcessors = new HashSet <string>(
            ((IEnumerable)configuration.ProfileSettings["ForceCopyXNBProcessors"]).Cast <string>()
            );

        Dictionary <string, Common.CompressResult> existingJournal = new Dictionary <string, CompressResult>();

        Common.CompressResult?existingJournalEntry;
        var jss = new JavaScriptSerializer();

        foreach (var builtContentProject in contentProjects)
        {
            var contentProjectPath = builtContentProject.File;

            if (contentProjectsProcessed.Contains(contentProjectPath))
            {
                continue;
            }

            var journal     = new List <Common.CompressResult>();
            var journalPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "JSIL",
                                           contentProjectPath.Replace("\\", "_").Replace(":", ""));

            Common.EnsureDirectoryExists(Path.GetDirectoryName(journalPath));
            if (File.Exists(journalPath))
            {
                var journalEntries = jss.Deserialize <Common.CompressResult[]>(File.ReadAllText(journalPath));

                if (journalEntries != null)
                {
                    existingJournal = journalEntries.ToDictionary(
                        (je) => {
                        if (je.Key != null)
                        {
                            return(je.SourceFilename + ":" + je.Key);
                        }
                        else
                        {
                            return(je.SourceFilename);
                        }
                    }
                        );
                }
            }

            contentProjectsProcessed.Add(contentProjectPath);
            Console.Error.WriteLine("// Processing content project '{0}' ...", contentProjectPath);

            var project           = projectCollection.LoadProject(contentProjectPath);
            var projectProperties = project.Properties.ToDictionary(
                (p) => p.Name
                );

            Project parentProject = null, rootProject = null;
            Dictionary <string, ProjectProperty> parentProjectProperties = null, rootProjectProperties = null;

            if (builtContentProject.Parent != null)
            {
                parentProject           = projectCollection.LoadProject(builtContentProject.Parent.File);
                parentProjectProperties = parentProject.Properties.ToDictionary(
                    (p) => p.Name
                    );
            }

            {
                var parent = builtContentProject.Parent;

                while (parent != null)
                {
                    var nextParent = parent.Parent;
                    if (nextParent != null)
                    {
                        parent = nextParent;
                        continue;
                    }

                    rootProject           = projectCollection.LoadProject(parent.File);
                    rootProjectProperties = rootProject.Properties.ToDictionary(
                        (p) => p.Name
                        );
                    break;
                }
            }

            var contentProjectDirectory = Path.GetDirectoryName(contentProjectPath);
            var localOutputDirectory    = contentOutputDirectory
                                          .Replace("%contentprojectpath%", contentProjectDirectory)
                                          .Replace("/", "\\");

            var contentManifest = new StringBuilder();
            contentManifest.AppendFormat("// {0}\r\n", JSIL.AssemblyTranslator.GetHeaderText());
            contentManifest.AppendLine();
            contentManifest.AppendLine("if (typeof (contentManifest) !== \"object\") { contentManifest = {}; };");
            contentManifest.AppendLine("contentManifest[\"" + Path.GetFileNameWithoutExtension(contentProjectPath) +
                                       "\"] = [");

            Action <string, string, Dictionary <string, object> > logOutput =
                (type, filename, properties) => {
                var fileInfo = new FileInfo(filename);

                var localPath = filename.Replace(localOutputDirectory, "");
                if (localPath.StartsWith("\\"))
                {
                    localPath = localPath.Substring(1);
                }

                Console.WriteLine(localPath);

                string propertiesObject;

                if (properties == null)
                {
                    properties = new Dictionary <string, object> {
                        { "sizeBytes", fileInfo.Length }
                    };
                }

                contentManifest.AppendFormat(
                    "  [\"{0}\", \"{1}\", {2}],{3}",
                    type, localPath.Replace("\\", "/"),
                    jss.Serialize(properties),
                    Environment.NewLine
                    );
            };

            Action <ProjectItem> copyRawFile =
                (item) => {
                var sourcePath = Path.Combine(
                    contentProjectDirectory,
                    item.EvaluatedInclude
                    );
                var outputPath = FixupOutputDirectory(
                    localOutputDirectory,
                    item.EvaluatedInclude
                    );

                Common.EnsureDirectoryExists(
                    Path.GetDirectoryName(outputPath));

                File.Copy(sourcePath, outputPath, true);
                logOutput("File", outputPath, null);
            };

            Action <ProjectItem, string, string> copyRawXnb =
                (item, xnbPath, type) => {
                if (xnbPath == null)
                {
                    throw new FileNotFoundException("Asset " + item.EvaluatedInclude + " was not built.");
                }

                var outputPath = FixupOutputDirectory(
                    localOutputDirectory,
                    item.EvaluatedInclude.Replace(
                        Path.GetExtension(item.EvaluatedInclude),
                        ".xnb")
                    );

                Common.EnsureDirectoryExists(
                    Path.GetDirectoryName(outputPath));

                File.Copy(xnbPath, outputPath, true);
                logOutput(type, outputPath, null);
            };

            foreach (var item in project.Items)
            {
                switch (item.ItemType)
                {
                case "Reference":
                case "ProjectReference":
                    continue;

                case "Compile":
                case "None":
                    break;

                default:
                    continue;
                }

                var itemOutputDirectory = FixupOutputDirectory(
                    localOutputDirectory,
                    Path.GetDirectoryName(item.EvaluatedInclude)
                    );

                var sourcePath = Path.Combine(contentProjectDirectory, item.EvaluatedInclude);
                var metadata   = item.DirectMetadata.ToDictionary((md) => md.Name);

                if (item.ItemType == "None")
                {
                    string          copyToOutputDirectory = "Always";
                    ProjectMetadata temp2;

                    if (metadata.TryGetValue("CopyToOutputDirectory", out temp2))
                    {
                        copyToOutputDirectory = temp2.EvaluatedValue;
                    }

                    switch (copyToOutputDirectory)
                    {
                    case "Always":
                    case "PreserveNewest":
                        copyRawFile(item);
                        break;

                    default:
                        break;
                    }

                    continue;
                }

                var    importerName  = metadata["Importer"].EvaluatedValue;
                var    processorName = metadata["Processor"].EvaluatedValue;
                string xnbPath       = null;

                Common.CompressResult temp;
                if (existingJournal.TryGetValue(sourcePath, out temp))
                {
                    existingJournalEntry = temp;
                }
                else
                {
                    existingJournalEntry = null;
                }

                var evaluatedXnbPath   = item.EvaluatedInclude.Replace(Path.GetExtension(item.EvaluatedInclude), ".xnb");
                var matchingBuiltPaths = (from bi in builtXNBs where
                                          bi.OutputPath.Contains(":\\") &&
                                          bi.OutputPath.EndsWith(evaluatedXnbPath)
                                          select bi.Metadata["FullPath"]).Distinct().ToArray();

                if (matchingBuiltPaths.Length == 0)
                {
                }
                else if (matchingBuiltPaths.Length > 1)
                {
                    throw new AmbiguousMatchException("Found multiple outputs for asset " + evaluatedXnbPath);
                }
                else
                {
                    xnbPath = matchingBuiltPaths[0];
                    if (!File.Exists(xnbPath))
                    {
                        throw new FileNotFoundException("Asset " + xnbPath + " not found.");
                    }
                }

                if (GetFileSettings(configuration.ProfileSettings, item.EvaluatedInclude).Contains("usexnb"))
                {
                    copyRawXnb(item, xnbPath, "XNB");
                }
                else if (
                    forceCopyProcessors.Contains(processorName) ||
                    forceCopyImporters.Contains(importerName)
                    )
                {
                    copyRawXnb(item, xnbPath, "XNB");
                }
                else
                {
                    switch (processorName)
                    {
                    case "XactProcessor":
                        Common.ConvertXactProject(
                            item.EvaluatedInclude, contentProjectDirectory, itemOutputDirectory,
                            configuration.ProfileSettings, existingJournal,
                            journal, logOutput
                            );

                        continue;

                    case "FontTextureProcessor":
                    case "FontDescriptionProcessor":
                        copyRawXnb(item, xnbPath, "SpriteFont");
                        continue;

                    case "SoundEffectProcessor":
                    case "SongProcessor":
                        journal.AddRange(CompressAudioGroup(
                                             item.EvaluatedInclude, contentProjectDirectory, itemOutputDirectory,
                                             configuration.ProfileSettings, existingJournal, logOutput
                                             ));
                        continue;

                    case "TextureProcessor":
                        if (Path.GetExtension(sourcePath).ToLower() == ".tga")
                        {
                            copyRawXnb(item, xnbPath, "Texture2D");
                            continue;
                        }

                        var result = Common.CompressImage(
                            item.EvaluatedInclude, contentProjectDirectory, itemOutputDirectory,
                            configuration.ProfileSettings, metadata, existingJournalEntry
                            );

                        if (result.HasValue)
                        {
                            journal.Add(result.Value);
                            logOutput("Image", result.Value.Filename, null);
                        }

                        continue;

                    case "EffectProcessor":
                        copyRawXnb(item, xnbPath, "XNB");
                        continue;
                    }

                    switch (importerName)
                    {
                    case "XmlImporter":
                        copyRawXnb(item, xnbPath, "XNB");
                        break;

                    default:
                        Console.Error.WriteLine(
                            "// Can't process '{0}': importer '{1}' and processor '{2}' both unsupported.",
                            item.EvaluatedInclude, importerName, processorName);
                        break;
                    }
                }
            }

            contentManifest.AppendLine("];");
            File.WriteAllText(
                Path.Combine(configuration.OutputDirectory, Path.GetFileName(contentProjectPath) + ".manifest.js"),
                contentManifest.ToString()
                );

            File.WriteAllText(
                journalPath, jss.Serialize(journal).Replace("{", "\r\n{")
                );
        }

        if (contentProjects.Length > 0)
        {
            Console.Error.WriteLine("// Done processing content.");
        }
    }