PageRenderTime 14ms CodeModel.GetById 7ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 4using System;
 5using System.IO;
 6using ICSharpCode.SharpDevelop.Project;
 7using NuGet;
 8
 9namespace ICSharpCode.PackageManagement
10{
11	public class SettingsProvider : ISettingsProvider
12	{
13		public static Func<IFileSystem, string, IMachineWideSettings, ISettings> LoadDefaultSettings
14			= Settings.LoadDefaultSettings;
15		
16		IPackageManagementProjectService projectService;
17		
18		public SettingsProvider()
19			: this(PackageManagementServices.ProjectService)
20		{
21		}
22		
23		public SettingsProvider(IPackageManagementProjectService projectService)
24		{
25			this.projectService = projectService;
26			projectService.SolutionOpened += OnSettingsChanged;
27			projectService.SolutionClosed += OnSettingsChanged;
28		}
29		
30		public event EventHandler SettingsChanged;
31		
32		void OnSettingsChanged(object sender, SolutionEventArgs e)
33		{
34			if (SettingsChanged != null) {
35				SettingsChanged(this, new EventArgs());
36			}
37		}
38		
39		public ISettings LoadSettings()
40		{
41			return LoadSettings(GetSolutionDirectory());
42		}
43		
44		string GetSolutionDirectory()
45		{
46			ISolution solution = projectService.OpenSolution;
47			if (solution != null) {
48				return Path.Combine(solution.Directory, ".nuget");
49			}
50			return null;
51		}
52		
53		ISettings LoadSettings(string directory)
54		{
55			if (directory == null) {
56				return LoadDefaultSettings(null, null, null);
57			}
58			
59			return LoadDefaultSettings(new PhysicalFileSystem(directory), null, null);
60		}
61	}
62}