/* OpenFileOrDie: * Helper function that actually opens the file and dumps it, or handles an IO exception * before returning. */ private void OpenFileOrDie() { try { Dumper d = new Dumper(); string fileToDump = openFileDialog1.FileName; d.ColumnWidth = Convert.ToInt32(cbxColumnWidth.Text); d.IsVerbose = !chkVerbose.Checked; d.BytesPerLine = Convert.ToUInt32(cbxBytesPerLine.Text); int value = cbxBaseList.SelectedIndex; if (d.BytesPerLine % d.ColumnWidth != 0) { throw new AddressSizeException(); } if (value == 0) { d.BaseSelected = Dumper.BaseOption.OCTAL; } else if (value == 1) { d.BaseSelected = Dumper.BaseOption.HEXA; } else { d.BaseSelected = Dumper.BaseOption.DECIMAL; } int offset = txtSkip.Text.Length > 0? Convert.ToInt32(txtSkip.Text) : 0; switch (cbxSizeSuffix.SelectedIndex) { case 2: offset *= 1024 * 1024; break; case 1: offset *= 1024; break; case 0: default: break; } txtOutput.Text = d.dump(fileToDump, offset); } catch (IOException) { MessageBox.Show("The file may be too big, was corrupted, or could not be found!"); } catch (UnauthorizedAccessException) { MessageBox.Show("You do not have the necessary permissions to open this!"); } catch (AddressSizeException ex) { MessageBox.Show(ex.Message); cbxColumnWidth.Focus(); } catch (FormatException) { MessageBox.Show("Please enter a whole number only."); cbxColumnWidth.Focus(); } catch (IndexOutOfRangeException) { MessageBox.Show("Please enter a whole number only."); txtSkip.Focus(); } }
/* OpenFileOrDie: * Helper function that actually opens the file and dumps it, or handles an IO exception * before returning. */ private void OpenFileOrDie() { try { Dumper d = new Dumper(); string fileToDump = openFileDialog1.FileName; d.ColumnWidth = Convert.ToInt32(cbxColumnWidth.Text); d.IsVerbose = !chkVerbose.Checked; d.BytesPerLine = Convert.ToUInt32(cbxBytesPerLine.Text); int value = cbxBaseList.SelectedIndex; if (d.BytesPerLine % d.ColumnWidth != 0) throw new AddressSizeException(); if (value == 0) d.BaseSelected = Dumper.BaseOption.OCTAL; else if (value == 1) d.BaseSelected = Dumper.BaseOption.HEXA; else d.BaseSelected = Dumper.BaseOption.DECIMAL; int offset = txtSkip.Text.Length > 0? Convert.ToInt32(txtSkip.Text) : 0; switch(cbxSizeSuffix.SelectedIndex) { case 2: offset *= 1024 * 1024; break; case 1: offset *= 1024; break; case 0: default: break; } txtOutput.Text = d.dump(fileToDump, offset); } catch (IOException) { MessageBox.Show("The file may be too big, was corrupted, or could not be found!"); } catch (UnauthorizedAccessException) { MessageBox.Show("You do not have the necessary permissions to open this!"); } catch (AddressSizeException ex) { MessageBox.Show(ex.Message); cbxColumnWidth.Focus(); } catch (FormatException) { MessageBox.Show("Please enter a whole number only."); cbxColumnWidth.Focus(); } catch (IndexOutOfRangeException) { MessageBox.Show("Please enter a whole number only."); txtSkip.Focus(); } }