Exemplo n.º 1
0
        private void SelectFileButton_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog fileDialog = new OpenFileDialog())
            {
                // fileDialog settings
                fileDialog.RestoreDirectory = true;
                fileDialog.Filter           = "N64 rom files|*.n64;*.z64;*.v64;*.N64;*.Z64;*.V64";

                // open dialog and get result
                DialogResult result = fileDialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    romFileName = fileDialog.FileName;

                    using (RomConverter romConverter = new RomConverter(romFileName))
                    {
                        RomConverter.RomFormat format = romConverter.GetFormat();

                        switch (format)
                        {
                        // invalid
                        case RomConverter.RomFormat.INVALID:
                            MessageBox.Show("Invalid ROM!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            // disable all buttons
                            ConvertButton1.Enabled = false;
                            ConvertButton2.Enabled = false;
                            ConvertButton3.Enabled = false;
                            // reset textboxes
                            RomFileInputText.Text = "";
                            RomInfoText.Text      = "";
                            return;

                        case RomConverter.RomFormat.N64:
                            ConvertButton1.Enabled = false;
                            ConvertButton2.Enabled = true;
                            ConvertButton3.Enabled = true;
                            break;

                        case RomConverter.RomFormat.V64:
                            ConvertButton1.Enabled = true;
                            ConvertButton2.Enabled = false;
                            ConvertButton3.Enabled = true;
                            break;

                        case RomConverter.RomFormat.Z64:
                            ConvertButton1.Enabled = true;
                            ConvertButton2.Enabled = true;
                            ConvertButton3.Enabled = false;
                            break;
                        }

                        RomFileInputText.Text = romFileName;
                        RomInfoText.Text      = $"FORMAT     | {format.ToString()}" + Environment.NewLine +
                                                $"HEADER     | {romConverter.RomHeader}" + Environment.NewLine +
                                                $"MD5 HASH | {romConverter.GetMd5Hash()}";
                    }
                }
            }
        }
        private void SelectFileButton_Clicked(object sender, EventArgs a)
        {
            FileChooserDialog fc =
                new FileChooserDialog("Select ROM",
                                      this,
                                      FileChooserAction.Open,
                                      "Cancel", ResponseType.Cancel,
                                      "Open", ResponseType.Accept);

            FileFilter fileFilter = new FileFilter();

            fileFilter.Name = "N64 rom";
            string[] allowedExtensions = { "n64", "z64", "v64" };
            foreach (string extension in allowedExtensions)
            {
                fileFilter.AddPattern("*." + extension.ToLower());
                fileFilter.AddPattern("*." + extension.ToUpper());
            }

            fc.AddFilter(fileFilter);

            if (fc.Run() != (int)ResponseType.Accept)
            {
                fc.Destroy();
                return;
            }

            FileName = fc.Filename;
            fc.Destroy();

            // since Gtk# lacks docs(thanks!)
            // I have no idea how to make the textview 'locked'
            // so if we use more characters than 48, our GUI will look ugly
            // so just..use a simple loop and trim the string
            if (FileName.Length <= 48)
            {
                RomFileInputText.Buffer.Text = FileName;
            }
            else
            {
                string trimmedFileName = null;

                for (int i = 0; i <= 48; i++)
                {
                    trimmedFileName += FileName[i];
                }

                RomFileInputText.Buffer.Text = trimmedFileName;
            }

            using (RomConverter romConverter = new RomConverter(FileName))
            {
                RomInfoText.Buffer.Text = $"FORMAT      | {romConverter.GetFormat()}" + Environment.NewLine +
                                          $"HEADER       | {romConverter.RomHeader}" + Environment.NewLine +
                                          $"MD5 HASH | {romConverter.GetMd5Hash()}";
            }
        }