Beispiel #1
0
 public Task <bool> updateAsync(string xmlResourcePath, string xmlResourceTmpPath)
 {
     return(Task <bool> .Run(async() =>
     {
         string updateUrl = @"https://github.com/liuguangw/php_env/raw/master/php_env/data/resource.xml";
         //下载
         DownloadHelper downloadHelper = new DownloadHelper();
         await downloadHelper.downloadFileAsync(new Uri(updateUrl), xmlResourceTmpPath, (long processed, long total) =>
         {
             this.setting.Dispatcher.Invoke(() =>
             {
                 this.setting.updateProgressBar.IsIndeterminate = false;
                 this.setting.updateProgressBar.Value = processed;
                 this.setting.updateProgressBar.Maximum = total;
             });
         });
         this.setting.Dispatcher.Invoke(() =>
         {
             this.setting.composerProgressBar.IsIndeterminate = true;
         });
         //获取两者的md5
         string[] md5Result = await this.compareMd5Async(xmlResourcePath, xmlResourceTmpPath);
         bool needUpdate = (md5Result[0] != md5Result[1]);
         FileInfo tmpFileInfo = new FileInfo(xmlResourceTmpPath);
         if (needUpdate)
         {
             tmpFileInfo.CopyTo(xmlResourcePath, true);
         }
         tmpFileInfo.Delete();
         return needUpdate;
     }));
 }
Beispiel #2
0
        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;
                });
            }));
        }
Beispiel #3
0
 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);
     }));
 }