Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
Refactor ADB detection, download automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
AtlasTheProto committed Sep 29, 2021
1 parent a979944 commit 7f96a85
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
9 changes: 1 addition & 8 deletions ADBForwarder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<TrimMode>link</TrimMode>
<TrimmerDefaultAction>link</TrimmerDefaultAction>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNetZip" Version="1.15.0" />
<PackageReference Include="SharpAdbClient" Version="2.3.23" />
</ItemGroup>

Expand Down
42 changes: 30 additions & 12 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
using System;
using SharpAdbClient;
using System.Net;
using System.IO;
using Ionic.Zip;

namespace ADBForwarder
{
class Program
{
const string sidequest = "\\Programs\\SideQuest\\resources\\app.asar.unpacked\\build\\platform-tools\\adb.exe";
static string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
static string adbPath = localAppData + sidequest; //i fucking hate this but path.combine was not having it
//const string sidequest = "\\Programs\\SideQuest\\resources\\app.asar.unpacked\\build\\platform-tools\\adb.exe";
//static string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
static string adbPath = Path.GetTempPath() + "\\adb\\platform-tools\\adb.exe";
static Uri uri = new Uri("https://dl.google.com/android/repository/platform-tools-latest-windows.zip");


static void Main(string[] args)
{
Console.WriteLine("starting");

var endPoint = new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort);

AdbServer server = new AdbServer();
try

if(!File.Exists(adbPath))
{
Console.WriteLine("ADB not found, downloading in the background...");
DownloadADB();
Console.WriteLine("Download Successful, starting ADB Daemon...");
var result = server.StartServer(adbPath, restartServerIfNewer: false);
Console.WriteLine("ADB Daemon Started");

}
catch
else
{
Console.WriteLine("SideQuest not installed.");
Console.ReadKey();
return;
var result = server.StartServer(adbPath, restartServerIfNewer: false);
Console.WriteLine("Starting ADB Daemon...");
}


var client = new AdbClient();
client.Connect(endPoint);
Expand Down Expand Up @@ -57,6 +61,20 @@ static void Main(string[] args)
}
}
}

static void DownloadADB()
{
using (var client = new WebClient())
{
client.DownloadFile(uri, "adb.zip");

using (ZipFile zip = ZipFile.Read("adb.zip"))
{
zip.ExtractAll(Path.GetTempPath() + "\\adb",
ExtractExistingFileAction.DoNotOverwrite);
}
}
}
}
}

0 comments on commit 7f96a85

Please sign in to comment.