Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Added check to not notify if newest version is lower than current (fo…
Browse files Browse the repository at this point in the history
…r example due to cache)
  • Loading branch information
Petschko committed Feb 26, 2021
1 parent b208d93 commit f48ac15
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/org/petschko/lib/update/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ private void checkVersion() {
if(this.newestVersion == null)
return;

this.hasNewVersion = ! this.currentVersion.versionsEqual(this.newestVersion);
if(! this.currentVersion.versionsEqual(this.newestVersion))
this.hasNewVersion = this.currentVersion.thisIsLowerThan(this.newestVersion);
}

/**
Expand Down
47 changes: 47 additions & 0 deletions src/org/petschko/lib/update/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,51 @@ public String getVersion() {
public boolean versionsEqual(Version version) {
return this.version.equals(version.getVersion());
}

/**
* Checks if this Version is lower than the other Version
*
* @param version - Version to compare
* @return - This Version is lower than the other
*/
public boolean thisIsLowerThan(Version version) {
String[] thisVersion = this.version.split("\\.");
String[] otherVersion = version.version.split("\\.");

// Ensure same length arrays
if(thisVersion.length > otherVersion.length) {
String[] tmp = new String[thisVersion.length];

for(int i = 0; i < tmp.length; i++) {
if(i < otherVersion.length)
tmp[i] = otherVersion[i];
else
tmp[i] = "0";
}

otherVersion = tmp;
} else if(otherVersion.length > thisVersion.length) {
String[] tmp = new String[otherVersion.length];

for(int i = 0; i < tmp.length; i++) {
if(i < thisVersion.length)
tmp[i] = thisVersion[i];
else
tmp[i] = "0";
}

thisVersion = tmp;
}

// Compare Versions
for(int n = 0; n < thisVersion.length; n++) {
int thisNumber = Integer.parseInt(thisVersion[n]);
int otherNumber = Integer.parseInt(otherVersion[n]);

if(thisNumber < otherNumber)
return true;
}

return false;
}
}

0 comments on commit f48ac15

Please sign in to comment.