Better update checking for auto Updater (GravityDevelopment)

Discussion in 'Bukkit Tools' started by Zettelkasten, Jul 16, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Zettelkasten

    The update method from GravityDevelopment's updater class just checks whether local and remote version are different. I changed the method shouldUpdate(String localVersion, String remoteVersion) to check if the version is really newer. This is especially useful if you have development builds with never version numbers then the recent Bukkit Dev version.
    Version format
    Code:text
    1. X.Y.Z

    For this to work, the versions have to be in the format above. You may use as many digits as you want.
    Example versions: 1.6.4; 1.4.0.2; 4; 1.7.10
    Code
    Code:java
    1. public boolean shouldUpdate(String localVersion, String remoteVersion) {
    2. try {
    3. int digitLength = localVersion.length() > remoteVersion.length() ? localVersion.length() : remoteVersion.length();
    4. String[] localVersionArray = Arrays.copyOf(localVersion.split("\\."), digitLength);
    5. String[] remoteVersionArray = Arrays.copyOf(remoteVersion.split("\\."), digitLength);
    6. for (int i = 0; i < digitLength; i++) {
    7. if (parseInt(localVersionArray[i]) < parseInt(remoteVersionArray[i])) {
    8. return true;
    9. }
    10. }
    11. return false;
    12. } catch (Exception e) {
    13. return !localVersion.equalsIgnoreCase(remoteVersion);
    14. }
    15. }
    16.  
    17. private int parseInt(String str) {
    18. try {
    19. return Integer.parseInt(str);
    20. } catch (Exception e) {
    21. return 0;
    22. }
    23. }[/i][/i]


    Fell free to use the code and tell me what you think! Improvements are welcome, too!
     
Thread Status:
Not open for further replies.

Share This Page