/** * Check for new version */ int answer = -1; Release release = new Release(); release.setpkgver("1.0"); release.setPkgrel("1"); ReleaseXMLParser parser = new ReleaseXMLParser(); try { Release current = parser.parse("http://niovi.aueb.gr/~p3070130/latest.xml", Modes.URL); if (current.compareTo(release) > 0) { answer = JOptionPane.showConfirmDialog(rootPane, "A new version of this" + " program is available\nWould you like to install it?", "Update", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); switch (answer) { case 0: /** * Download needed files */ Downloader dl = new Downloader(); dl.download("http://niovi.aueb.gr/~p3070130/files.xml", "tmp", Modes.URL); break; case 1: break; } } } catch (SAXException ex) { JOptionPane.showMessageDialog(rootPane, "The xml wasn't loaded succesfully!\n", "Something went wrong!", JOptionPane.WARNING_MESSAGE); Logger.getLogger(JUPARDemo.class.getName()).log(Level.SEVERE, null, ex); answer = -1; } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(rootPane, "Files were unable to be read or created successfully!\n" + "Please be sure that you have the right permissions and" + " internet connectivity!", "Something went wrong!", JOptionPane.WARNING_MESSAGE); Logger.getLogger(JUPARDemo.class.getName()).log(Level.SEVERE, null, ex); answer = -1; } catch (IOException ex) { JOptionPane.showMessageDialog(rootPane, "IOEXception!", "Something went wrong!", JOptionPane.WARNING_MESSAGE); Logger.getLogger(JUPARDemo.class.getName()).log(Level.SEVERE, null, ex); answer = -1; } catch (InterruptedException ex) { JOptionPane.showMessageDialog(rootPane, "The connection has been lost!\n" + "Please check your internet connectivity!", "Something went wrong!", JOptionPane.WARNING_MESSAGE); Logger.getLogger(JUPARDemo.class.getName()).log(Level.SEVERE, null, ex); answer = -1; } /** * Start the updating procedure */ if (answer == 0) { try { Updater update = new Updater(); update.update("update.xml", "tmp", Modes.FILE); JOptionPane.showMessageDialog(rootPane, "The update was completed successfuly.\n" + "Please restart the application in order the changes take effect."); } catch (SAXException ex) { Logger.getLogger(JUPARDemo.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(JUPARDemo.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(JUPARDemo.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(JUPARDemo.class.getName()).log(Level.SEVERE, null, ex); } } /** * Delete tmp directory */ File tmp = new File("tmp"); if (tmp.exists()) { for (File file : tmp.listFiles()) { file.delete(); } tmp.delete(); }