Skip to content

Commit

Permalink
Refactored version comparisons to be more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidArthurCole committed Aug 25, 2021
1 parent d565378 commit 64042a0
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/main/java/com/BlendGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.Random;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

Expand All @@ -63,7 +64,7 @@
public class BlendGUI extends Application {

//Global current version indicator
private static final String VERSION = "1.2.16";
private static final String VERSION = "1.3.0";

//Prevents threading errors in some cases
private boolean alreadySaved = false;
Expand Down Expand Up @@ -357,14 +358,17 @@ public String getTagFromGitJson(String tagName){
return(obj.get(tagName).getAsString());
}

public boolean isOutOfDate(){

String[] compLatest = getTagFromGitJson("tag_name").split("\\.");
String[] compCurrent = VERSION.split("\\.");

return(Integer.parseInt(compCurrent[0]) < Integer.parseInt(compLatest[0]) // X.z.z <- If first digit is less
|| (Integer.parseInt(compCurrent[0]) >= Integer.parseInt(compLatest[0]) && Integer.parseInt(compCurrent[1]) < Integer.parseInt(compLatest[1])) // z.X.z <- If second digit is less
|| (Integer.parseInt(compCurrent[0]) >= Integer.parseInt(compLatest[0]) && Integer.parseInt(compCurrent[1]) >= Integer.parseInt(compLatest[1]) && Integer.parseInt(compCurrent[2]) < Integer.parseInt(compLatest[2]))); // z.z.X <- If third digit is less
public int compareVersions(String v1, String v2) {
String[] components1 = v1.split("\\.");
String[] components2 = v2.split("\\.");
int length = Math.min(components1.length, components2.length);
for(int i = 0; i < length; i++) {
int result = Integer.compare(Integer.parseInt(components1[i]), Integer.parseInt(components2[i]));
if(result != 0) {
return result;
}
}
return Integer.compare(components1.length, components2.length);
}

public void buildSecondaryScene(){
Expand Down Expand Up @@ -502,7 +506,7 @@ public void start(Stage stage) throws Exception {
String publishDate = getTagFromGitJson("published_at");

String releaseDate;
if(isOutOfDate()) releaseDate = "Release date unknown";
if(compareVersions(VERSION, getTagFromGitJson("tag_name")) == -1) releaseDate = "Release date unknown";
else releaseDate = "Release date: " + publishDate.substring(0, publishDate.length() - 1).replace("T", " ");

Alert aboutAlert = new Alert(AlertType.INFORMATION, releaseDate);
Expand All @@ -516,7 +520,7 @@ public void start(Stage stage) throws Exception {
//Literally just gets the latest version number from the git repo
String latest = getTagFromGitJson("tag_name");

if(isOutOfDate()){
if(compareVersions(VERSION, getTagFromGitJson("tag_name")) == -1){

ButtonType no = new ButtonType("No", ButtonBar.ButtonData.OK_DONE);
ButtonType yes = new ButtonType("Yes", ButtonBar.ButtonData.CANCEL_CLOSE);
Expand Down

0 comments on commit 64042a0

Please sign in to comment.