public static void Log(Config cfg, LogType type = LogType.Info) { var cfgSerializer = new DataContractSerializer(typeof(Config)); var 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 V4 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 (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 = "bmcl.xml") { if (cfg == null) { cfg = BmclCore.Config; } var fs = new FileStream(file, FileMode.Create); var ser = new DataContractSerializer(typeof(Config)); ser.WriteObject(fs, cfg); fs.Close(); }