public FreelancerIni(string path, FileSystem vfs)
        {
            if (vfs == null)
            {
                throw new ArgumentNullException(nameof(vfs), "vfs cannot be null");
            }
            IsLibrelancer = path.EndsWith("librelancer.ini", StringComparison.OrdinalIgnoreCase);
            if (IsLibrelancer)
            {
                DacomPath = null;
            }
            EquipmentPaths = new List <string> ();
            LoadoutPaths   = new List <string> ();
            ShiparchPaths  = new List <string> ();
            SoundPaths     = new List <string>();
            GraphPaths     = new List <string>();
            EffectPaths    = new List <string>();
            AsteroidPaths  = new List <string> ();
            RichFontPaths  = new List <string>();
            FontPaths      = new List <string>();
            PetalDbPaths   = new List <string>();
            StartupMovies  = new List <string>();
            GoodsPaths     = new List <string>();
            MarketsPaths   = new List <string>();
            FusePaths      = new List <string>();
            NewCharDBPaths = new List <string>();
            VoicePaths     = new List <string>();
            bool extNoNavmaps = false;
            bool extHideFac   = false;

            NoNavmapSystems = new List <string>(NoNavmaps);
            HiddenFactions  = new List <string>(NoShowFactions);

            var fullPath = vfs.Resolve(path);

            foreach (Section s in ParseFile(fullPath, vfs))
            {
                switch (s.Name.ToLowerInvariant())
                {
                case "freelancer":
                    foreach (Entry e in s)
                    {
                        if (e.Name.ToLowerInvariant() == "data path")
                        {
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (DataPath != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            if (IsLibrelancer)
                            {
                                DataPath = EndInSep(e[0].ToString());
                            }
                            else
                            {
                                DataPath = "EXE\\" + EndInSep(e[0].ToString());
                            }
                        }
                        if (e.Name.ToLowerInvariant() == "dacom path")
                        {
                            DacomPath = e[0].ToString();
                        }
                    }
                    break;

                case "jsonresources":
                    JsonResources = new List <string>();
                    foreach (var e in s)
                    {
                        if (e.Name.ToLowerInvariant() != "file")
                        {
                            FLLog.Warning("Ini", $"Unexpected entry `{e.Name}` in [JsonResources] (expected file)");
                            continue;
                        }
                        JsonResources.Add(DataPath + e[0].ToString());
                    }
                    break;

                case "resources":
                    Resources = new List <DllFile> ();
                    //NOTE: Freelancer hardcodes resources.dll
                    //Not hardcoded for librelancer.ini as it will break
                    string start = IsLibrelancer ? "" : "EXE\\";
                    string pathStr;
                    if (!IsLibrelancer)
                    {
                        if ((pathStr = vfs.Resolve(start + "resources.dll", false)) != null)
                        {
                            Resources.Add(new DllFile(pathStr, vfs));
                        }
                        else
                        {
                            FLLog.Warning("Dll", "resources.dll not found");
                        }
                    }
                    foreach (Entry e in s)
                    {
                        if (e.Name.ToLowerInvariant() != "dll")
                        {
                            continue;
                        }
                        if ((pathStr = vfs.Resolve(start + e[0].ToString(), false)) != null)
                        {
                            Resources.Add(new DllFile(pathStr, vfs));
                        }
                        else
                        {
                            FLLog.Warning("Dll", e[0].ToString());
                        }
                    }
                    break;

                case "startup":
                    foreach (Entry e in s)
                    {
                        if (e.Name.ToLowerInvariant() != "movie_file")
                        {
                            continue;
                        }
                        StartupMovies.Add(e [0].ToString());
                    }
                    break;

                case "extended":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "xinterface":
                            if (System.IO.Directory.Exists(e[0].ToString()))
                            {
                                XInterfacePath = e[0].ToString();
                            }
                            else
                            {
                                XInterfacePath = DataPath + e[0].ToString();
                            }
                            if (!XInterfacePath.EndsWith("\\", StringComparison.InvariantCulture) &&
                                !XInterfacePath.EndsWith("/", StringComparison.InvariantCulture))
                            {
                                XInterfacePath += "/";
                            }
                            break;

                        case "dataversion":
                            DataVersion = e[0].ToString();
                            break;

                        case "nonavmap":
                            if (!extNoNavmaps)
                            {
                                NoNavmapSystems = new List <string>(); extNoNavmaps = true;
                            }
                            NoNavmapSystems.Add(e[0].ToString());
                            break;

                        case "hidefaction":
                            if (!extHideFac)
                            {
                                HiddenFactions = new List <string>();  extHideFac = true;
                            }
                            ;
                            HiddenFactions.Add(e[0].ToString());
                            break;
                        }
                    }
                    break;

                case "data":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "solar":
                            SolarPath = DataPath + e [0].ToString();
                            break;

                        case "universe":
                            UniversePath = DataPath + e [0].ToString();
                            break;

                        case "equipment":
                            EquipmentPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "loadouts":
                            LoadoutPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "stars":
                            StarsPath = DataPath + e [0].ToString();
                            break;

                        case "bodyparts":
                            BodypartsPath = DataPath + e [0].ToString();
                            break;

                        case "costumes":
                            CostumesPath = DataPath + e [0];
                            break;

                        case "sounds":
                            SoundPaths.Add(DataPath + e[0]);
                            break;

                        case "ships":
                            ShiparchPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "rich_fonts":
                            RichFontPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "fonts":
                            FontPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "igraph":
                            GraphPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "effect_shapes":
                            EffectShapesPath = DataPath + e[0].ToString();
                            break;

                        case "effects":
                            EffectPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "asteroids":
                            AsteroidPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "petaldb":
                            PetalDbPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "hud":
                            HudPath = DataPath + e[0].ToString();
                            break;

                        case "goods":
                            GoodsPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "markets":
                            MarketsPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "fuses":
                            FusePaths.Add(DataPath + e[0].ToString());
                            break;

                        case "newchardb":
                            NewCharDBPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "voices":
                            VoicePaths.Add(DataPath + e[0].ToString());
                            break;

                        //extended
                        case "newplayer":
                            NewPlayerPath = DataPath + e[0].ToString();
                            break;

                        case "mpnewcharacter":
                            MpNewCharacterPath = DataPath + e[0].ToString();
                            break;

                        case "mbases":
                            if (MBasesPaths == null)
                            {
                                MBasesPaths = new List <string>();
                            }
                            MBasesPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "mouse":
                            MousePath = DataPath + e[0].ToString();
                            break;

                        case "cameras":
                            CamerasPath = DataPath + e[0].ToString();
                            break;

                        case "constants":
                            ConstantsPath = DataPath + e[0].ToString();
                            break;

                        case "navmap":
                            NavmapPath = DataPath + e[0].ToString();
                            break;
                        }
                    }
                    break;
                }
            }

            if (string.IsNullOrEmpty(MousePath))
            {
                MousePath = DataPath + "mouse.ini";
            }
            if (string.IsNullOrEmpty(CamerasPath))
            {
                CamerasPath = DataPath + "cameras.ini";
            }
            if (string.IsNullOrEmpty(ConstantsPath))
            {
                ConstantsPath = DataPath + "constants.ini";
            }
        }
Exemple #2
0
        public FreelancerIni(string path)
        {
            EquipmentPaths = new List <string> ();
            LoadoutPaths   = new List <string> ();
            ShiparchPaths  = new List <string> ();
            SoundPaths     = new List <string>();
            GraphPaths     = new List <string>();
            EffectPaths    = new List <string>();
            AsteroidPaths  = new List <string> ();
            RichFontPaths  = new List <string>();
            PetalDbPaths   = new List <string>();
            StartupMovies  = new List <string>();
            GoodsPaths     = new List <string>();
            MarketsPaths   = new List <string>();
            FusePaths      = new List <string>();
            NewCharDBPaths = new List <string>();

            bool extNoNavmaps = false;
            bool extHideFac   = false;

            NoNavmapSystems = new List <string>(NoNavmaps);
            HiddenFactions  = new List <string>(NoShowFactions);

            //For DLL resolving (skip VFS for editor usage)
            var fullPath  = VFS.GetPath(path);
            var directory = Path.GetDirectoryName(fullPath);
            var dirFiles  = Directory.GetFiles(directory).Select(a => Path.GetFileName(a));
            Func <string, string> resolveFileEXE = (x) =>
            {
                if (File.Exists(Path.Combine(directory, x)))
                {
                    return(Path.Combine(directory, x));
                }
                var res = dirFiles.FirstOrDefault(y => y.Equals(x, StringComparison.OrdinalIgnoreCase));
                if (res != null)
                {
                    return(Path.Combine(directory, res));
                }
                return(null);
            };

            foreach (Section s in ParseFile(fullPath))
            {
                switch (s.Name.ToLowerInvariant())
                {
                case "freelancer":
                    foreach (Entry e in s)
                    {
                        if (e.Name.ToLowerInvariant() == "data path")
                        {
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (DataPath != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            DataPath = "EXE\\" + e [0].ToString() + "\\";
                        }
                    }
                    break;

                case "jsonresources":
                    JsonResources = new Tuple <string, string>(resolveFileEXE(s[0][0].ToString()), resolveFileEXE(s[0][1].ToString()));
                    break;

                case "resources":
                    Resources = new List <DllFile> ();
                    //NOTE: Freelancer hardcodes resources.dll
                    string pathStr;
                    if ((pathStr = resolveFileEXE("resources.dll")) != null)
                    {
                        Resources.Add(new DllFile(pathStr));
                    }
                    else
                    {
                        FLLog.Warning("Dll", "resources.dll not found");
                    }
                    foreach (Entry e in s)
                    {
                        if (e.Name.ToLowerInvariant() != "dll")
                        {
                            continue;
                        }
                        if ((pathStr = resolveFileEXE(e[0].ToString())) != null)
                        {
                            Resources.Add(new DllFile(pathStr));
                        }
                        else
                        {
                            FLLog.Warning("Dll", e[0].ToString());
                        }
                    }
                    break;

                case "startup":
                    foreach (Entry e in s)
                    {
                        if (e.Name.ToLowerInvariant() != "movie_file")
                        {
                            continue;
                        }
                        StartupMovies.Add(e [0].ToString());
                    }
                    break;

                case "extended":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "xinterface":
                            if (System.IO.Directory.Exists(e[0].ToString()))
                            {
                                XInterfacePath = e[0].ToString();
                            }
                            else
                            {
                                XInterfacePath = DataPath + e[0].ToString();
                            }
                            if (!XInterfacePath.EndsWith("\\", StringComparison.InvariantCulture) &&
                                !XInterfacePath.EndsWith("/", StringComparison.InvariantCulture))
                            {
                                XInterfacePath += "/";
                            }
                            break;

                        case "dataversion":
                            DataVersion = e[0].ToString();
                            break;

                        case "nonavmap":
                            if (!extNoNavmaps)
                            {
                                NoNavmapSystems = new List <string>(); extNoNavmaps = true;
                            }
                            NoNavmapSystems.Add(e[0].ToString());
                            break;

                        case "hidefaction":
                            if (!extHideFac)
                            {
                                HiddenFactions = new List <string>();  extHideFac = true;
                            }
                            ;
                            HiddenFactions.Add(e[0].ToString());
                            break;
                        }
                    }
                    break;

                case "data":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "solar":
                            SolarPath = DataPath + e [0].ToString();
                            break;

                        case "universe":
                            UniversePath = DataPath + e [0].ToString();
                            break;

                        case "equipment":
                            EquipmentPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "loadouts":
                            LoadoutPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "stars":
                            StarsPath = DataPath + e [0].ToString();
                            break;

                        case "bodyparts":
                            BodypartsPath = DataPath + e [0].ToString();
                            break;

                        case "costumes":
                            CostumesPath = DataPath + e [0];
                            break;

                        case "sounds":
                            SoundPaths.Add(DataPath + e[0]);
                            break;

                        case "ships":
                            ShiparchPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "rich_fonts":
                            RichFontPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "igraph":
                            GraphPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "effect_shapes":
                            EffectShapesPath = DataPath + e[0].ToString();
                            break;

                        case "effects":
                            EffectPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "asteroids":
                            AsteroidPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "petaldb":
                            PetalDbPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "hud":
                            HudPath = DataPath + e[0].ToString();
                            break;

                        case "goods":
                            GoodsPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "markets":
                            MarketsPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "fuses":
                            FusePaths.Add(DataPath + e[0].ToString());
                            break;

                        case "newchardb":
                            NewCharDBPaths.Add(DataPath + e[0].ToString());
                            break;
                        }
                    }
                    break;
                }
            }
        }
Exemple #3
0
        public FreelancerIni()
        {
            EquipmentPaths = new List <string> ();
            LoadoutPaths   = new List <string> ();
            ShiparchPaths  = new List <string> ();
            SoundPaths     = new List <string>();
            GraphPaths     = new List <string>();
            EffectPaths    = new List <string>();
            AsteroidPaths  = new List <string> ();
            RichFontPaths  = new List <string>();
            PetalDbPaths   = new List <string>();
            StartupMovies  = new List <string>();
            GoodsPaths     = new List <string>();
            MarketsPaths   = new List <string>();
            FusePaths      = new List <string>();

            bool extNoNavmaps = false;
            bool extHideFac   = false;

            NoNavmapSystems = new List <string>(NoNavmaps);
            HiddenFactions  = new List <string>(NoShowFactions);

            foreach (Section s in ParseFile("EXE\\freelancer.ini"))
            {
                switch (s.Name.ToLowerInvariant())
                {
                case "freelancer":
                    foreach (Entry e in s)
                    {
                        if (e.Name.ToLowerInvariant() == "data path")
                        {
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (DataPath != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            DataPath = "EXE\\" + e [0].ToString() + "\\";
                        }
                    }
                    break;

                case "jsonresources":
                    JsonResources = new Tuple <string, string>(s[0][0].ToString(), s[0][1].ToString());
                    break;

                case "resources":
                    Resources = new List <DllFile> ();
                    //NOTE: Freelancer hardcodes resources.dll
                    Resources.Add(new DllFile("EXE\\resources.dll"));
                    foreach (Entry e in s)
                    {
                        if (e.Name.ToLowerInvariant() != "dll")
                        {
                            continue;
                        }
                        Resources.Add(new DllFile("EXE\\" + e [0]));
                    }
                    break;

                case "startup":
                    foreach (Entry e in s)
                    {
                        if (e.Name.ToLowerInvariant() != "movie_file")
                        {
                            continue;
                        }
                        StartupMovies.Add(e [0].ToString());
                    }
                    break;

                case "extended":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "xinterface":
                            if (System.IO.Directory.Exists(e[0].ToString()))
                            {
                                XInterfacePath = e[0].ToString();
                            }
                            else
                            {
                                XInterfacePath = DataPath + e[0].ToString();
                            }
                            if (!XInterfacePath.EndsWith("\\", StringComparison.InvariantCulture) &&
                                !XInterfacePath.EndsWith("/", StringComparison.InvariantCulture))
                            {
                                XInterfacePath += "/";
                            }
                            break;

                        case "dataversion":
                            DataVersion = e[0].ToString();
                            break;

                        case "nonavmap":
                            if (!extNoNavmaps)
                            {
                                NoNavmapSystems = new List <string>(); extNoNavmaps = true;
                            }
                            NoNavmapSystems.Add(e[0].ToString());
                            break;

                        case "hidefaction":
                            if (!extHideFac)
                            {
                                HiddenFactions = new List <string>();  extHideFac = true;
                            }
                            ;
                            HiddenFactions.Add(e[0].ToString());
                            break;
                        }
                    }
                    break;

                case "data":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "solar":
                            SolarPath = DataPath + e [0].ToString();
                            break;

                        case "universe":
                            UniversePath = DataPath + e [0].ToString();
                            break;

                        case "equipment":
                            EquipmentPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "loadouts":
                            LoadoutPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "stars":
                            StarsPath = DataPath + e [0].ToString();
                            break;

                        case "bodyparts":
                            BodypartsPath = DataPath + e [0].ToString();
                            break;

                        case "costumes":
                            CostumesPath = DataPath + e [0];
                            break;

                        case "sounds":
                            SoundPaths.Add(DataPath + e[0]);
                            break;

                        case "ships":
                            ShiparchPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "rich_fonts":
                            RichFontPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "igraph":
                            GraphPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "effect_shapes":
                            EffectShapesPath = DataPath + e[0].ToString();
                            break;

                        case "effects":
                            EffectPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "asteroids":
                            AsteroidPaths.Add(DataPath + e [0].ToString());
                            break;

                        case "petaldb":
                            PetalDbPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "hud":
                            HudPath = DataPath + e[0].ToString();
                            break;

                        case "goods":
                            GoodsPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "markets":
                            MarketsPaths.Add(DataPath + e[0].ToString());
                            break;

                        case "fuses":
                            FusePaths.Add(DataPath + e[0].ToString());
                            break;
                        }
                    }
                    break;
                }
            }
        }