11using System ;
22using System . Diagnostics ;
3+ using System . Runtime . InteropServices ;
34using JavaVersionSwitcher . Logging ;
45
56namespace JavaVersionSwitcher . Adapters
@@ -14,8 +15,14 @@ public ShellAdapter(ILogger logger)
1415 _logger = logger ;
1516 }
1617
18+
1719 public ShellType GetShellType ( )
1820 {
21+ if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
22+ {
23+ return ShellType . Unknown ;
24+ }
25+
1926 try
2027 {
2128 var proc = GetParentProcess ( Process . GetCurrentProcess ( ) ) ;
@@ -45,11 +52,20 @@ public ShellType GetShellType()
4552 }
4653 }
4754
48- private static Process GetParentProcess ( Process process ) {
55+ private static Process GetParentProcess ( Process process )
56+ {
4957 return FindPidFromIndexedProcessName ( FindIndexedProcessName ( process . Id ) ) ;
5058 }
5159
52- private static string FindIndexedProcessName ( int pid ) {
60+ #pragma warning disable CA1416
61+ private static string FindIndexedProcessName ( int pid )
62+ {
63+ if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
64+ {
65+ throw new NotImplementedException (
66+ "Accessing parent process is currently only available on windows." ) ;
67+ }
68+
5369 var processName = Process . GetProcessById ( pid ) . ProcessName ;
5470 var processesByName = Process . GetProcessesByName ( processName ) ;
5571 string processIndexedName = null ;
@@ -66,8 +82,15 @@ private static string FindIndexedProcessName(int pid) {
6682 }
6783
6884 private static Process FindPidFromIndexedProcessName ( string indexedProcessName ) {
85+ if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
86+ {
87+ throw new NotImplementedException (
88+ "Accessing parent process is currently only available on windows." ) ;
89+ }
90+
6991 var parentId = new PerformanceCounter ( "Process" , "Creating Process ID" , indexedProcessName ) ;
7092 return Process . GetProcessById ( ( int ) parentId . NextValue ( ) ) ;
7193 }
94+ #pragma warning restore CA1416
7295 }
7396}
0 commit comments