Пример #1
0
        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();
            }
        }
Пример #2
0
 void engine_LoadRequested(object sender, SaveRestoreEventArgs e)
 {
     if (test.HasSaveFile)
     {
         e.Stream = new MemoryStream(File.ReadAllBytes(test.SaveFileName));
     }
 }
Пример #3
0
        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();
        }
Пример #4
0
 void engine_LoadRequested(object sender, SaveRestoreEventArgs e)
 {
     if (LoadRequested != null)
     {
         LoadRequested(this, e);
     }
 }
Пример #5
0
 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);
     }
 }
Пример #6
0
 private void vm_LoadRequested(object sender, SaveRestoreEventArgs e)
 {
     e.Stream = restoreStream;
 }
Пример #7
0
 private void vm_SaveRequested(object sender, SaveRestoreEventArgs e)
 {
     saveStream = new MemoryStream();
     e.Stream   = saveStream;
 }
Пример #8
0
 private void vm_LoadRequested(object sender, SaveRestoreEventArgs e)
 {
     e.Stream = (Stream)this.Invoke(new Func <Stream>(RequestLoadStream));
 }