Exemple #1
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            try
            {
                using (var d = new OpenFileDialog())
                {
                    d.Filter = "Text file|*.txt";
                    if (d.ShowDialog() == DialogResult.OK)
                    {
                        Shapes.Clear();
                        listBox1.Items.Clear();

                        var strs   = File.ReadAllLines(d.FileName);
                        var shapes = Serializer.Deserialize(strs);

                        foreach (var shape in shapes)
                        {
                            Shapes.Push(shape);
                            listBox1.Items.Add(shape);
                        }
                        Redraw();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid data format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        async void loadPlayground()
        {
            var filePath = string.Empty;

#if Windows
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                using (OpenFileDialog openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.InitialDirectory = "D:\\School-D\\Jaar 2 1\\Periode 3\\Design Patterns\\MonoPaint\\Saves";
                    openFileDialog.Filter           = "monoPaint files (*.mp)|";
                    openFileDialog.FilterIndex      = 1;
                    openFileDialog.RestoreDirectory = true;

                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        filePath = openFileDialog.FileName;
                    }
                }
            }
#elif OSX
            filePath = "Saves/save.mp";
#endif

            if (filePath != string.Empty)
            {
                if (File.Exists(filePath))
                {
                    List <aShape> loadedShapes = ShapeSerializer.Deserialize(filePath);
                    SetShapes(loadedShapes);
                }
                else
                {
                    Console.WriteLine("You need to save before you can open the save");
                }
            }
        }