This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Mantas-2155X/main
Recode, port to Linux, quest 1 support
- Loading branch information
Showing
8 changed files
with
305 additions
and
107 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{D61008B2-6278-4C15-9F4B-D4E229573D4E}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>ADBForwarder</RootNamespace> | ||
<AssemblyName>ADBForwarder</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<LangVersion>8</LangVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>none</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="ICSharpCode.SharpZipLib, Version=1.3.3.11, Culture=neutral, PublicKeyToken=1b03e6acf1164f73"> | ||
<HintPath>..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"> | ||
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="mscorlib" /> | ||
<Reference Include="SharpAdbClient, Version=2.3.0.0, Culture=neutral, PublicKeyToken=d728076f5d82a2e8"> | ||
<HintPath>..\packages\SharpAdbClient.2.3.23\lib\net461\SharpAdbClient.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"> | ||
<HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Configuration" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Drawing.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"> | ||
<HintPath>..\packages\System.Drawing.Common.4.5.0\lib\net461\System.Drawing.Common.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Net" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="PostBuildUnix" AfterTargets="PostBuildEvent" Condition=" '$(OS)' == 'Unix' "> | ||
<Exec Command="mkdir $(TargetDir)Libraries" /> | ||
<Exec Command="mv $(TargetDir)*.dll $(TargetDir)Libraries" /> | ||
<Exec Command="mv $(TargetDir)*.xml $(TargetDir)Libraries" /> | ||
<Exec Command="mv $(TargetDir)*.pdb $(TargetDir)Libraries" /> | ||
</Target> | ||
<Target Name="PostBuildWindows" AfterTargets="PostBuildEvent" Condition=" '$(OS)' != 'Unix' "> | ||
<Exec Command="mkdir $(TargetDir)Libraries" /> | ||
<Exec Command="move $(TargetDir)*.dll $(TargetDir)Libraries" /> | ||
<Exec Command="move $(TargetDir)*.xml $(TargetDir)Libraries" /> | ||
<Exec Command="move $(TargetDir)*.pdb $(TargetDir)Libraries" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> | ||
</startup> | ||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<probing privatePath="Libraries;"/> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Reflection; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
|
||
using SharpAdbClient; | ||
using ICSharpCode.SharpZipLib.Zip; | ||
|
||
namespace ADBForwarder | ||
{ | ||
internal class Program | ||
{ | ||
public const string VERSION = "0.2"; | ||
|
||
private static readonly string[] deviceNames = | ||
{ | ||
"monterey", // Oculus Quest 1 | ||
"hollywood" // Oculus Quest 2 | ||
}; | ||
|
||
private static readonly AdbClient client = new AdbClient(); | ||
private static readonly AdbServer server = new AdbServer(); | ||
private static readonly IPEndPoint endPoint = new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort); | ||
|
||
private static void Main() | ||
{ | ||
var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
if (currentDirectory == null) | ||
{ | ||
Console.WriteLine("Path error!"); | ||
return; | ||
} | ||
|
||
var adbPath = "adb/platform-tools/{0}"; | ||
var downloadUri = "https://dl.google.com/android/repository/platform-tools-latest-{0}.zip"; | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
Console.WriteLine("Platform: Linux"); | ||
|
||
adbPath = string.Format(adbPath, "adb"); | ||
downloadUri = string.Format(downloadUri, "linux"); | ||
} | ||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
Console.WriteLine("Platform: Windows"); | ||
|
||
adbPath = string.Format(adbPath, "adb.exe"); | ||
downloadUri = string.Format(downloadUri, "windows"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Unsupported platform!"); | ||
return; | ||
} | ||
|
||
var absoluteAdbPath = Path.Combine(currentDirectory, adbPath); | ||
if (!File.Exists(absoluteAdbPath)) | ||
{ | ||
Console.WriteLine("ADB not found, downloading in the background..."); | ||
DownloadADB(downloadUri); | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
SetExecutable(absoluteAdbPath); | ||
} | ||
|
||
Console.WriteLine("Starting ADB Daemon..."); | ||
server.StartServer(absoluteAdbPath, false); | ||
|
||
client.Connect(endPoint); | ||
|
||
var monitor = new DeviceMonitor(new AdbSocket(endPoint)); | ||
monitor.DeviceConnected += Monitor_DeviceConnected; | ||
monitor.DeviceDisconnected += Monitor_DeviceDisconnected; | ||
monitor.Start(); | ||
|
||
while (true) | ||
{ | ||
// Main thread needs to stay alive, 100ms is acceptable idle time | ||
Thread.Sleep(100); | ||
} | ||
} | ||
|
||
private static void Monitor_DeviceConnected(object sender, DeviceDataEventArgs e) | ||
{ | ||
Console.WriteLine($"Connected device: {e.Device.Serial}"); | ||
Forward(e.Device); | ||
} | ||
|
||
private static void Monitor_DeviceDisconnected(object sender, DeviceDataEventArgs e) | ||
{ | ||
Console.WriteLine($"Disconnected device: {e.Device.Serial}"); | ||
} | ||
|
||
private static void Forward(DeviceData device) | ||
{ | ||
// DeviceConnected calls without product set yet | ||
Thread.Sleep(1000); | ||
|
||
foreach (var deviceData in client.GetDevices().Where(deviceData => device.Serial == deviceData.Serial)) | ||
{ | ||
if (!deviceNames.Contains(deviceData.Product)) | ||
{ | ||
Console.WriteLine($"Skipped forwarding device: {(string.IsNullOrEmpty(deviceData.Product) ? deviceData.Serial : deviceData.Product)}"); | ||
return; | ||
} | ||
|
||
client.CreateForward(deviceData, 9943, 9943); | ||
client.CreateForward(deviceData, 9944, 9944); | ||
|
||
Console.WriteLine($"Successfully forwarded device: {deviceData.Serial} [{deviceData.Product}]"); | ||
|
||
return; | ||
} | ||
} | ||
|
||
private static void DownloadADB(string downloadUri) | ||
{ | ||
using var web = new WebClient(); | ||
web.DownloadFile(downloadUri, "adb.zip"); | ||
Console.WriteLine("Download successful"); | ||
|
||
var zip = new FastZip(); | ||
zip.ExtractZip("adb.zip", "adb", null); | ||
Console.WriteLine("Extraction successful"); | ||
|
||
File.Delete("adb.zip"); | ||
} | ||
|
||
private static void SetExecutable(string fileName) | ||
{ | ||
Console.WriteLine("Giving adb executable permissions"); | ||
|
||
var args = $"chmod u+x {fileName}"; | ||
var escapedArgs = args.Replace("\"", "\\\""); | ||
|
||
using var process = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
WindowStyle = ProcessWindowStyle.Hidden, | ||
FileName = "/bin/bash", | ||
Arguments = $"-c \"{escapedArgs}\"" | ||
} | ||
}; | ||
|
||
process.Start(); | ||
process.WaitForExit(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("ADBForwarder")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("ADBForwarder")] | ||
[assembly: AssemblyCopyright("Copyright © 2021")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("D61008B2-6278-4C15-9F4B-D4E229573D4E")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion(ADBForwarder.Program.VERSION)] | ||
[assembly: AssemblyFileVersion(ADBForwarder.Program.VERSION)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Microsoft.Extensions.Logging.Abstractions" version="2.0.0" targetFramework="net461" /> | ||
<package id="SharpAdbClient" version="2.3.23" targetFramework="net461" /> | ||
<package id="SharpZipLib" version="1.3.3" targetFramework="net461" /> | ||
<package id="System.Buffers" version="4.5.0" targetFramework="net461" /> | ||
<package id="System.Drawing.Common" version="4.5.0" targetFramework="net461" /> | ||
</packages> |
Oops, something went wrong.