Example #1
0
        public static IniFile Read(string InputPath)
        {
            IniFile File = new IniFile();
            using (StreamReader Reader = new StreamReader(InputPath))
            {
                IniSection CurrentSection = null;
                while (!Reader.EndOfStream)
                {
                    string Line = Reader.ReadLine().Trim();
                    if (Line.Length > 0 && !Line.StartsWith(";"))
                    {
                        // Check if it's a section heading or key/value pair
                        if (Line[0] == '[')
                        {
                            if (Line[Line.Length - 1] != ']') throw new InvalidDataException();

                            string Name = Line.Substring(1, Line.Length - 2);
                            CurrentSection = new IniSection(Name);

                            File.Sections.Add(CurrentSection);
                            if(File.NameToSection.ContainsKey(Name.ToLowerInvariant()))
                            {
                                Console.WriteLine("{0} has already been added", Name);
                            }
                            File.NameToSection.Add(Name.ToLowerInvariant(), CurrentSection);
                        }
                        else
                        {
                            string Key, Value;

                            // Split the line into key/value
                            int ValueIdx = Line.IndexOf('=');
                            if(ValueIdx == -1)
                            {
                                Key = Line;
                                Value = "";
                            }
                            else
                            {
                                Key = Line.Substring(0, ValueIdx);
                                Value = Line.Substring(ValueIdx + 1);
                            }

                            // If it's an append operation, add the existing value
                            if(Key.Length > 0 && Key[0] == '+')
                            {
                                CurrentSection.Append(Key.Substring(1), Value);
                            }
                            else
                            {
                                CurrentSection.Set(Key, Value);
                            }
                        }
                    }
                }
            }
            return File;
        }
        public static APIModule Build(APIPage InParent, DoxygenModule InModule)
        {
            // Find the description and category
            string ModuleSettingsPath = "Module." + InModule.Name;
            string Description        = Program.Settings.FindValueOrDefault(ModuleSettingsPath + ".Description", "");

            // Get the filter settings
            IniSection FilterSection   = Program.Settings.FindSection(ModuleSettingsPath + ".Filter");
            IniSection WithholdSection = Program.Settings.FindSection(ModuleSettingsPath + ".Withhold");

            // Build a module from all the members
            APIModule Module = new APIModule(InParent, InModule.Name, Description);

            // Normalize the base directory
            string NormalizedBaseSrcDir = Path.GetFullPath(InModule.BaseSrcDir).ToLowerInvariant();

            if (!NormalizedBaseSrcDir.EndsWith("\\"))
            {
                NormalizedBaseSrcDir += "\\";
            }

            // Separate the members into categories, based on their path underneath the module source directory
            Dictionary <APIFilter, List <DoxygenEntity> > MembersByFilter = new Dictionary <APIFilter, List <DoxygenEntity> >();

            foreach (DoxygenEntity Entity in InModule.Entities)
            {
                string FilterPath = null;

                // Try to get the filter path from the ini section
                if (FilterSection != null)
                {
                    FilterPath = FilterSection.Find(Entity.Name);
                }

                // If we didn't have one set explicitly, generate one from the subdirectory
                if (FilterPath == null)
                {
                    string EntityFile = String.IsNullOrEmpty(Entity.File)? "" : Path.GetFullPath(Entity.File);
                    if (EntityFile.ToLowerInvariant().StartsWith(NormalizedBaseSrcDir))
                    {
                        int MinIndex = EntityFile.IndexOf('\\', NormalizedBaseSrcDir.Length);
                        if (MinIndex == -1)
                        {
                            FilterPath = "";
                        }
                        else if (IsVisibleFolder(EntityFile.Substring(NormalizedBaseSrcDir.Length, MinIndex - NormalizedBaseSrcDir.Length)))
                        {
                            int MaxIndex = EntityFile.LastIndexOf('\\');
                            FilterPath = EntityFile.Substring(MinIndex + 1, Math.Max(MaxIndex - MinIndex - 1, 0));
                        }
                    }
                }

                // Add this entity to the right filters
                if (FilterPath != null)
                {
                    // Create all the categories for this entry
                    APIFilter ParentFilter = Module;
                    if (FilterPath.Length > 0)
                    {
                        string[] Folders = FilterPath.Split('\\');
                        for (int Idx = 0; Idx < Folders.Length; Idx++)
                        {
                            APIFilter NextFilter = ParentFilter.Filters.FirstOrDefault(x => String.Compare(x.Name, Folders[Idx], true) == 0);
                            if (NextFilter == null)
                            {
                                NextFilter = new APIFilter(ParentFilter, Folders[Idx]);
                                ParentFilter.Filters.Add(NextFilter);
                            }
                            ParentFilter = NextFilter;
                        }
                    }

                    // Add this entity to the pending list for this filter
                    Utility.AddToDictionaryList(ParentFilter, Entity, MembersByFilter);
                }
            }

            // Try to fixup all of the filters
            foreach (KeyValuePair <APIFilter, List <DoxygenEntity> > Members in MembersByFilter)
            {
                APIFilter Filter = Members.Key;
                Filter.Members.AddRange(APIMember.CreateChildren(Filter, Members.Value));
            }
            return(Module);
        }
Example #3
0
        public static IniFile Read(string InputPath)
        {
            if (!File.Exists(InputPath))
            {
                Console.WriteLine("Ini File {0} not found!", InputPath);
                return(new IniFile());
            }

            IniFile InputIniFile = new IniFile();

            using (StreamReader Reader = new StreamReader(InputPath))
            {
                IniSection CurrentSection = null;
                while (!Reader.EndOfStream)
                {
                    string Line = Reader.ReadLine().Trim();
                    if (Line.Length > 0 && !Line.StartsWith(";"))
                    {
                        // Check if it's a section heading or key/value pair
                        if (Line[0] == '[')
                        {
                            if (Line[Line.Length - 1] != ']')
                            {
                                throw new InvalidDataException();
                            }

                            string Name = Line.Substring(1, Line.Length - 2);
                            CurrentSection = new IniSection(Name);

                            InputIniFile.Sections.Add(CurrentSection);
                            if (InputIniFile.NameToSection.ContainsKey(Name.ToLowerInvariant()))
                            {
                                Console.WriteLine("{0} has already been added", Name);
                            }
                            InputIniFile.NameToSection.Add(Name.ToLowerInvariant(), CurrentSection);
                        }
                        else
                        {
                            string Key, Value;

                            // Split the line into key/value
                            int ValueIdx = Line.IndexOf('=');
                            if (ValueIdx == -1)
                            {
                                Key   = Line;
                                Value = "";
                            }
                            else
                            {
                                Key   = Line.Substring(0, ValueIdx);
                                Value = Line.Substring(ValueIdx + 1);
                            }

                            // If it's an append operation, add the existing value
                            if (Key.Length > 0 && Key[0] == '+')
                            {
                                CurrentSection.Append(Key.Substring(1), Value);
                            }
                            else
                            {
                                CurrentSection.Set(Key, Value);
                            }
                        }
                    }
                }
            }
            return(InputIniFile);
        }