1111using System . Text . RegularExpressions ;
1212using UnityEngine ;
1313using IOPath = System . IO . Path ;
14+ using System . Runtime . InteropServices ;
15+ using System . Text ;
1416
1517namespace Microsoft . Unity . VisualStudio . Editor
1618{
@@ -96,14 +98,14 @@ public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioI
9698
9799 try
98100 {
99- string manifestBase ;
101+ var manifestBase = GetRealPath ( editorPath ) ;
100102
101103 if ( VisualStudioEditor . IsWindows ) // on Windows, editorPath is a file, resources as subdirectory
102- manifestBase = IOPath . GetDirectoryName ( editorPath ) ;
104+ manifestBase = IOPath . GetDirectoryName ( manifestBase ) ;
103105 else if ( VisualStudioEditor . IsOSX ) // on Mac, editorPath is a directory
104- manifestBase = IOPath . Combine ( editorPath , "Contents" ) ;
106+ manifestBase = IOPath . Combine ( manifestBase , "Contents" ) ;
105107 else // on Linux, editorPath is a file, in a bin sub-directory
106- manifestBase = Directory . GetParent ( editorPath ) ? . Parent ? . FullName ;
108+ manifestBase = Directory . GetParent ( manifestBase ) ? . Parent ? . FullName ;
107109
108110 if ( manifestBase == null )
109111 return false ;
@@ -155,7 +157,6 @@ public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallation
155157 }
156158 else
157159 {
158- candidates . Add ( "/usr/share/code/bin/code" ) ;
159160 candidates . Add ( "/usr/bin/code" ) ;
160161 candidates . Add ( "/bin/code" ) ;
161162 candidates . Add ( "/usr/local/bin/code" ) ;
@@ -168,6 +169,26 @@ public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallation
168169 }
169170 }
170171
172+ #if UNITY_EDITOR_LINUX
173+ [ DllImport ( "libc" ) ]
174+ private static extern int readlink ( string path , byte [ ] buffer , int buflen ) ;
175+
176+ internal static string GetRealPath ( string path )
177+ {
178+ byte [ ] buf = new byte [ 512 ] ;
179+ int ret = readlink ( path , buf , buf . Length ) ;
180+ if ( ret == - 1 ) return path ;
181+ char [ ] cbuf = new char [ 512 ] ;
182+ int chars = System . Text . Encoding . Default . GetChars ( buf , 0 , ret , cbuf , 0 ) ;
183+ return new String ( cbuf , 0 , chars ) ;
184+ }
185+ #else
186+ internal static string GetRealPath ( string path )
187+ {
188+ return path ;
189+ }
190+ #endif
191+
171192 public override void CreateExtraFiles ( string projectDirectory )
172193 {
173194 try
0 commit comments