Пример #1
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"));
            }
        }