Esempio n. 1
0
        private Task initComposer(string appPath, string composerMirrorUrl, List <string> userPathList)
        {
            Task t1 = Task.Run(() =>
            {
                //生成批处理文件
                File.WriteAllText(appPath + @"\composer.bat", "@php \"%~dp0composer.phar\" %*", System.Text.Encoding.Default);
                //判断Path环境变量中是否有当前目录
                List <string> pathList = PathEnvironment.getPathList(EnvironmentVariableTarget.Machine);
                pathList.AddRange(PathEnvironment.getPathList(EnvironmentVariableTarget.User));
                if (!pathList.Contains(appPath))
                {
                    userPathList.Add(appPath);
                    PathEnvironment.setPathList(userPathList, EnvironmentVariableTarget.User);
                }
            });

            //设置全局镜像
            if (composerMirrorUrl != "")
            {
                Task t2 = this.setComposerMirrorAsync(appPath, composerMirrorUrl);
                return(Task.WhenAll(t1, t2));
            }
            else
            {
                return(t1);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 用户Path环境变量中删除
 /// </summary>
 /// <param name="appPath"></param>
 private void removeUserPath(string appPath)
 {
     System.Collections.Generic.List <string> userPathList = PathEnvironment.getPathList(EnvironmentVariableTarget.User);
     if (userPathList.Contains(appPath))
     {
         userPathList.Remove(appPath);
         PathEnvironment.setPathList(userPathList, EnvironmentVariableTarget.User);
     }
 }
Esempio n. 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);
     }));
 }