7
7
using System . Security . AccessControl ;
8
8
using System . Security . Principal ;
9
9
using Newtonsoft . Json . Linq ;
10
+ using System . Runtime . InteropServices ;
10
11
11
12
namespace BrowserStack
12
13
{
13
14
public enum LocalState { Idle , Connecting , Connected , Error , Disconnected } ;
14
15
15
16
public class BrowserStackTunnel : IDisposable
16
17
{
18
+ // Need to get rid of this variable, instead use getBinaryName()
17
19
static readonly string binaryName = isDarwin ( ) ? "BrowserStackLocal-darwin-x64" : "BrowserStackLocal.exe" ;
18
20
static readonly string downloadURL = isDarwin ( ) ?
19
21
"https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal-darwin-x64" :
@@ -39,8 +41,77 @@ public class BrowserStackTunnel : IDisposable
39
41
40
42
static Boolean isDarwin ( )
41
43
{
42
- OperatingSystem os = Environment . OSVersion ;
43
- return os . Platform . ToString ( ) == "Unix" ;
44
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
45
+ {
46
+ return true ;
47
+ }
48
+ }
49
+
50
+ static Boolean isWindows ( )
51
+ {
52
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
53
+ {
54
+ return true ;
55
+ }
56
+ }
57
+
58
+ static Boolean isLinux ( )
59
+ {
60
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
61
+ {
62
+ return true ;
63
+ }
64
+ }
65
+
66
+ static Boolean isAlpine ( )
67
+ {
68
+ const string osReleaseFile = "/etc/os-release" ;
69
+
70
+ if ( File . Exists ( osReleaseFile ) )
71
+ {
72
+ string [ ] lines = File . ReadAllLines ( osReleaseFile ) ;
73
+ foreach ( string line in lines )
74
+ {
75
+ if ( line . StartsWith ( "ID=" ) )
76
+ {
77
+ string id = line . Substring ( 3 ) . Trim ( '"' ) ; // Remove 'ID=' and quotes
78
+ if ( id . Equals ( "alpine" , StringComparison . OrdinalIgnoreCase ) )
79
+ {
80
+ return true ;
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ static staring getBinaryName ( )
87
+ {
88
+ if isDarwin ( )
89
+ {
90
+ binaryName = "BrowserStackLocal-darwin-x64"
91
+ }
92
+ else if isWindows( )
93
+ {
94
+ binaryName = "BrowserStackLocal.exe"
95
+ }
96
+ else if isLinux( )
97
+ {
98
+ if ( RuntimeInformation . OSArchitecture == Architecture . X64
99
+ || RuntimeInformation . OSArchitecture == Architecture . Arm64 )
100
+ {
101
+ if isAlpine ( )
102
+ {
103
+ binaryName = "BrowserStackLocal-alpine"
104
+ }
105
+ else
106
+ {
107
+ binaryName = "BrowserStackLocal-linux-x64"
108
+ }
109
+ }
110
+ else
111
+ {
112
+ binaryName = "BrowserStackLocal- linux - ia32"
113
+ }
114
+ }
44
115
}
45
116
46
117
public virtual void addBinaryPath ( string binaryAbsolute )
0 commit comments