void Save(List <Note_Handler.Note> noteList, List <Deck_Handler.Deck> deckList, bool audio) // Save the notes and flashcard decks currently available { FileStream file = null; try { BinaryFormatter bf = new BinaryFormatter(); file = File.Create(Application.persistentDataPath + dataPath); Save_File dataSet = new Save_File(noteList, deckList, audio); bf.Serialize(file, dataSet); } catch (Exception e) { if (e != null) { Debug.LogError("File Saving Failed."); Debug.LogException(e, this); } } finally { if (file != null) { file.Close(); } } }
private static Save_File_Data LoadFileV0_4_4_0(BinaryReader reader) { return(new Save_File_Data { Options = Game_Options.read(reader), File = Save_File.read(reader) }); }
void Load() // Load the notes and decks that were saved on quit { FileStream file = null; try { BinaryFormatter bf = new BinaryFormatter(); file = File.Open(Application.persistentDataPath + dataPath, FileMode.Open); loadedFile = bf.Deserialize(file) as Save_File; List <Note_Handler.Note> clearednoteList = new List <Note_Handler.Note>(loadedFile.noteList); List <Deck_Handler.Deck> cleareddeckList = new List <Deck_Handler.Deck>(loadedFile.deckList); if (clearednoteList != null) { foreach (var note in clearednoteList) { note.instantiated = false; } } if (cleareddeckList != null) { foreach (var deck in cleareddeckList) { deck.instantiated = false; foreach (var card in deck.content) { card.instantiated = false; } foreach (var session in deck.practiceSessions) { foreach (var detail in session.details) { detail.instantiated = false; } } } } if (clearednoteList != null && cleareddeckList != null) { note_handler.dataList = clearednoteList; note_handler.UpdateList(); deck_handler.dataList = cleareddeckList; deck_handler.UpdateList(); } else { throw new ArgumentException("Load data is empty."); } settings.audioToggle.isOn = loadedFile.audio; settings.ToggleAudio(); } catch (Exception e) { if (e != null) { Debug.LogError("File Loading Failed."); Debug.LogException(e, this); } } finally { if (file != null) { file.Close(); } } }