public LoadProjectControler()
        {
            if (GlowingEarth.getInstance().getMaster().getTitle().Contains("*"))
            {
                DialogResult dr = MessageBox.Show("Do you want to save changes?", "Save changes", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                {
                    OpenFileDialog fid = new OpenFileDialog();
                    fid.DefaultExt = ".gemap";
                    fid.Filter     = "Glowing Earth Map (*.gemap)|*.gemap";

                    DialogResult diir = fid.ShowDialog();
                    if (diir == System.Windows.Forms.DialogResult.OK)
                    {
                        SaveProjectControler spc = new SaveProjectControler();
                    }
                }
            }
            OpenFileDialog fd = new OpenFileDialog();

            fd.DefaultExt = ".gemap";
            fd.Filter     = "Glowing Earth Map (*.gemap)|*.gemap";

            DialogResult dir = fd.ShowDialog();

            if (dir == System.Windows.Forms.DialogResult.OK)
            {
                path = fd.FileName;
                BinaryFormatter fm = new BinaryFormatter();
                FileStream      sm = null;
                try {
                    sm = File.OpenRead(path);
                    Model.MasterClass x = (Model.MasterClass)fm.Deserialize(sm);
                    GlowingEarth.getInstance().getMaster().setTags(x.getTags());
                    GlowingEarth.getInstance().getMaster().setTypes(x.getTypes());
                    GlowingEarth.getInstance().getMaster().setResources(x.getResources());
                    GlowingEarth.getInstance().getMaster().setTitle(x.getTitle());
                    GlowingEarth.getInstance().getMaster().setSerPath(x.getSerPath());
                    GlowingEarth.getInstance().getMaster().setMapItems(x.getMapItems());
                    ThisWasLastController tc = new ThisWasLastController("save");
                }
                catch (Exception e)
                {
                    MessageBox.Show("Loading went wrong. Please, try again. If the problem persists, contact your administrator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    if (sm != null)
                    {
                        sm.Dispose();
                        sm.Close();
                    }
                }
            }
        }
示例#2
0
        public NewProjectControler(string name)
        {
            if (GlowingEarth.getInstance().getMaster().getTitle().Contains("*"))
            {
                if (MessageBox.Show("You have some unsaved changes on current map. Do you want to save those changes?", "Save changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    SaveFileDialog fd = new SaveFileDialog();
                    fd.DefaultExt = ".gemap";
                    fd.Filter     = "Glowing Earth Map (*.gemap)|*.gemap";

                    DialogResult dr = fd.ShowDialog();
                    if (dr == System.Windows.Forms.DialogResult.OK)
                    {
                        GlowingEarth.getInstance().getMaster().setSerPath(fd.FileName);
                        saveProject(fd.FileName);
                    }
                }
            }
            projName = "Glowing Earth - " + name;
            GlowingEarth.getInstance().getMaster().getResources().Clear();
            GlowingEarth.getInstance().getMaster().getTypes().Clear();
            GlowingEarth.getInstance().getMaster().getTags().Clear();
            GlowingEarth.getInstance().getMaster().getMapItems().Clear();
            GlowingEarth.getInstance().getMaster().setTitle(projName);

            if (MessageBox.Show("To see this project next time you open Glowing Earth, you should save this project.\nDo you want to save this project?", "Save new project", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                SaveFileDialog fd = new SaveFileDialog();
                fd.DefaultExt = ".gemap";
                fd.Filter     = "Glowing Earth Map (*.gemap)|*.gemap";

                DialogResult dr = fd.ShowDialog();
                if (dr == System.Windows.Forms.DialogResult.OK)
                {
                    GlowingEarth.getInstance().getMaster().setSerPath(fd.FileName);
                    saveProject(fd.FileName);
                    ThisWasLastController tc = new ThisWasLastController("save");
                }
            }
        }