Ejemplo n.º 1
0
        public static void LoadProject <T>(ISavable <T> view, bool dialog = false, bool message = true)
        {
            if (dialog)
            {
                Directory.CreateDirectory(view.DefaultSaveFolder);
            }
            string path = dialog ? IOHelper.LoadProjectDialog(view.DefaultSaveFolder) : view.AutoSavePath;

            // If the file name is not an empty string open it for saving.
            if (path == "")
            {
                return;
            }
            try {
                T project = LoadJson <T>(path);

                if (project == null)
                {
                    throw new Exception("Loaded project is a null reference.");
                }

                view.SetSaveData(project);
            } catch (Exception ex) {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);

                if (message)
                {
                    MessageBox.Show("Project could not be loaded!");
                    ex.Show();
                }
            }
        }
Ejemplo n.º 2
0
        public static void NewProject <T>(ISavable <T> view, bool dialog = false, bool message = true)
        {
            if (dialog)
            {
                var messageBoxResult = MessageBox.Show("Are you sure you want to start a new project? All unsaved progress will be lost.", "Confirm new project", MessageBoxButton.YesNo);
                if (messageBoxResult != MessageBoxResult.Yes)
                {
                    return;
                }
            }

            try {
                T project = Activator.CreateInstance <T>();
                view.SetSaveData(project);
            } catch (Exception ex) {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);

                if (message)
                {
                    MessageBox.Show("New project could not be initialized!");
                    ex.Show();
                }
            }
        }