<commit_before>﻿using System.IO;
using System.Linq;
using OpenSage.Data;
using OpenSage.Data.Ini;
using OpenSage.Mods.BuiltIn;
using Xunit;
using Xunit.Abstractions;

namespace OpenSage.Tests.Data.Ini
{
    public class IniFileTests
    {
        private readonly ITestOutputHelper _output;

        public IniFileTests(ITestOutputHelper output)
        {
            _output = output;
        }

        [Fact]
        public void CanReadIniFiles()
        {
            // TODO: Finish INI parsing for BFME2 and subsequent games.
            var gameDefinitions = new[]
            {
                GameDefinition.FromGame(SageGame.CncGenerals),
                GameDefinition.FromGame(SageGame.CncGeneralsZeroHour),
                GameDefinition.FromGame(SageGame.Bfme),
                GameDefinition.FromGame(SageGame.Bfme2),
                GameDefinition.FromGame(SageGame.Bfme2Rotwk),
            };

            foreach(var gameDefinition in gameDefinitions)
            {
                var rootDirectories = InstallationLocators.FindAllInstallations(gameDefinition)
                .Select(i => i.Path)
                .Where(x => Directory.Exists(x))
                .ToList();

                foreach (var rootDirectory in rootDirectories)
                {
                    using (var fileSystem = new FileSystem(rootDirectory))
                    {
                        var dataContext = new IniDataContext(fileSystem, gameDefinition.Game);

                        switch (gameDefinition.Game)
                        {
                            case SageGame.Bfme:
                            case SageGame.Bfme2:
                            case SageGame.Bfme2Rotwk:
                                dataContext.LoadIniFile(@"Data\INI\GameData.ini");
                                break;
                        }
                        

                        foreach (var file in fileSystem.Files)
                        {
                            if (Path.GetExtension(file.FilePath).ToLowerInvariant() != ".ini")
                            {
                                continue;
                            }

                            var filename = Path.GetFileName(file.FilePath).ToLowerInvariant();

                            switch (filename)
                            {
                                case "buttonsets.ini": // Doesn't seem to be used?
                                case "scripts.ini": // Only needed by World Builder?
                                case "commandmapdebug.ini": // Only applies to DEBUG and INTERNAL builds
                                case "fxparticlesystemcustom.ini": // Don't know if this is used, it uses Emitter property not used elsewhere
                                case "lightpoints.ini": // Don't know if this is used.
                                    continue;

                                case "optionregistry.ini": // Don't know if this is used
                                case "localization.ini": // Don't know if we need this
                                    switch(gameDefinition.Game)
                                    {
                                        case SageGame.Bfme:
                                        case SageGame.Bfme2:
                                        case SageGame.Bfme2Rotwk:
                                            continue;
                                    }
                                    break;
                            }

                            switch (gameDefinition.Game)
                            {
                                case SageGame.Bfme2:
                                    switch (filename)
                                    {
                                        case "ingamenotificationbox.ini":
                                        case "meshinstancingmanager.ini":
                                        case "commandset.ini": //problem
                                        case "riskcampaign.ini":<commit_msg>address review feedback<commit_after>﻿using System.IO;
using System.Linq;
using OpenSage.Data;
using OpenSage.Data.Ini;
using OpenSage.Mods.BuiltIn;
using Xunit;
using Xunit.Abstractions;

namespace OpenSage.Tests.Data.Ini
{
    public class IniFileTests
    {
        private readonly ITestOutputHelper _output;

        public IniFileTests(ITestOutputHelper output)
        {
            _output = output;
        }

        [Fact]
        public void CanReadIniFiles()
        {
            // TODO: Finish INI parsing for BFME2 and subsequent games.
            var gameDefinitions = new[]
            {
                GameDefinition.FromGame(SageGame.CncGenerals),
                GameDefinition.FromGame(SageGame.CncGeneralsZeroHour),
                GameDefinition.FromGame(SageGame.Bfme),
                GameDefinition.FromGame(SageGame.Bfme2),
                GameDefinition.FromGame(SageGame.Bfme2Rotwk),
            };

            foreach(var gameDefinition in gameDefinitions)
            {
                var rootDirectories = InstallationLocators.FindAllInstallations(gameDefinition)
                .Select(i => i.Path)
                .ToList();

                foreach (var rootDirectory in rootDirectories)
                {
                    using (var fileSystem = new FileSystem(rootDirectory))
                    {
                        var dataContext = new IniDataContext(fileSystem, gameDefinition.Game);

                        switch (gameDefinition.Game)
                        {
                            case SageGame.Bfme:
                            case SageGame.Bfme2:
                            case SageGame.Bfme2Rotwk:
                                dataContext.LoadIniFile(@"Data\INI\GameData.ini");
                                break;
                        }
                        

                        foreach (var file in fileSystem.Files)
                        {
                            if (Path.GetExtension(file.FilePath).ToLowerInvariant() != ".ini")
                            {
                                continue;
                            }

                            var filename = Path.GetFileName(file.FilePath).ToLowerInvariant();

                            switch (filename)
                            {
                                case "buttonsets.ini": // Doesn't seem to be used?
                                case "scripts.ini": // Only needed by World Builder?
                                case "commandmapdebug.ini": // Only applies to DEBUG and INTERNAL builds
                                case "fxparticlesystemcustom.ini": // Don't know if this is used, it uses Emitter property not used elsewhere
                                case "lightpoints.ini": // Don't know if this is used.
                                    continue;

                                case "optionregistry.ini": // Don't know if this is used
                                case "localization.ini": // Don't know if we need this
                                    switch(gameDefinition.Game)
                                    {
                                        case SageGame.Bfme:
                                        case SageGame.Bfme2:
                                        case SageGame.Bfme2Rotwk:
                                            continue;
                                    }
                                    break;
                            }

                            //TODO: parse these files
                            switch (gameDefinition.Game)
                            {
                                case SageGame.Bfme2:
                                    switch (filename)
                                    {
                                        case "ingamenotificationbox.ini":
                                        case "meshinstancingmanager.ini":
                                        case "commandset.ini": //problem
                                        case "riskcampaign.ini":
{'fraction_non_alphanumeric': 0.06337245213094503, 'fraction_numerical': 0.001976528721432983, 'mean_word_length': 0.9085337105139085, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '818792', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1671, 'n_words': 377}