Skip to content

Commit d99d1a3

Browse files
committed
LOC-5824 Changes are still in progess, added check for os, added changes for binaryName selection
1 parent cf8eab3 commit d99d1a3

File tree

1 file changed

+73
-2
lines changed

1 file changed

+73
-2
lines changed

BrowserStackLocal/BrowserStackLocal/BrowserStackTunnel.cs

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
using System.Security.AccessControl;
88
using System.Security.Principal;
99
using Newtonsoft.Json.Linq;
10+
using System.Runtime.InteropServices;
1011

1112
namespace BrowserStack
1213
{
1314
public enum LocalState { Idle, Connecting, Connected, Error, Disconnected };
1415

1516
public class BrowserStackTunnel : IDisposable
1617
{
18+
// Need to get rid of this variable, instead use getBinaryName()
1719
static readonly string binaryName = isDarwin() ? "BrowserStackLocal-darwin-x64" : "BrowserStackLocal.exe";
1820
static readonly string downloadURL = isDarwin() ?
1921
"https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal-darwin-x64" :
@@ -39,8 +41,77 @@ public class BrowserStackTunnel : IDisposable
3941

4042
static Boolean isDarwin()
4143
{
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+
}
44115
}
45116

46117
public virtual void addBinaryPath(string binaryAbsolute)

0 commit comments

Comments
 (0)