Inheritance: ICloneable
Exemple #1
0
 public static void log(Config cfg, LogType type = LogType.Info)
 {
     DataContractSerializer cfgSerializer = new DataContractSerializer(typeof(Config));
     MemoryStream ms = new MemoryStream();
     cfgSerializer.WriteObject(ms, cfg);
     ms.Position = 0;
     write(ms, type);
 }
Exemple #2
0
        static MeCore()
        {
            version = Application.ResourceAssembly.FullName.Split('=')[1];
            version = version.Substring(0, version.IndexOf(','));
            Logger.log("----------" + DateTime.Now.ToLongTimeString() + " launch log----------");
            Logger.log("MTMCL Ver." + version + " launching");
            Logger.log("Appdata: " + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
            if (File.Exists(Cfgfile))
            {
                LoadConfig(Cfgfile);
            }
            else if (File.Exists(CfgfileOrigin)) {
                LoadConfig(CfgfileOrigin);
            }
            else
            {
                needGuide = true;
                Config = new Config();
                Logger.log("loaded default config");
                LoadLanguage();
                LoadColor();
            }
            if (Config.requiredGuide)
            {
                needGuide = true;
            }
            if (Config.Javaw == "autosearch")
            {
                Config.Javaw = Config.GetJavaDir() ?? "javaw.exe";
            }
            if (Config.Javaxmx == -1)
            {
                Config.Javaxmx = Config.GetMemory() / 4;
            }
            LangManager.UseLanguage(Config.Lang);
            TileColor = Customize.TileColor.Load(DataDirectory + "\\mtmcl_tile_color.json");
#if DEBUG
#else
            if (!Config.failUpdateLastTime) ReleaseCheck();
            else Config.failUpdateLastTime = false;
#endif
        }
Exemple #3
0
        private static void LoadConfig(string path) {
            Config = Config.Load(path);
            Logger.log(string.Format("loaded {0}", path));
            Logger.log(Config.ToReadableLog());

            LoadLanguage();
            LoadColor();
            LoadTheme();
            if (Config.Server != null)
            {
                if (App.forceNonDedicate)
                {
                    IsServerDedicated = false;
                    Logger.log("Launching normal version due to the argument");
                }
                else
                {
                    IsServerDedicated = true;
                    Logger.log("Launching server-dedicated version");
                }
            }
            else
            {
                IsServerDedicated = false;
                Logger.log("Launching normal version due to null server info");
            }
            if (string.IsNullOrWhiteSpace(Config.MCPath))
            {
                Logger.log("Minecraft path is null or whitespace. Guide is required.");
                needGuide = true;
            }
            if (string.IsNullOrWhiteSpace(Config.Javaw))
            {
                Logger.log("javaw.exe path is null or whitespace. Guide is required.");
                needGuide = true;
            }
        }
Exemple #4
0
 public static void Save(Config cfg = null ,string file = null)
 {
     if (ConfigReadOnly) return;
     try
     {
         if (cfg == null)
         {
             cfg = MeCore.Config;
         }
         if (file == null)
         {
             ///for json
             file = MeCore.DataDirectory + "mtmcl_config.json";
             ///for xml
             //file = MeCore.BaseDirectory + "mtmcl_config.xml";
         }
         //var fs = new FileStream(file, FileMode.Create);
         ///for xml
         /*var ser = new DataContractSerializer(typeof(Config));
         ser.WriteObject(fs, cfg);*/
         ///for json
         StringBuilder sbuild = new StringBuilder();
     File.WriteAllText(file, JsonConvert.SerializeObject(cfg, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }), Encoding.UTF8);
         //fs.Close();
     }
     catch (Exception e)
     {
         Logger.log(e);
         //MessageBox.Show("cannot save config file");
     }
 }