/// <summary> /// Opens a bin-file and converts it to a SaveFile that gets returned. /// </summary> public SaveFile LoadState() { SaveFile tmpFile = new SaveFile(); Stream fileStreamer; BinaryFormatter bf; try { using(fileStreamer = File.Open("state.bin", FileMode.Open)) { bf = new BinaryFormatter(); var tmpState = bf.Deserialize(fileStreamer); tmpFile = (SaveFile)tmpState; return tmpFile; } } catch { return tmpFile; } }
/// <summary> /// Takes a SaveFile and puts it to a binary file. /// </summary> public void SaveState(SaveFile pSaveFile) { Stream fileStreamer; BinaryFormatter bf; fileStreamer = File.Open("state.bin", FileMode.Create); bf = new BinaryFormatter(); bf.Serialize(fileStreamer, pSaveFile); fileStreamer.Close(); }
/// <summary> /// Save the current state of the program when the form is closed /// </summary> private void saveState() { SaveFile tmpSaveFile = new SaveFile(mathEngine, oldNumber, newNumber, firstNumberEntered, resultInTextbox, calcButtonClicked, calculationSign, currentCalculation, currentInput, previousCalculations); SaveLoad tmpSaver = new SaveLoad(); tmpSaver.SaveState(tmpSaveFile); }