public static ProgramConfiguration Load(FileInfo file) { using (FileStream fs = file.OpenRead()) { ProgramConfiguration config = Serializer.Deserialize(fs) as ProgramConfiguration; if (config != null) { config.SerializationFile = file; } return(config); } }
private static bool ReadConfiguration() { try { FileInfo file = new FileInfo(CONFIGURATION_FILE); ProgramConfiguration config; if (file.Exists) { config = ProgramConfiguration.Load(file); if (config.ChangeThisToTrue) { Configuration = config; return(true); } else { Logger.Warning("Initial configuration not completely edited. \"ChangeThisToTrue\" is false."); Exit(ExitCodes.ConfigurationEditRequired); return(false); } } else { config = new ProgramConfiguration(); config.Initialize(file); config.Save(); Logger.Info("Initial configuration created. Edit it, then re-run program."); Exit(ExitCodes.InitializedConfiguration); return(false); } } catch (Exception ex) { Logger.Error("Unable to read/write configuration file: {0}", ex.Message); Exit(ExitCodes.ConfigurationIOError); return(false); } }