private Task downloadAppAsync(AppItem appItem, string zipTmpPath) { DownloadHelper downloadHelper = new DownloadHelper(); return(downloadHelper.downloadFileAsync(new Uri(appItem.downloadUrl), zipTmpPath, (string progressPercentage) => { this.setting.Dispatcher.Invoke(() => { appItem.progressPercentage = progressPercentage; }); })); }
public Task installAsync(string appPath, List <string> toRemoveDirs) { return(Task.Run(async() => { List <string> userPathList = PathEnvironment.getPathList(EnvironmentVariableTarget.User); //删除已安装的composer:文件+用户Path环境变量 if (toRemoveDirs != null) { bool needDelEnv = false; foreach (string tmpPath in toRemoveDirs) { FileInfo batFile = new FileInfo(tmpPath + @"\composer.bat"); if (batFile.Exists) { batFile.Delete(); } FileInfo pharFile = new FileInfo(tmpPath + @"\composer.phar"); if (pharFile.Exists) { pharFile.Delete(); } if (userPathList.Contains(tmpPath)) { needDelEnv = true; userPathList.Remove(tmpPath); } } if (needDelEnv) { PathEnvironment.setPathList(userPathList, EnvironmentVariableTarget.User); } } //获取url string composerUrl = null; string composerMirrorUrl = null; this.setting.Dispatcher.Invoke(() => { MainWindow mainWin = this.setting.Owner as MainWindow; composerUrl = mainWin.xmlResource.composerUrl; composerMirrorUrl = mainWin.xmlResource.composerMirror; }); //下载 string savePath = appPath + @"\composer.phar"; DownloadHelper downloadHelper = new DownloadHelper(); await downloadHelper.downloadFileAsync(new Uri(composerUrl), savePath, (long processed, long total) => { this.setting.Dispatcher.Invoke(() => { this.setting.composerProgressBar.IsIndeterminate = false; this.setting.composerProgressBar.Value = processed; this.setting.composerProgressBar.Maximum = total; }); }); this.setting.Dispatcher.Invoke(() => { this.setting.composerProgressBar.IsIndeterminate = true; }); //初始化 await this.initComposer(appPath, composerMirrorUrl, userPathList); })); }