Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Discovery.cs 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Linq;
  3. using JetBrains.Rider.PathLocator;
  4. using Packages.Rider.Editor.Util;
  5. using Unity.CodeEditor;
  6. namespace Packages.Rider.Editor
  7. {
  8. internal interface IDiscovery
  9. {
  10. CodeEditor.Installation[] PathCallback();
  11. }
  12. internal class Discovery : IDiscovery
  13. {
  14. public static readonly RiderPathLocator RiderPathLocator;
  15. public static readonly RiderFileOpener RiderFileOpener;
  16. static Discovery()
  17. {
  18. var env = new RiderLocatorEnvironment();
  19. RiderPathLocator = new RiderPathLocator(env);
  20. RiderFileOpener = new RiderFileOpener(env);
  21. }
  22. public CodeEditor.Installation[] PathCallback()
  23. {
  24. // still we want to search for installations, when Preferences is opened
  25. var res = RiderPathLocator.GetAllRiderPaths()
  26. .Select(riderInfo => new CodeEditor.Installation
  27. {
  28. Path = riderInfo.Path,
  29. Name = riderInfo.Presentation
  30. })
  31. .ToList();
  32. var editorPath = RiderScriptEditor.CurrentEditor;
  33. if (RiderScriptEditor.IsRiderOrFleetInstallation(editorPath) &&
  34. !res.Any(a => a.Path == editorPath) &&
  35. FileSystemUtil.EditorPathExists(editorPath))
  36. {
  37. // External editor manually set from custom location
  38. var info = new RiderPathLocator.RiderInfo(RiderPathLocator, editorPath, false);
  39. var installation = new CodeEditor.Installation
  40. {
  41. Path = info.Path,
  42. Name = info.Presentation
  43. };
  44. res.Add(installation);
  45. }
  46. return res.ToArray();
  47. }
  48. }
  49. internal class RiderLocatorEnvironment : IRiderLocatorEnvironment
  50. {
  51. public OS CurrentOS
  52. {
  53. get
  54. {
  55. switch (UnityEngine.SystemInfo.operatingSystemFamily)
  56. {
  57. case UnityEngine.OperatingSystemFamily.Windows:
  58. return OS.Windows;
  59. case UnityEngine.OperatingSystemFamily.MacOSX:
  60. return OS.MacOSX;
  61. case UnityEngine.OperatingSystemFamily.Linux:
  62. return OS.Linux;
  63. default:
  64. return OS.Other;
  65. }
  66. }
  67. }
  68. public T FromJson<T>(string json)
  69. {
  70. return (T)UnityEngine.JsonUtility.FromJson(json, typeof(T));
  71. }
  72. public void Verbose(string message, Exception e = null)
  73. {
  74. // only writes to Editor.log
  75. Console.WriteLine(message);
  76. if (e != null)
  77. Console.WriteLine(e);
  78. }
  79. public void Info(string message, Exception e = null)
  80. {
  81. UnityEngine.Debug.Log(message);
  82. if (e != null)
  83. UnityEngine.Debug.Log(e);
  84. }
  85. public void Warn(string message, Exception e = null)
  86. {
  87. UnityEngine.Debug.LogWarning(message);
  88. if (e != null)
  89. UnityEngine.Debug.LogWarning(e);
  90. }
  91. public void Error(string message, Exception e = null)
  92. {
  93. UnityEngine.Debug.LogError(message);
  94. if (e != null)
  95. UnityEngine.Debug.LogException(e);
  96. }
  97. }
  98. }