Initial commit
This commit is contained in:
commit
546011063f
7 changed files with 164 additions and 0 deletions
20
MetaforceInstaller.Cli/MetaforceInstaller.Cli.csproj
Normal file
20
MetaforceInstaller.Cli/MetaforceInstaller.Cli.csproj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AdvancedSharpAdbClient" Version="3.4.14" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="adb\adb.exe" />
|
||||
<EmbeddedResource Include="adb\AdbWinApi.dll" />
|
||||
<EmbeddedResource Include="adb\AdbWinApi.dll" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
123
MetaforceInstaller.Cli/Program.cs
Normal file
123
MetaforceInstaller.Cli/Program.cs
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
using System.Reflection;
|
||||
using AdvancedSharpAdbClient;
|
||||
using AdvancedSharpAdbClient.DeviceCommands;
|
||||
using AdvancedSharpAdbClient.Models;
|
||||
|
||||
namespace MetaforceInstaller.Cli;
|
||||
|
||||
class Program
|
||||
{
|
||||
static AdbClient adbClient;
|
||||
static DeviceData deviceData;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var adbPath = ExtractAdbFiles();
|
||||
|
||||
var server = new AdbServer();
|
||||
var result = server.StartServer(adbPath, restartServerIfNewer: false);
|
||||
Console.WriteLine($"ADB сервер запущен: {result}");
|
||||
|
||||
adbClient = new AdbClient();
|
||||
|
||||
var devices = adbClient.GetDevices();
|
||||
|
||||
if (!devices.Any())
|
||||
{
|
||||
Console.WriteLine("Устройства не найдены. Подключите Android-устройство и включите отладку по USB.");
|
||||
return;
|
||||
}
|
||||
|
||||
deviceData = devices.FirstOrDefault();
|
||||
Console.WriteLine($"Найдено устройство: {deviceData.Serial}");
|
||||
Console.WriteLine($"Состояние: {deviceData.State}");
|
||||
Console.WriteLine($"Имя устройства: {deviceData.Name} - {deviceData.Model}");
|
||||
|
||||
// Пример установки APK
|
||||
// InstallApk("path/to/your/app.apk");
|
||||
|
||||
// Пример копирования файла
|
||||
// CopyFileToDevice("path/to/your/file.zip", "/sdcard/file.zip");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
static void ExtractResource(string resourceName, string outputPath)
|
||||
{
|
||||
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
|
||||
using var fileStream = File.Create(outputPath);
|
||||
stream.CopyTo(fileStream);
|
||||
}
|
||||
|
||||
static string ExtractAdbFiles()
|
||||
{
|
||||
var tempDir = Path.Combine(Path.GetTempPath(), "MetaforceInstaller", "adb");
|
||||
Directory.CreateDirectory(tempDir);
|
||||
|
||||
var adbPath = Path.Combine(tempDir, "adb.exe");
|
||||
|
||||
if (!File.Exists(adbPath))
|
||||
{
|
||||
ExtractResource("MetaforceInstaller.Cli.adb.adb.exe", adbPath);
|
||||
ExtractResource("MetaforceInstaller.Cli.adb.AdbWinApi.dll", Path.Combine(tempDir, "AdbWinApi.dll"));
|
||||
ExtractResource("MetaforceInstaller.Cli.adb.AdbWinUsbApi.dll", Path.Combine(tempDir, "AdbWinUsbApi.dll"));
|
||||
}
|
||||
|
||||
return adbPath;
|
||||
}
|
||||
|
||||
static void InstallApk(string apkPath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// try
|
||||
// {
|
||||
// if (!File.Exists(apkPath))
|
||||
// {
|
||||
// Console.WriteLine($"APK файл не найден: {apkPath}");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Console.WriteLine($"Установка APK: {apkPath}");
|
||||
//
|
||||
// using var apkStream = File.OpenRead(apkPath);
|
||||
// var packageManager = new PackageManager(adbClient, deviceData);
|
||||
// packageManager.InstallPackage(apkStream, "temp.apk");
|
||||
//
|
||||
// Console.WriteLine("APK успешно установлен!");
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine($"Ошибка установки APK: {ex.Message}");
|
||||
// }
|
||||
}
|
||||
|
||||
static void CopyFileToDevice(string localPath, string remotePath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// try
|
||||
// {
|
||||
// if (!File.Exists(localPath))
|
||||
// {
|
||||
// Console.WriteLine($"Локальный файл не найден: {localPath}");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Console.WriteLine($"Копирование файла {localPath} в {remotePath}");
|
||||
//
|
||||
// using var fileStream = File.OpenRead(localPath);
|
||||
// var syncService = new SyncService(adbClient, deviceData);
|
||||
// syncService.Push(fileStream, remotePath, UnixFileStatus.DefaultFileMode, DateTime.Now, null);
|
||||
//
|
||||
// Console.WriteLine("Файл успешно скопирован!");
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine($"Ошибка копирования файла: {ex.Message}");
|
||||
// }
|
||||
}
|
||||
}
|
||||
BIN
MetaforceInstaller.Cli/adb/AdbWinApi.dll
Normal file
BIN
MetaforceInstaller.Cli/adb/AdbWinApi.dll
Normal file
Binary file not shown.
BIN
MetaforceInstaller.Cli/adb/AdbWinUsbApi.dll
Normal file
BIN
MetaforceInstaller.Cli/adb/AdbWinUsbApi.dll
Normal file
Binary file not shown.
BIN
MetaforceInstaller.Cli/adb/adb.exe
Normal file
BIN
MetaforceInstaller.Cli/adb/adb.exe
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue