Skip to content

Commit

Permalink
Added ability to use system adb
Browse files Browse the repository at this point in the history
  • Loading branch information
Meister1593 committed Aug 14, 2024
1 parent d86419f commit dfa322e
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions ADBForwarder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ private static void Main()
var adbPath = Path.Combine(adbFolderPath, "platform-tools");
var downloadUri = "https://dl.google.com/android/repository/platform-tools-latest-{0}.zip";

string platformSpecificAdbExecutable;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Console.WriteLine("Platform: Linux");

adbPath = Path.Combine(adbPath, "adb");
platformSpecificAdbExecutable = "adb";
downloadUri = string.Format(downloadUri, "linux");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine("Platform: Windows");

adbPath = Path.Combine(adbPath, "adb.exe");
platformSpecificAdbExecutable = "adb.exe";
downloadUri = string.Format(downloadUri, "windows");
}
else
Expand All @@ -70,9 +69,29 @@ private static void Main()
return;
}

var absoluteAdbPath = Path.Combine(currentDirectory, adbPath);
if (!File.Exists(absoluteAdbPath))
adbPath = Path.Combine(adbPath, platformSpecificAdbExecutable);

var absoluteAdbPath = adbPath;

var foundSystemAdb = false;
var pathVariableString = Environment.GetEnvironmentVariable("PATH");
if (pathVariableString != null)
{
foreach (var pathString in pathVariableString.Split(":"))
{
if (File.Exists(Path.Combine(pathString, platformSpecificAdbExecutable)))
{
Console.WriteLine("Using system ADB");
foundSystemAdb = true;
absoluteAdbPath = Path.Combine(pathString, platformSpecificAdbExecutable);
break;
}
}
}

if (!foundSystemAdb && !File.Exists(Path.Combine(currentDirectory, adbPath)))
{
absoluteAdbPath = Path.Combine(currentDirectory, adbPath);
Console.WriteLine("ADB not found, downloading...");
DownloadAdb(adbFolderPath, downloadUri).Wait();

Expand All @@ -84,7 +103,7 @@ private static void Main()
}
}

Server.StartServer(absoluteAdbPath, false);
Server.StartServer(absoluteAdbPath, true);

Client.Connect(EndPoint);

Expand Down

0 comments on commit dfa322e

Please sign in to comment.