slightly changed the way ProjectConverter works and added two new converters:
- AnxConverter (which converts a ANX project to a XNA project) - XnaConverter (which converts a XNA project to a ANX project) The projects file content is changed in memory, but will not be written to disc currently. Next to come: Finished project converter and converting content projects.
This commit is contained in:
parent
d7bd5b7018
commit
d0f477790b
@ -19,8 +19,17 @@ namespace ProjectConverter
|
||||
"Microsoft.Xna.GameStudio.ContentPipelineExtensions.targets";
|
||||
|
||||
protected ProjectPath CurrentProject { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Postfix is used as a extension for a project file name
|
||||
/// </summary>
|
||||
public abstract string Postfix { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The Name is used to identify the converter
|
||||
/// </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
#region ConvertAllProjects
|
||||
public void ConvertAllProjects(string solutionFilepath)
|
||||
{
|
||||
|
114
Tools/ProjectConverter/Platforms/AbstractXna2AnxConverter.cs
Normal file
114
Tools/ProjectConverter/Platforms/AbstractXna2AnxConverter.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectConverter.Platforms
|
||||
{
|
||||
public abstract class AbstractXna2AnxConverter : Converter
|
||||
{
|
||||
protected internal List<string> csharpFiles = new List<string>();
|
||||
|
||||
public override string Postfix
|
||||
{
|
||||
get { return string.Empty; }
|
||||
}
|
||||
|
||||
protected override void ConvertItemGroup(System.Xml.Linq.XElement element)
|
||||
{
|
||||
var groups = element.Elements().ToList();
|
||||
foreach (var group in groups)
|
||||
{
|
||||
if (group.Name.LocalName.Equals("compile", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var attributes = group.Attributes().ToList();
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
if (attribute.Name.LocalName.Equals("include", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
if (attribute.Value.EndsWith(".cs", true, System.Globalization.CultureInfo.InvariantCulture))
|
||||
{
|
||||
csharpFiles.Add(attribute.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
base.ConvertItemGroup(element);
|
||||
}
|
||||
|
||||
protected override void PostConvert()
|
||||
{
|
||||
foreach (var file in csharpFiles)
|
||||
{
|
||||
string target = string.Empty;
|
||||
ConvertUsingDirectives(file, ref target);
|
||||
}
|
||||
|
||||
base.PostConvert();
|
||||
}
|
||||
|
||||
protected abstract void ConvertUsingDirectives(string file, ref string target);
|
||||
|
||||
protected void ConvertUsingDirectivesImpl(ref string content, ref string target, string sourceNamespace, string targetNamespace, string[] namespaces)
|
||||
{
|
||||
int lastPos = 0;
|
||||
int currentPos = -1;
|
||||
int endPos = 0;
|
||||
int tokenLength = 5;
|
||||
|
||||
do
|
||||
{
|
||||
currentPos = content.IndexOf("using", currentPos + 1, StringComparison.InvariantCultureIgnoreCase);
|
||||
if (currentPos >= 0)
|
||||
{
|
||||
endPos = NextTokenPos(ref content, currentPos + tokenLength, ref tokenLength);
|
||||
string directive = content.Substring(currentPos + 5, endPos - currentPos - 5);
|
||||
|
||||
target += content.Substring(lastPos, (currentPos + 6) - lastPos);
|
||||
|
||||
if (namespaces.Contains<string>(directive.Trim()))
|
||||
{
|
||||
directive = directive.Replace(sourceNamespace, targetNamespace);
|
||||
}
|
||||
|
||||
target += directive;
|
||||
lastPos = endPos;
|
||||
}
|
||||
} while (currentPos >= 0);
|
||||
|
||||
target += content.Substring(lastPos);
|
||||
}
|
||||
|
||||
private int NextTokenPos(ref string content, int startPos, ref int tokenLength)
|
||||
{
|
||||
int semicolonPos = content.IndexOf(";", startPos, StringComparison.InvariantCultureIgnoreCase);
|
||||
int usingPos = content.IndexOf("using", startPos, StringComparison.InvariantCultureIgnoreCase);
|
||||
int endPos = content.Length;
|
||||
int ret = 0;
|
||||
|
||||
if (semicolonPos < 0) semicolonPos = int.MaxValue;
|
||||
if (usingPos < 0) usingPos = int.MaxValue;
|
||||
|
||||
if (semicolonPos < usingPos)
|
||||
{
|
||||
ret = semicolonPos;
|
||||
tokenLength = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = usingPos;
|
||||
tokenLength = 5;
|
||||
}
|
||||
|
||||
if (ret < endPos)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
tokenLength = endPos - startPos;
|
||||
return endPos;
|
||||
}
|
||||
}
|
||||
}
|
41
Tools/ProjectConverter/Platforms/AnxConverter.cs
Normal file
41
Tools/ProjectConverter/Platforms/AnxConverter.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectConverter.Platforms
|
||||
{
|
||||
public class AnxConverter : AbstractXna2AnxConverter
|
||||
{
|
||||
private readonly string[] xnaNamespaces = new string[] { "Microsoft.XNA.Framework",
|
||||
"Microsoft.XNA.Framework.Avatar",
|
||||
"Microsoft.XNA.Framework.Content.Pipeline.AudioImporters",
|
||||
"Microsoft.XNA.Framework.Content.Pipeline",
|
||||
"Microsoft.XNA.Framework.Content.Pipeline.EffectImporter",
|
||||
"Microsoft.XNA.Framework.Content.Pipeline.FBXImporter",
|
||||
"Microsoft.XNA.Framework.Content.Pipeline.TextureImporter",
|
||||
"Microsoft.XNA.Framework.Content.Pipeline.VideoImporters",
|
||||
"Microsoft.XNA.Framework.Content.Pipeline.XImporter",
|
||||
"Microsoft.XNA.Framework.Game",
|
||||
"Microsoft.XNA.Framework.GamerServices",
|
||||
"Microsoft.XNA.Framework.Graphics",
|
||||
"Microsoft.XNA.Framework.Input",
|
||||
"Microsoft.XNA.Framework.Input.Touch",
|
||||
"Microsoft.XNA.Framework.Net",
|
||||
"Microsoft.XNA.Framework.Storage",
|
||||
"Microsoft.XNA.Framework.Video",
|
||||
"Microsoft.XNA.Framework.Xact",
|
||||
};
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "anx2xna"; }
|
||||
}
|
||||
|
||||
protected override void ConvertUsingDirectives(string file, ref string target)
|
||||
{
|
||||
string content = System.IO.File.ReadAllText(System.IO.Path.Combine(CurrentProject.FullSourceDirectoryPath, file));
|
||||
ConvertUsingDirectivesImpl(ref content, ref target, "Microsoft.XNA.Framework", "ANX.Framework", xnaNamespaces);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,12 +12,14 @@ namespace ProjectConverter.Platforms
|
||||
{
|
||||
public override string Postfix
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Linux";
|
||||
}
|
||||
get { return "Linux"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "linux"; }
|
||||
}
|
||||
|
||||
#region ConvertImport
|
||||
protected override void ConvertImport(XElement element, XAttribute projectAttribute)
|
||||
{
|
||||
|
@ -22,6 +22,11 @@ namespace ProjectConverter.Platforms
|
||||
get { return "WindowsMetro"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "windowsmetro"; }
|
||||
}
|
||||
|
||||
#region ConvertImport
|
||||
protected override void ConvertImport(XElement element, XAttribute projectAttribute)
|
||||
{
|
||||
|
@ -11,12 +11,15 @@ namespace ProjectConverter.Platforms
|
||||
{
|
||||
public override string Postfix
|
||||
{
|
||||
get
|
||||
{
|
||||
return "PSVita";
|
||||
}
|
||||
get { return "PSVita"; }
|
||||
}
|
||||
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "PSVita"; }
|
||||
}
|
||||
|
||||
#region ConvertImport
|
||||
protected override void ConvertImport(XElement element, XAttribute projectAttribute)
|
||||
{
|
||||
|
41
Tools/ProjectConverter/Platforms/XnaConverter.cs
Normal file
41
Tools/ProjectConverter/Platforms/XnaConverter.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectConverter.Platforms
|
||||
{
|
||||
public class XnaConverter : AbstractXna2AnxConverter
|
||||
{
|
||||
private readonly string[] anxNamespaces = new string[] { "ANX.Framework",
|
||||
"ANX.Framework.Avatar",
|
||||
"ANX.Framework.Content.Pipeline.AudioImporters",
|
||||
"ANX.Framework.Content.Pipeline",
|
||||
"ANX.Framework.Content.Pipeline.EffectImporter",
|
||||
"ANX.Framework.Content.Pipeline.FBXImporter",
|
||||
"ANX.Framework.Content.Pipeline.TextureImporter",
|
||||
"ANX.Framework.Content.Pipeline.VideoImporters",
|
||||
"ANX.Framework.Content.Pipeline.XImporter",
|
||||
"ANX.Framework.Game",
|
||||
"ANX.Framework.GamerServices",
|
||||
"ANX.Framework.Graphics",
|
||||
"ANX.Framework.Input",
|
||||
"ANX.Framework.Input.Touch",
|
||||
"ANX.Framework.Net",
|
||||
"ANX.Framework.Storage",
|
||||
"ANX.Framework.Video",
|
||||
"ANX.Framework.Xact",
|
||||
};
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "xna2anx"; }
|
||||
}
|
||||
|
||||
protected override void ConvertUsingDirectives(string file, ref string target)
|
||||
{
|
||||
string content = System.IO.File.ReadAllText(System.IO.Path.Combine(CurrentProject.FullSourceDirectoryPath, file));
|
||||
ConvertUsingDirectivesImpl(ref content, ref target, "ANX.Framework", "Microsoft.XNA.Framework", anxNamespaces);
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,9 @@ namespace ProjectConverter
|
||||
{
|
||||
new LinuxConverter(),
|
||||
new MetroConverter(),
|
||||
new PsVitaConverter()
|
||||
new PsVitaConverter(),
|
||||
new AnxConverter(),
|
||||
new XnaConverter(),
|
||||
};
|
||||
|
||||
[STAThread]
|
||||
@ -58,7 +60,7 @@ namespace ProjectConverter
|
||||
string fileExt = Path.GetExtension(file).ToLowerInvariant();
|
||||
foreach (Converter converter in Converters)
|
||||
{
|
||||
if (switches.Contains(converter.Postfix.ToLowerInvariant()))
|
||||
if (switches.Contains(converter.Name.ToLowerInvariant()))
|
||||
{
|
||||
switch (fileExt)
|
||||
{
|
||||
|
@ -48,6 +48,9 @@
|
||||
<Compile Include="AssemblyInfoFixer.cs" />
|
||||
<Compile Include="Converter.cs" />
|
||||
<Compile Include="DefinesConverter.cs" />
|
||||
<Compile Include="Platforms\AbstractXna2AnxConverter.cs" />
|
||||
<Compile Include="Platforms\AnxConverter.cs" />
|
||||
<Compile Include="Platforms\XnaConverter.cs" />
|
||||
<Compile Include="Platforms\LinuxConverter.cs" />
|
||||
<Compile Include="Platforms\MetroConverter.cs" />
|
||||
<Compile Include="Platforms\Metro\AppxManifest.cs" />
|
||||
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.2.1.*")]
|
||||
[assembly: AssemblyFileVersion("1.2.1.0")]
|
||||
[assembly: AssemblyVersion("1.2.2.*")]
|
||||
[assembly: AssemblyFileVersion("1.2.2.0")]
|
||||
|
@ -3,8 +3,8 @@ setlocal
|
||||
set ProgRoot=%ProgramFiles%
|
||||
if not "%ProgramFiles(x86)%" == "" set ProgRoot=%ProgramFiles(x86)%
|
||||
|
||||
if EXIST "%ProgRoot%\Microsoft Visual Studio 11.0" goto vs2011
|
||||
if EXIST "%ProgRoot%\Microsoft Visual Studio 10.0" goto vs2010
|
||||
if EXIST "%ProgRoot%\Microsoft Visual Studio 11.0\vc\vcvarsall.bat" goto vs2011
|
||||
if EXIST "%ProgRoot%\Microsoft Visual Studio 10.0\vc\vcvarsall.bat" goto vs2010
|
||||
goto error_msg
|
||||
|
||||
:vs2011
|
||||
|
Loading…
x
Reference in New Issue
Block a user