@@ -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,22 +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- {
108- // on Linux, editorPath is a file, in a bin sub-directory
109- var parent = Directory . GetParent ( manifestBase ) ;
110- // but we can link to [vscode]/code or [vscode]/bin/code
111- manifestBase = parent ? . Name == "bin" ? parent . Parent ? . FullName : parent ? . FullName ;
112- }
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
113114
114115 if ( manifestBase == null )
115116 return false ;
116117
117- var manifestFullPath = IOPath . Combine ( manifestBase , @ "resources", "app" , "package.json" ) ;
118+ var manifestFullPath = IOPath . Combine ( manifestBase , "resources" , "app" , "package.json" ) ;
118119 if ( File . Exists ( manifestFullPath ) )
119120 {
120121 var manifest = JsonUtility . FromJson < VisualStudioCodeManifest > ( File . ReadAllText ( manifestFullPath ) ) ;
@@ -143,32 +144,27 @@ public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallation
143144 {
144145 var candidates = new List < string > ( ) ;
145146
146- if ( VisualStudioEditor . IsWindows )
147- {
148- var localAppPath = IOPath . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "Programs" ) ;
149- 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 ) ) ;
150150
151- foreach ( var basePath in new [ ] { localAppPath , programFiles } )
152- {
153- candidates . Add ( IOPath . Combine ( basePath , "Microsoft VS Code" , "Code.exe" ) ) ;
154- candidates . Add ( IOPath . Combine ( basePath , "Microsoft VS Code Insiders" , "Code - Insiders.exe" ) ) ;
155- }
156- }
157- else if ( VisualStudioEditor . IsOSX )
151+ foreach ( var basePath in new [ ] { localAppPath , programFiles } )
158152 {
159- var appPath = IOPath . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) ) ;
160- candidates . AddRange ( Directory . EnumerateDirectories ( appPath , "Visual Studio Code*.app" ) ) ;
161- }
162- else
163- {
164- // Well known locations
165- candidates . Add ( "/usr/bin/code" ) ;
166- candidates . Add ( "/bin/code" ) ;
167- candidates . Add ( "/usr/local/bin/code" ) ;
168-
169- // Preference ordered base directories relative to which desktop files should be searched
170- 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" ) ) ;
171155 }
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
172168
173169 foreach ( var candidate in candidates . Distinct ( ) )
174170 {
@@ -177,6 +173,7 @@ public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallation
177173 }
178174 }
179175
176+ #if UNITY_EDITOR_LINUX
180177 private static readonly Regex DesktopFileExecEntry = new Regex ( @"Exec=(\S+)" , RegexOptions . Singleline | RegexOptions . Compiled ) ;
181178
182179 private static IEnumerable < string > GetXdgCandidates ( )
@@ -212,7 +209,6 @@ private static IEnumerable<string> GetXdgCandidates()
212209 }
213210 }
214211
215- #if UNITY_EDITOR_LINUX
216212 [ System . Runtime . InteropServices . DllImport ( "libc" ) ]
217213 private static extern int readlink ( string path , byte [ ] buffer , int buflen ) ;
218214
@@ -519,13 +515,14 @@ public override bool Open(string path, int line, int column, string solution)
519515
520516 private static ProcessStartInfo ProcessStartInfoFor ( string application , string arguments )
521517 {
522- if ( ! VisualStudioEditor . IsOSX )
523- return ProcessRunner . ProcessStartInfoFor ( application , arguments , redirect : false ) ;
524-
518+ #if UNITY_EDITOR_OSX
525519 // wrap with built-in OSX open feature
526520 arguments = $ "-n \" { application } \" --args { arguments } ";
527521 application = "open" ;
528522 return ProcessRunner . ProcessStartInfoFor ( application , arguments , redirect : false , shell : true ) ;
523+ #else
524+ return ProcessRunner . ProcessStartInfoFor ( application , arguments , redirect : false ) ;
525+ #endif
529526 }
530527
531528 public static void Initialize ( )
0 commit comments