Esempio n. 1
0
  public static boolean copyFile(File inputFile, File outputFile, Boolean moveFile) {

    if (!inputFile.exists()) return false;

    if (outputFile.exists()) outputFile.delete();

    InputStream in;

    try {

      in = new FileInputStream(inputFile);
      OutputStream out = new FileOutputStream(outputFile);

      byte[] buffer = new byte[65536];
      int bytesRead = -1;

      while ((bytesRead = in.read(buffer)) != -1) out.write(buffer, 0, bytesRead);

      in.close();
      out.close();
    } catch (FileNotFoundException e) {
      if (Main.isDebug()) e.printStackTrace();
      return false;
    } catch (IOException e) {
      if (Main.isDebug()) e.printStackTrace();
      return false;
    }

    if (moveFile) inputFile.delete();

    return true;
  }
Esempio n. 2
0
  public static String getPlsTitle(File file) {
    String result = file.getName();

    if (!file.exists()) return file.getName();

    try {
      BufferedReader br = new BufferedReader(new FileReader(file));

      String inLine;
      while ((inLine = br.readLine()) != null) {
        if (inLine.toLowerCase().contains("title") && inLine.length() > 7) {
          if (inLine.contains("(#")
              && inLine.contains(" - ")
              && inLine.contains("/")
              && inLine.contains(") ")) {
            String[] split = inLine.split("\\) "); // remove number of listeners information
            if (split != null && split.length > 1) {
              result = split[1];
              break;
            }
          } else {
            result = inLine.substring(7);
            break;
          }
        }
      }
      br.close();

    } catch (FileNotFoundException e) {
      if (Main.isDebug()) e.printStackTrace();
    } catch (IOException e) {
      if (Main.isDebug()) e.printStackTrace();
    }

    return result;
  }
  public static void updateSpoutcraftYMLCache() {
    if (!updated) {
      synchronized (key) {
        String urlName =
            MirrorUtils.getMirrorUrl("spoutcraft.yml", "http://get.spout.org/spoutcraft.yml", null);
        if (urlName != null) {
          try {
            int selected = -1;
            if (spoutcraftYML.exists()) {
              try {
                YAMLProcessor config = new YAMLProcessor(spoutcraftYML, false);
                config.load();
                selected = config.getInt("current", -1);
              } catch (Exception ex) {
                ex.printStackTrace();
              }
            }

            URL url = new URL(urlName);
            HttpURLConnection con = (HttpURLConnection) (url.openConnection());
            System.setProperty("http.agent", "");
            con.setRequestProperty(
                "User-Agent",
                "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30");
            Utils.copy(con.getInputStream(), new FileOutputStream(spoutcraftYML));

            YAMLProcessor config = new YAMLProcessor(spoutcraftYML, false);
            config.load();
            config.setProperty("current", selected);
            config.setProperty("launcher", Main.getBuild("launcher-version"));
            config.save();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
        updated = true;
      }
    }
  }