From 2ecf3e87c7735ca3de0a62958ca7f76055bafea0 Mon Sep 17 00:00:00 2001 From: Vhati Date: Mon, 26 Aug 2013 09:50:31 -0400 Subject: [PATCH] Added mod file date to the 'description missing' notice --- .../vhati/modmanager/core/ModUtilities.java | 32 +++++++++++++++++++ .../net/vhati/modmanager/ui/ManagerFrame.java | 25 +++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/vhati/modmanager/core/ModUtilities.java b/src/main/java/net/vhati/modmanager/core/ModUtilities.java index 5bfbb80..e7b5f65 100644 --- a/src/main/java/net/vhati/modmanager/core/ModUtilities.java +++ b/src/main/java/net/vhati/modmanager/core/ModUtilities.java @@ -709,6 +709,38 @@ public class ModUtilities { } + /** + * Returns the latest modification time among files within a mod. + * + * If no files have timestamps, -1 is returned. + * + * Presumably, this time is measured in milliseconds since the + * epoch (00:00:00 GMT, January 1, 1970). + * + * @see java.util.zip.ZipEntry#getTime() + */ + public static long getModFileTime( File modFile ) throws IOException { + long result = -1; + + ZipInputStream zis = null; + try { + zis = new ZipInputStream( new FileInputStream( modFile ) ); + ZipEntry item; + while ( (item = zis.getNextEntry()) != null ) { + long n = item.getTime(); + if ( n > result ) result = n; + zis.closeEntry(); + } + } + finally { + try {if ( zis != null ) zis.close();} + catch ( IOException e ) {} + } + + return result; + } + + /** * A holder for results from decodeText(). diff --git a/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java b/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java index b190a32..0f989c0 100644 --- a/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java +++ b/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java @@ -21,6 +21,7 @@ import java.io.InputStreamReader; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.charset.Charset; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Collections; import java.util.Date; @@ -457,11 +458,29 @@ public class ManagerFrame extends JFrame implements ActionListener, HashObserver infoArea.setDescription( modInfo.getTitle(), modInfo.getAuthor(), modInfo.getVersion(), modInfo.getURL(), modInfo.getDescription() ); } else { + long epochTime = -1; + try { + epochTime = ModUtilities.getModFileTime( modFileInfo.getFile() ); + } catch ( IOException e ) { + log.error( String.format( "Error while getting modified time of mod file contents for \"%s\".", modFileInfo.getFile() ), e ); + } + String body = ""; body += "No info is available for the selected mod.\n\n"; - body += "If it's stable, please let the Slipstream devs know "; - body += "where you found it and include this md5 hash:\n"; - body += modHash +"\n"; + + if ( epochTime != -1 ) { + SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy/MM/dd" ); + String dateString = dateFormat.format( new Date( epochTime ) ); + body += "It was released sometime after "+ dateString +".\n\n"; + } else { + body += "The date of its release could not be determined.\n\n"; + } + + body += "If it is stable and has been out for over a month,\n"; + body += "please let the Slipstream devs know where you "; + body += "found it.\n"; + body += "Include the mod's version, and this hash.\n"; + body += "MD5: "+ modHash +"\n"; infoArea.setDescription( modFileInfo.getName(), body ); } }