Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<Title>BrowserStackLocal</Title>
<Product>BrowserStackLocal</Product>
<Description>C# Bindings for BrowserStack Local</Description>
<Version>2.3.1</Version>
<AssemblyVersion>2.3.1</AssemblyVersion>
<FileVersion>2.3.1</FileVersion>
<Version>2.4.0</Version>
<AssemblyVersion>2.4.0</AssemblyVersion>
<FileVersion>2.4.0</FileVersion>
<Authors>BrowserStack</Authors>
<Company>BrowserStack</Company>
<Copyright>Copyright © 2016</Copyright>
Expand All @@ -31,4 +31,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
59 changes: 50 additions & 9 deletions BrowserStackLocal/BrowserStackLocal/BrowserStackTunnel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public enum LocalState { Idle, Connecting, Connected, Error, Disconnected };

public class BrowserStackTunnel : IDisposable
{
static readonly string binaryName = isDarwin() ? "BrowserStackLocal-darwin-x64" : "BrowserStackLocal.exe";
static readonly string downloadURL = isDarwin() ?
"https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal-darwin-x64" :
"https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal.exe";
static readonly string homepath = isDarwin() ?
static readonly string uname = Util.GetUName();
static readonly string binaryName = GetBinaryName();
static readonly string downloadURL = "https://www.browserstack.com/local-testing/downloads/binaries/" + binaryName;

static readonly string homepath = !IsWindows() ?
Environment.GetFolderPath(Environment.SpecialFolder.Personal) :
Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
public static readonly string[] basePaths = new string[] {
Expand All @@ -37,10 +37,51 @@ public class BrowserStackTunnel : IDisposable

Process process = null;

static Boolean isDarwin()
static bool IsDarwin(string osName)
{
return osName.Contains("darwin");
}


static bool IsWindows()
{
return Environment.OSVersion.VersionString?.ToLower().Contains("windows") ?? false;
}

static bool IsLinux(string osName)
{
return osName.Contains("linux");
}

static bool IsAlpine()
{
OperatingSystem os = Environment.OSVersion;
return os.Platform.ToString() == "Unix";
try
{
string[] output = Util.RunShellCommand("grep", "-w \'NAME\' /etc/os-release");
return output[0]?.ToLower()?.Contains("alpine") ?? false;
}
catch (System.Exception ex)
{
Console.WriteLine("Exception while check isAlpine " + ex);
}
return false;
}

static string GetBinaryName()
{
if (IsWindows()) return "BrowserStackLocal.exe";
if (IsDarwin(uname)) return "BrowserStackLocal-darwin-x64";

if (IsLinux(uname))
{
if (Util.Is64BitOS())
{
return IsAlpine() ? "BrowserStackLocal-alpine" : "BrowserStackLocal-linux-x64";
}
return "BrowserStackLocal-linux-ia32";
}

return "BrowserStackLocal.exe";
}

public virtual void addBinaryPath(string binaryAbsolute)
Expand Down Expand Up @@ -79,7 +120,7 @@ public virtual void fallbackPaths()

public void modifyBinaryPermission()
{
if (isDarwin())
if (!IsWindows())
{
try
{
Expand Down
52 changes: 52 additions & 0 deletions BrowserStackLocal/BrowserStackLocal/Util.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Diagnostics;

namespace BrowserStack
{
public class Util {

// Only Unix Support
public static string[] RunShellCommand(string command, string args = "")
{
ProcessStartInfo psi = new ProcessStartInfo {
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
FileName = command,
Arguments = args
};

Process process = new Process { StartInfo = psi };
process.Start();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
return new string[]{output, error};
}

public static string GetUName()
{
string osName = "";
try
{
string[] output = RunShellCommand("uname");
osName = output[0]?.ToLower();
}
catch (System.Exception) {}
return osName;
}

// Using for Linux Only
public static bool Is64BitOS()
{
#if NET48_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NETCOREAPP3_0_OR_GREATER
return Environment.Is64BitOperatingSystem;
#endif
// https://learn.microsoft.com/en-gb/dotnet/standard/choosing-core-framework-server?WT.mc_id=dotnet-35129-website
// linux won't be supported in .NET Framework and fallback to 64 bit
return true;
}
}
}

Loading