in resharper/resharper-unity/src/Unity/UnityEditorIntegration/UnityInstallationFinder.cs [134:239]
private static List<VirtualFileSystemPath> GetPossibleApplicationPaths(string engineName)
{
switch (PlatformUtil.RuntimePlatform)
{
case JetPlatform.MacOsX:
{
var appsHome = VirtualFileSystemPath.Parse("/Applications", InteractionContext.SolutionContext);
var unityApps = appsHome.GetChildDirectories($"{engineName}*").Select(a=>a.Combine($"{engineName}.app")).ToList();
var defaultHubLocation = appsHome.Combine($"{engineName}/Hub/Editor");
var hubLocations = new List<VirtualFileSystemPath> {defaultHubLocation};
// Hub custom location
var home = Environment.GetEnvironmentVariable("HOME");
if (!string.IsNullOrEmpty(home))
{
var localAppData = VirtualFileSystemPath.Parse(home, InteractionContext.SolutionContext).Combine("Library/Application Support");
var hubCustomLocation = GetCustomHubInstallPath(engineName, localAppData);
if (!hubCustomLocation.IsEmpty)
hubLocations.Add(hubCustomLocation);
}
// /Applications/Unity/Hub/Editor/2018.1.0b4/Unity.app
unityApps.AddRange(hubLocations.SelectMany(l=>l.GetChildDirectories().Select(unityDir =>
unityDir.Combine($@"{engineName}.app"))));
return unityApps.Where(a=>a.ExistsDirectory).Distinct().OrderBy(b=>b.FullPath).ToList();
}
case JetPlatform.Linux:
{
var unityApps = new List<VirtualFileSystemPath>();
var homeEnv = Environment.GetEnvironmentVariable("HOME");
var homes = new List<VirtualFileSystemPath> {VirtualFileSystemPath.Parse("/opt", InteractionContext.SolutionContext)};
if (!string.IsNullOrEmpty(homeEnv))
{
homes.Add(VirtualFileSystemPath.Parse(homeEnv, InteractionContext.SolutionContext));
}
// Old style installations
unityApps.AddRange(
homes.SelectMany(a => a.GetChildDirectories($"{engineName}*"))
.Select(unityDir => unityDir.Combine($@"Editor/{engineName}")));
// Installations with Unity Hub
if (!string.IsNullOrEmpty(homeEnv))
{
var home = VirtualFileSystemPath.Parse(homeEnv, InteractionContext.SolutionContext);
var defaultHubLocation = home.Combine($"{engineName}/Hub/Editor");
var hubLocations = new List<VirtualFileSystemPath> {defaultHubLocation};
// Hub custom location
var configPath = home.Combine(".config");
var customHubInstallPath = GetCustomHubInstallPath(engineName, configPath);
if (!customHubInstallPath.IsEmpty)
hubLocations.Add(customHubInstallPath);
unityApps.AddRange(hubLocations.SelectMany(l=>l.GetChildDirectories().Select(unityDir =>
unityDir.Combine($@"Editor/{engineName}"))));
}
return unityApps.Where(a=>a.ExistsFile).Distinct().OrderBy(b=>b.FullPath).ToList();
}
case JetPlatform.Windows:
{
var unityApps = new List<VirtualFileSystemPath>();
var programFiles = GetProgramFiles();
unityApps.AddRange(
programFiles.GetChildDirectories($"{engineName}*")
.Select(unityDir => unityDir.Combine($@"Editor\{engineName}.exe"))
);
// default Hub location
//"C:\Program Files\Unity\Hub\Editor\2018.1.0b4\Editor\Data\MonoBleedingEdge"
unityApps.AddRange(
programFiles.Combine($@"{engineName}\Hub\Editor").GetChildDirectories()
.Select(unityDir => unityDir.Combine($@"Editor\{engineName}.exe"))
);
// custom Hub location
var appData = VirtualFileSystemPath.Parse(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), InteractionContext.SolutionContext);
var customHubInstallPath = GetCustomHubInstallPath(engineName, appData);
if (!customHubInstallPath.IsEmpty)
{
unityApps.AddRange(
customHubInstallPath.GetChildDirectories()
.Select(unityDir => unityDir.Combine($@"Editor\{engineName}.exe"))
);
}
var lnks = VirtualFileSystemPath.Parse(@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs", InteractionContext.SolutionContext)
.GetChildDirectories($"{engineName}*").SelectMany(a => a.GetChildFiles($"{engineName}.lnk")).ToArray();
unityApps.AddRange(lnks
.Select(t => ShellLinkHelper.ResolveLinkTarget(t.ToNativeFileSystemPath()).ToVirtualFileSystemPath())
.OrderBy(c => new FileInfo(c.FullPath).CreationTime));
foreach (var VirtualFileSystemPath in unityApps)
{
ourLogger.Log(LoggingLevel.VERBOSE, "Possible unity path: " + VirtualFileSystemPath);
}
return unityApps.Where(a=>a.ExistsFile).Distinct().OrderBy(b=>b.FullPath).ToList();
}
}
ourLogger.Error("Unknown runtime platform");
return new List<VirtualFileSystemPath>();
}