Skip to content

Commit d4a023f

Browse files
authored
Merge pull request #52 from browserstack/release_v2_4_0
Release v2.4.0
2 parents 30d1dec + 8678f9a commit d4a023f

File tree

3 files changed

+106
-13
lines changed

3 files changed

+106
-13
lines changed

BrowserStackLocal/BrowserStackLocal/BrowserStackLocal.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<Title>BrowserStackLocalTitle>
88
<Product>BrowserStackLocalProduct>
99
<Description>C# Bindings for BrowserStack LocalDescription>
10-
<Version>2.3.1Version>
11-
<AssemblyVersion>2.3.1AssemblyVersion>
12-
<FileVersion>2.3.1FileVersion>
10+
<Version>2.4.0Version>
11+
<AssemblyVersion>2.4.0AssemblyVersion>
12+
<FileVersion>2.4.0FileVersion>
1313
<Authors>BrowserStackAuthors>
1414
<Company>BrowserStackCompany>
1515
<Copyright>Copyright © 2016Copyright>
@@ -31,4 +31,4 @@
3131
3232
3333
-->
34-
Project>
34+
Project>

BrowserStackLocal/BrowserStackLocal/BrowserStackTunnel.cs

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public enum LocalState { Idle, Connecting, Connected, Error, Disconnected };
1414

1515
public class BrowserStackTunnel : IDisposable
1616
{
17-
static readonly string binaryName = isDarwin() ? "BrowserStackLocal-darwin-x64" : "BrowserStackLocal.exe";
18-
static readonly string downloadURL = isDarwin() ?
19-
"https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal-darwin-x64" :
20-
"https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal.exe";
21-
static readonly string homepath = isDarwin() ?
17+
static readonly string uname = Util.GetUName();
18+
static readonly string binaryName = GetBinaryName();
19+
static readonly string downloadURL = "https://www.browserstack.com/local-testing/downloads/binaries/" + binaryName;
20+
21+
static readonly string homepath = !IsWindows() ?
2222
Environment.GetFolderPath(Environment.SpecialFolder.Personal) :
2323
Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
2424
public static readonly string[] basePaths = new string[] {
@@ -37,10 +37,51 @@ public class BrowserStackTunnel : IDisposable
3737

3838
Process process = null;
3939

40-
static Boolean isDarwin()
40+
static bool IsDarwin(string osName)
41+
{
42+
return osName.Contains("darwin");
43+
}
44+
45+
46+
static bool IsWindows()
47+
{
48+
return Environment.OSVersion.VersionString?.ToLower().Contains("windows") ?? false;
49+
}
50+
51+
static bool IsLinux(string osName)
52+
{
53+
return osName.Contains("linux");
54+
}
55+
56+
static bool IsAlpine()
4157
{
42-
OperatingSystem os = Environment.OSVersion;
43-
return os.Platform.ToString() == "Unix";
58+
try
59+
{
60+
string[] output = Util.RunShellCommand("grep", "-w \'NAME\' /etc/os-release");
61+
return output[0]?.ToLower()?.Contains("alpine") ?? false;
62+
}
63+
catch (System.Exception ex)
64+
{
65+
Console.WriteLine("Exception while check isAlpine " + ex);
66+
}
67+
return false;
68+
}
69+
70+
static string GetBinaryName()
71+
{
72+
if (IsWindows()) return "BrowserStackLocal.exe";
73+
if (IsDarwin(uname)) return "BrowserStackLocal-darwin-x64";
74+
75+
if (IsLinux(uname))
76+
{
77+
if (Util.Is64BitOS())
78+
{
79+
return IsAlpine() ? "BrowserStackLocal-alpine" : "BrowserStackLocal-linux-x64";
80+
}
81+
return "BrowserStackLocal-linux-ia32";
82+
}
83+
84+
return "BrowserStackLocal.exe";
4485
}
4586

4687
public virtual void addBinaryPath(string binaryAbsolute)
@@ -79,7 +120,7 @@ public virtual void fallbackPaths()
79120

80121
public void modifyBinaryPermission()
81122
{
82-
if (isDarwin())
123+
if (!IsWindows())
83124
{
84125
try
85126
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace BrowserStack
5+
{
6+
public class Util {
7+
8+
// Only Unix Support
9+
public static string[] RunShellCommand(string command, string args = "")
10+
{
11+
ProcessStartInfo psi = new ProcessStartInfo {
12+
RedirectStandardOutput = true,
13+
RedirectStandardError = true,
14+
UseShellExecute = false,
15+
CreateNoWindow = true,
16+
FileName = command,
17+
Arguments = args
18+
};
19+
20+
Process process = new Process { StartInfo = psi };
21+
process.Start();
22+
string output = process.StandardOutput.ReadToEnd();
23+
string error = process.StandardError.ReadToEnd();
24+
process.WaitForExit();
25+
return new string[]{output, error};
26+
}
27+
28+
public static string GetUName()
29+
{
30+
string osName = "";
31+
try
32+
{
33+
string[] output = RunShellCommand("uname");
34+
osName = output[0]?.ToLower();
35+
}
36+
catch (System.Exception) {}
37+
return osName;
38+
}
39+
40+
// Using for Linux Only
41+
public static bool Is64BitOS()
42+
{
43+
#if NET48_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NETCOREAPP3_0_OR_GREATER
44+
return Environment.Is64BitOperatingSystem;
45+
#endif
46+
// https://learn.microsoft.com/en-gb/dotnet/standard/choosing-core-framework-server?WT.mc_id=dotnet-35129-website
47+
// linux won't be supported in .NET Framework and fallback to 64 bit
48+
return true;
49+
}
50+
}
51+
}
52+

0 commit comments

Comments
 (0)