495 lines
No EOL
19 KiB
C#
495 lines
No EOL
19 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using TeaBox.Extensions.IsIn;
|
|
using TeaBox.SourceControl;
|
|
using TeaBox.Code;
|
|
using TeaBox.Macros;
|
|
using TeaBox.Macros.Gui.Runner;
|
|
|
|
namespace TeaBox.UAF
|
|
{
|
|
/// <summary>
|
|
/// Utilities over the tool enums.
|
|
/// </summary>
|
|
public static class ToolExtensions
|
|
{
|
|
private static readonly ConcurrentDictionary<Tool, ToolPaths> _pathsPerTool = new ConcurrentDictionary<Tool, ToolPaths>();
|
|
|
|
public static IEnumerable<Tool> All
|
|
{
|
|
get { return Enum.GetValues(typeof(Tool)).Cast<Tool>(); }
|
|
}
|
|
|
|
public static IEnumerable<ToolPaths> AllPaths
|
|
{
|
|
get { return All.Select(x => x.Paths()).Where(x => x != null); }
|
|
}
|
|
|
|
public static ToolPaths Paths(this Tool tool)
|
|
{
|
|
return _pathsPerTool.GetOrAdd(tool, x =>
|
|
{
|
|
switch (tool)
|
|
{
|
|
case Tool.AfterEffectPlugin:
|
|
return AfterEffectPaths;
|
|
|
|
case Tool.GearStudio:
|
|
return GearStudioPaths;
|
|
|
|
case Tool.Sharpmake:
|
|
return SharpmakePaths;
|
|
|
|
case Tool.TeaBox:
|
|
return TeaBoxPaths;
|
|
|
|
case Tool.TeaBoxConsole:
|
|
return TeaBoxConsolePaths;
|
|
|
|
case Tool.UA_Engine:
|
|
return UA_EnginePaths;
|
|
|
|
case Tool.ScoringTool:
|
|
return ScoringToolPaths;
|
|
|
|
case Tool.Mars:
|
|
return MarsToolPaths;
|
|
|
|
default:
|
|
return Default(tool);
|
|
}
|
|
});
|
|
}
|
|
|
|
public static ToolPaths UA_EnginePaths
|
|
{
|
|
get
|
|
{
|
|
var tool = Tool.UA_Engine;
|
|
var result = Default(tool);
|
|
result.DebugExeDirectory = Path.Combine(RootFolder.Value, "output", "bin", "Debug");
|
|
result.ReleaseExeDirectory = Path.Combine(RootFolder.Value, "output", "bin", "Release");
|
|
result.DeliveredExeDirectory = Path.Combine(UAFConstants.EngineRootDir);
|
|
result.BetaExeDirectory = Path.Combine(UAFConstants.BetaFolder, tool.GetToolName(), tool.GetToolName());
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
public static ToolPaths ScoringToolPaths
|
|
{
|
|
get
|
|
{
|
|
var tool = Tool.ScoringTool;
|
|
|
|
var result = new ToolPaths(tool)
|
|
{
|
|
LocalExeFile = "ScoringTool.exe",
|
|
DebugExeDirectory = Path.Combine(RootFolder.Value, "output", "bin", "Debug", "Tools", "scoringtools", "scoringtool"),
|
|
ReleaseExeDirectory = Path.Combine(RootFolder.Value, "output", "bin", "Release", "Tools", "scoringtools", "scoringtool"),
|
|
BetaExeDirectory = Path.Combine(UAFConstants.BetaFolder, "ScoringTools", "bin"),
|
|
DeliveredExeDirectory = Path.Combine(UAFConstants.EngineRootDir, "Tools", "scoringtools", "scoringtool"),
|
|
};
|
|
|
|
var visualStudioVersion = UAFConstants.ToolsVisualStudioVersion.ToString().Replace("vs", "");
|
|
result.Solution = Path.Combine(UAFConstants.ToolsFolder, $"ScoringTools.{UAFConstants.BranchName}.{visualStudioVersion}.sln");
|
|
|
|
result.BuildCommand = new VisualStudioCommand(result.Solution)
|
|
{
|
|
BuildVariant = DevEnvBuildVariant.Release.ToString(),
|
|
Version = UAFConstants.ToolsVisualStudioVersion,
|
|
};
|
|
|
|
if (result.BuildCommand.SolutionName == UAFConstants.ToolsSolution)
|
|
{
|
|
result.BuildCommand.Project = tool + UAFConstants.ToolsVisualStudioVersion.ToString();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public static ToolPaths MarsToolPaths
|
|
{
|
|
get
|
|
{
|
|
var tool = Tool.Mars;
|
|
|
|
var result = new ToolPaths(tool)
|
|
{
|
|
LocalExeFile = "Mars.exe",
|
|
DebugExeDirectory = Path.Combine(RootFolder.Value, "output", "bin", "Debug", "Tools", "scoringtools", "mars"),
|
|
ReleaseExeDirectory = Path.Combine(RootFolder.Value, "output", "bin", "Release", "Tools", "scoringtools", "mars"),
|
|
BetaExeDirectory = Path.Combine(UAFConstants.BetaFolder, "Mars", "bin"),
|
|
DeliveredExeDirectory = Path.Combine(UAFConstants.EngineRootDir, "Tools", "scoringtools", "mars"),
|
|
};
|
|
|
|
result.Solution = UAFConstants.GetManagedScoringTools();
|
|
|
|
result.BuildCommand = new VisualStudioCommand(result.Solution)
|
|
{
|
|
BuildVariant = DevEnvBuildVariant.Release.ToString(),
|
|
Version = UAFConstants.ToolsVisualStudioVersion,
|
|
};
|
|
|
|
if (result.BuildCommand.SolutionName == UAFConstants.ToolsSolution)
|
|
{
|
|
result.BuildCommand.Project = tool + UAFConstants.ToolsVisualStudioVersion.ToString();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
public static bool IsTestableAsync(this Tool tool)
|
|
{
|
|
return tool.IsIn(
|
|
Tool.AutoDance, Tool.TempoBlaster, Tool.Traviata, Tool.TRec);
|
|
}
|
|
|
|
public static bool IsTestableSync(this Tool tool)
|
|
{
|
|
return tool.IsIn();
|
|
}
|
|
|
|
/// <summary>
|
|
/// True if the tool is automatically delivered in the output by the build machines.
|
|
/// </summary>
|
|
public static bool IsDelivered(this Tool tool)
|
|
{
|
|
return !tool.IsIn(Tool.AssetCookerFriendly, Tool.GearStudio,
|
|
Tool.MemoryProfiler, Tool.ParticleEditor, Tool.Sharpmake, Tool.SupportHelper, Tool.WiiDLCMaker,
|
|
Tool.AssetBrowser, Tool.DataFileAnalyzer, Tool.ConfigurePlus,
|
|
Tool.VisualInputVCR);
|
|
}
|
|
|
|
public static IEnumerable<Tool> GetTestableTools(bool async)
|
|
{
|
|
return Enum.GetValues(typeof(Tool)).Cast<Tool>().Where(tool => async ? tool.IsTestableAsync() : tool.IsTestableSync());
|
|
}
|
|
|
|
|
|
|
|
public static string GetToolName(this Tool tool)
|
|
{
|
|
MemberInfo memberInfo = typeof(Tool).GetMember(tool.ToString())
|
|
.FirstOrDefault();
|
|
|
|
string toolName = tool.ToString();
|
|
if (memberInfo == null) return toolName;
|
|
|
|
DescriptionAttribute attribute = (DescriptionAttribute)
|
|
memberInfo.GetCustomAttributes(typeof(DescriptionAttribute), false)
|
|
.FirstOrDefault();
|
|
return attribute?.Description ?? toolName;
|
|
|
|
}
|
|
|
|
private static ToolPaths Default(Tool tool)
|
|
{
|
|
string toolName = tool.GetToolName();
|
|
var result = new ToolPaths(tool)
|
|
{
|
|
LocalExeFile = AddUAExtension(tool) + toolName + ".exe",
|
|
DebugExeDirectory = Path.Combine(RootFolder.Value, "output", "bin", "Debug", "Tools", toolName),
|
|
ReleaseExeDirectory = Path.Combine(RootFolder.Value, "output", "bin", "Release", "Tools", toolName),
|
|
BetaExeDirectory = Path.Combine(UAFConstants.BetaFolder, toolName, toolName),
|
|
DeliveredExeDirectory = Path.Combine(UAFConstants.EngineRootDir, "Tools", toolName),
|
|
};
|
|
|
|
result.BuildCommand = new VisualStudioCommand(result.Solution)
|
|
{
|
|
BuildVariant = DevEnvBuildVariant.Release.ToString(),
|
|
Version = UAFConstants.ToolsVisualStudioVersion,
|
|
};
|
|
|
|
if (result.BuildCommand.SolutionName == UAFConstants.ToolsSolution)
|
|
{
|
|
result.BuildCommand.Project = toolName;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Some tools are built under a folder without UA_ but have the executable named UA_. Example:
|
|
/// The warning tool has this path:
|
|
/// WarningTool\UA_WarningTool.exe.
|
|
/// </summary>
|
|
private static string AddUAExtension(Tool tool)
|
|
{
|
|
if (tool.IsIn(Tool.BundleExplorer,
|
|
Tool.ConfigurePlus,
|
|
Tool.DataFileAnalyzer,
|
|
Tool.EngineMonitor))
|
|
{
|
|
return "UA_";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public static ToolPaths AfterEffectPaths
|
|
{
|
|
get
|
|
{
|
|
return new ToolPaths(Tool.AfterEffectPlugin)
|
|
{
|
|
LocalExeFile = "JustDance.jsx",
|
|
DebugExeDirectory = Path.Combine(UAFConstants.ToolsFolder, "thirdparty", "AfterEffect", "AfterEffectPlugin"),
|
|
ReleaseExeDirectory = Path.Combine(UAFConstants.ToolsFolder, "thirdparty", "AfterEffect", "AfterEffectPlugin"),
|
|
DeliveredExeDirectories = System.IO.Directory.EnumerateDirectories(UAFConstants.HubNas).Select(directory => Path.Combine(directory, "INSTALL", "AfterEffect")).ToList(),
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
private static ToolPaths SharpmakePaths
|
|
{
|
|
get
|
|
{
|
|
return new ToolPaths(Tool.Sharpmake)
|
|
{
|
|
LocalExeFile = "Sharpmake.exe",
|
|
DeliveredExeDirectory = Path.Combine(RootFolder.Value, @"tools\extern\Alexandrie\bin\Sharpmake\"),
|
|
ReleaseExeDirectory = Path.Combine(RootFolder.Value, @"tools\extern\Alexandrie\apps\Sharpmake\Sharpmake.Application\output\release\"),
|
|
DebugExeDirectory = Path.Combine(RootFolder.Value, @"tools\extern\Alexandrie\apps\Sharpmake\Sharpmake.Application\output\debug\"),
|
|
BetaExeDirectory = Path.Combine(UAFConstants.BetaFolder, "Sharpmake"),
|
|
BuildCommand = new VisualStudioCommand(UAFConstants.SharpmakeSolution)
|
|
{
|
|
BuildVariant = DevEnvBuildVariant.Release.ToString(),
|
|
Version = UAFConstants.ToolsVisualStudioVersion,
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
public static ToolPaths TeaBoxPaths
|
|
{
|
|
get
|
|
{
|
|
var result = Default(Tool.TeaBox);
|
|
result.LocalExeFile = "TeaBox.exe";
|
|
result.ReleaseExeDirectory = Path.Combine(RootFolder.Value, @"tools\apps\TeaBox\");
|
|
result.DebugExeDirectory = result.ReleaseExeDirectory;
|
|
result.Solution = UAFConstants.ToolsSolution;
|
|
result.BuildCommand = new VisualStudioCommand(UAFConstants.ToolsSolution)
|
|
{
|
|
BuildVariant = DevEnvBuildVariant.Release.ToString(),
|
|
Version = UAFConstants.ToolsVisualStudioVersion,
|
|
};
|
|
result.AdditionalQuickOpenItems = () => new[]
|
|
{
|
|
new QuickOpenItem
|
|
{
|
|
Name = "Update JD dependencies",
|
|
Image = ImageService.Load("publish.png"),
|
|
ActivateAction = () =>
|
|
{
|
|
var macro = new MethodMacro(typeof(PublishMacros).GetMethod(nameof(PublishMacros.UpdateTeaBoxDependencies)));
|
|
var entry = new Playlist.Entry(macro);
|
|
MacroRunnerPad.Instance.Schedule(entry);
|
|
},
|
|
}
|
|
};
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public static ToolPaths TeaBoxConsolePaths
|
|
{
|
|
get
|
|
{
|
|
var result = TeaBoxPaths;
|
|
result.LocalExeFile = "TeaBox.com";
|
|
return result;
|
|
}
|
|
}
|
|
|
|
private static ToolPaths GearStudioPaths
|
|
{
|
|
get
|
|
{
|
|
string solutionFile;
|
|
if (FindGearStudioSolutionFile(out solutionFile))
|
|
{
|
|
string solutionFolder = Path.GetDirectoryName(solutionFile);
|
|
|
|
return new ToolPaths(Tool.GearStudio)
|
|
{
|
|
Solution = solutionFile,
|
|
LocalExeFile = "GearStudio.exe",
|
|
DeliveredExeDirectory = Path.Combine(RootFolder.Value, @"extern\GearStudio"),
|
|
ReleaseExeDirectory = Path.Combine(solutionFolder, @"studio\bin\x64\Release\"),
|
|
DebugExeDirectory = Path.Combine(solutionFolder, @"studio\bin\x64\Debug\"),
|
|
BetaExeDirectory = Path.Combine(UAFConstants.BetaFolder, "GearStudio"),
|
|
BuildCommand = new VisualStudioCommand(solutionFile)
|
|
{
|
|
BuildVariant = DevEnvBuildVariant.Release.ToString(),
|
|
Version = UAFConstants.ToolsVisualStudioVersion,
|
|
}
|
|
};
|
|
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static bool FindGearStudioSolutionFile(out string solutionFile)
|
|
{
|
|
const string gearStudioSolution = "//technology-group-playground/gear/users/codev/gear_studio/gear_studio.sln";
|
|
|
|
IList<FileStatus> files;
|
|
|
|
var sourceControl = SourceControlService.Instance.Generic(UAFConstants.GearStudioServer,
|
|
UAFConstants.GearStudioServer, gearStudioSolution);
|
|
sourceControl.GetLocalFiles(new[] { PathEntry.FromFile(gearStudioSolution) }, out files);
|
|
|
|
solutionFile = files != null ? files.Select(x => x.ClientFilePath).FirstOrDefault() : null;
|
|
return solutionFile != null;
|
|
}
|
|
}
|
|
|
|
public enum ToolPath
|
|
{
|
|
Debug,
|
|
Release,
|
|
Delivery,
|
|
Beta
|
|
}
|
|
|
|
public class ToolPaths
|
|
{
|
|
private readonly Tool _tool;
|
|
|
|
public ToolPaths(Tool tool)
|
|
{
|
|
_tool = tool;
|
|
}
|
|
|
|
public string LocalExeFile { get; set; }
|
|
|
|
/// <summary>
|
|
/// Path of the debug version of the compiled exe (ex: Output\Bin\Debug\Tools\TempoBlaster\TempoBlaster.exe"
|
|
/// </summary>
|
|
public string DebugExeFile { get { return Path.Combine(DebugExeDirectory, LocalExeFile); } }
|
|
|
|
/// <summary>
|
|
/// Path of the debug version of the compiled exe (ex: Output\Bin\Debug\Tools\TempoBlaster\TempoBlaster.exe"
|
|
/// </summary>
|
|
public string DebugExeDirectory { get; set; }
|
|
|
|
/// /// <summary>
|
|
/// Path of the release version of the compiled exe (ex: Output\Bin\Release\Tools\TempoBlaster\TempoBlaster.exe"
|
|
/// </summary>
|
|
public string ReleaseExeDirectory { get; set; }
|
|
|
|
/// <summary>
|
|
/// Path of the release version of the compiled exe (ex: Output\Bin\Release\Tools\TempoBlaster\"
|
|
/// </summary>
|
|
public string ReleaseExeFile { get { return Path.Combine(ReleaseExeDirectory, LocalExeFile); } }
|
|
|
|
/// <summary>
|
|
/// Path on which to deploy the version
|
|
/// </summary>
|
|
public string DeliveredExeDirectory
|
|
{
|
|
get { return DeliveredExeDirectories.FirstOrDefault(); }
|
|
set
|
|
{
|
|
if (DeliveredExeDirectories.IsEmpty())
|
|
{
|
|
DeliveredExeDirectories.Add(value);
|
|
}
|
|
else
|
|
{
|
|
DeliveredExeDirectories[0] = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<string> DeliveredExeDirectories { get; set; } = new List<string>();
|
|
|
|
public string DeliveredExeFile { get { return Path.Combine(DeliveredExeDirectory, LocalExeFile); } }
|
|
|
|
/// <summary>
|
|
/// Path of a "closed beta" version that allows the user to test an unofficial version before the publish.
|
|
/// </summary>
|
|
public string BetaExeDirectory { get; set; }
|
|
|
|
/// <summary>
|
|
/// Path of a "closed beta" version that allows the user to test an unofficial version before the publish.
|
|
/// </summary>
|
|
public string BetaExeFile { get { return Path.Combine(BetaExeDirectory, LocalExeFile); } }
|
|
|
|
private string _solution;
|
|
public string Solution
|
|
{
|
|
get
|
|
{
|
|
if (_solution != null)
|
|
{
|
|
return _solution;
|
|
}
|
|
|
|
string visualStudioVersion = UAFConstants.ToolsVisualStudioVersion.ToString().Replace("vs", "");
|
|
string fileName = string.Format("{0}.{1}.{2}.sln", _tool.GetToolName(), UAFConstants.BranchName, visualStudioVersion);
|
|
var apps = Path.Combine(UAFConstants.ToolsFolder, "apps", _tool.GetToolName(), fileName);
|
|
var qa = Path.Combine(UAFConstants.ToolsFolder, "qa", _tool.GetToolName(), fileName);
|
|
var legacy = Path.Combine(UAFConstants.ToolsFolder, "legacy", _tool.GetToolName(), fileName);
|
|
return new[] { apps, qa, legacy }.FirstOrDefault(System.IO.File.Exists) ?? UAFConstants.ToolsSolution;
|
|
}
|
|
set { _solution = value; }
|
|
}
|
|
|
|
public string ExeDirectory(ToolPath toolPath)
|
|
{
|
|
switch (toolPath)
|
|
{
|
|
case ToolPath.Debug: return DebugExeDirectory;
|
|
case ToolPath.Release: return ReleaseExeDirectory;
|
|
case ToolPath.Delivery: return DeliveredExeDirectory;
|
|
case ToolPath.Beta: return BetaExeDirectory;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public string ExeFile(ToolPath toolPath)
|
|
{
|
|
switch (toolPath)
|
|
{
|
|
case ToolPath.Debug: return DebugExeFile;
|
|
case ToolPath.Release: return ReleaseExeFile;
|
|
case ToolPath.Delivery: return DeliveredExeFile;
|
|
case ToolPath.Beta: return BetaExeFile;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Finds the latest executable (typically that was compiled last)
|
|
/// </summary>
|
|
public string DefaultExeFile()
|
|
{
|
|
var paths = new[] { ToolPath.Release, ToolPath.Debug, ToolPath.Delivery };
|
|
|
|
var latest = (from path in paths
|
|
let exeFile = ExeFile(path)
|
|
where System.IO.File.Exists(exeFile)
|
|
let writeTime = System.IO.File.GetLastWriteTime(exeFile)
|
|
orderby System.IO.File.GetLastWriteTime(exeFile) descending
|
|
select exeFile).FirstOrDefault();
|
|
|
|
return latest;
|
|
}
|
|
|
|
public VisualStudioCommand BuildCommand { get; set; }
|
|
|
|
public Func<IEnumerable<IQuickOpenItem>> AdditionalQuickOpenItems { get; set; }
|
|
}
|
|
} |