2015-04-08 14:50:03 +02:00
|
|
|
|
using ANX.Framework.Content.Pipeline;
|
|
|
|
|
using ANX.Framework.VisualStudio.Nodes;
|
|
|
|
|
using Microsoft.VisualStudio.Project.Automation;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Microsoft.VisualStudio.Shell;
|
|
|
|
|
using Microsoft.VisualStudio.Shell.Interop;
|
|
|
|
|
using Microsoft.VisualStudio;
|
|
|
|
|
|
|
|
|
|
namespace ANX.Framework.VisualStudio
|
|
|
|
|
{
|
|
|
|
|
class Utilities
|
|
|
|
|
{
|
|
|
|
|
private static EnvDTE.DTE _dte;
|
|
|
|
|
|
2015-04-26 19:47:26 +02:00
|
|
|
|
private static Dictionary<string, TargetPlatform> _displayNames;
|
|
|
|
|
|
2015-04-08 14:50:03 +02:00
|
|
|
|
public static void Initialize(EnvDTE.DTE dte)
|
|
|
|
|
{
|
|
|
|
|
if (dte == null)
|
|
|
|
|
throw new ArgumentNullException("dte");
|
|
|
|
|
|
|
|
|
|
_dte = dte;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ContentProjectNode GetCurrentProject()
|
|
|
|
|
{
|
|
|
|
|
if (AppDomain.CurrentDomain.IsBuildAppDomain())
|
|
|
|
|
throw new InvalidOperationException("GetCurrentProject called from the wrong appDomain.");
|
|
|
|
|
|
|
|
|
|
if (_dte == null)
|
|
|
|
|
throw new InvalidOperationException("The converters have not been initialized.");
|
|
|
|
|
|
|
|
|
|
Array projects = (Array)_dte.ActiveSolutionProjects;
|
|
|
|
|
if (projects.Length == 0)
|
|
|
|
|
throw new InvalidOperationException("There's currently no ContentProject selected.");
|
|
|
|
|
|
|
|
|
|
if (projects.Length > 1)
|
|
|
|
|
throw new Exception("Test, too many Projects.");
|
|
|
|
|
|
|
|
|
|
EnvDTE.Project project = (EnvDTE.Project)projects.GetValue(0);
|
|
|
|
|
if (project is OAProject)
|
|
|
|
|
{
|
|
|
|
|
var oaProject = (OAProject)project;
|
|
|
|
|
|
|
|
|
|
if (oaProject.ProjectNode is ContentProjectNode)
|
|
|
|
|
{
|
|
|
|
|
return (ContentProjectNode)oaProject.ProjectNode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-26 19:47:26 +02:00
|
|
|
|
private static void InitializeTargetPlatforms()
|
2015-04-08 14:50:03 +02:00
|
|
|
|
{
|
2015-04-26 19:47:26 +02:00
|
|
|
|
if (_displayNames == null)
|
2015-04-08 14:50:03 +02:00
|
|
|
|
{
|
2015-04-26 19:47:26 +02:00
|
|
|
|
_displayNames = new Dictionary<string, TargetPlatform>();
|
|
|
|
|
foreach (var enumValue in typeof(TargetPlatform).GetEnumValues())
|
|
|
|
|
{
|
|
|
|
|
var enumInstance = (TargetPlatform)Enum.ToObject(typeof(TargetPlatform), enumValue);
|
|
|
|
|
_displayNames.Add(enumInstance.ToDisplayName(), enumInstance);
|
|
|
|
|
}
|
2015-04-08 14:50:03 +02:00
|
|
|
|
}
|
2015-04-26 19:47:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TargetPlatform ParseTargetPlatform(string displayName)
|
|
|
|
|
{
|
|
|
|
|
InitializeTargetPlatforms();
|
|
|
|
|
|
|
|
|
|
TargetPlatform targetPlatform;
|
|
|
|
|
if (_displayNames.TryGetValue(displayName, out targetPlatform))
|
|
|
|
|
return targetPlatform;
|
|
|
|
|
|
2015-04-08 14:50:03 +02:00
|
|
|
|
return default(TargetPlatform);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string[] GetTargetPlatformDisplayNames()
|
|
|
|
|
{
|
2015-04-26 19:47:26 +02:00
|
|
|
|
InitializeTargetPlatforms();
|
2015-04-08 14:50:03 +02:00
|
|
|
|
|
2015-04-26 19:47:26 +02:00
|
|
|
|
return _displayNames.Keys.ToArray();
|
2015-04-08 14:50:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetDisplayName(TargetPlatform platform)
|
|
|
|
|
{
|
2015-04-26 19:47:26 +02:00
|
|
|
|
return platform.ToDisplayName();
|
2015-04-08 14:50:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetTargetPlatformName(string displayName)
|
|
|
|
|
{
|
2015-04-26 19:47:26 +02:00
|
|
|
|
InitializeTargetPlatforms();
|
|
|
|
|
|
|
|
|
|
TargetPlatform targetPlatform;
|
|
|
|
|
if (_displayNames.TryGetValue(displayName, out targetPlatform))
|
|
|
|
|
return targetPlatform.ToString();
|
2015-04-08 14:50:03 +02:00
|
|
|
|
|
|
|
|
|
return displayName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|