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); }
static BmclCore() { BmclVersion = Application.ResourceAssembly.FullName.Split('=')[1]; BmclVersion = BmclVersion.Substring(0, BmclVersion.IndexOf(',')); Logger.log("BMCL V3 Ver." + BmclVersion + "正在启动"); if (File.Exists(Cfgfile)) { Config = Config.Load(Cfgfile); if (Config.Passwd == null) { Config.Passwd = new byte[0]; //V2的密码存储兼容 } Logger.log(String.Format("加载{0}文件", Cfgfile)); Logger.log(Config); LoadLanguage(); ChangeLanguage(Config.Lang); } else { Config = new Config(); Logger.log("加载默认配置"); } if (!Directory.Exists(BaseDirectory + ".minecraft")) { Directory.CreateDirectory(BaseDirectory + ".minecraft"); } if (Config.Javaw == "autosearch") { Config.Javaw = Config.GetJavaDir(); } if (Config.Javaxmx == "autosearch") { Config.Javaxmx = (Config.GetMemory() / 4).ToString(CultureInfo.InvariantCulture); } LangManager.UseLanguage(Config.Lang); if (!App.SkipPlugin) { LoadPlugin(LangManager.GetLangFromResource("LangName")); } #if DEBUG #else ReleaseCheck(); #endif }
public static void Save(Config cfg = null ,string file = null) { if (cfg == null) { cfg = BmclCore.Config; } if (file == null) { file = BmclCore.BaseDirectory + "bmcl.xml"; } var fs = new FileStream(file, FileMode.Create); var ser = new DataContractSerializer(typeof(Config)); ser.WriteObject(fs, cfg); fs.Close(); }