Permalink
Browse files

Added content building classes.

Added solution for windows content pipeline.
  • Loading branch information...
1 parent 345cddf commit 75106f88346b8326c810fda7dbe756a84df39676 @tomspilman tomspilman committed Dec 26, 2012
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.Content.Pipeline.Windows", "MonoGame.Framework.Content.Pipeline\MonoGame.Framework.Content.Pipeline.Windows.csproj", "{B950DE10-AC5D-4BD9-B817-51247C4A732D}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|x86.ActiveCfg = Debug|x86
+ {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|x86.Build.0 = Debug|x86
+ {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|x86.ActiveCfg = Release|x86
+ {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,60 @@
+// MonoGame - Copyright (C) The MonoGame Team
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE.txt', which is part of this source code package.
+
+using System;
+using System.IO;
+
+namespace MonoGame.Framework.Content.Pipeline.Builder
+{
+ public static class PathHelper
+ {
+ /// <summary>
+ /// Returns a path string normalized to the/universal/standard.
+ /// </summary>
+ public static string Normalize(string path)
+ {
+ return path.Replace('\\', '/');
+ }
+
+ /// <summary>
+ /// Returns a path string normalized to the\Windows\standard.
+ /// </summary>
+ public static string NormalizeWindows(string path)
+ {
+ return path.Replace('/', '\\');
+ }
+
+ /// <summary>
+ /// Returns a path string normalized to the current platform standard.
+ /// </summary>
+ public static string NormalizeOS(string path)
+ {
+#if WINRT
+ return NormalizeWindows(path);
+#else
+ path = path.Replace('\\', Path.DirectorySeparatorChar);
+ path = path.Replace('/', Path.DirectorySeparatorChar);
+ return path;
+#endif
+ }
+
+ /// <summary>
+ /// Returns a path relative to the base path.
+ /// </summary>
+ /// <param name="basePath">The path to make relative to. Must end with directory seperator.</param>
+ /// <param name="path">The path to be made relative to the basePath.</param>
+ /// <returns>The relative path or the original string if it is not absolute or cannot be made relative.</returns>
+ public static string GetRelativePath(string basePath, string path)
+ {
+ Uri uri;
+ if (!Uri.TryCreate(path, UriKind.Absolute, out uri))
+ return path;
+
+ uri = new Uri(basePath).MakeRelativeUri(uri);
+ var str = Uri.UnescapeDataString(uri.ToString());
+
+ return NormalizeOS(str);
+ }
+ }
+}
@@ -0,0 +1,163 @@
+// MonoGame - Copyright (C) The MonoGame Team
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE.txt', which is part of this source code package.
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.IO;
+using System.Text;
+using System.Xml.Serialization;
+using Microsoft.Xna.Framework.Content.Pipeline;
+
+namespace MonoGame.Framework.Content.Pipeline.Builder
+{
+ public class PipelineBuildEvent
+ {
+ public PipelineBuildEvent()
+ {
+ SourceFile = string.Empty;
+ DestFile = string.Empty;
+ Importer = string.Empty;
+ Processor = string.Empty;
+ Parameters = new OpaqueDataDictionary();
+ ParametersXML = new List<Pair>();
+ Dependancies = new List<string>();
+ BuildAsset = new List<string>();
+ }
+
+ public string SourceFile { get; set; }
+
+ public string DestFile { get; set; }
+
+ public DateTime DestTime { get; set; }
+
+ public string Importer { get; set; }
+
+ public string Processor { get; set; }
+
+ [XmlIgnore]
+ public OpaqueDataDictionary Parameters { get; set; }
+
+ public class Pair
+ {
+ public string Key { get; set; }
+ public string Value { get; set; }
+ }
+
+ [XmlElement("Parameters")]
+ public List<Pair> ParametersXML { get; set; }
+
+ public List<string> Dependancies { get; set; }
+
+ public List<string> BuildAsset { get; set; }
+
+ public static PipelineBuildEvent Load(string filePath)
+ {
+ var deserializer = new XmlSerializer(typeof (PipelineBuildEvent));
+ PipelineBuildEvent pipelineEvent;
+ try
+ {
+ using (var textReader = new StreamReader(filePath))
+ pipelineEvent = (PipelineBuildEvent) deserializer.Deserialize(textReader);
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+
+ // Repopulate the parameters from the serialized state.
+ foreach (var pair in pipelineEvent.ParametersXML)
+ pipelineEvent.Parameters.Add(pair.Key, pair.Value);
+ pipelineEvent.ParametersXML.Clear();
+
+ return pipelineEvent;
+ }
+
+ public void Save(string filePath)
+ {
+ // Make sure the directory exists.
+ Directory.CreateDirectory(Path.GetDirectoryName(filePath) + @"\");
+
+ // Convert the parameters into something we can serialize.
+ ParametersXML.Clear();
+ foreach (var pair in Parameters)
+ {
+ var converter = TypeDescriptor.GetConverter(pair.Value.GetType());
+ ParametersXML.Add(new Pair { Key = pair.Key, Value = converter.ConvertToString(pair.Value) });
+ }
+
+ // Serialize our state.
+ var serializer = new XmlSerializer(typeof (PipelineBuildEvent));
+ using (var textWriter = new StreamWriter(filePath, false, new UTF8Encoding(false)))
+ serializer.Serialize(textWriter, this);
+ }
+
+ public bool NeedsRebuild(PipelineBuildEvent cachedEvent)
+ {
+ // If we have no previously cached build event then we cannot
+ // be sure that the state hasn't changed... force a rebuild.
+ if (cachedEvent == null)
+ return true;
+
+ // Verify that the last write time of the dest file matches
+ // what we recorded when it was built. If it is different
+ // that means someone modified it and we need to rebuild.
+ var destWriteTime = File.GetLastWriteTime(DestFile);
+ if (cachedEvent.DestTime != destWriteTime)
+ return true;
+
+ // If the source and dest files changed... this is always a rebuild.
+ if (File.GetLastWriteTime(SourceFile) >= destWriteTime)
+ return true;
+
+ // Are any of the dependancy files newer than the dest file?
+ foreach (var depFile in cachedEvent.Dependancies)
+ {
+ if (File.GetLastWriteTime(depFile) >= destWriteTime)
+ return true;
+ }
+
+ // This shouldn't happen... but if the source or dest files changed
+ // then force a rebuild.
+ if (cachedEvent.SourceFile != SourceFile ||
+ cachedEvent.DestFile != DestFile)
+ return true;
+
+ // Did the importer change?
+ // TODO: I need to test the assembly versions here!
+ if (cachedEvent.Importer != Importer)
+ return true;
+
+ // Did the processor change?
+ // TODO: I need to test the assembly versions here!
+ if (cachedEvent.Processor != Processor)
+ return true;
+
+ // Finally did any of the processor parameters change?
+ foreach (var pair in cachedEvent.Parameters)
+ {
+ // If the key value doesn't exist... then rebuild.
+ object value;
+ if (!Parameters.TryGetValue(pair.Key, out value))
+ return true;
+
+ // If the values are the same type and do not match... rebuild.
+ if (value.GetType().IsInstanceOfType(pair.Value))
+ {
+ if (!value.Equals(pair.Value))
+ return true;
+ }
+ else
+ {
+ var typeConverter = TypeDescriptor.GetConverter(value.GetType());
+ var converted = typeConverter.ConvertTo(value, pair.Value.GetType());
+ if (!converted.Equals(pair.Value))
+ return true;
+ }
+ }
+
+ return false;
+ }
+ };
+}
@@ -0,0 +1,23 @@
+// MonoGame - Copyright (C) The MonoGame Team
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE.txt', which is part of this source code package.
+
+using Microsoft.Xna.Framework.Content.Pipeline;
+
+namespace MonoGame.Framework.Content.Pipeline.Builder
+{
+ public class PipelineBuildLogger : ContentBuildLogger
+ {
+ public override void LogMessage(string message, params object[] messageArgs)
+ {
+ }
+
+ public override void LogImportantMessage(string message, params object[] messageArgs)
+ {
+ }
+
+ public override void LogWarning(string helpLink, ContentIdentity contentIdentity, string message, params object[] messageArgs)
+ {
+ }
+ }
+}
@@ -0,0 +1,26 @@
+// MonoGame - Copyright (C) The MonoGame Team
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE.txt', which is part of this source code package.
+
+using Microsoft.Xna.Framework.Content.Pipeline;
+
+namespace MonoGame.Framework.Content.Pipeline.Builder
+{
+ public class PipelineImporterContext : ContentImporterContext
+ {
+ private readonly PipelineManager _manager;
+
+ public PipelineImporterContext(PipelineManager manager)
+ {
+ _manager = manager;
+ }
+
+ public override string IntermediateDirectory { get { return _manager.IntermediateDirectory; } }
+ public override string OutputDirectory { get { return _manager.OutputDirectory; } }
+ public override ContentBuildLogger Logger { get { return _manager.Logger; } }
+
+ public override void AddDependency(string filename)
+ {
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 75106f8

Please sign in to comment.