private void Export(object sender, EventArgs e) { var saveFileDialog = new SaveFileDialog() { AddExtension = true, DefaultExt = ".vsextensionslist", CheckPathExists = true, Filter = "Extensions List (.vsextensionslist)|*.vsextensionslist", FilterIndex = 1, //InitialDirectory = "%userprofile%", }; var userClickedOK = saveFileDialog.ShowDialog() ?? false; if (!userClickedOK) { return; } if (string.IsNullOrWhiteSpace(saveFileDialog.FileName)) { WriteToOutputPane("Extensions not exported - please choose a filename."); } WriteToOutputPane("Exporting your extensions..."); var installedExtensions = Commands.GetExtensions(_manager); var sbInstalledExtensions = new StringBuilder(installedExtensions.Count() * 50); foreach (var ext in installedExtensions) { sbInstalledExtensions.AppendLine(ext.Header.Identifier); } try { File.WriteAllText(saveFileDialog.FileName, sbInstalledExtensions.ToString()); WriteToOutputPane("Extensions exported."); } catch { WriteToOutputPane("Problem exporting extensions."); } }
private void DownloadAndInstall() { IEnumerable <IInstalledExtension> extensions = Commands.GetExtensions(_manager); foreach (IInstalledExtension extension in extensions) { if (!Settings.IsEnabled(extension.Header.Identifier)) { continue; } IInstallableExtension update; bool updateAvailable = _checker.CheckForUpdate(extension, out update); if (updateAvailable && update != null) { _manager.Disable(extension); _manager.Uninstall(extension); _manager.InstallAsync(update, false); } } }
private void Import(object sender, EventArgs e) { if (_isImportProcessing) { WriteToOutputPane("Extensions import ignored - one is currently already running."); return; } var openFileDialog = new OpenFileDialog() { AddExtension = true, DefaultExt = ".vsextensionslist", CheckPathExists = true, Filter = "Extensions List (.vsextensionslist)|*.vsextensionslist", FilterIndex = 1, //InitialDirectory = "%userprofile%", }; var userClickedOK = openFileDialog.ShowDialog() ?? false; if (!userClickedOK) { return; } if (string.IsNullOrWhiteSpace(openFileDialog.FileName)) { WriteToOutputPane("Extensions not imported - please select a file."); return; } _isImportProcessing = true; WriteToOutputPane("Importing extensions..."); string[] importFileLines = null; try { importFileLines = File.ReadAllLines(openFileDialog.FileName).Where(l => !String.IsNullOrWhiteSpace(l)).Select(l => l.Trim()).ToArray(); } catch { WriteToOutputPane("Error accessing/reading import file."); _isImportProcessing = false; return; } if (!importFileLines.Any()) { WriteToOutputPane("No extensions were found in the import file."); _isImportProcessing = false; return; } // Get extensions not already installed var _installedExtensions = Commands.GetExtensions(_manager).ToDictionary(ie => ie.Header.Identifier, ie => ie.Header.Name); _toInstallExtensions = importFileLines.Where(l => _installedExtensions.All(ie => ie.Key != l)).ToArray(); if (!_toInstallExtensions.Any()) { WriteToOutputPane("You've already got all the extensions listed in the import file."); _isImportProcessing = false; return; } // Query for the complete new extension objects var query = _repository.CreateQuery <GalleryEntry>(false, true, "ExtensionManagerQuery") .Where(entry => _toInstallExtensions.Contains(entry.VsixID)) .OrderBy(entry => entry.Name) .Skip(0) .Take(500) as IVsExtensionRepositoryQuery <GalleryEntry>; WriteToOutputPane( string.Format("Looking up {0} potentially new extension/s in the gallery after skipping {1} already installed extension/s...", _toInstallExtensions.Length, importFileLines.Length - _toInstallExtensions.Length ) ); query.ExecuteCompleted += Query_ExecuteCompleted; query.ExecuteAsync(); }