commit 546011063f4ddee27b26cb1f17d97d8f841647cb Author: Elizaveta Chirkova Date: Sun Sep 14 10:46:13 2025 +0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add57be --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ \ No newline at end of file diff --git a/MetaforceInstaller.Cli/MetaforceInstaller.Cli.csproj b/MetaforceInstaller.Cli/MetaforceInstaller.Cli.csproj new file mode 100644 index 0000000..03c6098 --- /dev/null +++ b/MetaforceInstaller.Cli/MetaforceInstaller.Cli.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + diff --git a/MetaforceInstaller.Cli/Program.cs b/MetaforceInstaller.Cli/Program.cs new file mode 100644 index 0000000..f21fb42 --- /dev/null +++ b/MetaforceInstaller.Cli/Program.cs @@ -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}"); + // } + } +} \ No newline at end of file diff --git a/MetaforceInstaller.Cli/adb/AdbWinApi.dll b/MetaforceInstaller.Cli/adb/AdbWinApi.dll new file mode 100644 index 0000000..7abe26c Binary files /dev/null and b/MetaforceInstaller.Cli/adb/AdbWinApi.dll differ diff --git a/MetaforceInstaller.Cli/adb/AdbWinUsbApi.dll b/MetaforceInstaller.Cli/adb/AdbWinUsbApi.dll new file mode 100644 index 0000000..e7a6de1 Binary files /dev/null and b/MetaforceInstaller.Cli/adb/AdbWinUsbApi.dll differ diff --git a/MetaforceInstaller.Cli/adb/adb.exe b/MetaforceInstaller.Cli/adb/adb.exe new file mode 100644 index 0000000..85bfeaa Binary files /dev/null and b/MetaforceInstaller.Cli/adb/adb.exe differ diff --git a/MetaforceInstaller.sln b/MetaforceInstaller.sln new file mode 100644 index 0000000..44d9b89 --- /dev/null +++ b/MetaforceInstaller.sln @@ -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