瀏覽代碼

Merge pull request #36598 from van800/rpl

Improve searching for installed Rider editor
Rémi Verschelde 5 年之前
父節點
當前提交
9a203d89a9
共有 1 個文件被更改,包括 60 次插入18 次删除
  1. 60 18
      modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs

+ 60 - 18
modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs

@@ -11,6 +11,10 @@ using Environment = System.Environment;
 using File = System.IO.File;
 using File = System.IO.File;
 using Path = System.IO.Path;
 using Path = System.IO.Path;
 using OS = GodotTools.Utils.OS;
 using OS = GodotTools.Utils.OS;
+// ReSharper disable UnassignedField.Local
+// ReSharper disable InconsistentNaming
+// ReSharper disable UnassignedField.Global
+// ReSharper disable MemberHidesStaticFromOuterClass
 
 
 namespace GodotTools.Ides.Rider
 namespace GodotTools.Ides.Rider
 {
 {
@@ -131,28 +135,45 @@ namespace GodotTools.Ides.Rider
             if (OS.IsWindows)
             if (OS.IsWindows)
             {
             {
                 var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                 var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
-                return Path.Combine(localAppData, @"JetBrains\Toolbox\apps\Rider");
+                return GetToolboxRiderRootPath(localAppData);
             }
             }
 
 
             if (OS.IsOSX)
             if (OS.IsOSX)
             {
             {
                 var home = Environment.GetEnvironmentVariable("HOME");
                 var home = Environment.GetEnvironmentVariable("HOME");
-                if (!string.IsNullOrEmpty(home))
-                {
-                    return Path.Combine(home, @"Library/Application Support/JetBrains/Toolbox/apps/Rider");
-                }
+                if (string.IsNullOrEmpty(home)) 
+                    return string.Empty;
+                var localAppData = Path.Combine(home, @"Library/Application Support");
+                return GetToolboxRiderRootPath(localAppData);
             }
             }
 
 
             if (OS.IsUnixLike())
             if (OS.IsUnixLike())
             {
             {
                 var home = Environment.GetEnvironmentVariable("HOME");
                 var home = Environment.GetEnvironmentVariable("HOME");
-                if (!string.IsNullOrEmpty(home))
-                {
-                    return Path.Combine(home, @".local/share/JetBrains/Toolbox/apps/Rider");
-                }
+                if (string.IsNullOrEmpty(home)) 
+                    return string.Empty;
+                var localAppData = Path.Combine(home, @".local/share");
+                return GetToolboxRiderRootPath(localAppData);
+            }
+
+            return string.Empty;
+        }
+
+
+        private static string GetToolboxRiderRootPath(string localAppData)
+        {
+            var toolboxPath = Path.Combine(localAppData, @"JetBrains\Toolbox");
+            var settingsJson = Path.Combine(toolboxPath, ".settings.json");
+
+            if (File.Exists(settingsJson))
+            {
+                var path = SettingsJson.GetInstallLocationFromJson(File.ReadAllText(settingsJson));
+                if (!string.IsNullOrEmpty(path))
+                    toolboxPath = path;
             }
             }
 
 
-            throw new Exception("Unexpected OS.");
+            var toolboxRiderRootPath = Path.Combine(toolboxPath, @"apps\Rider");
+            return toolboxRiderRootPath;
         }
         }
 
 
         internal static ProductInfo GetBuildVersion(string path)
         internal static ProductInfo GetBuildVersion(string path)
@@ -226,8 +247,8 @@ namespace GodotTools.Ides.Rider
               {
               {
                   try
                   try
                   {
                   {
-                // use history.json - last entry stands for the active build https://jetbrains.slack.com/archives/C07KNP99D/p1547807024066500?thread_ts=1547731708.057700&cid=C07KNP99D
-                var historyFile = Path.Combine(channelDir, ".history.json");
+                      // use history.json - last entry stands for the active build https://jetbrains.slack.com/archives/C07KNP99D/p1547807024066500?thread_ts=1547731708.057700&cid=C07KNP99D
+                      var historyFile = Path.Combine(channelDir, ".history.json");
                       if (File.Exists(historyFile))
                       if (File.Exists(historyFile))
                       {
                       {
                           var json = File.ReadAllText(historyFile);
                           var json = File.ReadAllText(historyFile);
@@ -255,14 +276,14 @@ namespace GodotTools.Ides.Rider
                           }
                           }
                       }
                       }
 
 
-                // changes in toolbox json files format may brake the logic above, so return all found Rider installations
-                return Directory.GetDirectories(channelDir)
-                  .SelectMany(buildDir => GetExecutablePaths(dirName, searchPattern, isMac, buildDir));
+                      // changes in toolbox json files format may brake the logic above, so return all found Rider installations
+                      return Directory.GetDirectories(channelDir)
+                          .SelectMany(buildDir => GetExecutablePaths(dirName, searchPattern, isMac, buildDir));
                   }
                   }
                   catch (Exception e)
                   catch (Exception e)
                   {
                   {
-                // do not write to Debug.Log, just log it.
-                Logger.Warn($"Failed to get RiderPath from {channelDir}", e);
+                      // do not write to Debug.Log, just log it.
+                      Logger.Warn($"Failed to get RiderPath from {channelDir}", e);
                   }
                   }
 
 
                   return new string[0];
                   return new string[0];
@@ -288,6 +309,27 @@ namespace GodotTools.Ides.Rider
         // Note that Unity disable this warning in the generated C# projects
         // Note that Unity disable this warning in the generated C# projects
 #pragma warning disable 0649
 #pragma warning disable 0649
 
 
+        [Serializable]
+        class SettingsJson
+        {
+            public string install_location;
+      
+            [CanBeNull]
+            public static string GetInstallLocationFromJson(string json)
+            {
+                try
+                {
+                    return JsonConvert.DeserializeObject<SettingsJson>(json).install_location;
+                }
+                catch (Exception)
+                {
+                    Logger.Warn($"Failed to get install_location from json {json}");
+                }
+
+                return null;
+            }
+        }
+
         [Serializable]
         [Serializable]
         class ToolboxHistory
         class ToolboxHistory
         {
         {
@@ -372,7 +414,6 @@ namespace GodotTools.Ides.Rider
         [Serializable]
         [Serializable]
         class ActiveApplication
         class ActiveApplication
         {
         {
-            // ReSharper disable once InconsistentNaming
             public List<string> builds;
             public List<string> builds;
         }
         }
 
 
@@ -380,6 +421,7 @@ namespace GodotTools.Ides.Rider
 
 
         public struct RiderInfo
         public struct RiderInfo
         {
         {
+            // ReSharper disable once NotAccessedField.Global
             public bool IsToolbox;
             public bool IsToolbox;
             public string Presentation;
             public string Presentation;
             public Version BuildNumber;
             public Version BuildNumber;