Skip to content

Commit

Permalink
Drop SharpAdbClient as it's not working with last scrcpy release
Browse files Browse the repository at this point in the history
  • Loading branch information
alfeg committed Jul 27, 2019
1 parent 1f2bce4 commit 8747d83
Show file tree
Hide file tree
Showing 11 changed files with 385 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,5 @@ ASALocalRun
.nvuser

# MFractors (Xamarin productivity tool) working folder
.mfractor
.mfractor
/_ReSharper.Caches
98 changes: 98 additions & 0 deletions DeviceManager/AdbManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;

namespace DeviceManager
{
public class AdbManager
{
private readonly string scrScpPath;
private readonly string adb;
public AdbManager(string scrScpPath)
{
this.scrScpPath = scrScpPath;
adb = Path.Combine(this.scrScpPath, "adb.exe");
}

public List<DeviceData> GetDevices()
{
var result = ConsoleExeRunner.Execute(adb, "devices");

bool skipping = true;
var deviceSerials = new List<string>();
foreach (var line in result)
{
if (line.StartsWith("List of devices"))
{
skipping = false;
continue;
}

if(skipping) continue;

if(string.IsNullOrWhiteSpace(line)) continue;

deviceSerials.Add(line.Split('\t')[0]);
}

var devices = new List<DeviceData>();
foreach (var serial in deviceSerials)
{
var data = GetDeviceData(serial);

devices.Add(data);
}

return devices;
}

public DeviceData GetDeviceData(string serial)
{
var result = ConsoleExeRunner.Execute(adb, $"-s {serial} shell getprop");

/*
*
*[ro.product.model]: [Nexus 9]
[ro.product.name]: [volantis]
*
*/
var deviceData = new DeviceData
{
Serial = serial,
State = DeviceState.Offline

};

bool TryParse(string line, out (string key, string value) res)
{
var match = Regex.Match(line, @"\[(?<key>.*)\]: \[(?<value>.*)\]");
if (match.Success)
{
res = (match.Groups["key"].Value, match.Groups["value"].Value);
return true;
}

res = (String.Empty, String.Empty);
return false;
}

foreach (var line in result)
{
if (TryParse(line, out var kv))
{
deviceData.State = DeviceState.Online;
if (kv.key == "ro.product.model") { deviceData.Model = kv.value; }
if (kv.key == "ro.product.name") { deviceData.Name = kv.value; }
}
}

return deviceData;
}

public void Reboot(DeviceData device)
{
ConsoleExeRunner.Execute(adb, $"-s {device.Serial} reboot");
}
}
}
37 changes: 37 additions & 0 deletions DeviceManager/ConsoleExeRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace DeviceManager
{
public class ConsoleExeRunner
{
public static string[] Execute(string cmd, string args)
{
var info = new ProcessStartInfo
{
FileName = cmd,
Arguments = args,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardOutput = true,
UseShellExecute = false
};
var p = Process.Start(info);
var result = ReadLines(p.StandardOutput).ToArray();
p.WaitForExit(5000);

return result;
}

public static IEnumerable<string> ReadLines(StreamReader reader)
{
string line;
while ((line = reader.ReadLine()) != null)
{
yield return line;
}
}
}
}
10 changes: 10 additions & 0 deletions DeviceManager/DeviceData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DeviceManager
{
public class DeviceData
{
public string Serial { get; set; }
public string Name { get; set; }
public string Model { get; set; }
public DeviceState State { get; set; }
}
}
60 changes: 51 additions & 9 deletions DeviceManager/DeviceManager.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Costura.Fody.4.0.0\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.4.0.0\build\Costura.Fody.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -14,6 +15,22 @@
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>1.1.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -37,12 +54,21 @@
<PropertyGroup>
<ApplicationIcon>Resources\TrayIcon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>57B639B7C625C96B0AE238A1E54A464948A41183</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>DeviceManager_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="Costura, Version=3.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.3.1.0\lib\net46\Costura.dll</HintPath>
</Reference>
<Reference Include="SharpAdbClient, Version=2.2.0.0, Culture=neutral, PublicKeyToken=d728076f5d82a2e8, processorArchitecture=MSIL">
<HintPath>..\packages\SharpAdbClient.2.2.9\lib\net451\SharpAdbClient.dll</HintPath>
<Reference Include="Costura, Version=4.0.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.4.0.0\lib\net40\Costura.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -57,6 +83,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AdbManager.cs" />
<Compile Include="ConsoleExeRunner.cs" />
<Compile Include="DeviceData.cs" />
<Compile Include="DeviceState.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resource.Designer.cs">
Expand All @@ -78,6 +108,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="DeviceManager_TemporaryKey.pfx" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand All @@ -98,14 +129,25 @@
<Content Include="FodyWeavers.xml" />
<None Include="Resources\TrayIcon.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.7.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.3.1.3\build\Fody.targets" Condition="Exists('..\packages\Fody.3.1.3\build\Fody.targets')" />
<Import Project="..\packages\Fody.5.1.1\build\Fody.targets" Condition="Exists('..\packages\Fody.5.1.1\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.3.1.3\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.3.1.3\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.3.1.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.3.1.0\build\Costura.Fody.targets'))" />
<Error Condition="!Exists('..\packages\Fody.5.1.1\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.5.1.1\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.4.0.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.4.0.0\build\Costura.Fody.props'))" />
</Target>
<Import Project="..\packages\Costura.Fody.3.1.0\build\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.3.1.0\build\Costura.Fody.targets')" />
</Project>
13 changes: 13 additions & 0 deletions DeviceManager/DeviceManager.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory>publish\</PublishUrlHistory>
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>
7 changes: 7 additions & 0 deletions DeviceManager/DeviceState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DeviceManager
{
public enum DeviceState
{
Offline, Online
}
}
7 changes: 3 additions & 4 deletions DeviceManager/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
<Costura>
</Costura>
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura></Costura>
</Weavers>
Loading

0 comments on commit 8747d83

Please sign in to comment.