/src/AddIns/Misc/PackageManagement/Project/Src/SettingsProvider.cs

https://github.com/ajadex/SharpDevelop · C# · 62 lines · 49 code · 11 blank · 2 comment · 6 complexity · 7760fefde0626d55f0a83f3ec9dbd115 MD5 · raw file

  1. // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2. // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
  3. using System;
  4. using System.IO;
  5. using ICSharpCode.SharpDevelop.Project;
  6. using NuGet;
  7. namespace ICSharpCode.PackageManagement
  8. {
  9. public class SettingsProvider : ISettingsProvider
  10. {
  11. public static Func<IFileSystem, string, IMachineWideSettings, ISettings> LoadDefaultSettings
  12. = Settings.LoadDefaultSettings;
  13. IPackageManagementProjectService projectService;
  14. public SettingsProvider()
  15. : this(PackageManagementServices.ProjectService)
  16. {
  17. }
  18. public SettingsProvider(IPackageManagementProjectService projectService)
  19. {
  20. this.projectService = projectService;
  21. projectService.SolutionOpened += OnSettingsChanged;
  22. projectService.SolutionClosed += OnSettingsChanged;
  23. }
  24. public event EventHandler SettingsChanged;
  25. void OnSettingsChanged(object sender, SolutionEventArgs e)
  26. {
  27. if (SettingsChanged != null) {
  28. SettingsChanged(this, new EventArgs());
  29. }
  30. }
  31. public ISettings LoadSettings()
  32. {
  33. return LoadSettings(GetSolutionDirectory());
  34. }
  35. string GetSolutionDirectory()
  36. {
  37. ISolution solution = projectService.OpenSolution;
  38. if (solution != null) {
  39. return Path.Combine(solution.Directory, ".nuget");
  40. }
  41. return null;
  42. }
  43. ISettings LoadSettings(string directory)
  44. {
  45. if (directory == null) {
  46. return LoadDefaultSettings(null, null, null);
  47. }
  48. return LoadDefaultSettings(new PhysicalFileSystem(directory), null, null);
  49. }
  50. }
  51. }