public static BinaryStorage Get(BinarySerializationEngine<BinaryStorage> serializationEngine) { if (storage == null) { storage = new BinaryStorage(); storage.binStorage = serializationEngine; try { storage.FolderLinks = storage.binStorage.Get().FolderLinks; storage.Settings = storage.binStorage.Get().Settings; } catch (NullReferenceException nex) { storage.FolderLinks = new List<FolderLink>(); storage.Settings = new List<Setting>(); } } return storage; }
private void button8_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "K+ Shortcut SaveFile|*.bin"; if (ofd.ShowDialog() == DialogResult.OK) { try { BinarySerializationEngine<BinaryStorage> b = new BinarySerializationEngine<BinaryStorage>(ofd.FileName); var v = b.Get(); try { if(File.Exists(SystemUtility.StorageFileInAppDataPath)) { File.Delete(SystemUtility.StorageFileInAppDataPath); } File.Copy(ofd.FileName, SystemUtility.StorageFileInAppDataPath); Form1.msg("Your application settings were restored successfully!"); } catch (Exception ex) { Form1.msg(ex.Message + " " + "Please try again!", MessageBoxIcon.Exclamation); } } catch (Exception ex) {Form1.msg("The save file is currupted!. " + ex.Message, MessageBoxIcon.Exclamation);} } }