public static void ReadConfig(FTR2LO_Config cf) { FTR2LO_Config cf_tmp = new FTR2LO_Config(); XmlSerializer ser = new XmlSerializer(typeof(FTR2LO_Config)); if (ConfigExists()) { //create a deep copy of cf_tmp using (FileStream fs = new FileStream(_filepathConfig, FileMode.Open)) { cf_tmp = (FTR2LO_Config)ser.Deserialize(fs); cf.FilepathLO = cf_tmp.FilepathLO; cf.EarlyStart = cf_tmp.EarlyStart; cf.ServerName = cf_tmp.ServerName; cf.ServerPort = cf_tmp.ServerPort; cf.RefreshIntervalInMins = cf_tmp.RefreshIntervalInMins; cf.LogLevel = cf_tmp.LogLevel; cf.PurgeOldFTR2LOItems = cf_tmp.PurgeOldFTR2LOItems; } } else { LoadDefaults(cf); SaveConfig(cf); } }
public static void LoadDefaults(FTR2LO_Config cf) { cf.FilepathLO = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\LightsOut\\TaskList.xml"; cf.EarlyStart = "3"; cf.ServerName = "localhost"; cf.ServerPort = "49943"; cf.RefreshIntervalInMins = "1"; cf.LogLevel = FTR2LO_Log.FTR2LO_log.stringLogLevel((int)FTR2LO_Log.FTR2LO_log.LogLevel.WARNING); cf.PurgeOldFTR2LOItems = bool.FalseString; }
public static void LoadDefaults(FTR2LO_Config cf) { cf.FilepathLO = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\LightsOut\\TaskList.xml"; cf.EarlyStart = "3"; cf.ServerName = "localhost"; cf.ServerPort = "49943"; cf.RefreshIntervalInMins = "1"; cf.LogLevel = FTR2LO_Log.FTR2LO_log.stringLogLevel((int)FTR2LO_Log.FTR2LO_log.LogLevel.WARNING); cf.PurgeOldFTR2LOItems = bool.FalseString; }
public static void CheckExistingConfigValidity() { FTR2LO_Config cf = new FTR2LO_Config(); FTR2LO_Config cf_default = new FTR2LO_Config(); bool _updaterequired = false; if (ConfigExists()) { ReadConfig(cf); } LoadDefaults(cf_default); if (String.IsNullOrEmpty(cf.FilepathLO)) { cf.FilepathLO = cf_default.FilepathLO; _updaterequired = true; } if (String.IsNullOrEmpty(cf.EarlyStart)) { cf.EarlyStart = cf_default.EarlyStart; _updaterequired = true; } if (String.IsNullOrEmpty(cf.ServerName)) { cf.ServerName = cf_default.ServerName; _updaterequired = true; } if (String.IsNullOrEmpty(cf.ServerPort)) { cf.ServerPort = cf_default.ServerPort; _updaterequired = true; } if (String.IsNullOrEmpty(cf.RefreshIntervalInMins)) { cf.RefreshIntervalInMins = cf_default.RefreshIntervalInMins; _updaterequired = true; } if (String.IsNullOrEmpty(cf.LogLevel)) { cf.LogLevel = cf_default.LogLevel; _updaterequired = true; } if (String.IsNullOrEmpty(cf.PurgeOldFTR2LOItems)) { cf.PurgeOldFTR2LOItems = cf_default.PurgeOldFTR2LOItems; _updaterequired = true; } if (_updaterequired) { SaveConfig(cf); } }
public static void CheckExistingConfigValidity() { FTR2LO_Config cf = new FTR2LO_Config(); FTR2LO_Config cf_default = new FTR2LO_Config(); bool _updaterequired = false; if(ConfigExists()) ReadConfig(cf); LoadDefaults(cf_default); if (String.IsNullOrEmpty(cf.FilepathLO)) { cf.FilepathLO = cf_default.FilepathLO; _updaterequired = true; } if(String.IsNullOrEmpty(cf.EarlyStart)) { cf.EarlyStart = cf_default.EarlyStart; _updaterequired = true; } if(String.IsNullOrEmpty(cf.ServerName)) { cf.ServerName = cf_default.ServerName; _updaterequired = true; } if(String.IsNullOrEmpty(cf.ServerPort)) { cf.ServerPort = cf_default.ServerPort; _updaterequired = true; } if (String.IsNullOrEmpty(cf.RefreshIntervalInMins)) { cf.RefreshIntervalInMins = cf_default.RefreshIntervalInMins; _updaterequired = true; } if (String.IsNullOrEmpty(cf.LogLevel)) { cf.LogLevel = cf_default.LogLevel; _updaterequired = true; } if(String.IsNullOrEmpty(cf.PurgeOldFTR2LOItems)) { cf.PurgeOldFTR2LOItems = cf_default.PurgeOldFTR2LOItems; _updaterequired = true; } if (_updaterequired) SaveConfig(cf); }
public static void SaveConfig(FTR2LO_Config cf) { XmlSerializer ser = new XmlSerializer(typeof(FTR2LO_Config)); FileMode myfilemode; if (ConfigExists()) { myfilemode = FileMode.Truncate; } else { myfilemode = FileMode.Create; } using (FileStream fs = new FileStream(_filepathConfig, myfilemode)) { TextWriter tw = new StreamWriter(fs); ser.Serialize(tw, cf); tw.Close(); } }
public static void ReadConfig(FTR2LO_Config cf) { FTR2LO_Config cf_tmp = new FTR2LO_Config(); XmlSerializer ser = new XmlSerializer(typeof(FTR2LO_Config)); if (ConfigExists()) { //create a deep copy of cf_tmp using (FileStream fs = new FileStream(_filepathConfig, FileMode.Open)) { cf_tmp = (FTR2LO_Config)ser.Deserialize(fs); cf.FilepathLO = cf_tmp.FilepathLO; cf.EarlyStart = cf_tmp.EarlyStart; cf.ServerName = cf_tmp.ServerName; cf.ServerPort = cf_tmp.ServerPort; cf.RefreshIntervalInMins = cf_tmp.RefreshIntervalInMins; cf.LogLevel = cf_tmp.LogLevel; cf.PurgeOldFTR2LOItems = cf_tmp.PurgeOldFTR2LOItems; } } else { LoadDefaults(cf); SaveConfig(cf); } }
public static void SaveConfig(FTR2LO_Config cf) { XmlSerializer ser = new XmlSerializer(typeof(FTR2LO_Config)); FileMode myfilemode; if (ConfigExists()) { myfilemode = FileMode.Truncate; } else { myfilemode = FileMode.Create; } using (FileStream fs = new FileStream(_filepathConfig, myfilemode)) { TextWriter tw = new StreamWriter(fs); ser.Serialize(tw, cf); tw.Close(); } }