From 9ac55a89a66597b61dd64f2098a73faac5fac38c Mon Sep 17 00:00:00 2001 From: Jakub Wlodek Date: Mon, 18 Nov 2024 12:08:12 -0500 Subject: [PATCH 1/2] Use path object so file separator is not needed, default to install property file in .config --- .../EPICS_NTNDA_Viewer.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/ImageJ/EPICS_areaDetector/EPICS_NTNDA_Viewer.java b/ImageJ/EPICS_areaDetector/EPICS_NTNDA_Viewer.java index 4b3e935..db8cdd1 100755 --- a/ImageJ/EPICS_areaDetector/EPICS_NTNDA_Viewer.java +++ b/ImageJ/EPICS_areaDetector/EPICS_NTNDA_Viewer.java @@ -19,6 +19,10 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.PrintStream; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.Path; +import java.nio.file.Paths; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; @@ -829,17 +833,21 @@ private void logMessage(String message, boolean logDisplay, boolean logFile) private void readProperties() { - String temp, path = null; + String temp = null; + Path path = Paths.get(System.getProperty("user.home"), ".config"); try { - String fileSep = System.getProperty("file.separator"); - path = System.getProperty("user.home") + fileSep + propertyFile; - FileInputStream file = new FileInputStream(path); + if (!Files.exists(path)){ + path = path.getParent(); + } + path = Paths.get(path.toString(), propertyFile); + + FileInputStream file = new FileInputStream(path.toString()); properties.load(file); file.close(); temp = properties.getProperty("channelName"); if (temp != null) channelName = temp; - IJ.log("Read properties file: " + path + " channelName= " + channelName); + IJ.log("Read properties file: " + path.toString() + " channelName= " + channelName); } catch (Exception ex) { @@ -849,16 +857,19 @@ private void readProperties() private void writeProperties() { - String path; + Path path = Paths.get(System.getProperty("user.home"), ".config"); try { - String fileSep = System.getProperty("file.separator"); - path = System.getProperty("user.home") + fileSep + propertyFile; + if (!Files.exists(path)){ + path = path.getParent(); + } + path = Paths.get(path.toString(), propertyFile); + properties.setProperty("channelName", channelName); - FileOutputStream file = new FileOutputStream(path); + FileOutputStream file = new FileOutputStream(path.toString()); properties.store(file, "EPICS_NTNDA_Viewer Properties"); file.close(); - logMessage("Wrote properties file: " + path, true, true); + logMessage("Wrote properties file: " + path.toString(), true, true); } catch (Exception ex) { From ae2d996447cbc06632b829c9ae729d8897b05d29 Mon Sep 17 00:00:00 2001 From: Jakub Wlodek Date: Thu, 13 Feb 2025 14:25:29 -0500 Subject: [PATCH 2/2] Remove unused import --- ImageJ/EPICS_areaDetector/EPICS_NTNDA_Viewer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ImageJ/EPICS_areaDetector/EPICS_NTNDA_Viewer.java b/ImageJ/EPICS_areaDetector/EPICS_NTNDA_Viewer.java index db8cdd1..25b342d 100755 --- a/ImageJ/EPICS_areaDetector/EPICS_NTNDA_Viewer.java +++ b/ImageJ/EPICS_areaDetector/EPICS_NTNDA_Viewer.java @@ -20,7 +20,6 @@ import java.io.FileOutputStream; import java.io.PrintStream; import java.nio.file.Files; -import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.Paths; import java.text.DecimalFormat; @@ -837,6 +836,7 @@ private void readProperties() Path path = Paths.get(System.getProperty("user.home"), ".config"); try { + // If the .config directory does not exist, move back up to the home dir if (!Files.exists(path)){ path = path.getParent(); } @@ -860,6 +860,7 @@ private void writeProperties() Path path = Paths.get(System.getProperty("user.home"), ".config"); try { + // If the .config directory does not exist, move back up to the home dir if (!Files.exists(path)){ path = path.getParent(); }