Ejemplo n.º 1
0
  private static void versionCheck() {
    try {

      String location = REMOTE_VERSION_FILE;
      HttpURLConnection conn = null;
      while (location != null && !location.isEmpty()) {
        URL url = new URL(location);

        if (conn != null) {
          conn.disconnect();
        }

        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty(
            "User-Agent",
            "Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)");
        conn.connect();
        location = conn.getHeaderField("Coordinates");
      }

      if (conn == null) {
        throw new NullPointerException();
      }

      BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

      String line;
      while ((line = reader.readLine()) != null) {
        String[] tokens = line.split(":");
        if (mcVersion.matches(tokens[0])) {
          currentVersion = new SoftwareVersion(tokens[1]);
          break;
        }
      }

      status = UpdateStatus.CURRENT;
      if (modVersion.compareTo(currentVersion) < 0) status = UpdateStatus.OUTDATED;

      conn.disconnect();
      reader.close();

    } catch (Exception e) {
      ModLog.warn("Unable to read remote version data", e);
      status = UpdateStatus.COMM_ERROR;
    }
  }
Ejemplo n.º 2
0
  @Override
  public void run() {

    int count = 0;

    ModLog.info("Checking for newer mod version");

    try {

      do {
        if (count > 0) {
          ModLog.info("Awaiting attempt %d", count);
          Thread.sleep(VERSION_CHECK_INTERVAL);
        }
        versionCheck();
        count++;
      } while (count < VERSION_CHECK_RETRIES && status == UpdateStatus.COMM_ERROR);

    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    switch (status) {
      case COMM_ERROR:
        ModLog.warn("Version check failed");
        break;
      case CURRENT:
        ModLog.info(
            "Dynamic Surroundings version [%s] is the same or newer than the current version [%s]",
            modVersion, currentVersion);
        break;
      case OUTDATED:
        ModLog.warn(
            "Using outdated version ["
                + modVersion
                + "] for Minecraft "
                + mcVersion
                + ". Consider updating to "
                + currentVersion
                + ".");
        break;
      case UNKNOWN:
        ModLog.warn("Unknown version check status!");
        break;
      default:
        break;
    }
  }