Initial commit

This commit is contained in:
Elizaveta Chirkova 2025-09-14 10:46:13 +05:00
commit 546011063f
7 changed files with 164 additions and 0 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/

View 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>

View 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}");
// }
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

16
MetaforceInstaller.sln Normal file
View file

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetaforceInstaller.Cli", "MetaforceInstaller.Cli\MetaforceInstaller.Cli.csproj", "{4928C2AC-6B63-4B18-9472-705807A15893}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4928C2AC-6B63-4B18-9472-705807A15893}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4928C2AC-6B63-4B18-9472-705807A15893}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4928C2AC-6B63-4B18-9472-705807A15893}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4928C2AC-6B63-4B18-9472-705807A15893}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal