Esempio n. 1
0
        public static bool LoadState(Application app)
        {
            // Opens up a file browser window, to choose a simulation save file

            using (OpenFileDialog dialog = new OpenFileDialog()) {
                // Filters what files are shown, to only show *.bin files
                dialog.Filter = "Save State|*.bin";
                dialog.Title  = "Load Simulation State";

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    SimulationSave save = ReadBinaryFile(dialog.FileName);
                    if (save != null)
                    {
                        // If the file is read correctly, switch the app state to the loaded simulation
                        app.SwitchState(ReadBinaryFile(dialog.FileName).ToSimulation(app));
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
 public static void WriteBinaryFile(string filePath, SimulationSave toWrite)
 {
     // Creates a new file, with a serialized simulation save
     using (Stream stream = File.Open(filePath, FileMode.Create))
         new BinaryFormatter().Serialize(stream, toWrite);
 }