|
| 1 | +using System; |
1 | 2 | using System.Diagnostics; |
2 | | -using Microsoft.Win32; |
| 3 | +using System.Threading.Tasks; |
3 | 4 |
|
4 | 5 | namespace WebDriverManager.Helpers |
5 | 6 | { |
6 | 7 | public static class RegistryHelper |
7 | 8 | { |
8 | | - private const string CurrentUserRegistryPathPattern = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\<executableFileName>"; |
9 | | - private const string LocalMachineRegistryPathPattern = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\<executableFileName>"; |
| 9 | + public static string GetInstalledBrowserVersionLinux(string executableFileName, string arguments) |
| 10 | + { |
| 11 | + try |
| 12 | + { |
| 13 | + var outputVersion = Task.Run(() => VersionHelper.GetVersionFromProcess(executableFileName, arguments)) |
| 14 | + .Result; |
| 15 | + return outputVersion; |
| 16 | + } |
| 17 | + catch (Exception e) |
| 18 | + { |
| 19 | + throw new Exception( |
| 20 | + $"An error occured trying to locate installed browser version for runtime platform {Environment.OSVersion.Platform}", |
| 21 | + e); |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + public static string GetInstalledBrowserVersionOsx(string executableFileName, string arguments) |
| 26 | + { |
| 27 | + try |
| 28 | + { |
| 29 | + var executableFilePath = $"/Applications/{executableFileName}.app/Contents/MacOS/{executableFileName}"; |
| 30 | + var outputVersion = Task.Run(() => VersionHelper.GetVersionFromProcess(executableFilePath, arguments)) |
| 31 | + .Result; |
| 32 | + return outputVersion.Replace($"{executableFileName} ", ""); |
| 33 | + } |
| 34 | + catch (Exception e) |
| 35 | + { |
| 36 | + throw new Exception( |
| 37 | + $"An error occured trying to locate installed browser version for runtime platform {Environment.OSVersion.Platform}", |
| 38 | + e); |
| 39 | + } |
| 40 | + } |
10 | 41 |
|
11 | | - public static string GetInstalledBrowserVersion(string executableFileName) |
| 42 | + public static string GetInstalledBrowserVersionWin(string executableFileName) |
12 | 43 | { |
13 | | - var currentUserPath = Registry.GetValue(CurrentUserRegistryPathPattern.Replace("<executableFileName>", executableFileName), "", null); |
| 44 | + const string currentUserRegistryPathPattern = |
| 45 | + @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\<executableFileName>"; |
| 46 | + const string localMachineRegistryPathPattern = |
| 47 | + @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\<executableFileName>"; |
| 48 | + |
| 49 | + var currentUserPath = Microsoft.Win32.Registry.GetValue( |
| 50 | + currentUserRegistryPathPattern.Replace("<executableFileName>", executableFileName), "", null); |
14 | 51 | if (currentUserPath != null) |
15 | 52 | { |
16 | 53 | return FileVersionInfo.GetVersionInfo(currentUserPath.ToString()).FileVersion; |
17 | 54 | } |
18 | 55 |
|
19 | | - var localMachinePath = Registry.GetValue(LocalMachineRegistryPathPattern.Replace("<executableFileName>", executableFileName), "", null); |
| 56 | + var localMachinePath = Microsoft.Win32.Registry.GetValue( |
| 57 | + localMachineRegistryPathPattern.Replace("<executableFileName>", executableFileName), "", null); |
20 | 58 | if (localMachinePath != null) |
21 | 59 | { |
22 | 60 | return FileVersionInfo.GetVersionInfo(localMachinePath.ToString()).FileVersion; |
|
0 commit comments