Example #1
0
 public void PrintError(string txt, bool log = false)
 {
     if (txt.IndexOf('\n') == -1)
     {
         PrintLine(txt, color: UnityUtil.NewColorRGB(255, 110, 110));
     }
     else
     {
         foreach (var line in txt.Split('\n'))
         {
             PrintError(line);
         }
     }
     if (log)
     {
         _Logger.ErrorPretty(txt);
     }
 }
Example #2
0
 public void PrintError(string txt, bool log = false)
 {
     if (txt.IndexOf('\n') == -1)
     {
         PrintLine(txt, color: new Color(255 / 255f, 110 / 255f, 110 / 255f));
     }
     else
     {
         foreach (var line in txt.Split('\n'))
         {
             PrintError(line);
         }
     }
     if (log)
     {
         Logger.ErrorPretty(txt);
     }
 }
Example #3
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);
                }
            }
        }