private FileSystemPath GetDocumentationRoot() { var appPath = mySolutionsManager.Solution?.GetComponent <UnityVersion>().GetActualAppPathForSolution(); var contentsPath = UnityInstallationFinder.GetApplicationContentsPath(appPath); return(contentsPath.Combine(@"Documentation/en")); }
public override RdProjectTemplateContent CreateContent(DotNetProjectTemplateExpander expander, IDotNetTemplateContentFactory factory, int index, IDictionary <string, string> context) { var content = factory.CreateNextParameters(new[] { expander }, index + 1, context); var parameter = expander.TemplateInfo.GetParameter(Name); if (parameter == null) { return(content); } var possiblePaths = UnityInstallationFinder.GetPossibleMonoPaths().Select(a => a.Directory.Combine("Managed/UnityEngine.dll")).Where(b => b.ExistsFile).ToArray(); var options = new List <RdProjectTemplateGroupOption>(); foreach (var path in possiblePaths) { var optionContext = new Dictionary <string, string>(context) { { Name, path.FullPath } }; var content1 = factory.CreateNextParameters(new[] { expander }, index + 1, optionContext); options.Add(new RdProjectTemplateGroupOption(path.FullPath, path.FullPath, null, content1)); } options.Add(new RdProjectTemplateGroupOption( "Custom", possiblePaths.Any()?"Custom":"Custom (Unity installation was not found)", null, new RdProjectTemplateTextParameter(Name, "Custom path", null, Tooltip, RdTextParameterStyle.FileChooser, content))); return(new RdProjectTemplateGroupParameter(Name, "UnityEngineDll", possiblePaths.Any()?possiblePaths.Last().FullPath:string.Empty, null, options)); }
public UnityInstallationSynchronizer(Lifetime lifetime, UnityReferencesTracker referencesTracker, UnityHost host, UnityInstallationFinder finder, UnityVersion unityVersion) { referencesTracker.HasUnityReference.Advise(lifetime, hasReference => { if (!hasReference) { return; } var version = unityVersion.GetActualVersionForSolution(); var path = finder.GetApplicationPath(version); if (path == null) { return; } var contentPath = finder.GetApplicationContentsPath(version); host.PerformModelAction(rd => { // ApplicationPath may be already set via UnityEditorProtocol, which is more accurate if (!rd.ApplicationPath.HasValue()) { rd.ApplicationPath.SetValue(path.FullPath); } if (!rd.ApplicationContentsPath.HasValue()) { rd.ApplicationContentsPath.SetValue(contentPath.FullPath); } }); }); }
private List <PackageData> GetPackagesFromPackagesLockJson() { if (!myPackagesLockPath.ExistsFile) { myLogger.Verbose("packages-lock.json does not exist"); return(null); } if (myManifestPath.ExistsFile && ShouldSkipPackagesLock()) { myLogger.Info("packages-lock.json is out of date. Skipping"); return(null); } myLogger.Verbose("Getting packages from packages-lock.json"); var appPath = myUnityVersion.GetActualAppPathForSolution(); var builtInPackagesFolder = UnityInstallationFinder.GetBuiltInPackagesFolder(appPath); return(myLogger.CatchSilent(() => { var packagesLockJson = PackagesLockJson.FromJson(myPackagesLockPath.ReadAllText2().Text); var packages = new List <PackageData>(); foreach (var(id, details) in packagesLockJson.Dependencies) { packages.Add(GetPackageData(id, details, builtInPackagesFolder)); } return packages; })); }
public UnityProjectDataCache BuildData(FileSystemPath projectFileLocation, XmlDocument document) { var documentElement = document.DocumentElement; if (documentElement == null || documentElement.Name != "Project") { return(UnityProjectDataCache.Empty); } var explicitLangVersion = false; var unityVersion = new Version(0, 0); var appPath = UnityInstallationFinder.GetAppPathByDll(documentElement); var versionFromDll = UnityVersion.GetVersionByAppPath(appPath); foreach (XmlNode propertyGroup in documentElement.GetElementsByTagName("PropertyGroup")) { var xmlElement = propertyGroup as XmlElement; if (xmlElement == null) { continue; } // We can't just grab the value here because there may be multiple values set, one per configuration. // I haven't seen Unity or Rider do this, so it must be VSTU, but I don't have proof... if (xmlElement.GetElementsByTagName("LangVersion").Count > 0) { explicitLangVersion = true; } if (versionFromDll != null) { continue; } // Ideally, we could get the defines through the project model (see IManagedProjectConfiguration), but // that only seems to give us the currently active project settings, and Unity's own .csproj creator // only sets the version for the Debug build, not the Release build. VSTU sets the defines in both // configurations. foreach (XmlNode defines in xmlElement.GetElementsByTagName("DefineConstants")) { unityVersion = GetVersionFromDefines(defines.InnerText, unityVersion); } } return(new UnityProjectDataCache(versionFromDll ?? unityVersion, explicitLangVersion, appPath)); }
private void NotifyFrontend(UnityHost host, UnityVersion unityVersion) { var version = unityVersion.GetActualVersionForSolution(); var applicationPath = unityVersion.GetActualAppPathForSolution(); if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.MacOsX && !applicationPath.ExistsDirectory || PlatformUtil.RuntimePlatform != PlatformUtil.Platform.MacOsX && !applicationPath.ExistsFile) { var info = UnityInstallationFinder.GetApplicationInfo(version); if (info == null) { return; } applicationPath = info.Path; version = info.Version; } host.PerformModelAction(rd => { // if model is there, then ApplicationPath was already set via UnityEditorProtocol, it would be more correct than any counted value if (myUnityEditorProtocol.UnityModel.Value != null) { return; } rd.ApplicationPath.SetValue(applicationPath.FullPath); var contentsPath = UnityInstallationFinder.GetApplicationContentsPath(applicationPath); if (!contentsPath.IsEmpty) { rd.ApplicationContentsPath.SetValue(contentsPath.FullPath); } if (version != null) { rd.ApplicationVersion.SetValue(UnityVersion.VersionToString(version)); } }); }
public UnityInstallationSynchronizer(Lifetime lifetime, UnitySolutionTracker solutionTracker, UnityHost host, UnityInstallationFinder finder, UnityVersion unityVersion) { solutionTracker.IsUnityProjectFolder.AdviseNotNull(lifetime, isUnityProjectFolder => { if (!isUnityProjectFolder) { return; } var version = unityVersion.GetActualVersionForSolution(); var info = finder.GetApplicationInfo(version); if (info == null) { return; } var contentPath = finder.GetApplicationContentsPath(version); host.PerformModelAction(rd => { // ApplicationPath may be already set via UnityEditorProtocol, which is more accurate if (!rd.ApplicationPath.HasValue()) { rd.ApplicationPath.SetValue(info.Path.FullPath); } if (!rd.ApplicationContentsPath.HasValue()) { rd.ApplicationContentsPath.SetValue(contentPath.FullPath); } if (!rd.ApplicationVersion.HasValue()) { rd.ApplicationVersion.SetValue(UnityVersion.VersionToString(info.Version)); } }); }); }
public UnityMonoPathProvider(ILogger logger, UnityInstallationFinder installationFinder) { myLogger = logger; myInstallationFinder = installationFinder; }
private List <PackageData> GetPackagesFromManifestJson() { if (!myManifestPath.ExistsFile) { // This is not really expected, unless we're on an older Unity that doesn't support package manager myLogger.Info("manifest.json does not exist"); return(null); } myLogger.Verbose("Getting packages from manifest.json"); try { var projectManifest = ManifestJson.FromJson(myManifestPath.ReadAllText2().Text); // Now we've deserialised manifest.json, log why we skipped packages-lock.json LogWhySkippedPackagesLock(projectManifest); var appPath = myUnityVersion.GetActualAppPathForSolution(); var builtInPackagesFolder = UnityInstallationFinder.GetBuiltInPackagesFolder(appPath); // Read the editor's default manifest, which gives us the minimum versions for various packages var globalManifestPath = UnityInstallationFinder.GetPackageManagerDefaultManifest(appPath); if (globalManifestPath.ExistsFile && myLastReadGlobalManifestPath != globalManifestPath) { myLastReadGlobalManifestPath = globalManifestPath; myGlobalManifest = SafelyReadGlobalManifestFile(globalManifestPath); } var registry = projectManifest.Registry ?? DefaultRegistryUrl; var packages = new Dictionary <string, PackageData>(); foreach (var(id, version) in projectManifest.Dependencies) { if (version.Equals("exclude", StringComparison.OrdinalIgnoreCase)) { continue; } projectManifest.Lock.TryGetValue(id, out var lockDetails); packages[id] = GetPackageData(id, version, registry, builtInPackagesFolder, lockDetails); } // From observation, Unity treats package folders in the Packages folder as actual packages, even if they're // not registered in manifest.json. They must have a */package.json file, in the root of the package itself foreach (var child in myPackagesFolder.GetChildDirectories()) { // The folder name is not reliable to act as ID, so we'll use the ID from package.json. All other // packages get the ID from manifest.json or packages-lock.json. This is assumed to be the same as // the ID in package.json var packageData = GetPackageDataFromFolder(null, child, PackageSource.Embedded); if (packageData != null) { packages[packageData.Id] = packageData; } } // Calculate the transitive dependencies. Based on observation, we simply go with the highest available var packagesToProcess = new List <PackageData>(packages.Values); while (packagesToProcess.Count > 0) { var foundDependencies = GetPackagesFromDependencies(registry, builtInPackagesFolder, packages, packagesToProcess); foreach (var package in foundDependencies) { packages[package.Id] = package; } packagesToProcess = foundDependencies; } return(new List <PackageData>(packages.Values)); } catch (Exception e) { myLogger.LogExceptionSilently(e); return(null); } }