void engine_SaveRequested(object sender, SaveRestoreEventArgs e) { if (ShowSaveLoad("Save")) { var stream = new DeferredMemoryStream(); var saveComplete = new AutoResetEvent(false); stream.Closed += delegate { Dispatcher.BeginInvoke(delegate { try { saveLoadPopup.GetSaveFile(saveLoadPopup.SaveFileName, true).Write(stream.GetBuffer(), 0, (int)stream.Length); } catch { // Ignore errors for now } finally { HideSaveLoad(); } }); }; e.Stream = stream; } else { HideSaveLoad(); } }
void engine_LoadRequested(object sender, SaveRestoreEventArgs e) { if (test.HasSaveFile) { e.Stream = new MemoryStream(File.ReadAllBytes(test.SaveFileName)); } }
void engine_LoadRequested(object sender, SaveRestoreEventArgs e) { if (ShowSaveLoad("Load")) { var loadComplete = new AutoResetEvent(false); Dispatcher.BeginInvoke(delegate { try { var name = saveLoadPopup.SaveFileName; if (saveLoadPopup.SaveFileExists(name)) { var stream = saveLoadPopup.GetSaveFile(name, false); var buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); e.Stream = new MemoryStream(buffer); } } catch { // Ignore errors for now } finally { loadComplete.Set(); } }); loadComplete.WaitOne(); } HideSaveLoad(); }
void engine_LoadRequested(object sender, SaveRestoreEventArgs e) { if (LoadRequested != null) { LoadRequested(this, e); } }
void engine_SaveRequested(object sender, SaveRestoreEventArgs e) { if (test.HasSaveFile) { e.Stream = new FileStream(test.SaveFileName, FileMode.CreateNew); } else { // first we have to make the filename test.HasSaveFile = true; test.SaveFileName = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + test.UniqueId; e.Stream = new FileStream(test.SaveFileName, FileMode.CreateNew); } }
private void vm_LoadRequested(object sender, SaveRestoreEventArgs e) { e.Stream = restoreStream; }
private void vm_SaveRequested(object sender, SaveRestoreEventArgs e) { saveStream = new MemoryStream(); e.Stream = saveStream; }
private void vm_LoadRequested(object sender, SaveRestoreEventArgs e) { e.Stream = (Stream)this.Invoke(new Func <Stream>(RequestLoadStream)); }