예제 #1
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 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);
            }
        }