From 74a1ca741743dad9dde0fe317b21c5d1c398dcf0 Mon Sep 17 00:00:00 2001 From: "SND\\AstrorEnales_cp" Date: Thu, 10 Nov 2011 21:36:49 +0000 Subject: [PATCH] added cmd compatibility to the converter tool and now you can convert from anx to xna as well (only todo is getting the FullName of the XNA assembly references and extensive testing) --- .../ConverterForm.Designer.cs | 21 ++++++- Tools/XNAToANXConverter/ConverterForm.cs | 7 ++- Tools/XNAToANXConverter/Program.cs | 47 +++++++++++++-- Tools/XNAToANXConverter/ProjectData.cs | 59 ++++++++++++++----- 4 files changed, 112 insertions(+), 22 deletions(-) diff --git a/Tools/XNAToANXConverter/ConverterForm.Designer.cs b/Tools/XNAToANXConverter/ConverterForm.Designer.cs index 9bc2c88b..a26172f5 100644 --- a/Tools/XNAToANXConverter/ConverterForm.Designer.cs +++ b/Tools/XNAToANXConverter/ConverterForm.Designer.cs @@ -35,6 +35,7 @@ this.browsePath2 = new System.Windows.Forms.Button(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.label1 = new System.Windows.Forms.Label(); + this.listBox1 = new System.Windows.Forms.ListBox(); this.SuspendLayout(); // // convertButton @@ -43,7 +44,7 @@ this.convertButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.convertButton.Location = new System.Drawing.Point(161, 64); this.convertButton.Name = "convertButton"; - this.convertButton.Size = new System.Drawing.Size(275, 25); + this.convertButton.Size = new System.Drawing.Size(275, 40); this.convertButton.TabIndex = 0; this.convertButton.Text = "Convert"; this.convertButton.UseVisualStyleBackColor = true; @@ -110,11 +111,26 @@ this.label1.TabIndex = 6; this.label1.Text = "Source"; // + // listBox1 + // + this.listBox1.Font = new System.Drawing.Font("Consolas", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.listBox1.FormattingEnabled = true; + this.listBox1.IntegralHeight = false; + this.listBox1.ItemHeight = 18; + this.listBox1.Items.AddRange(new object[] { + "XNA -> ANX", + "ANX -> XNA"}); + this.listBox1.Location = new System.Drawing.Point(15, 64); + this.listBox1.Name = "listBox1"; + this.listBox1.Size = new System.Drawing.Size(140, 40); + this.listBox1.TabIndex = 7; + // // ConverterForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(451, 101); + this.ClientSize = new System.Drawing.Size(451, 114); + this.Controls.Add(this.listBox1); this.Controls.Add(this.label1); this.Controls.Add(this.checkBox1); this.Controls.Add(this.browsePath2); @@ -142,6 +158,7 @@ private System.Windows.Forms.Button browsePath2; private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox listBox1; } } diff --git a/Tools/XNAToANXConverter/ConverterForm.cs b/Tools/XNAToANXConverter/ConverterForm.cs index 7bfb3773..9c4d0e2a 100644 --- a/Tools/XNAToANXConverter/ConverterForm.cs +++ b/Tools/XNAToANXConverter/ConverterForm.cs @@ -15,6 +15,8 @@ namespace XNAToANXConverter destPath.Enabled = false; browsePath2.Enabled = false; + + listBox1.SelectedIndex = 0; } #endregion @@ -100,7 +102,10 @@ namespace XNAToANXConverter return; } - ProjectData.Convert(source, dest); + string target = listBox1.SelectedIndex == 0 ? + "anx" : "xna"; + + ProjectData.Convert(target, source, dest); MessageBox.Show("Finished conversion!", "Conversion"); } #endregion diff --git a/Tools/XNAToANXConverter/Program.cs b/Tools/XNAToANXConverter/Program.cs index 2513dbc6..495b5c78 100644 --- a/Tools/XNAToANXConverter/Program.cs +++ b/Tools/XNAToANXConverter/Program.cs @@ -1,19 +1,56 @@ using System; using System.Windows.Forms; +using System.IO; namespace XNAToANXConverter { static class Program { /// - /// Der Haupteinstiegspunkt für die Anwendung. + /// Starting the tool via cmd: + /// + /// Converting into the same file: + /// "XNAToANXConverter.exe anx C:\code\testproject.csproj" + /// + /// Converting into different file: + /// "XNAToANXConverter.exe anx C:\code\testproject.csproj C:\converted\test.csproj" + /// + /// Converting ANX to XNA: + /// "XNAToANXConverter.exe xna C:\code\testproject.csproj" /// [STAThread] - static void Main() + static void Main(string[] args) { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new ConverterForm()); + if (args.Length > 0) + { + #region Cmd starting + string target = args[0].ToLower(); + if (target != "anx" && + target != "xna") + { + Console.WriteLine("Unknown target '" + target + + "'. Valid targets are 'xna' or 'anx'."); + return; + } + string sourcePath = args[1]; + if (File.Exists(sourcePath) == false) + { + Console.WriteLine("Failed to convert. The sourcefile doesn't exist!"); + return; + } + string destPath = args.Length > 2 ? args[2] : sourcePath; + + Console.WriteLine("Starting conversion..."); + ProjectData.Convert(target, sourcePath, destPath); + Console.WriteLine("Conversion complete!"); + #endregion + } + else + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new ConverterForm()); + } } } } diff --git a/Tools/XNAToANXConverter/ProjectData.cs b/Tools/XNAToANXConverter/ProjectData.cs index 4c0f62a9..0cb4e16b 100644 --- a/Tools/XNAToANXConverter/ProjectData.cs +++ b/Tools/XNAToANXConverter/ProjectData.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Xml; -using System.Xml.Linq; +using System.Collections.Generic; using System.IO; +using System.Xml.Linq; namespace XNAToANXConverter { @@ -12,7 +10,8 @@ namespace XNAToANXConverter private const string AnxBaseName = "ANX.Framework"; #region Convert - public static void Convert(string sourceFilepath, string destinationFilepath) + public static void Convert(string target, string sourceFilepath, + string destinationFilepath) { string sourceFolderPath = sourceFilepath.Replace(Path.GetFileName(sourceFilepath), ""); @@ -40,17 +39,37 @@ namespace XNAToANXConverter { #region Process Reference string assemblyPath = item.Attribute("Include").Value; - if (assemblyPath.Contains(XnaBaseName)) + if (target == "anx") { - item.Remove(); - - string anxPath = assemblyPath.Replace(XnaBaseName, AnxBaseName); - if (anxPath.Contains(", Version")) + #region ANX + if (assemblyPath.Contains(XnaBaseName)) { - anxPath = anxPath.Substring(0, anxPath.IndexOf(',')) + ".dll"; + item.Remove(); + + string anxPath = assemblyPath.Replace(XnaBaseName, AnxBaseName); + if (anxPath.Contains(", Version")) + { + anxPath = anxPath.Substring(0, anxPath.IndexOf(',')) + ".dll"; + } + propertyGroup.Add(new XElement("Reference", + new XAttribute("Include", anxPath))); } - propertyGroup.Add(new XElement("Reference", - new XAttribute("Include", anxPath))); + #endregion + } + else + { + #region XNA + if (assemblyPath.Contains(AnxBaseName)) + { + item.Remove(); + + // TODO: FQN of the xna assemby + + string xnaPath = assemblyPath.Replace(AnxBaseName, XnaBaseName); + propertyGroup.Add(new XElement("Reference", + new XAttribute("Include", xnaPath))); + } + #endregion } #endregion } @@ -61,7 +80,14 @@ namespace XNAToANXConverter string absolutePath = Path.Combine(sourceFolderPath, codeFilepath); string text = File.ReadAllText(absolutePath); - text = text.Replace(XnaBaseName, AnxBaseName); + if (target == "anx") + { + text = text.Replace(XnaBaseName, AnxBaseName); + } + else + { + text = text.Replace(AnxBaseName, XnaBaseName); + } string destCodeFolderPath = codeFilepath.Replace( Path.GetFileName(codeFilepath), ""); @@ -79,6 +105,11 @@ namespace XNAToANXConverter } else if (item.Name.LocalName == "BootstrapperPackage") { + if (target == "xna") + { + continue; + } + #region Process BootstrapperPackage // Remove all bootstrapper tasks for XNA. string includeName = item.Attribute("Include").Value;