public static void LoadSaved() { string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\smartchain"; if ((!System.IO.Directory.Exists(path))) { System.IO.Directory.CreateDirectory(path); } System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); if (File.Exists(path + "\\utxos.sc")) { FileStream DataFileStream = new FileStream(path + "\\utxos.sc", FileMode.Open); try { SaveFile save = (SaveFile)bf.Deserialize(DataFileStream); utxos = save.utxos; SyncHeight = save.sync_height; DataFileStream.Close(); } catch (Exception ex) { DataFileStream.Close(); } } if (File.Exists(path + "\\stakes.sc")) { FileStream DataFileStream = new FileStream(path + "\\stakes.sc", FileMode.Open); try { stakesSaveFile _stakes = (stakesSaveFile)bf.Deserialize(DataFileStream); stakes = _stakes.Stakes; DataFileStream.Close(); } catch (Exception ex) { DataFileStream.Close(); } } //End If }
public static void Save(Collection <utxo> _utxos, int _SyncHeight, Collection <stake> _stakes) { SaveFile savedstate = new SaveFile { sync_height = _SyncHeight, utxos = _utxos, }; stakesSaveFile savedStakes = new stakesSaveFile { Stakes = _stakes, }; string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\smartchain"; if ((!System.IO.Directory.Exists(path))) { System.IO.Directory.CreateDirectory(path); } FileStream SaveDataFilestream = new FileStream(path + "\\utxos.sc", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None); FileStream SaveStakeFilestream = new FileStream(path + "\\stakes.sc", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None); System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); try { bf.Serialize(SaveDataFilestream, savedstate); bf.Serialize(SaveStakeFilestream, savedStakes); } catch (Exception ex1) { throw ex1; } SaveDataFilestream.Close(); SaveStakeFilestream.Close(); Console.WriteLine("sucessfully wrote save data"); return; }