not working
This commit is contained in:
parent
546011063f
commit
22f8df4642
2 changed files with 142 additions and 62 deletions
|
|
@ -14,7 +14,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="adb\adb.exe" />
|
<EmbeddedResource Include="adb\adb.exe" />
|
||||||
<EmbeddedResource Include="adb\AdbWinApi.dll" />
|
<EmbeddedResource Include="adb\AdbWinApi.dll" />
|
||||||
<EmbeddedResource Include="adb\AdbWinApi.dll" />
|
<EmbeddedResource Include="adb\AdbWinUsbApi.dll" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -7,39 +7,51 @@ namespace MetaforceInstaller.Cli;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
// 1. Получить имя апк и зипки, если не предоставлены - забить дефолтными значениями
|
||||||
|
// 2. Распаковать в временную директорию adb (готово)
|
||||||
|
// 3. Установить апк
|
||||||
|
// 4. Получить имя пакета
|
||||||
|
// 5. Сформировать строку пути для контента
|
||||||
|
// 6. Копировать зип по сформированному пути
|
||||||
|
|
||||||
static AdbClient adbClient;
|
static AdbClient adbClient;
|
||||||
static DeviceData deviceData;
|
static DeviceData deviceData;
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var (apkPath, zipPath, outputPath) = ParseArguments(args);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(apkPath) || string.IsNullOrEmpty(zipPath) || string.IsNullOrEmpty(outputPath))
|
||||||
|
{
|
||||||
|
ShowUsage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var adbPath = ExtractAdbFiles();
|
var adbPath = ExtractAdbFiles();
|
||||||
|
|
||||||
var server = new AdbServer();
|
var server = new AdbServer();
|
||||||
var result = server.StartServer(adbPath, restartServerIfNewer: false);
|
var result = server.StartServer(adbPath, restartServerIfNewer: false);
|
||||||
Console.WriteLine($"ADB сервер запущен: {result}");
|
Console.WriteLine($"ADB сервер запущен: {result}");
|
||||||
|
|
||||||
adbClient = new AdbClient();
|
adbClient = new AdbClient();
|
||||||
|
|
||||||
var devices = adbClient.GetDevices();
|
var devices = adbClient.GetDevices();
|
||||||
|
|
||||||
if (!devices.Any())
|
if (!devices.Any())
|
||||||
{
|
{
|
||||||
Console.WriteLine("Устройства не найдены. Подключите Android-устройство и включите отладку по USB.");
|
Console.WriteLine("Устройства не найдены. Подключите Android-устройство и включите отладку по USB.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceData = devices.FirstOrDefault();
|
deviceData = devices.FirstOrDefault();
|
||||||
Console.WriteLine($"Найдено устройство: {deviceData.Serial}");
|
Console.WriteLine($"Найдено устройство: {deviceData.Serial}");
|
||||||
Console.WriteLine($"Состояние: {deviceData.State}");
|
Console.WriteLine($"Состояние: {deviceData.State}");
|
||||||
Console.WriteLine($"Имя устройства: {deviceData.Name} - {deviceData.Model}");
|
Console.WriteLine($"Имя устройства: {deviceData.Name} - {deviceData.Model}");
|
||||||
|
|
||||||
// Пример установки APK
|
InstallApk(apkPath);
|
||||||
// InstallApk("path/to/your/app.apk");
|
CopyFileToDevice(zipPath, outputPath);
|
||||||
|
|
||||||
// Пример копирования файла
|
|
||||||
// CopyFileToDevice("path/to/your/file.zip", "/sdcard/file.zip");
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -47,14 +59,85 @@ class Program
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ExtractResource(string resourceName, string outputPath)
|
static void ShowUsage()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Использование:");
|
||||||
|
Console.WriteLine(
|
||||||
|
" MetaforceInstaller.exe --apk <путь_к_apk> --content <путь_к_zip> --output <путь_для контента>");
|
||||||
|
Console.WriteLine(" MetaforceInstaller.exe -a <путь_к_apk> -c <путь_к_zip> -o <путь_для_контента>");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Параметры:");
|
||||||
|
Console.WriteLine(" --apk, -a Путь к APK файлу");
|
||||||
|
Console.WriteLine(" --content, -c Путь к ZIP файлу с контентом");
|
||||||
|
Console.WriteLine(" --output, -o Путь для копирования контента");
|
||||||
|
Console.WriteLine(" --help, -h Показать эту справку");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Пример:");
|
||||||
|
Console.WriteLine(
|
||||||
|
" MetaforceInstaller.exe --apk \"C:\\app.apk\" --content \"C:\\data.zip\" --output \"/sdcard/data.zip\"");
|
||||||
|
Console.WriteLine(" MetaforceInstaller.exe -a app.apk -c data.zip -o /sdcard/data.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static (string? apkPath, string? zipPath, string? outputPath) ParseArguments(string[] args)
|
||||||
|
{
|
||||||
|
string apkPath = null;
|
||||||
|
string zipPath = null;
|
||||||
|
string outputPath = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < args.Length; i++)
|
||||||
|
{
|
||||||
|
switch (args[i].ToLower())
|
||||||
|
{
|
||||||
|
case "--apk":
|
||||||
|
case "-a":
|
||||||
|
if (i + 1 < args.Length)
|
||||||
|
{
|
||||||
|
apkPath = args[i + 1];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "--content":
|
||||||
|
case "-c":
|
||||||
|
if (i + 1 < args.Length)
|
||||||
|
{
|
||||||
|
zipPath = args[i + 1];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "--output":
|
||||||
|
case "-o":
|
||||||
|
if (i + 1 < args.Length)
|
||||||
|
{
|
||||||
|
outputPath = args[i + 1];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "--help":
|
||||||
|
case "-h":
|
||||||
|
ShowUsage();
|
||||||
|
Environment.Exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (apkPath, zipPath, outputPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ExtractResource(string resourceName, string outputPath)
|
||||||
{
|
{
|
||||||
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
|
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
|
||||||
using var fileStream = File.Create(outputPath);
|
using var fileStream = File.Create(outputPath);
|
||||||
stream.CopyTo(fileStream);
|
stream.CopyTo(fileStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
static string ExtractAdbFiles()
|
private static string ExtractAdbFiles()
|
||||||
{
|
{
|
||||||
var tempDir = Path.Combine(Path.GetTempPath(), "MetaforceInstaller", "adb");
|
var tempDir = Path.Combine(Path.GetTempPath(), "MetaforceInstaller", "adb");
|
||||||
Directory.CreateDirectory(tempDir);
|
Directory.CreateDirectory(tempDir);
|
||||||
|
|
@ -67,57 +150,54 @@ class Program
|
||||||
ExtractResource("MetaforceInstaller.Cli.adb.AdbWinApi.dll", Path.Combine(tempDir, "AdbWinApi.dll"));
|
ExtractResource("MetaforceInstaller.Cli.adb.AdbWinApi.dll", Path.Combine(tempDir, "AdbWinApi.dll"));
|
||||||
ExtractResource("MetaforceInstaller.Cli.adb.AdbWinUsbApi.dll", Path.Combine(tempDir, "AdbWinUsbApi.dll"));
|
ExtractResource("MetaforceInstaller.Cli.adb.AdbWinUsbApi.dll", Path.Combine(tempDir, "AdbWinUsbApi.dll"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return adbPath;
|
return adbPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InstallApk(string apkPath)
|
private static void InstallApk(string apkPath)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
try
|
||||||
// try
|
{
|
||||||
// {
|
if (!File.Exists(apkPath))
|
||||||
// if (!File.Exists(apkPath))
|
{
|
||||||
// {
|
Console.WriteLine($"APK файл не найден: {apkPath}");
|
||||||
// Console.WriteLine($"APK файл не найден: {apkPath}");
|
return;
|
||||||
// return;
|
}
|
||||||
// }
|
|
||||||
//
|
Console.WriteLine($"Установка APK: {apkPath}");
|
||||||
// Console.WriteLine($"Установка APK: {apkPath}");
|
|
||||||
//
|
var packageManager = new PackageManager(adbClient, deviceData);
|
||||||
// using var apkStream = File.OpenRead(apkPath);
|
packageManager.InstallPackage(apkPath, new Action<InstallProgressEventArgs>(o => { }));
|
||||||
// var packageManager = new PackageManager(adbClient, deviceData);
|
|
||||||
// packageManager.InstallPackage(apkStream, "temp.apk");
|
Console.WriteLine("APK успешно установлен!");
|
||||||
//
|
}
|
||||||
// Console.WriteLine("APK успешно установлен!");
|
catch (Exception ex)
|
||||||
// }
|
{
|
||||||
// catch (Exception ex)
|
Console.WriteLine($"Ошибка установки APK: {ex.Message}");
|
||||||
// {
|
}
|
||||||
// Console.WriteLine($"Ошибка установки APK: {ex.Message}");
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CopyFileToDevice(string localPath, string remotePath)
|
private static void CopyFileToDevice(string localPath, string remotePath)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
try
|
||||||
// try
|
{
|
||||||
// {
|
if (!File.Exists(localPath))
|
||||||
// if (!File.Exists(localPath))
|
{
|
||||||
// {
|
Console.WriteLine($"Локальный файл не найден: {localPath}");
|
||||||
// Console.WriteLine($"Локальный файл не найден: {localPath}");
|
return;
|
||||||
// return;
|
}
|
||||||
// }
|
|
||||||
//
|
Console.WriteLine($"Копирование файла {localPath} в {remotePath}");
|
||||||
// Console.WriteLine($"Копирование файла {localPath} в {remotePath}");
|
|
||||||
//
|
using var fileStream = File.OpenRead(localPath);
|
||||||
// using var fileStream = File.OpenRead(localPath);
|
var syncService = new SyncService(adbClient, deviceData);
|
||||||
// var syncService = new SyncService(adbClient, deviceData);
|
syncService.Push(fileStream, remotePath, UnixFileStatus.DefaultFileMode, DateTime.Now, null);
|
||||||
// syncService.Push(fileStream, remotePath, UnixFileStatus.DefaultFileMode, DateTime.Now, null);
|
|
||||||
//
|
Console.WriteLine("Файл успешно скопирован!");
|
||||||
// Console.WriteLine("Файл успешно скопирован!");
|
}
|
||||||
// }
|
catch (Exception ex)
|
||||||
// catch (Exception ex)
|
{
|
||||||
// {
|
Console.WriteLine($"Ошибка копирования файла: {ex.Message}");
|
||||||
// Console.WriteLine($"Ошибка копирования файла: {ex.Message}");
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue