/** * gets the time from the creeperhost servers * * @return - the time in the DDMMYY format */ public static String getTime() { String content = null; Scanner scanner = null; String resolved = (downloadServers.containsKey(Settings.getSettings().getDownloadServer())) ? "http://" + downloadServers.get(Settings.getSettings().getDownloadServer()) : "http://www.creeperrepo.net"; resolved += "/getdate"; HttpURLConnection connection = null; try { connection = (HttpURLConnection) new URL(resolved).openConnection(); if (connection.getResponseCode() != 200) { for (String server : downloadServers.values()) { if (connection.getResponseCode() != 200 && !server.equalsIgnoreCase("www.creeperrepo.net")) { resolved = "http://" + server + "/getdate"; connection = (HttpURLConnection) new URL(resolved).openConnection(); } else if (connection.getResponseCode() == 200) { break; } } } scanner = new Scanner(connection.getInputStream()); scanner.useDelimiter("\\Z"); content = scanner.next(); } catch (IOException e) { } finally { connection.disconnect(); if (scanner != null) { scanner.close(); } } return content; }
@Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); if (optionsPane != null) { chooser.setCurrentDirectory(new File(Settings.getSettings().getInstallPath())); chooser.setDialogTitle(choosertitle); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { Logger.logInfo("getCurrentDirectory(): " + chooser.getCurrentDirectory()); Logger.logInfo("getSelectedFile() : " + chooser.getSelectedFile()); optionsPane.setInstallFolderText(chooser.getSelectedFile().getPath()); } else { Logger.logWarn("No Selection."); } } else if (editMPD != null) { if (!Settings.getSettings().getLastAddPath().isEmpty()) { chooser.setCurrentDirectory(new File(Settings.getSettings().getLastAddPath())); } chooser.setDialogTitle("Please select the mod to install"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(true); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File destination = new File(editMPD.folder, chooser.getSelectedFile().getName()); if (!destination.exists()) { try { FileUtils.copyFile(chooser.getSelectedFile(), destination); Settings.getSettings().setLastAddPath(chooser.getSelectedFile().getPath()); LaunchFrame.getInstance().saveSettings(); } catch (IOException e1) { Logger.logError(e1.getMessage()); } editMPD.updateLists(); } else { ErrorUtils.tossError("File already exists, cannot add mod!"); } } else { Logger.logWarn("No Selection."); } } else { chooser.setCurrentDirectory(new File(Settings.getSettings().getInstallPath())); chooser.setDialogTitle(choosertitle); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { Logger.logInfo("getCurrentDirectory(): " + chooser.getCurrentDirectory()); Logger.logInfo("getSelectedFile() : " + chooser.getSelectedFile()); installDialog.setInstallFolderText(chooser.getSelectedFile().getPath()); } else { Logger.logWarn("No Selection."); } } }