Skip to content

Commit

Permalink
Added version checker (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
bowring authored Feb 20, 2022
1 parent 12661bb commit 9796c08
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ tempDataForAliquotUploadzip
*.dat
STANDARDS_DATA_CHECK_FILES/

!.currentVersion.txt

# Resources
!src/main/resources/**/*.xml
!src/main/resources/**/listOfModelFiles.txt
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>org.cirdles</groupId>
<artifactId>ET_Redux</artifactId>
<name>ET_Redux</name>
<version>3.7.0</version>
<version>3.7.1</version>
<description>Successor to U-Pb_Redux</description>
<url>https://cirdles.org</url>
<inceptionYear>2006</inceptionYear>
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/earthtime/ETRedux.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import javax.swing.JOptionPane;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import org.cirdles.commons.util.ResourceExtractor;
import org.earthtime.UPb_Redux.exceptions.BadLabDataException;
import org.earthtime.UPb_Redux.user.ReduxPersistentState;
import org.earthtime.exceptions.ETWarningDialog;
import org.earthtime.utilities.VersionChecker;

/**
*
Expand Down Expand Up @@ -69,7 +71,7 @@ public ETRedux(File reduxFile) //throws3 IOException, InvalidPreferencesFormatEx
try (BufferedReader reader = Files.newBufferedReader(resourcePath, charset)) {

String[] versionText = reader.readLine().split("=");
VERSION = versionText[1];
VERSION = versionText[1].trim();

String[] versionDate = reader.readLine().split("=");
RELEASE_DATE = versionDate[1];
Expand All @@ -79,6 +81,19 @@ public ETRedux(File reduxFile) //throws3 IOException, InvalidPreferencesFormatEx
System.err.format("IOException: %s%n", x);
}

try {
boolean upToDate = VersionChecker.checkIfCurrentVersion(VERSION);
if (!upToDate){
JOptionPane.showMessageDialog(
null,
new String[]{"There is a newer version of ET_Redux at " + "https://github.com/CIRDLES/ET_Redux/releases/ " + "."},
"ET Redux Announcement",
JOptionPane.INFORMATION_MESSAGE);
}

} catch (Exception exception) {
}

// get redux persistent state file
myState = ReduxPersistentState.getExistingPersistentState();

Expand Down
54 changes: 54 additions & 0 deletions src/main/java/org/earthtime/utilities/VersionChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2022 CIRDLES.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.earthtime.utilities;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Base64;
import org.earthtime.ETRedux;

/**
*
* @author bowring
*/
public class VersionChecker {

public static boolean checkIfCurrentVersion(String runningVersion) throws Exception {

boolean retVal = true;
java.net.URL url = null;
String file = "";
try {
url = new java.net.URL("https://raw.githubusercontent.com/CIRDLES/ET_Redux/master/.currentVersion.txt");
java.net.URLConnection uc;
uc = url.openConnection();

uc.setRequestProperty("X-Requested-With", "Curl");
java.util.ArrayList<String> list = new java.util.ArrayList<>();

BufferedReader reader = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String line = reader.readLine();
retVal = line.trim().compareToIgnoreCase(runningVersion) == 0;


} catch (IOException e) {
System.out.println("Could not read .currentVersion.txt");
}

return retVal;
}
}

0 comments on commit 9796c08

Please sign in to comment.