@@ -66,13 +66,13 @@ public override IGenerator ProjectGenerator
6666
6767 private static bool IsCandidateForDiscovery ( string path )
6868 {
69- if ( VisualStudioEditor . IsOSX )
70- return Directory . Exists ( path ) && Regex . IsMatch ( path , ".*Code.*.app$" , RegexOptions . IgnoreCase ) ;
71-
72- if ( VisualStudioEditor . IsWindows )
73- return File . Exists ( path ) && Regex . IsMatch ( path , ".*Code.*.exe$" , RegexOptions . IgnoreCase ) ;
74-
69+ #if UNITY_EDITOR_OSX
70+ return Directory . Exists ( path ) && Regex . IsMatch ( path , ".*Code.*.app$" , RegexOptions . IgnoreCase ) ;
71+ #elif UNITY_EDITOR_WIN
72+ return File . Exists ( path ) && Regex . IsMatch ( path , ".*Code.*.exe$" , RegexOptions . IgnoreCase ) ;
73+ #else
7574 return File . Exists ( path ) && path . EndsWith ( "code" , StringComparison . OrdinalIgnoreCase ) ;
75+ #endif
7676 }
7777
7878 [ Serializable ]
@@ -99,21 +99,23 @@ public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioI
9999 {
100100 var manifestBase = GetRealPath ( editorPath ) ;
101101
102- if ( VisualStudioEditor . IsWindows ) // on Windows, editorPath is a file, resources as subdirectory
103- manifestBase = IOPath . GetDirectoryName ( manifestBase ) ;
104- else if ( VisualStudioEditor . IsOSX ) // on Mac, editorPath is a directory
105- manifestBase = IOPath . Combine ( manifestBase , "Contents" ) ;
106- else {
107- // on Linux, editorPath is a file, in a bin sub-directory
108- var parent = Directory . GetParent ( manifestBase ) ;
109- // but we can link to [vscode]/code or [vscode]/bin/code
110- manifestBase = parent ? . Name == "bin" ? parent . Parent ? . FullName : parent ? . FullName ;
111- }
102+ #if UNITY_EDITOR_WIN
103+ // on Windows, editorPath is a file, resources as subdirectory
104+ manifestBase = IOPath . GetDirectoryName ( manifestBase ) ;
105+ #elif UNITY_EDITOR_OSX
106+ // on Mac, editorPath is a directory
107+ manifestBase = IOPath . Combine ( manifestBase , "Contents" ) ;
108+ #else
109+ // on Linux, editorPath is a file, in a bin sub-directory
110+ var parent = Directory . GetParent ( manifestBase ) ;
111+ // but we can link to [vscode]/code or [vscode]/bin/code
112+ manifestBase = parent ? . Name == "bin" ? parent . Parent ? . FullName : parent ? . FullName ;
113+ #endif
112114
113115 if ( manifestBase == null )
114116 return false ;
115117
116- var manifestFullPath = IOPath . Combine ( manifestBase , @ "resources", "app" , "package.json" ) ;
118+ var manifestFullPath = IOPath . Combine ( manifestBase , "resources" , "app" , "package.json" ) ;
117119 if ( File . Exists ( manifestFullPath ) )
118120 {
119121 var manifest = JsonUtility . FromJson < VisualStudioCodeManifest > ( File . ReadAllText ( manifestFullPath ) ) ;
@@ -142,32 +144,27 @@ public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallation
142144 {
143145 var candidates = new List < string > ( ) ;
144146
145- if ( VisualStudioEditor . IsWindows )
146- {
147- var localAppPath = IOPath . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "Programs" ) ;
148- var programFiles = IOPath . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) ) ;
147+ #if UNITY_EDITOR_WIN
148+ var localAppPath = IOPath . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "Programs" ) ;
149+ var programFiles = IOPath . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) ) ;
149150
150- foreach ( var basePath in new [ ] { localAppPath , programFiles } )
151- {
152- candidates . Add ( IOPath . Combine ( basePath , "Microsoft VS Code" , "Code.exe" ) ) ;
153- candidates . Add ( IOPath . Combine ( basePath , "Microsoft VS Code Insiders" , "Code - Insiders.exe" ) ) ;
154- }
155- }
156- else if ( VisualStudioEditor . IsOSX )
151+ foreach ( var basePath in new [ ] { localAppPath , programFiles } )
157152 {
158- var appPath = IOPath . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) ) ;
159- candidates . AddRange ( Directory . EnumerateDirectories ( appPath , "Visual Studio Code*.app" ) ) ;
160- }
161- else
162- {
163- // Well known locations
164- candidates . Add ( "/usr/bin/code" ) ;
165- candidates . Add ( "/bin/code" ) ;
166- candidates . Add ( "/usr/local/bin/code" ) ;
167-
168- // Preference ordered base directories relative to which desktop files should be searched
169- candidates . AddRange ( GetXdgCandidates ( ) ) ;
153+ candidates . Add ( IOPath . Combine ( basePath , "Microsoft VS Code" , "Code.exe" ) ) ;
154+ candidates . Add ( IOPath . Combine ( basePath , "Microsoft VS Code Insiders" , "Code - Insiders.exe" ) ) ;
170155 }
156+ #elif UNITY_EDITOR_OSX
157+ var appPath = IOPath . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) ) ;
158+ candidates . AddRange ( Directory . EnumerateDirectories ( appPath , "Visual Studio Code*.app" ) ) ;
159+ #elif UNITY_EDITOR_LINUX
160+ // Well known locations
161+ candidates . Add ( "/usr/bin/code" ) ;
162+ candidates . Add ( "/bin/code" ) ;
163+ candidates . Add ( "/usr/local/bin/code" ) ;
164+
165+ // Preference ordered base directories relative to which desktop files should be searched
166+ candidates . AddRange ( GetXdgCandidates ( ) ) ;
167+ #endif
171168
172169 foreach ( var candidate in candidates . Distinct ( ) )
173170 {
@@ -176,6 +173,7 @@ public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallation
176173 }
177174 }
178175
176+ #if UNITY_EDITOR_LINUX
179177 private static readonly Regex DesktopFileExecEntry = new Regex ( @"Exec=(\S+)" , RegexOptions . Singleline | RegexOptions . Compiled ) ;
180178
181179 private static IEnumerable < string > GetXdgCandidates ( ) {
@@ -207,7 +205,6 @@ private static IEnumerable<string> GetXdgCandidates() {
207205 }
208206 }
209207
210- #if UNITY_EDITOR_LINUX
211208 [ System . Runtime . InteropServices . DllImport ( "libc" ) ]
212209 private static extern int readlink ( string path , byte [ ] buffer , int buflen ) ;
213210
@@ -514,13 +511,14 @@ public override bool Open(string path, int line, int column, string solution)
514511
515512 private static ProcessStartInfo ProcessStartInfoFor ( string application , string arguments )
516513 {
517- if ( ! VisualStudioEditor . IsOSX )
518- return ProcessRunner . ProcessStartInfoFor ( application , arguments , redirect : false ) ;
519-
514+ #if UNITY_EDITOR_OSX
520515 // wrap with built-in OSX open feature
521516 arguments = $ "-n \" { application } \" --args { arguments } ";
522517 application = "open" ;
523518 return ProcessRunner . ProcessStartInfoFor ( application , arguments , redirect : false , shell : true ) ;
519+ #else
520+ return ProcessRunner . ProcessStartInfoFor ( application , arguments , redirect : false ) ;
521+ #endif
524522 }
525523
526524 public static void Initialize ( )
0 commit comments