Beispiel #1
0
            private void ViewInfo()
            {
                try {
                    if (ExportSelect.SelectedItems.Count > 0)
                    {
                        Elem.Select.SelectItem lvl = (Elem.Select.SelectItem)ExportSelect.SelectedItems[0];
                        dynamic LevelInfo          = GDTools.GetLevelInfo(lvl.Text);

                        string Info = "";

                        foreach (PropertyInfo i in LevelInfo.GetType().GetProperties())
                        {
                            if (i.Name != "Name" && i.Name != "Creator" && i.Name != "Description")
                            {
                                Info += $"{i.Name.Replace("_", " ")}: {i.GetValue(LevelInfo)}\n";
                            }
                        }

                        MessageBox.Show(Info, $"Info for {lvl.Text}", MessageBoxButtons.OK, MessageBoxIcon.None);
                    }
                } catch (Exception err) {
                    MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
Beispiel #2
0
            public Backups()
            {
                this.Name = "Backups";
                this.Dock = DockStyle.Fill;
                Meth.HandleTheme(this);

                EventHandler ViewBackup = (s, e) => {
                    if (BackupSelect.SelectedItem != null)
                    {
                        Elem.Select.SelectItem backup = (Elem.Select.SelectItem)BackupSelect.SelectedItem;

                        Form Info = new Form();
                        Info.Size        = new Size(Meth._S(350), Meth._S(400));
                        Info.Text        = $"Viewing {backup.Text}";
                        Info.Icon        = new Icon(Settings.IconPath);
                        Info.FormClosed += (s, e) => Info.Dispose();

                        Meth.HandleTheme(Info);

                        Elem.Text Load = new Elem.Text("Loading...");

                        Info.Show();

                        Info.Controls.Add(Load);

                        dynamic BackupInfo = GDTools.Backups.GetBackupInfo(backup.Text);

                        string User = "";

                        Elem.Select Levels = new Elem.Select(false);
                        Levels.DoubleClick += (s, e) => {
                            if (Levels.SelectedItem != null)
                            {
                                Elem.Select.SelectItem lvl = (Elem.Select.SelectItem)Levels.SelectedItem;
                                dynamic LevelInfo          = GDTools.GetLevelInfo(lvl.Text, BackupInfo.Levels);

                                string Info = "";

                                foreach (PropertyInfo i in LevelInfo.GetType().GetProperties())
                                {
                                    if (i.Name != "Name" && i.Name != "Creator" && i.Name != "Description")
                                    {
                                        Info += $"{i.Name.Replace("_", " ")}: {i.GetValue(LevelInfo)}\n";
                                    }
                                }

                                MessageBox.Show(Info, $"Info for {lvl.Text}", MessageBoxButtons.OK, MessageBoxIcon.None);
                            }
                        };

                        foreach (PropertyInfo i in BackupInfo.User.Stats.GetType().GetProperties())
                        {
                            User += $"{i.Name.Replace("_", " ")}: {i.GetValue(BackupInfo.User.Stats)}\r\n";
                        }

                        foreach (dynamic lvl in BackupInfo.Levels)
                        {
                            Levels.AddItem(lvl.Name);
                        }

                        Info.Controls.Remove(Load);

                        FlowLayoutPanel Contain = new FlowLayoutPanel();
                        Contain.Dock     = DockStyle.Fill;
                        Contain.AutoSize = true;

                        Contain.Controls.Add(new Elem.Text(User));
                        Contain.Controls.Add(new Elem.BigNewLine());
                        Contain.Controls.Add(Levels);
                        Contain.Controls.Add(new Elem.Text("Double-click to view level"));

                        Info.Controls.Add(Contain);
                    }
                };

                GDTools.Backups.InitBackups();

                BackupSelect              = new Elem.Select(false);
                BackupSelect.DoubleClick += ViewBackup;

                BackupPath  = new Elem.Text();
                BackupsSize = new Elem.Text();

                RefreshBackupList();

                ContextMenuStrip CM = new ContextMenuStrip();

                CM.Items.Add(new ToolStripMenuItem("View selected backup", null, ViewBackup));
                BackupSelect.ContextMenuStrip = CM;

                this.Controls.Add(BackupSelect);

                this.Controls.Add(BackupsSize);

                this.Controls.Add(new Elem.Div(new Control[] {
                    new Elem.But("View", ViewBackup, "This button shows info about the backup. (You can do the same by double-clicking a backup on the list)"),
                    new Elem.But("Load", (s, e) => {
                        Elem.ChooseForm BackupCurrent = new Elem.ChooseForm(
                            "Backup current progress?",
                            new string[] { "Yes", "No", "Cancel" },
                            "Would you like to backup your current GD progress before loading?"
                            );

                        BackupCurrent.Show();

                        BackupCurrent.Finish += (s) => {
                            if (s == 2)
                            {
                                return;
                            }
                            if (BackupSelect.SelectedItem != null)
                            {
                                if (s == 0)
                                {
                                    GDTools.Backups.CreateNewBackup();
                                }

                                GDTools.Backups.SwitchToBackup(((Elem.Select.SelectItem)BackupSelect.SelectedItem).Text);

                                Program.MainForm.FullReload();
                            }
                        };
                    }, "Switches your current GD progress to that of the backup. Asks you before switching if you'd like to save your current progress."),
                    new Elem.But("Delete", (s, e) => {
                        if (BackupSelect.SelectedItem != null)
                        {
                            Elem.ChooseForm Y = new Elem.ChooseForm("Are you sure?", new string[] { "Yes", "Cancel" }, "Are you sure you want to delete this backup?");

                            Y.Show();

                            Y.Finish += s => {
                                if (s != 0)
                                {
                                    return;
                                }

                                GDTools.Backups.DeleteBackup(((Elem.Select.SelectItem)BackupSelect.SelectedItem).Text);

                                RefreshBackupList();
                            };
                        }
                    }, "Deletes the selected backup permanently.")
                }));

                this.Controls.Add(new Elem.Div(new Control[] {
                    new Elem.But("New", (s, e) => {
                        GDTools.Backups.CreateNewBackup();
                        RefreshBackupList();
                    }, "Creates a new backup of your current GD progress."),
                    new Elem.But("Import Backup", (s, e) => {
                        Elem.ChooseForm FileOrFolder = new Elem.ChooseForm("Select backup type", new string[] { "Folder", $"Compressed file (.zip / .{GDTools.Ext.Backup})" });

                        FileOrFolder.Show();

                        FileOrFolder.Finish += (s) => {
                            if (s == 0)
                            {
                                using (FolderBrowserDialog ofd = new FolderBrowserDialog()) {
                                    ofd.Description = "Select a backup folder";

                                    if (ofd.ShowDialog() == DialogResult.OK)
                                    {
                                        GDTools.Backups.ImportBackup(ofd.SelectedPath);
                                        RefreshBackupList();
                                    }
                                }
                            }
                            else
                            {
                                using (OpenFileDialog ofd = new OpenFileDialog()) {
                                    ofd.InitialDirectory = "c:\\";
                                    ofd.Filter           = GDTools.Ext.BackupFilter;
                                    ofd.FilterIndex      = 1;
                                    ofd.RestoreDirectory = true;
                                    ofd.Multiselect      = true;

                                    if (ofd.ShowDialog() == DialogResult.OK)
                                    {
                                        foreach (string file in ofd.FileNames)
                                        {
                                            ImportBackup(file);
                                        }
                                    }
                                }
                            }
                        };
                    }, "This button lets you import backups you've made before.")
                }));

                this.Controls.Add(new Elem.BigNewLine());
                this.Controls.Add(BackupPath);

                this.Controls.Add(new Elem.Div(new Control[] {
                    new Elem.But("Change Folder", (s, e) => {
                        using (FolderBrowserDialog ofd = new FolderBrowserDialog()) {
                            ofd.Description = "Select backup directory";

                            if (ofd.ShowDialog() == DialogResult.OK)
                            {
                                GDTools.Backups.SetBackupLocation(ofd.SelectedPath);
                                RefreshBackupList();
                            }
                        }
                    }, "Change the folder where backups are saved. All backups are automatically moved to the new location."),
                    new Elem.But("Open Folder", (s, e) => Process.Start("explorer.exe", GDTools._BackupDirectory), "Opens the backup folder in File Explorer."),
                    new Elem.But("Refresh Folder", (s, e) => RefreshBackupList(), "Reloads the backup list.")
                }));
                this.Controls.Add(new Elem.BigNewLine());
                this.Controls.Add(new Elem.But("Help", (s, e) => Pages.SettingPage.ShowHelp("backups")));
                //this.Controls.Add(new Elem.BigNewLine());
                //this.Controls.Add(new Elem.But("Link backups to Google Drive"));
            }