Exemplo n.º 1
0
        public void ExecuteCommandAndPrintResult(string cmd)
        {
            if (PrintUsedCommand)
            {
                PrintLine("> " + cmd, color: new Color(87 / 255f, 87 / 255f, 87 / 255f));
            }
            try {
                PrintLine(ExecuteCommand(cmd));
            } catch (Exception e) {
                PrintError("Exception while executing command:");
                PrintError(e.Message);
                PrintError("More detailed info in the log.");

                Logger.Error($"Exception while running command '{cmd}':");
                Logger.Error(e.Message);
                var stlines = e.StackTrace.Split('\n');

                for (int i = 0; i < stlines.Length; i++)
                {
                    Logger.ErrorIndent(stlines[i]);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads mods from the SemiMods folder, respecting order.txt, blacklist.txt and MySemiMods.txt.
        /// </summary>
        internal static void LoadMods()
        {
            FlatModInfos = new Dictionary <string, ModInfo>();

            var            mods_dir      = FileHierarchy.ModsFolder;
            var            mod_files     = Directory.GetFileSystemEntries(mods_dir);
            var            ignore_ary    = SimpleListFileParser.ParseFile(FileHierarchy.ModsBlacklistFile, trim: true);
            var            order_ary     = SimpleListFileParser.ParseFile(FileHierarchy.ModsOrderFile, trim: true);
            List <ModInfo> ordered_infos = null;

            Logger.Debug($"Preloading mods.");

            for (int i = 0; i < mod_files.Length; i++)
            {
                var mod_file = mod_files[i];
                Logger.Debug($"Entry: {mod_file}");

                var filename = Path.GetFileName(mod_file);

                if (filename == FileHierarchy.MODS_ORDER_FILE_NAME)
                {
                    continue;
                }
                if (filename == FileHierarchy.MODS_BLACKLIST_FILE_NAME)
                {
                    continue;
                }
                if (filename == FileHierarchy.MODS_CACHE_FOLDER_NAME)
                {
                    continue;
                }
                if (filename.EndsWithInvariant(".sum"))
                {
                    continue;
                }

                if (ignore_ary != null && ignore_ary.Contains(filename))
                {
                    continue;
                }

                if (File.Exists(mod_file))
                {
                    throw new Exception("mod archives not supported yet");
                }
                try {
                    var is_ordered = order_ary != null && order_ary.Contains(filename);

                    var info = PreloadModDir(filename, mod_file, order_ary != null && order_ary.Contains(filename));

                    if (is_ordered)
                    {
                        if (ordered_infos == null)
                        {
                            ordered_infos = new List <ModInfo>();
                        }
                        ordered_infos.Add(info);
                    }
                } catch (Exception e) {
                    ModLoadErrors.Add(new ModError {
                        Name      = CurrentLoadingModName,
                        ID        = CurrentLoadingModID ?? filename,
                        Exception = e
                    });
                    Logger.Error($"Failed preloading mod: [{e.GetType().Name}] {e.Message}");
                    Logger.ErrorPretty(e.StackTrace);
                }
            }

            Logger.Debug($"{FlatModInfos.Count} mods found.");

            ModLoadOrder = new List <ModConfig>();

            if (ordered_infos != null)
            {
                Logger.Debug($"Loading ordered mods first");

                for (var i = 0; i < ordered_infos.Count; i++)
                {
                    var mod_info = ordered_infos[i];
                    Logger.Debug($"Forced order mod #{i + 1}: '{mod_info.Config.ID}'");

                    try {
                        LoadMod(mod_info);
                    } catch (Exception e) {
                        ModLoadErrors.Add(new ModError {
                            Name      = CurrentLoadingModName,
                            ID        = CurrentLoadingModID ?? "???",
                            Exception = e
                        });
                        Logger.Error($"Failed loading mod: [{e.GetType().Name}] {e.Message}");
                        Logger.ErrorPretty(e.StackTrace);
                    }
                }
            }

            Logger.Debug($"Loading mods");

            foreach (var mod in FlatModInfos)
            {
                Logger.Debug($"Mod: '{mod.Key}'");

                try {
                    LoadMod(mod.Value);
                } catch (Exception e) {
                    ModLoadErrors.Add(new ModError {
                        Name      = CurrentLoadingModName,
                        ID        = CurrentLoadingModID ?? "???",
                        Exception = e
                    });
                    Logger.Error($"Failed loading mod: [{e.GetType().Name}] {e.Message}");
                    Logger.ErrorPretty(e.StackTrace);
                }
            }
        }