Example #1
0
        public static void SaveChanges(Settings settings, bool WotC, bool disableMods)
        {
            // XComModOptions
            var modOptions = new DefaultConfigFile("ModOptions", WotC, false);

            if (!disableMods)
            {
                foreach (var m in settings.Mods.Active.OrderBy(m => m.Index))
                {
                    modOptions.Add("Engine.XComModOptions", "ActiveMods", m.ID);
                }
            }

            modOptions.Save();

            // XComEngine
            var engine = new DefaultConfigFile("Engine", WotC);

            // Remove old ModClassOverrides
            engine.Remove("Engine.Engine", "ModClassOverrides");

            // Set Mod Paths
            engine.Remove("Engine.DownloadableContentEnumerator", "ModRootDirs");
            foreach (var modPath in settings.ModPaths)
            {
                engine.Add("Engine.DownloadableContentEnumerator", "ModRootDirs", modPath);
            }

            // Save
            engine.Save();
        }
Example #2
0
        /// <summary>
        /// Reads the mod directories from the XComEngine.ini file.
        /// </summary>
        /// <returns>List of mod directories. NULL if the ini file is missing or couldn't be accessed.</returns>
        public static IEnumerable <string> DetectModDirs()
        {
            // Prevent stack overflow (Issue #19)
            if (_gameDir == null)
            {
                return(new string[0]);
            }

            List <string> currentModDirs;
            var           validModDirs = new List <string>();

            try
            {
                currentModDirs = new DefaultConfigFile("Engine").Get("Engine.DownloadableContentEnumerator", "ModRootDirs");
            }
            catch (IOException ex)
            {
                Log.Warn("Unable to access 'XComEngine.ini'", ex);
                return(null);
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.Warn("Unable to access 'XComEngine.ini'", ex);
                return(null);
            }

            if (currentModDirs == null)
            {
                Log.Warn("No mod directories found in XComEngine.ini");
                return(new string[0]);
            }

            foreach (var modDir in currentModDirs)
            {
                try
                {
                    string dir;

                    if (Path.IsPathRooted(modDir))
                    {
                        // make sure all directories end with '\' (can only happen if someone adds a dir manually?)
                        dir = modDir.EndsWith(@"\") ? modDir : modDir + @"\";
                    }
                    else
                    {
                        dir = Path.GetFullPath(Path.Combine(GameDir, "bin", "Win64", modDir));
                        Log.Debug($"Changed non rooted mod directory from '{modDir}' to '{dir}'");
                    }

                    if (Directory.Exists(dir))
                    {
                        validModDirs.Add(dir);
                    }
                }
                catch (ArgumentException ex)
                {
                    Log.Error($"Invalid mod directory '{modDir}'", ex);
                }
            }

            return(validModDirs);
        }