public void InstallApk(DeviceBasicInfo targetDevice) { Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog(); fileDialog.Reset(); fileDialog.Title = App.Current.Resources["SelecteAFile"].ToString(); fileDialog.Filter = "安卓安装包ApkFile(*.apk)|*.apk"; fileDialog.Multiselect = true; if (fileDialog.ShowDialog() == true) { ApkInstaller installer = new ApkInstaller(); List <FileInfo> files = new List <FileInfo>(); foreach (string fileName in fileDialog.FileNames) { files.Add(new FileInfo(fileName)); } var args = new ApkInstallerArgs() { DevBasicInfo = targetDevice, Files = files, }; installer.Init(args); new ApkInstallingWindow(installer, files).ShowDialog(); } else { return; } }
public ApkInstallingWindow(ApkInstaller installer, List <FileInfo> files) { InitializeComponent(); this.installer = installer; _apkFilesCount = files.Count; Owner = App.Current.MainWindow; TBCountOfInstalled.Text = $"{_alreadyInstalledCount}/{_apkFilesCount}"; this.installer.Finished += (s, e) => { this.Dispatcher.Invoke(() => { Close(); new FlowResultWindow(e.Result).ShowDialog(); }); }; this.installer.OutputReceived += (s, e) => { this.Dispatcher.Invoke(() => { var bytes = Encoding.Default.GetBytes(e.Text); TBOutput.AppendText(Encoding.UTF8.GetString(bytes) + "\n"); TBOutput.ScrollToEnd(); }); }; this.installer.AApkIstanlltionCompleted += (s, e) => { this.Dispatcher.Invoke(() => { ProgressAdd(); if (!e.IsSuccess) //如果这次安装是失败的 { //询问用户是否在安装失败的情况下继续 //TODO } }); return(true); }; }