2012-08-11 13:06:29 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
using ProjectConverter.Platforms;
|
|
|
|
|
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
|
|
|
|
|
|
|
namespace ProjectConverter
|
|
|
|
{
|
|
|
|
public class ProjectPath
|
|
|
|
{
|
|
|
|
public string RelativeSourcePath
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
private set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string FullSourcePath
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
private set;
|
|
|
|
}
|
|
|
|
|
2012-08-13 11:23:26 +00:00
|
|
|
public string FullSourceDirectoryPath
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return Path.GetDirectoryName(FullSourcePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 13:06:29 +00:00
|
|
|
public string RelativeDestinationPath
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
private set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string FullDestinationPath
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
private set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public XDocument Document
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
private set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public XElement Root
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return Document.Root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 09:23:41 +00:00
|
|
|
public ProjectPath(Converter converter, string relativeSourcePath, string basePath, string destinationPath)
|
2012-08-11 13:06:29 +00:00
|
|
|
{
|
|
|
|
RelativeSourcePath = relativeSourcePath;
|
|
|
|
FullSourcePath = Path.Combine(basePath, relativeSourcePath);
|
|
|
|
|
2012-10-23 09:23:41 +00:00
|
|
|
if (string.IsNullOrEmpty(destinationPath))
|
|
|
|
{
|
|
|
|
RelativeDestinationPath = BuildTargetFilepath(converter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!Directory.Exists(destinationPath))
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(destinationPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
RelativeDestinationPath = Path.Combine(destinationPath, Path.GetFileName(relativeSourcePath));
|
|
|
|
}
|
|
|
|
|
2012-08-11 13:06:29 +00:00
|
|
|
FullDestinationPath = Path.Combine(basePath, RelativeDestinationPath);
|
|
|
|
|
2012-10-23 09:23:41 +00:00
|
|
|
//TODO: never ever ignore all exceptions without proper handling
|
|
|
|
|
|
|
|
//try
|
|
|
|
//{
|
2012-08-11 13:06:29 +00:00
|
|
|
LoadProjectFile();
|
2012-10-23 09:23:41 +00:00
|
|
|
//}
|
|
|
|
//catch
|
|
|
|
//{
|
|
|
|
//}
|
2012-08-11 13:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#region Save
|
|
|
|
public void Save()
|
|
|
|
{
|
|
|
|
Document.Save(FullDestinationPath, SaveOptions.None);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region BuildTargetFilepath
|
|
|
|
private string BuildTargetFilepath(Converter converter)
|
|
|
|
{
|
|
|
|
string basePath = Path.GetDirectoryName(RelativeSourcePath);
|
|
|
|
string filename = Path.GetFileNameWithoutExtension(RelativeSourcePath);
|
|
|
|
if (filename.Contains("_"))
|
|
|
|
{
|
|
|
|
filename = filename.Substring(0, filename.IndexOf('_'));
|
|
|
|
}
|
|
|
|
|
2012-10-23 09:23:41 +00:00
|
|
|
if (!string.IsNullOrEmpty(converter.Postfix))
|
|
|
|
{
|
|
|
|
filename += "_" + converter.Postfix;
|
|
|
|
}
|
2012-08-11 13:06:29 +00:00
|
|
|
|
|
|
|
return Path.Combine(basePath, filename + ".csproj");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region LoadProjectFile
|
|
|
|
private void LoadProjectFile()
|
|
|
|
{
|
|
|
|
string documentText = File.ReadAllText(FullSourcePath);
|
|
|
|
Document = XDocument.Parse(documentText);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2012-08-12 20:00:19 +00:00
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return "ProjectPath{" + RelativeSourcePath + "}";
|
|
|
|
}
|
|
|
|
|
2012-08-11 13:06:29 +00:00
|
|
|
private class ProjectPathTests
|
|
|
|
{
|
|
|
|
#region TestBuildTargetFilepath
|
|
|
|
[Test]
|
|
|
|
public static void TestBuildTargetFilepath()
|
|
|
|
{
|
|
|
|
string testBasePath = "C:\\code\\";
|
|
|
|
string testRelativeSourcePath = "ANX.Framework.csproj";
|
|
|
|
|
|
|
|
var projPath = new ProjectPath(new PsVitaConverter(),
|
2012-10-23 09:23:41 +00:00
|
|
|
testRelativeSourcePath, testBasePath, string.Empty);
|
2012-08-11 13:06:29 +00:00
|
|
|
Assert.AreEqual(projPath.RelativeDestinationPath,
|
|
|
|
"ANX.Framework_PSVita.csproj");
|
|
|
|
|
|
|
|
projPath = new ProjectPath(new LinuxConverter(),
|
2012-10-23 09:23:41 +00:00
|
|
|
"ANX.Framework_IOS.csproj", testBasePath, string.Empty);
|
2012-08-11 13:06:29 +00:00
|
|
|
|
|
|
|
Assert.AreEqual(projPath.RelativeDestinationPath,
|
|
|
|
"ANX.Framework_Linux.csproj");
|
|
|
|
|
|
|
|
projPath = new ProjectPath(new MetroConverter(),
|
2012-10-23 09:23:41 +00:00
|
|
|
"ANX.Framework_IOS_Android_WindowsXNA.csproj", testBasePath, string.Empty);
|
2012-08-11 13:06:29 +00:00
|
|
|
Assert.AreEqual(projPath.RelativeDestinationPath,
|
|
|
|
"ANX.Framework_WindowsMetro.csproj");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|