Ejemplo n.º 1
0
        public Task <bool> ShouldElevateAsync(IPackageManager sender, string operation)
        {
            var e = new QueryShouldElevateEventArgs(_factory);

            QueryShouldElevate?.Invoke(this, e);
            if (e.ElevateAsync != null)
            {
                return(e.ElevateAsync);
            }
            if (e.Cancel)
            {
                throw new OperationCanceledException();
            }
            return(Task.FromResult(e.Elevate));
        }
Ejemplo n.º 2
0
 public Task<bool> ShouldElevateAsync(IPackageManager sender, string operation) {
     var e = new QueryShouldElevateEventArgs(_factory);
     QueryShouldElevate?.Invoke(this, e);
     if (e.ElevateAsync != null) {
         return e.ElevateAsync;
     }
     if (e.Cancel) {
         throw new OperationCanceledException();
     }
     return Task.FromResult(e.Elevate);
 }
Ejemplo n.º 3
0
 private bool ShouldElevate(string targetPath) {
     var e = new QueryShouldElevateEventArgs(targetPath);
     QueryShouldElevate?.Invoke(this, e);
     if (e.Cancel) {
         throw new OperationCanceledException();
     }
     return e.Elevate;
 }
Ejemplo n.º 4
0
        private void PipExtensionProvider_QueryShouldElevate(object sender, QueryShouldElevateEventArgs e)
        {
            if (_pyService.GeneralOptions.ElevatePip) {
                e.Elevate = true;
                return;
            }

            try {
                // Create a test file and delete it immediately to ensure we can do it.
                // If this fails, prompt the user to see whether they want to elevate.
                var testFile = PathUtils.GetAvailableFilename(e.TargetDirectory, "access-test", ".txt");
                using (new FileStream(testFile, FileMode.CreateNew, FileAccess.Write, FileShare.Delete, 4096, FileOptions.DeleteOnClose)) { }
                e.Elevate = false;
                return;
            } catch (IOException) {
            } catch (UnauthorizedAccessException) {
            }

            var td = new TaskDialog(_site) {
                Title = Strings.ProductTitle,
                MainInstruction = Strings.ElevateForInstallPackage_MainInstruction,
                AllowCancellation = true,
            };
            var elevate = new TaskDialogButton(Strings.ElevateForInstallPackage_Elevate, Strings.ElevateForInstallPackage_Elevate_Note) {
                ElevationRequired = true
            };
            var noElevate = new TaskDialogButton(Strings.ElevateForInstallPackage_DoNotElevate, Strings.ElevateForInstallPackage_DoNotElevate_Note);
            var elevateAlways = new TaskDialogButton(Strings.ElevateForInstallPackage_ElevateAlways, Strings.ElevateForInstallPackage_ElevateAlways_Note) {
                ElevationRequired = true
            };
            td.Buttons.Add(elevate);
            td.Buttons.Add(noElevate);
            td.Buttons.Add(elevateAlways);
            td.Buttons.Add(TaskDialogButton.Cancel);
            var sel = td.ShowModal();
            if (sel == TaskDialogButton.Cancel) {
                e.Cancel = true;
            } else if (sel == noElevate) {
                e.Elevate = false;
            } else if (sel == elevateAlways) {
                _pyService.GeneralOptions.ElevatePip = true;
                _pyService.GeneralOptions.Save();
                e.Elevate = true;
            } else {
                e.Elevate = true;
            }
        }
Ejemplo n.º 5
0
 private void PipExtensionProvider_QueryShouldElevate(object sender, QueryShouldElevateEventArgs e) {
     try {
         e.Elevate = VsPackageManagerUI.ShouldElevate(_site, e.Factory.Configuration, "pip");
     } catch (OperationCanceledException) {
         e.Cancel = true;
     }
 }