internal ConfigurationService() { var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); _configPath = Path.Combine(appData, AppFolderName); _configFileName = Path.Combine(_configPath, ConfigFileName); if (!Directory.Exists(_configPath)) { try { Directory.CreateDirectory(_configPath); } catch (Exception exc) { if (exc.IsCritical()) { throw; } LoggingService.Global.Error(exc); } } Configuration = LoadConfig(ConfigFileName, "Configuration"); RootSection = Configuration.RootSection; GuiSection = RootSection.GetCreateSection("Gui"); GlobalSection = RootSection.GetCreateSection("Global"); ViewsSection = RootSection.GetCreateSection("Tools"); _providersSection = RootSection.GetCreateSection("Providers"); RepositoryManagerSection = RootSection.GetCreateSection("RepositoryManager"); }
/// <summary> /// /// </summary> /// <param name="allSections">Sections with correct hierarchy</param> /// <returns></returns> public static RootSection BuildTree(IEnumerable <SectionsFinder.SectionInfo> allSections) { var sections = allSections .Select(s => new { Section = s.Section, Lines = s.FullSection }) .ToList(); var dipestOrder = sections.EmptyToNull()?.Max(s => s.Section.Order) ?? -1; return(dipestOrder != -1 ? getRoot(0) : RootSection.EmptyRoot); ///////////////////////////////////////// RootSection getRoot(int offset) { var header = sections[offset]; var lines = new List <string>(header.Lines).ToEnumerable(); var children = new List <RootSection>(); for (int i = offset + 1; i < sections.Count; i++) { var curr = sections[i]; if (curr.Section.IsInsideSection(header.Section) && curr.Section.Order - 1 == header.Section.Order) { RootSection child; if (curr.Section.Order != dipestOrder) // continue unwrapping { child = getRoot(i); } else // leaf { child = new RootSection(curr.Section, Enumerable.Empty <RootSection>(), curr.Lines); } lines = lines.Concat(child.Lines); children.Add(child); } } return(new RootSection(header.Section, children, lines)); } }
static GameProfiles( ) { Game = new RootSection( ); }