From b3198a4f8bc78da51dc38ab39ada8f6c3153e130 Mon Sep 17 00:00:00 2001 From: Michal Date: Thu, 23 May 2024 15:07:15 +0200 Subject: [PATCH] Upload files to "src/cucky/jGuard" --- src/cucky/jGuard/BuilddDate.java | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/cucky/jGuard/BuilddDate.java diff --git a/src/cucky/jGuard/BuilddDate.java b/src/cucky/jGuard/BuilddDate.java new file mode 100644 index 0000000..0aa28ad --- /dev/null +++ b/src/cucky/jGuard/BuilddDate.java @@ -0,0 +1,43 @@ +package cucky.jGuard.lib; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Date; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; + +public class BuilddDate { + + public static Date get() { + Date d = null; + Class currentClass = new Object() { + }.getClass().getEnclosingClass(); + URL resource = currentClass.getResource(currentClass.getSimpleName() + ".class"); + if (resource != null) { + if (resource.getProtocol().equals("file")) { + try { + d = new Date(new File(resource.toURI()).lastModified()); + } catch (URISyntaxException ignored) { + } + } else if (resource.getProtocol().equals("jar")) { + String path = resource.getPath(); + d = new Date(new File(path.substring(5, path.indexOf("!"))).lastModified()); + } else if (resource.getProtocol().equals("zip")) { + String path = resource.getPath(); + File jarFileOnDisk = new File(path.substring(0, path.indexOf("!"))); + //long jfodLastModifiedLong = jarFileOnDisk.lastModified (); + //Date jfodLasModifiedDate = new Date(jfodLastModifiedLong); + try (JarFile jf = new JarFile(jarFileOnDisk)) { + ZipEntry ze = jf.getEntry(path.substring(path.indexOf("!") + 2));//Skip the ! and the / + long zeTimeLong = ze.getTime(); + Date zeTimeDate = new Date(zeTimeLong); + d = zeTimeDate; + } catch (IOException | RuntimeException ignored) { + } + } + } + return d; + } +}