예제 #1
0
        private static void CommandLineModPackOverride()
        {
            if (commandLineModPack == "")
            {
                return;
            }

            if (!commandLineModPack.EndsWith(".json"))
            {
                commandLineModPack += ".json";
            }

            string filePath = Path.Combine(UIModPacks.ModListSaveDirectory, commandLineModPack);

            try {
                Directory.CreateDirectory(UIModPacks.ModListSaveDirectory);
                Logging.ServerConsoleLine(Language.GetTextValue("tModLoader.LoadingSpecifiedModPack", commandLineModPack));
                var modSet = JsonConvert.DeserializeObject <HashSet <string> >(File.ReadAllText(filePath));
                foreach (var mod in FindMods())
                {
                    ModLoader.SetModEnabled(mod.Name, modSet.Contains(mod.Name));
                }
            }
            catch (Exception e) {
                var msg = (e is FileNotFoundException) ? Language.GetTextValue("tModLoader.ModPackDoesNotExist", filePath) : Language.GetTextValue("tModLoader.ModPackMalformed", commandLineModPack);
                throw new Exception(msg, e);
            }
            finally {
                commandLineModPack = "";
            }
        }
예제 #2
0
        private static bool CommandLineModPackOverride()
        {
            if (commandLineModPack == "")
            {
                return(true);
            }

            if (!commandLineModPack.EndsWith(".json"))
            {
                commandLineModPack += ".json";
            }

            string filePath = Path.Combine(UI.UIModPacks.ModListSaveDirectory, commandLineModPack);

            try
            {
                Directory.CreateDirectory(UI.UIModPacks.ModListSaveDirectory);

                Console.WriteLine(Language.GetTextValue("tModLoader.LoadingSpecifiedModPack", commandLineModPack) + "\n");
                var modSet = JsonConvert.DeserializeObject <HashSet <string> >(File.ReadAllText(filePath));
                foreach (var mod in ModOrganizer.FindMods())
                {
                    ModLoader.SetModEnabled(mod.Name, modSet.Contains(mod.Name));
                }

                return(true);
            }
            catch (Exception e)
            {
                string err;
                if (e is FileNotFoundException)
                {
                    err = Language.GetTextValue("tModLoader.ModPackDoesNotExist", filePath) + "\n";
                }
                else
                {
                    err = Language.GetTextValue("tModLoader.ModPackDoesNotExist", commandLineModPack, e.Message) + "\n";
                }

                if (Main.dedServ)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(err);
                    Console.ResetColor();
                }
                else
                {
                    Main.menuMode = Interface.errorMessageID;
                    Interface.errorMessage.SetMessage(err);
                }

                return(false);
            }
            finally
            {
                commandLineModPack = "";
            }
        }