public static IDisposable With(
            [CanBeNull] this ITextTemplatingComponents components,
            [CanBeNull] IVsHierarchy hierarchy,
            [CanBeNull] FileSystemPath inputFilePath
            )
        {
            if (components == null)
            {
                return(Disposable.Empty);
            }

            object oldHierarchy     = components.Hierarchy;
            string oldInputFileName = components.InputFile;

            return(Disposable.CreateBracket(
                       () => {
                components.Hierarchy = hierarchy;
                components.InputFile = inputFilePath.IsNullOrEmpty() ? null : inputFilePath.FullPath;
            },
                       () => {
                components.Hierarchy = oldHierarchy;
                components.InputFile = oldInputFileName;
            },
                       false
                       ));
        }
示例#2
0
        private void RegenerateProjectFiles(FileSystemPath uprojectFilePath)
        {
            void LogFailedRefreshProjectFiles()
            {
                myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage("Failed to refresh project files",
                                                                                ContentType.Normal));
                myUnrealHost.myModel.RiderLinkInstallMessage(
                    new InstallMessage("RiderLink will not be visible in solution explorer", ContentType.Normal));
                myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage(
                                                                 "Need to refresh project files in Unreal Editor or in File Explorer with context action for .uproject file 'Refresh Project files'",
                                                                 ContentType.Normal));
            }

            if (uprojectFilePath.IsNullOrEmpty())
            {
                myLogger.Warn(
                    $"[UnrealLink]: Failed refresh project files, couldn't find uproject path: {uprojectFilePath}");

                LogFailedRefreshProjectFiles();
                return;
            }

            var engineRoot = CppUE4FolderFinder.FindUnrealEngineRoot(uprojectFilePath);

            if (engineRoot.IsEmpty)
            {
                myLogger.Warn($"[UnrealLink]: Couldn't find Unreal Engine root for {uprojectFilePath}");

                LogFailedRefreshProjectFiles();
                return;
            }

            var pathToUnrealBuildToolBin = CppUE4FolderFinder.GetAbsolutePathToUnrealBuildToolBin(engineRoot);

            // 1. If project is under engine root, use GenerateProjectFiles.{extension} first
            if (GenerateProjectFilesCmd(engineRoot))
            {
                return;
            }
            // 2. If it's a standalone project, use UnrealVersionSelector
            //    The same way "Generate project files" from context menu of .uproject works
            if (RegenerateProjectUsingUVS(uprojectFilePath, engineRoot))
            {
                return;
            }
            // 3. If UVS is missing or have failed, fallback to UnrealBuildTool
            if (RegenerateProjectUsingUBT(uprojectFilePath, pathToUnrealBuildToolBin, engineRoot))
            {
                return;
            }

            myLogger.Warn("[UnrealLink]: Couldn't refresh project files");

            LogFailedRefreshProjectFiles();
        }
        public InstallationInfo GetInstallationInfo(FileSystemPath previousInstallationDir)
        {
            try
            {
                var assetsDir = mySolution.SolutionFilePath.Directory.CombineWithShortName("Assets");
                if (!assetsDir.IsAbsolute)
                {
                    myLogger.Warn($"Computed assetsDir {assetsDir} is not absolute. Skipping installation.");
                    return(ShouldNotInstall);
                }

                if (!assetsDir.ExistsDirectory)
                {
                    myLogger.Info("No Assets directory in the same directory as solution. Skipping installation.");
                    return(ShouldNotInstall);
                }

                var defaultDir = assetsDir
                                 .CombineWithShortName("Plugins")
                                 .CombineWithShortName("Editor")
                                 .CombineWithShortName("JetBrains");

                InstallationInfo result;

                var isFirstInstall = previousInstallationDir.IsNullOrEmpty();
                if (isFirstInstall)
                {
                    if (TryFindOnDisk(defaultDir, out result))
                    {
                        return(result);
                    }

                    // nothing in solution or default directory on first launch.
                    return(NotInstalled(defaultDir));
                }

                // default case: all is good, we have cached the installation dir
                if (TryFindOnDisk(previousInstallationDir, out result))
                {
                    return(result);
                }

                // not fresh install, but nothing in previously installed dir on in solution
                myLogger.Info("Plugin not found in previous installation dir '{0}' or in solution. Falling back to default directory.", previousInstallationDir);

                return(NotInstalled(defaultDir));
            }
            catch (Exception e)
            {
                myLogger.LogExceptionSilently(e);
                return(ShouldNotInstall);
            }
        }
示例#4
0
        public InstallationInfo GetInstallationInfo(FileSystemPath previousInstallationDir)
        {
            try
            {
                var unityGeneratedProjects = mySolution.GetAllProjects().Where(a => a.IsProjectCompiledByUnity()).ToArray();
                if (!unityGeneratedProjects.Any())
                {
                    myLogger.Info("No unity generated projects found. Skipping installation.");
                    return(ShouldNotInstall);
                }
                var assetsDir = unityGeneratedProjects.First().GetSubItems("Assets").First().Location;

                if (!assetsDir.IsAbsolute)
                {
                    myLogger.Warn($"Computed assetsDir {assetsDir} is not absolute. Skipping installation.");
                }

                var defaultDir = assetsDir
                                 .CombineWithShortName("Plugins")
                                 .CombineWithShortName("Editor")
                                 .CombineWithShortName("JetBrains");

                InstallationInfo result;

                var isFirstInstall = previousInstallationDir.IsNullOrEmpty();
                if (isFirstInstall)
                {
                    if (TryFindOnDisk(defaultDir, out result))
                    {
                        return(result);
                    }

                    // nothing in solution or default directory on first launch.
                    return(NotInstalled(defaultDir));
                }

                // default case: all is good, we have cached the installation dir
                if (TryFindOnDisk(previousInstallationDir, out result))
                {
                    return(result);
                }

                // not fresh install, but nothing in previously installed dir on in solution
                myLogger.Info("Plugin not found in previous installation dir '{0}' or in solution. Falling back to default directory.", previousInstallationDir);

                return(NotInstalled(defaultDir));
            }
            catch (Exception e)
            {
                myLogger.LogExceptionSilently(e);
                return(ShouldNotInstall);
            }
        }
示例#5
0
        public FindAndLoadSettings(Lifetime lifetimeComponent, SettingsStorageProvidersCollection publisher, SolutionFileLocationLive solfile, IThreading threading, IFileSystemTracker filetracker, FileSettingsStorageBehavior behavior, ISolution solution, IShellLocks locks)
        {
            // In case the solution path changes, watch each value anew
            solfile.SolutionFileLocation.ForEachValue_NotNull(lifetimeComponent, (lifetimeLocation, location) =>
            {
                double priority = ProjectModelSettingsStorageMountPointPriorityClasses.SolutionShared;
                for (FileSystemPath dir = location.Directory; !dir.IsNullOrEmpty(); dir = dir.Directory)
                {
                    try
                    {
                        priority *= .9; // The upper folder, the lower priority (regular solution-shared file takes over all of them)

                        // Walk up folders
                        // TODO: add file-system-watcher here
                        foreach (FileSystemPath settingsfile in dir.GetChildFiles("*." + AutoLoadExtension, PathSearchFlags.ExcludeDirectories | PathSearchFlags.ExcludeHidden))
                        {
                            var relativePath = settingsfile.MakeRelativeTo(location.Directory).FullPath;
                            var name         = relativePath.Replace("." + AutoLoadExtension, "");

                            // Physical storage
                            IProperty <FileSystemPath> livepath = new Property <FileSystemPath>(lifetimeLocation, "StoragePath", settingsfile);
                            var storage = new XmlFileSettingsStorage(lifetimeLocation, name, livepath, SettingsStoreSerializationToXmlDiskFile.SavingEmptyContent.KeepFile, threading, filetracker, behavior, null);

                            // Mount as a layer
                            IIsAvailable availability        = new IsAvailableByDataConstant <ISolution>(lifetimeLocation, ProjectModelDataConstants.SOLUTION, solution, locks); // Only when querying in solution context (includes Application-Wide)
                            ISettingsStorageMountPoint mount = new SettingsStorageMountPoint(storage.Storage, SettingsStorageMountPoint.MountPath.Default, 0, priority, availability, name);

                            // Metadata
                            livepath.FlowInto(lifetimeLocation, mount.Metadata.GetOrCreateProperty(UserFriendlySettingsLayers.DiskFilePath, null, true));
                            mount.Metadata.Set(UserFriendlySettingsLayers.Origin, string.Format("Automatically loaded from solution parent folder, \"{0}\"", relativePath));
                            mount.Metadata.Set(UserInjectedSettingsLayers.IsHostingUserInjections, true);

                            // Publish
                            publisher.Storages.Add(lifetimeLocation, storage.Storage);
                            publisher.MountPoints.Add(lifetimeLocation, mount);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(ex);
                    }
                }
            });
        }
示例#6
0
        public static FileSystemPath GetApplicationContentsPath(FileSystemPath applicationPath)
        {
            if (applicationPath.IsNullOrEmpty())
            {
                return(applicationPath);
            }

            AssertApplicationPath(applicationPath);

            switch (PlatformUtil.RuntimePlatform)
            {
            case PlatformUtil.Platform.MacOsX:
                return(applicationPath.Combine("Contents"));

            case PlatformUtil.Platform.Linux:
            case PlatformUtil.Platform.Windows:
                return(applicationPath.Directory.Combine("Data"));
            }
            ourLogger.Error("Unknown runtime platform");
            return(FileSystemPath.Empty);
        }
        private void TryInstallVsIntegration([CanBeNull] IVsExtensionManager vsExtensionManager)
        {
            if (vsExtensionManager == null)
            {
                return;
            }

            IInstalledExtension vsIntegrationExtension;

            if (vsExtensionManager.TryGetInstalledExtension(VsIntegrationExtensionId, out vsIntegrationExtension))
            {
                return;
            }

            FileSystemPath thisAssemblyPath = FileSystemPath.TryParse(typeof(VsIntegrationInstaller).Assembly.Location);

            if (thisAssemblyPath.IsNullOrEmpty())
            {
                return;
            }

            FileSystemPath vsixPath = thisAssemblyPath.Directory.Combine(VsIntegrationExtensionId + ".vsix");

            if (!vsixPath.ExistsFile)
            {
                MessageBox.ShowInfo("Does not exist: \"{0}\"".FormatEx(vsixPath.FullPath));
                return;
            }

            IInstallableExtension installableExtension = vsExtensionManager.CreateInstallableExtension(vsixPath.FullPath);
            RestartReason         restartReason        = vsExtensionManager.Install(installableExtension, false);

            if (restartReason != RestartReason.None)
            {
                _restartRequired = true;
            }
        }
        public override bool TryGetProjectOutputFilePath(IProject project, out FileSystemPath outputFilePath)
        {
            myShellLocks.AssertReadAccessAllowed();

            if (!project.IsUnityProject())
            {
                return(base.TryGetProjectOutputFilePath(project, out outputFilePath));
            }

            return(myProjectNameToOutputFilePathMap.TryGetValue(project.Name, out outputFilePath) && !outputFilePath.IsNullOrEmpty());
        }
示例#9
0
        public InstallationInfo GetInstallationInfo(FileSystemPath previousInstallationDir)
        {
            try
            {
                var assetsDir = mySolution.SolutionFilePath.Directory.CombineWithShortName(ProjectExtensions.AssetsFolder);
                if (!assetsDir.IsAbsolute)
                {
                    myLogger.Warn($"Computed assetsDir {assetsDir} is not absolute. Skipping installation.");
                    return(ShouldNotInstall);
                }

                if (!assetsDir.ExistsDirectory)
                {
                    myLogger.Info("No Assets directory in the same directory as solution. Skipping installation.");
                    return(ShouldNotInstall);
                }

                var defaultDir = assetsDir
                                 .CombineWithShortName("Plugins")
                                 .CombineWithShortName("Editor")
                                 .CombineWithShortName("JetBrains");

                InstallationInfo result;

                var isFirstInstall = previousInstallationDir.IsNullOrEmpty();
                if (isFirstInstall)
                {
                    // e.g.: fresh checkout from VCS
                    if (TryFindInSolution(mySolution, out result))
                    {
                        return(result);
                    }

                    if (TryFindOnDisk(defaultDir, out result))
                    {
                        return(result);
                    }

                    // nothing in solution or default directory on first launch.
                    return(NotInstalled(defaultDir));
                }

                // default case: all is good, we have cached the installation dir
                if (TryFindOnDisk(previousInstallationDir, out result))
                {
                    return(result);
                }

                // e.g.: user has moved the plugin from the time it was last installed
                // In such case we will be able to find if solution was regenerated by Unity after that
                if (TryFindInSolution(mySolution, out result))
                {
                    return(result);
                }

                // not fresh install, but nothing in previously installed dir on in solution
                myLogger.Info("Plugin not found in previous installation dir '{0}' or in solution. Falling back to default directory.", previousInstallationDir);

                return(NotInstalled(defaultDir));
            }
            catch (Exception e)
            {
                myLogger.LogExceptionSilently(e);
                return(ShouldNotInstall);
            }
        }
示例#10
0
        public InstallationInfo GetInstallationInfo(Version newVersion, FileSystemPath previousInstallationDir)
        {
            myLogger.Verbose("GetInstallationInfo.");
            try
            {
                var assetsDir = mySolution.SolutionFilePath.Directory.CombineWithShortName(ProjectExtensions.AssetsFolder);
                if (!assetsDir.IsAbsolute)
                {
                    myLogger.Warn($"Computed assetsDir {assetsDir} is not absolute. Skipping installation.");
                    return(InstallationInfo.DoNotInstall);
                }

                if (!assetsDir.ExistsDirectory)
                {
                    myLogger.Info("No Assets directory in the same directory as solution. Skipping installation.");
                    return(InstallationInfo.DoNotInstall);
                }

                var defaultDir = assetsDir
                                 .CombineWithShortName("Plugins")
                                 .CombineWithShortName("Editor")
                                 .CombineWithShortName("JetBrains");

                // default case: all is good, we have cached the installation dir
                if (!previousInstallationDir.IsNullOrEmpty() &&
                    TryFindExistingPluginOnDisk(previousInstallationDir, newVersion, out var installationInfo))
                {
                    return(installationInfo);
                }

                // e.g.: user has moved the plugin from the time it was last installed
                // In such case we will be able to find if solution was regenerated by Unity after that
                if (TryFindExistingPluginInSolution(mySolution, newVersion, out installationInfo))
                {
                    return(installationInfo);
                }

                // Check the default location
                if (TryFindExistingPluginOnDisk(defaultDir, newVersion, out installationInfo))
                {
                    return(installationInfo);
                }

                // not fresh install, but nothing in previously installed dir on in solution
                if (!previousInstallationDir.IsNullOrEmpty())
                {
                    myLogger.Info(
                        "Plugin not found in previous installation dir '{0}' or in solution. Falling back to default directory.",
                        previousInstallationDir);
                }
                else
                {
                    myLogger.Info("Plugin not found in solution. Installing to default location");
                }

                return(InstallationInfo.FreshInstall(defaultDir));
            }
            catch (Exception e)
            {
                myLogger.LogExceptionSilently(e);
                return(InstallationInfo.DoNotInstall);
            }
        }
        public static ISymbolTable GetReferenceSymbolTable(IPathReference pathReference, bool useReferenceName, bool includeHttpHandlers = true)
        {
            var propertiesSearcher =
                pathReference.GetTreeNode().GetSolution().GetComponent <MSBuildPropertiesCache>();

            string productHomeDir = propertiesSearcher.GetProjectPropertyByName(pathReference.GetTreeNode().GetProject(),
                                                                                "ProductHomeDir");
            var basePath = new FileSystemPath(productHomeDir);

            if (basePath.IsEmpty)
            {
                return(EmptySymbolTable.INSTANCE);
            }

            FolderQualifierInfo folderQualifierInfo = null;
            IPsiServices        psiServices         = pathReference.GetTreeNode().GetPsiServices();
            var baseProjectFolder = psiServices.Solution.FindProjectItemsByLocation(basePath).FirstOrDefault() as IProjectFolder;

            if (baseProjectFolder != null)
            {
                folderQualifierInfo = new FolderQualifierInfo(baseProjectFolder);
            }

            FileSystemPath websiteRoot = GetRootPath(pathReference);
            IQualifier     qualifier   = pathReference.GetQualifier();

            if (useReferenceName)
            {
                PathDeclaredElement target = null;
                string name = pathReference.GetName();
                switch (name)
                {
                case PathDeclaredElement.CURRENT_DIR_NAME:
                    target = new PathDeclaredElement(PathDeclaredElement.CURRENT_DIR_NAME, psiServices, basePath);
                    break;

                case PathDeclaredElement.LEVEL_UP_NAME:
                    target = new PathDeclaredElement(PathDeclaredElement.LEVEL_UP_NAME, psiServices, basePath.Directory);
                    break;

                case PathDeclaredElement.ROOT_NAME:
                    if (qualifier != null)
                    {
                        goto default;
                    }
                    target = new PathDeclaredElement(PathDeclaredElement.ROOT_NAME, psiServices, websiteRoot);
                    break;

                default:
                    try
                    {
                        string parserGenOutputBase =
                            propertiesSearcher.GetProjectPropertyByName(pathReference.GetTreeNode().GetProject(), "ParserGenOutputBase");
                        FileSystemPath path = basePath.Combine(parserGenOutputBase + "\\" + name);
                        target = new PathDeclaredElement(name, psiServices, path);
                    }
                    catch (InvalidPathException)
                    {
                    }
                    catch (ArgumentException)
                    {
                    }
                    break;
                }
                var table = new SymbolTable(psiServices, folderQualifierInfo != null ? new SymbolTableDependencySet(folderQualifierInfo) : null);
                if (target != null)
                {
                    table.AddSymbol(target, EmptySubstitution.INSTANCE, 1);
                }
                return(table);
            }

            FileSystemPath rootPath              = (qualifier == null) ? websiteRoot : FileSystemPath.Empty;
            ISymbolTable   symbolTableByPath     = PathReferenceUtil.GetSymbolTableByPath(basePath, psiServices, basePath.Directory, rootPath, true);
            FileSystemPath basePathBeforeMapping = GetBasePathBeforeMapping(pathReference);

            if (!basePathBeforeMapping.IsNullOrEmpty())
            {
                IWebProjectPathMapping pathMapping = WebPathMappingManager.GetPathMapping(pathReference);
                List <FileSystemPath>  mappedPaths = pathMapping.GetAllPathPartsIn(basePathBeforeMapping).ToList();
                if (mappedPaths.Any())
                {
                    var mappedPathsTable = new SymbolTable(psiServices, folderQualifierInfo != null ? new SymbolTableDependencySet(folderQualifierInfo) : null);
                    foreach (FileSystemPath mappedPath in mappedPaths)
                    {
                        var declaredElement = new PathDeclaredElement(psiServices, mappedPath);
                        mappedPathsTable.AddSymbol(declaredElement, EmptySubstitution.INSTANCE, 1);
                    }
                    symbolTableByPath = symbolTableByPath.Merge(mappedPathsTable);
                }
            }

            if (!includeHttpHandlers)
            {
                return(symbolTableByPath);
            }

            var httpHandlersTable = new SymbolTable(psiServices);

            return(httpHandlersTable.Merge(symbolTableByPath));
        }
        public InstallationInfo GetInstallationInfo(Version newVersion, FileSystemPath previousInstallationDir = null)
        {
            myLogger.Verbose("GetInstallationInfo.");
            try
            {
                var assetsDir = mySolution.SolutionDirectory.CombineWithShortName(ProjectExtensions.AssetsFolder);
                if (!assetsDir.IsAbsolute)
                {
                    myLogger.Warn($"Computed assetsDir {assetsDir} is not absolute. Skipping installation.");
                    return(InstallationInfo.DoNotInstall);
                }

                if (!assetsDir.ExistsDirectory)
                {
                    myLogger.Info("No Assets directory in the same directory as solution. Skipping installation.");
                    return(InstallationInfo.DoNotInstall);
                }

                var defaultDir = assetsDir
                                 .CombineWithShortName("Plugins")
                                 .CombineWithShortName("Editor")
                                 .CombineWithShortName("JetBrains");

                // default case: all is good, we have cached the installation dir
                if (!previousInstallationDir.IsNullOrEmpty() &&
                    TryFindExistingPluginOnDisk(previousInstallationDir, newVersion, out var installationInfo))
                {
                    return(installationInfo);
                }

                // Check the default location
                if (TryFindExistingPluginOnDisk(defaultDir, newVersion, out installationInfo))
                {
                    return(installationInfo);
                }

                // dll is there, but was not referenced by any project, for example - only Assembly-CSharp project is present
                if (TryFindExistingPluginOnDiskInFolderRecursive(assetsDir, newVersion, out var installationInfo1))
                {
                    return(installationInfo1);
                }

                // not fresh install, but nothing in previously installed dir on in solution
                if (!previousInstallationDir.IsNullOrEmpty())
                {
                    myLogger.Info(
                        "Plugin not found in previous installation dir '{0}' or in solution. Falling back to default directory.",
                        previousInstallationDir);
                }
                else
                {
                    myLogger.Info("Plugin not found in solution. Installing to default location");
                }

                return(InstallationInfo.FreshInstall(defaultDir));
            }
            catch (Exception e)
            {
                myLogger.LogExceptionSilently(e);
                return(InstallationInfo.DoNotInstall);
            }
        }