Skip to content

Commit

Permalink
Put url config file in config/jaunch
Browse files Browse the repository at this point in the history
  • Loading branch information
hinerm committed Jun 20, 2024
1 parent 774726b commit 7980160
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/main/java/net/imagej/ui/swing/updater/ImageJUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ else if (jdkDlLoc.toString().endsWith("zip")) {
if (exeName != null && !exeName.trim().isEmpty()) {
exeName = exeName.substring(exeName.lastIndexOf(File.separator));
exeName = exeName.substring(0, exeName.indexOf("-"));
final File appCfg = new File(imagejRoot + File.separator + exeName +
".cfg");
final File appCfg = new File(imagejRoot + File.separator + "config" +
File.separator + "jaunch" + File.separator + exeName + ".cfg");
Map<String, String> appProps = appCfg.exists() ? PropertiesHelper.get(
appCfg) : new HashMap<>();
appProps.put("jvm.app-configured", javaLoc);
Expand Down Expand Up @@ -404,8 +404,10 @@ private void doExtraction(final File jdkDir, final ArchiveInputStream tarIn)
* the appropriate directory.
*/
private void updateJavaIfNecessary(final File imagejRoot) {
final File jdkUrls = new File(imagejRoot.getAbsolutePath() +
File.separator + "jdk-urls.txt");
final File configDir = new File(imagejRoot.getAbsolutePath() +
File.separator + "config" + File.separator + "jaunch");
final File jdkUrlConf = new File(configDir.getAbsolutePath() +
File.separator + "jdk-urls.cfg");
final String modifiedKey = "LAST_MODIFIED";
final String jdkUrl = "https://downloads.imagej.net/java/jdk-urls.txt";
long lastModifiedRemote;
Expand All @@ -422,10 +424,16 @@ private void updateJavaIfNecessary(final File imagejRoot) {
return;
}

// Make the config dir if it doesn't already exist
if (!configDir.exists() && !configDir.mkdirs()) {
log.error("Unable to create configuration directory: " + configDir);
return;
}

// Check if we've already cached a local version of the JDK list
if (jdkUrls.exists()) {
if (jdkUrlConf.exists()) {
// check when the remote was last modified
Map<String, String> jdkVersionProps = PropertiesHelper.get(jdkUrls);
Map<String, String> jdkVersionProps = PropertiesHelper.get(jdkUrlConf);
if (lastModifiedRemote == 0) { // 0 means "not provided"
log.error("No modification date found in jdk-urls.txt");
return;
Expand All @@ -437,13 +445,13 @@ private void updateJavaIfNecessary(final File imagejRoot) {
if (lastModifiedLocal == lastModifiedRemote) return;

// Otherwise delete the conf file and re-download
jdkUrls.delete();
jdkUrlConf.delete();
}

// Download the new properties file
try {
Download dl = downloadService.download(locationService.resolve(jdkUrl),
locationService.resolve(jdkUrls.toURI()));
locationService.resolve(jdkUrlConf.toURI()));
dl.task().waitFor();
}
catch (URISyntaxException e) {
Expand All @@ -457,7 +465,7 @@ private void updateJavaIfNecessary(final File imagejRoot) {
}

// Inject the last modification date to the JDK list
Map<String, String> jdkUrlMap = PropertiesHelper.get(jdkUrls);
Map<String, String> jdkUrlMap = PropertiesHelper.get(jdkUrlConf);
jdkUrlMap.put(modifiedKey, Long.toString(lastModifiedRemote));

// Ask the user if they would like to proceed with a Java update
Expand All @@ -472,7 +480,7 @@ private void updateJavaIfNecessary(final File imagejRoot) {
imagejRoot))
{
// Store the current url list if we updated Java
PropertiesHelper.put(jdkUrlMap, jdkUrls);
PropertiesHelper.put(jdkUrlMap, jdkUrlConf);
}
}

Expand Down

0 comments on commit 7980160

Please sign in to comment.