diff options
| author | J08nY | 2019-07-24 23:19:03 +0200 |
|---|---|---|
| committer | J08nY | 2019-07-24 23:19:03 +0200 |
| commit | 2d09947b4200799b554c55de52afd612bb06d84e (patch) | |
| tree | 28bda4dc20527d0bb4b6d9fb50ed116f48bf1416 /src/cz/crcs/ectester/common/util/FileUtil.java | |
| parent | 628bfd7258bcefa5d0005a370d35e1227ce2f844 (diff) | |
| download | ECTester-2d09947b4200799b554c55de52afd612bb06d84e.tar.gz ECTester-2d09947b4200799b554c55de52afd612bb06d84e.tar.zst ECTester-2d09947b4200799b554c55de52afd612bb06d84e.zip | |
Diffstat (limited to 'src/cz/crcs/ectester/common/util/FileUtil.java')
| -rw-r--r-- | src/cz/crcs/ectester/common/util/FileUtil.java | 74 |
1 files changed, 70 insertions, 4 deletions
diff --git a/src/cz/crcs/ectester/common/util/FileUtil.java b/src/cz/crcs/ectester/common/util/FileUtil.java index 790596b..e6e319b 100644 --- a/src/cz/crcs/ectester/common/util/FileUtil.java +++ b/src/cz/crcs/ectester/common/util/FileUtil.java @@ -2,10 +2,13 @@ package cz.crcs.ectester.common.util; import cz.crcs.ectester.common.output.TeeOutputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; +import java.io.*; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.util.LinkedList; import java.util.List; @@ -13,6 +16,9 @@ import java.util.List; * @author Jan Jancar johny@neuromancer.sk */ public class FileUtil { + private static Path appData = null; + public static String LIB_RESOURCE_DIR = "/cz/crcs/ectester/standalone/libs/jni/"; + public static OutputStream openStream(String[] files) throws FileNotFoundException { if (files == null) { return null; @@ -30,4 +36,64 @@ public class FileUtil { } return new OutputStreamWriter(openStream(files)); } + + public static Path getAppData() { + if (appData != null) { + return appData; + } + + if (System.getProperty("os.name").startsWith("Windows")) { + appData = Paths.get(System.getenv("AppData")); + } else { + if (System.getProperty("os.name").startsWith("Linux")) { + String dataHome = System.getenv("XDG_DATA_HOME"); + if (dataHome != null) { + appData = Paths.get(dataHome); + } else { + appData = Paths.get(System.getProperty("user.home"), ".local", "share"); + } + } else { + appData = Paths.get(System.getProperty("user.home"), ".local", "share"); + } + } + return appData; + } + + public static boolean isNewer(URLConnection jarConn, Path realPath) throws IOException { + if (realPath.toFile().isFile()) { + long jarModified = jarConn.getLastModified(); + long realModified = Files.getLastModifiedTime(realPath).toMillis(); + return jarModified > realModified; + } + return true; + } + + public static boolean writeNewer(String resourcePath, Path outPath) throws IOException { + URL reqURL = FileUtil.class.getResource(resourcePath); + if (reqURL == null) { + return false; + } + URLConnection reqConn = reqURL.openConnection(); + if (isNewer(reqConn, outPath)) { + Files.copy(reqConn.getInputStream(), outPath, StandardCopyOption.REPLACE_EXISTING); + } + reqConn.getInputStream().close(); + return true; + } + + public static Path getLibDir() { + return getAppData().resolve("ECTesterStandalone"); + } + + public static Path getRequirementsDir() { + return getLibDir().resolve("lib"); + } + + public static String getLibSuffix() { + if (System.getProperty("os.name").startsWith("Windows")) { + return "dll"; + } else { + return "so"; + } + } } |
