public void saveToFile() { Console.WriteLine("Saving Preferences to {0}", MhoraGlobalOptions.getOptsFilename()); FileStream sOut = new FileStream(MhoraGlobalOptions.getOptsFilename(), FileMode.OpenOrCreate, FileAccess.Write); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(sOut, this); sOut.Close(); }
static public MhoraGlobalOptions readFromFile() { MhoraGlobalOptions gOpts = new MhoraGlobalOptions(); try { FileStream sOut; sOut = new FileStream(MhoraGlobalOptions.getOptsFilename(), FileMode.Open, FileAccess.Read); BinaryFormatter formatter = new BinaryFormatter(); formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; gOpts = (MhoraGlobalOptions)formatter.Deserialize(sOut); sOut.Close(); } catch { Console.WriteLine("MHora: Unable to read user preferences", "GlobalOptions"); } MhoraGlobalOptions.Instance = gOpts; return(gOpts); }