Ejemplo n.º 1
0
        private async Task <bool> DownloadIWYUWithProgressBar(string executablePath, IVsThreadedWaitDialogFactory dialogFactory)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsThreadedWaitDialog2 progressDialog;

            dialogFactory.CreateInstance(out progressDialog);
            if (progressDialog == null)
            {
                Output.Instance.WriteLine("Failed to get create wait dialog.");
                return(false);
            }

            progressDialog.StartWaitDialogWithPercentageProgress(
                szWaitCaption: "Include Toolbox - Downloading include-what-you-use",
                szWaitMessage: "", // comes in later.
                szProgressText: null,
                varStatusBmpAnim: null,
                szStatusBarText: "Downloading include-what-you-use",
                fIsCancelable: true,
                iDelayToShowDialog: 0,
                iTotalSteps: 100,
                iCurrentStep: 0);

            var cancellationToken = new System.Threading.CancellationTokenSource();

            try
            {
                await IWYUDownload.DownloadIWYU(executablePath, delegate(string section, string status, float percentage)
                {
                    ThreadHelper.ThrowIfNotOnUIThread();

                    bool canceled;
                    progressDialog.UpdateProgress(
                        szUpdatedWaitMessage: section,
                        szProgressText: status,
                        szStatusBarText: $"Downloading include-what-you-use - {section} - {status}",
                        iCurrentStep: (int)(percentage * 100),
                        iTotalSteps: 100,
                        fDisableCancel: true,
                        pfCanceled: out canceled);
                    if (canceled)
                    {
                        cancellationToken.Cancel();
                    }
                }, cancellationToken.Token);
            }
            catch (Exception e)
            {
                await Output.Instance.ErrorMsg("Failed to download include-what-you-use: {0}", e);

                return(false);
            }
            finally
            {
                progressDialog.EndWaitDialog();
            }

            return(true);
        }
        public async Task DownloadAsync()
        {
            var executableDir = GetCleanExecutableDir();

            Assert.AreEqual(false, File.Exists(executableDir));
            Assert.AreEqual(true, await IWYUDownload.IsNewerVersionAvailableOnline(executableDir)); // Nothing here practically means that there is a new version.

            await IWYUDownload.DownloadIWYU(executableDir, ReportProgress, new CancellationToken());

            Assert.AreEqual(false, await IWYUDownload.IsNewerVersionAvailableOnline(executableDir));
            Assert.AreEqual(true, File.Exists(executableDir));
        }
Ejemplo n.º 3
0
        public void Download()
        {
            var executableDir = GetCleanExecutableDir();

            Assert.AreEqual(false, File.Exists(executableDir));
            Assert.AreEqual(true, IWYUDownload.IsNewerVersionAvailableOnline(executableDir).Result); // Nothing here practically means that there is a new version.

            var downloadTask = IWYUDownload.DownloadIWYU(executableDir, ReportProgress, new CancellationToken());

            downloadTask.Wait();

            Assert.AreEqual(false, IWYUDownload.IsNewerVersionAvailableOnline(executableDir).Result);
            Assert.AreEqual(true, File.Exists(executableDir));
        }
Ejemplo n.º 4
0
        private async Task OptionalDownloadOrUpdate(IncludeWhatYouUseOptionsPage settings, IVsThreadedWaitDialogFactory dialogFactory)
        {
            // Check existence, offer to download if it's not there.
            bool downloadedNewIwyu = false;

            if (!File.Exists(settings.ExecutablePath))
            {
                if (await Output.Instance.YesNoMsg($"Can't find include-what-you-use in '{settings.ExecutablePath}'. Do you want to download it from '{IWYUDownload.DisplayRepositorURL}'?") != Output.MessageResult.Yes)
                {
                    return;
                }

                downloadedNewIwyu = await DownloadIWYUWithProgressBar(settings.ExecutablePath, dialogFactory);

                if (!downloadedNewIwyu)
                {
                    return;
                }
            }
            else if (settings.AutomaticCheckForUpdates && !checkedForUpdatesThisSession)
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                IVsThreadedWaitDialog2 dialog = null;
                dialogFactory.CreateInstance(out dialog);
                dialog?.StartWaitDialog("Include Toolbox", "Running Include-What-You-Use", null, null, "Checking for Updates for include-what-you-use", 0, false, true);
                bool newVersionAvailable = await IWYUDownload.IsNewerVersionAvailableOnline(settings.ExecutablePath);

                dialog?.EndWaitDialog();

                if (newVersionAvailable)
                {
                    checkedForUpdatesThisSession = true;
                    if (await Output.Instance.YesNoMsg($"There is a new version of include-what-you-use available. Do you want to download it from '{IWYUDownload.DisplayRepositorURL}'?") == Output.MessageResult.Yes)
                    {
                        downloadedNewIwyu = await DownloadIWYUWithProgressBar(settings.ExecutablePath, dialogFactory);
                    }
                }
            }
            if (downloadedNewIwyu)
            {
                settings.AddMappingFiles(IWYUDownload.GetMappingFilesNextToIwyuPath(settings.ExecutablePath));
            }
        }
        public void AddMappingFilesFromDownloadDir()
        {
            var executableDir = GetCleanExecutableDir();
            var folder        = Path.GetDirectoryName(executableDir);

            Directory.CreateDirectory(folder);

            string test0Path = Path.Combine(folder, "test0.imp");

            File.Create(test0Path);
            string test1Path = Path.Combine(folder, "test1.imp");

            File.Create(test1Path);
            File.Create(Path.Combine(folder, "test2.mip"));

            var optionPage = new IncludeToolbox.IncludeWhatYouUseOptionsPage();

            optionPage.MappingFiles = new string[] { "doesn't exist.imp", test1Path };

            var newMappingFiles = IWYUDownload.GetMappingFilesNextToIwyuPath(executableDir);

            {
                var newMappingFilesArray = newMappingFiles.ToArray();
                Assert.AreEqual(2, newMappingFilesArray.Length);
                Assert.AreEqual(test0Path, newMappingFilesArray[0]);
                Assert.AreEqual(test1Path, newMappingFilesArray[1]);
            }

            optionPage.AddMappingFiles(newMappingFiles);
            {
                Assert.AreEqual(3, optionPage.MappingFiles.Length);
                Assert.AreEqual(true, optionPage.MappingFiles.Contains(test0Path));
                Assert.AreEqual(true, optionPage.MappingFiles.Contains(test1Path));
                Assert.AreEqual(true, optionPage.MappingFiles.Contains("doesn't exist.imp"));
            }
        }