diff --git a/MetaforceInstaller.Cli/Program.cs b/MetaforceInstaller.Cli/Program.cs index 88b7a88..bf8bf51 100644 --- a/MetaforceInstaller.Cli/Program.cs +++ b/MetaforceInstaller.Cli/Program.cs @@ -13,8 +13,7 @@ static class Program if (installationRequest is null || string.IsNullOrEmpty(installationRequest.ApkPath) || - string.IsNullOrEmpty(installationRequest.ZipPath) || - string.IsNullOrEmpty(installationRequest.OutputPath)) + string.IsNullOrEmpty(installationRequest.ZipPath)) { ShowUsage(); return; @@ -22,6 +21,11 @@ static class Program var adbService = new AdbService(); + var apkInfo = ApkScrapper.GetApkInfo(installationRequest.ApkPath); + var zipName = Path.GetFileName(installationRequest.ZipPath); + var outputPath = + @$"/storage/emulated/0/Android/data/{apkInfo.PackageName}/files/{zipName}"; + // Подписка на события прогресса adbService.ProgressChanged += OnProgressChanged; adbService.StatusChanged += OnStatusChanged; @@ -41,7 +45,7 @@ static class Program Console.WriteLine(); // Копирование файла - await adbService.CopyFileAsync(installationRequest.ZipPath, installationRequest.OutputPath, progress); + await adbService.CopyFileAsync(installationRequest.ZipPath, outputPath, progress); Console.WriteLine(); Console.WriteLine("Операция завершена успешно!"); diff --git a/MetaforceInstaller.Core/MetaforceInstaller.Core.csproj b/MetaforceInstaller.Core/MetaforceInstaller.Core.csproj index 7542437..0a85bfc 100644 --- a/MetaforceInstaller.Core/MetaforceInstaller.Core.csproj +++ b/MetaforceInstaller.Core/MetaforceInstaller.Core.csproj @@ -13,6 +13,7 @@ + diff --git a/MetaforceInstaller.Core/Models/ApkInfo.cs b/MetaforceInstaller.Core/Models/ApkInfo.cs new file mode 100644 index 0000000..9f042bf --- /dev/null +++ b/MetaforceInstaller.Core/Models/ApkInfo.cs @@ -0,0 +1,3 @@ +namespace MetaforceInstaller.Core.Models; + +public record ApkInfo(string PackageName, string VersionName, string VersionCode); \ No newline at end of file diff --git a/MetaforceInstaller.Core/Services/ApkScrapper.cs b/MetaforceInstaller.Core/Services/ApkScrapper.cs new file mode 100644 index 0000000..c06c543 --- /dev/null +++ b/MetaforceInstaller.Core/Services/ApkScrapper.cs @@ -0,0 +1,19 @@ +using AlphaOmega.Debug; +using MetaforceInstaller.Core.Models; + +namespace MetaforceInstaller.Core.Services; + +public static class ApkScrapper +{ + public static ApkInfo GetApkInfo(string apkPath) + { + using var apk = new ApkFile(apkPath); + if (apk is { IsValid: true, AndroidManifest: not null }) + { + return new ApkInfo(apk.AndroidManifest.Package, apk.AndroidManifest.VersionName, + apk.AndroidManifest.VersionCode); + } + + throw new Exception("Invalid APK file"); + } +} \ No newline at end of file