コード例 #1
0
ファイル: DuplicatingIni.cs プロジェクト: ME3Tweaks/AutoTOC
        public static DuplicatingIni ParseIni(string iniText)
        {
            DuplicatingIni di             = new DuplicatingIni();
            var            splits         = iniText.Split('\n');
            Section        currentSection = null;

            foreach (var line in splits)
            {
                string trimmed = line.Trim();
                if (string.IsNullOrWhiteSpace(trimmed))
                {
                    continue;                                     //blank line
                }
                if (trimmed.StartsWith("[") && trimmed.EndsWith("]"))
                {
                    //New section
                    currentSection = new Section()
                    {
                        Header = trimmed.Trim('[', ']')
                    };
                    di.Sections.Add(currentSection);
                }
                else if (currentSection == null)
                {
                    continue; //this parser only supports section items
                }
                else
                {
                    currentSection.Entries.Add(new IniEntry(trimmed));
                }
            }
            return(di);
        }
コード例 #2
0
ファイル: TOCCreator.cs プロジェクト: ME3Tweaks/AutoTOC
        /// <summary>
        /// Parses LE1 DLC Autoload files and creates a list of files with correct DLC overrides.
        /// Only one instance of a specific filename will be output by this method
        /// </summary>
        /// <param name="basegameFiles">List of files for basegame toc</param>
        /// <param name="biogameDirectory">LE1 BioGame directory</param>
        /// <returns>List of files for toc, including DLC supercedances</returns>
        public static List <string> GetLE1Files(List <string> basegameFiles, string biogameDirectory)
        {
            if (!Directory.Exists(Path.Combine(biogameDirectory, "DLC")))
            {
                return(basegameFiles);
            }

            // Build dictionary of DLCs in mount priority
            Dictionary <int, string> dlcMounts = new Dictionary <int, string>();

            string[] dlcList = Directory.GetDirectories(Path.Combine(biogameDirectory, "DLC"), "*.*", SearchOption.TopDirectoryOnly);
            foreach (var dlcFolder in dlcList)
            {
                if (!(new DirectoryInfo(dlcFolder).Name).StartsWith("DLC_", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                string autoLoadPath = Path.Combine(dlcFolder, "autoload.ini");  //CHECK IF FILE EXISTS?
                if (File.Exists(autoLoadPath))
                {
                    DuplicatingIni dlcAutoload = DuplicatingIni.LoadIni(autoLoadPath);
                    int            mount       = Convert.ToInt32(dlcAutoload["ME1DLCMOUNT"]["ModMount"].Value);
                    dlcMounts.Add(mount, dlcFolder);
                }
            }

            // filename, filepath
            Dictionary <string, string> outFiles = new Dictionary <string, string>();

            foreach (var dlc in dlcMounts.OrderByDescending(t => t.Key))
            {
                var files = GetFiles(dlc.Value, false);
                foreach (var file in files)
                {
                    var name = new FileInfo(file).Name.ToUpper();
                    if (!outFiles.ContainsKey(name))
                    {
                        outFiles.Add(name, file);
                    }
                }
            }

            // Add in basegame files
            foreach (var file in basegameFiles)
            {
                var name = new FileInfo(file).Name.ToUpper();
                if (!outFiles.ContainsKey(name))
                {
                    outFiles.Add(name, file);
                }
            }

            return(outFiles.Values.ToList());
        }