Added mod file date to the 'description missing' notice

This commit is contained in:
Vhati 2013-08-26 09:50:31 -04:00
parent 0487d5d932
commit 2ecf3e87c7
2 changed files with 54 additions and 3 deletions

View file

@ -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(). * A holder for results from decodeText().

View file

@ -21,6 +21,7 @@ import java.io.InputStreamReader;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Date; 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() ); infoArea.setDescription( modInfo.getTitle(), modInfo.getAuthor(), modInfo.getVersion(), modInfo.getURL(), modInfo.getDescription() );
} }
else { 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 = ""; String body = "";
body += "No info is available for the selected mod.\n\n"; 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"; if ( epochTime != -1 ) {
body += modHash +"\n"; 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 ); infoArea.setDescription( modFileInfo.getName(), body );
} }
} }