From 657933ecb05a80cbc29cad958afa1cbe64d5724c Mon Sep 17 00:00:00 2001 From: integralfx Date: Fri, 16 Nov 2018 12:57:59 +1100 Subject: [PATCH] Added BIOS file validation --- src/TimingsEditor.java | 8 +++--- src/TimingsEditorGUI.java | 52 ++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/TimingsEditor.java b/src/TimingsEditor.java index 5395496..f1c1905 100644 --- a/src/TimingsEditor.java +++ b/src/TimingsEditor.java @@ -28,18 +28,18 @@ private static void print_timings(ATOM_VRAM_TIMING_ENTRY e) System.out.print(String.format("0x%02X ", b)); } - public TimingsEditor(String bios_file) + public TimingsEditor(String bios_file) throws IllegalArgumentException { Path path = Paths.get(bios_file); try { bios_bytes = Files.readAllBytes(path); if(!init()) - throw new Exception("invalid BIOS file"); + throw new IllegalArgumentException("Invalid BIOS file"); } - catch(Exception e) + catch(IOException e) { - System.err.println("exception caught: " + e.getMessage()); + System.err.println("failed to read " + bios_file); e.printStackTrace(); } } diff --git a/src/TimingsEditorGUI.java b/src/TimingsEditorGUI.java index 7630a01..cea52ae 100644 --- a/src/TimingsEditorGUI.java +++ b/src/TimingsEditorGUI.java @@ -93,35 +93,41 @@ public void actionPerformed(ActionEvent e) { if(fc.showOpenDialog(main_panel) == JFileChooser.APPROVE_OPTION) { - File file = fc.getSelectedFile(); + try { + File file = fc.getSelectedFile(); - lbl_file.setText(file.getName()); + timings_editor = new TimingsEditor(file.getAbsolutePath()); + timings = timings_editor.get_timings(); - timings_editor = new TimingsEditor(file.getAbsolutePath()); - timings = timings_editor.get_timings(); + lbl_file.setText(file.getName()); - SwingUtilities.invokeLater(new Runnable() - { - @Override - public void run() + SwingUtilities.invokeLater(new Runnable() { - if(panel_timings != null) + @Override + public void run() { - main_panel.remove(panel_timings); - panel_timings = null; + if(panel_timings != null) + { + main_panel.remove(panel_timings); + panel_timings = null; + } + + if(panel_indices == null) + add_indices_panel(); + + add_timings_panel(timings.get(0).ucIndex); + revalidate(); + repaint(); + pack(); + + update_indices_cbox(); } - - if(panel_indices == null) - add_indices_panel(); - - add_timings_panel(timings.get(0).ucIndex); - revalidate(); - repaint(); - pack(); - - update_indices_cbox(); - } - }); + }); + } + catch(IllegalArgumentException ex) + { + show_error_dialog(ex.getMessage()); + } } } else if(e.getSource() == menu_item_saveas)