void editDirectoryButton_Click(object sender, EventArgs e)
        {
            if (directoryList.SelectedItem != null)
            {
                Debug.Assert(directoryList.SelectedItem is GamesDirectory);
                GamesDirectory    selectedDirectory = (GamesDirectory)directoryList.SelectedItem;
                GameDirectoryForm gameDirectoryForm = new GameDirectoryForm(DirectoryFormIntent.Edit, selectedDirectory);
                gameDirectoryForm.FormClosing += (s, args) =>
                {
                    if (gameDirectoryForm.ResultID == DirectoryFormResult.Edited)
                    {
                        Config.Update();

                        var temp = directoryList.DataSource;
                        directoryList.DataSource = null;
                        directoryList.DataSource = temp;
                    }

                    Enabled = true;
                };

                Enabled = false;
                gameDirectoryForm.Show();
            }
        }
예제 #2
0
        public List <GamesDirectory> AddGamesDirectory(GamesDirectory newDirectory)
        {
            GamesDirectories.Add(newDirectory);
            Update();

            return(GamesDirectories);
        }
        public GameDirectoryForm(DirectoryFormIntent intent, GamesDirectory directory)
        {
            InitializeComponent();
            IntentID = intent;
            switch (intent)
            {
            case DirectoryFormIntent.Add:
            {
                break;
            }

            case DirectoryFormIntent.Edit:
            {
                Directory = directory;

                nameBox.Text = directory.Name;
                pathBox.Text = directory.DirectoryInfo.FullName;

                string extensionsString = "";
                for (int i = 0;
                     i < directory.Extensions.Length;
                     ++i)
                {
                    extensionsString += directory.Extensions[i] + ';';
                }
                extensionsBox.Text = extensionsString;
                break;
            }

            default:
            {
                throw new NullReferenceException("Invalid default case!");
                break;
            }
            }
        }
        void addDirectoryButton_Click(object sender, EventArgs e)
        {
            // NOTE(SpectatorQL): Perhaps adding MessageBoxes with warnings is a good idea?
            if (IntentID == DirectoryFormIntent.Add)
            {
                if (nameBox.Text != "" &&
                    pathBox.Text != "" &&
                    nameBox.Text != null &&
                    pathBox.Text != null)
                {
                    string[] extensions;
                    if (extensionsBox.Text != "")
                    {
                        extensions = extensionsBox.Text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0;
                             i < extensions.Length;
                             ++i)
                        {
                            if (extensions[i][0] != '.')
                            {
                                extensions[i] = '.' + extensions[i];
                            }
                        }
                    }
                    else
                    {
                        extensions = new string[0];
                    }

                    Directory = new GamesDirectory()
                    {
                        Name          = nameBox.Text,
                        DirectoryInfo = new DirectoryInfo(pathBox.Text),
                        Extensions    = extensions,
                    };

                    ResultID = DirectoryFormResult.Added;
                    Close();
                }
            }
            else if (IntentID == DirectoryFormIntent.Edit)
            {
                if (nameBox.Text != "" &&
                    pathBox.Text != "" &&
                    nameBox.Text != null &&
                    pathBox.Text != null)
                {
                    Directory.Name = nameBox.Text;

                    if (pathBox.Text != Directory.DirectoryInfo.FullName)
                    {
                        Directory.DirectoryInfo = new DirectoryInfo(pathBox.Text);
                    }

                    string[] newExtensions;
                    if (extensionsBox.Text != "")
                    {
                        newExtensions = extensionsBox.Text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0;
                             i < newExtensions.Length;
                             ++i)
                        {
                            if (newExtensions[i][0] != '.')
                            {
                                newExtensions[i] = '.' + newExtensions[i];
                            }
                        }
                    }
                    else
                    {
                        newExtensions = new string[0];
                    }
                    Directory.Extensions = newExtensions;

                    ResultID = DirectoryFormResult.Edited;
                    Close();
                }
            }
        }
        public GameListForm(Config config)
        {
            InitializeComponent();

            Config = config;

            directoryList.DataSource            = Config.GamesDirectories;
            directoryList.SelectedValueChanged += (s, args) =>
            {
                if (directoryList.SelectedItem != null)
                {
                    Debug.Assert(directoryList.SelectedItem is GamesDirectory);
                    GamesDirectory selectedDirectory = (GamesDirectory)directoryList.SelectedItem;

                    Games.Clear();
                    if (selectedDirectory.Extensions.Length != 0)
                    {
                        for (int i = 0;
                             i < selectedDirectory.Extensions.Length;
                             ++i)
                        {
                            FileInfo[] gameFiles = selectedDirectory.DirectoryInfo
                                                   .GetFiles($"*{selectedDirectory.Extensions[i]}", SearchOption.AllDirectories);
                            for (int j = 0;
                                 j < gameFiles.Length;
                                 ++j)
                            {
                                Games.Add(new GameData
                                {
                                    Extension = gameFiles[j].Extension,
                                    FileName  = gameFiles[j].Name,
                                    FullName  = gameFiles[j].FullName
                                });
                            }
                        }
                    }
                    else
                    {
                        FileInfo[] gameFiles = selectedDirectory.DirectoryInfo.GetFiles("*", SearchOption.AllDirectories);
                        for (int i = 0;
                             i < gameFiles.Length;
                             ++i)
                        {
                            Games.Add(new GameData
                            {
                                Extension = gameFiles[i].Extension,
                                FileName  = gameFiles[i].Name,
                                FullName  = gameFiles[i].FullName
                            });
                        }
                    }
                    Games.Sort(GameData.CompareExtensions);

                    gamesGridView.DataSource = null;
                    gamesGridView.Rows.Clear();
                    gamesGridView.Columns.Clear();
                    gamesGridView.DataSource = Games;
                }
                else
                {
                    gamesGridView.DataSource = null;
                }
            };
            directoryList.SelectedItem = null;


            gamesGridView.CellDoubleClick += (s, args) =>
            {
                SelectedGame = (GameData)gamesGridView.SelectedRows[0].DataBoundItem;
                Close();
            };
            gamesGridView.ColumnHeaderMouseClick += (s, args) =>
            {
                Debug.Assert(gamesGridView.DataSource is List <GameData>);
                int columnIndex           = args.ColumnIndex;
                DataGridViewColumn column = gamesGridView.Columns[columnIndex];
                if (columnIndex == 0)
                {
                    Games.Sort(GameData.CompareExtensions);
                }
                else if (columnIndex == 1)
                {
                    Games.Sort(GameData.CompareFileNames);
                }
                gamesGridView.DataSource = Games;
                gamesGridView.Invalidate();
            };
        }