2013-12-27 23:59:59 +01:00
|
|
|
package appeng.services;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLConnection;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2014-02-09 06:08:27 +01:00
|
|
|
import appeng.core.AEConfig;
|
2014-05-13 06:28:29 +02:00
|
|
|
import appeng.core.AELog;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public class VersionChecker implements Runnable
|
|
|
|
{
|
|
|
|
|
|
|
|
public static VersionChecker instance = null;
|
|
|
|
|
|
|
|
private long delay = 0;
|
|
|
|
|
|
|
|
public VersionChecker() {
|
|
|
|
long now = (new Date()).getTime();
|
2014-02-09 06:08:27 +01:00
|
|
|
delay = (1000 * 3600 * 5) - (now - AEConfig.instance.latestTimeStamp);
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( delay < 1 )
|
|
|
|
delay = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Thread.sleep( delay );
|
|
|
|
}
|
|
|
|
catch (InterruptedException e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
Thread.yield();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
URL url = new URL( "http://ae-mod.info/releases/?latest" );
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
String MCVersion = cpw.mods.fml.common.Loader.instance().getMCVersionString();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
URLConnection yc = url.openConnection();
|
2014-02-09 06:08:27 +01:00
|
|
|
yc.setRequestProperty( "User-Agent", "AE2/" + AEConfig.VERSION + " (Channel:" + AEConfig.CHANNEL + "," + MCVersion.replace( " ", ":" )
|
2014-02-09 02:34:52 +01:00
|
|
|
+ ")" );
|
2013-12-27 23:59:59 +01:00
|
|
|
BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream() ) );
|
|
|
|
|
|
|
|
String Version = "";
|
|
|
|
String inputLine;
|
|
|
|
|
|
|
|
while ((inputLine = in.readLine()) != null)
|
|
|
|
Version += inputLine;
|
|
|
|
|
|
|
|
in.close();
|
|
|
|
|
|
|
|
if ( Version.length() > 2 )
|
|
|
|
{
|
|
|
|
Matcher m = Pattern.compile( "\"Version\":\"([^\"]+)\"" ).matcher( Version );
|
|
|
|
m.find();
|
|
|
|
Version = m.group( 1 );
|
2014-02-09 06:08:27 +01:00
|
|
|
AEConfig.instance.latestVersion = Version;
|
|
|
|
AEConfig.instance.latestTimeStamp = (new Date()).getTime();
|
|
|
|
AEConfig.instance.save();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Thread.sleep( 1000 * 3600 * 4 );
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Thread.sleep( 1000 * 3600 * 4 );
|
|
|
|
}
|
|
|
|
catch (InterruptedException e1)
|
|
|
|
{
|
2014-02-07 21:37:22 +01:00
|
|
|
AELog.error( e );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|