|
|
@ -4,6 +4,8 @@ import java.io.File; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.net.HttpURLConnection; |
|
|
|
|
|
|
|
import java.net.MalformedURLException; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URL; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
@ -31,7 +33,7 @@ public class PluginManager implements Runnable{ |
|
|
|
|
|
|
|
|
|
|
|
void FetchPlugins(){ |
|
|
|
void FetchPlugins(){ |
|
|
|
for (int i=0;i<plugins.size();i++) { |
|
|
|
for (int i=0;i<plugins.size();i++) { |
|
|
|
try { |
|
|
|
/*try { |
|
|
|
FileUtils.copyURLToFile(new URL(plugins.get(i).url), new File(AutoPluginUpdate.datafolder,"updates/"+plugins.get(i).name)); |
|
|
|
FileUtils.copyURLToFile(new URL(plugins.get(i).url), new File(AutoPluginUpdate.datafolder,"updates/"+plugins.get(i).name)); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
@ -54,11 +56,56 @@ public class PluginManager implements Runnable{ |
|
|
|
file.close(); |
|
|
|
file.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
}*/ |
|
|
|
|
|
|
|
URL url = null; |
|
|
|
if ((plugins.get(i).hash==null || !md5.equalsIgnoreCase(plugins.get(i).hash))) { |
|
|
|
try { |
|
|
|
|
|
|
|
url = new URL(plugins.get(i).url); |
|
|
|
|
|
|
|
} catch (MalformedURLException e2) { |
|
|
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
|
|
e2.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (url!=null) { |
|
|
|
|
|
|
|
//AutoPluginUpdate.log("Valid URL. ", AutoPluginUpdate.LOG_NORMAL);
|
|
|
|
|
|
|
|
HttpURLConnection httpCon = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
httpCon = (HttpURLConnection) url.openConnection(); |
|
|
|
|
|
|
|
} catch (IOException e1) { |
|
|
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
|
|
e1.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (httpCon!=null) { |
|
|
|
|
|
|
|
//AutoPluginUpdate.log("Connection is good. ", AutoPluginUpdate.LOG_NORMAL);
|
|
|
|
|
|
|
|
long lastModifiedDate = httpCon.getContentLengthLong(); |
|
|
|
|
|
|
|
//AutoPluginUpdate.log("Last Modified Date Comparison: "+plugins.get(i).lastmodified+","+lastModifiedDate, AutoPluginUpdate.LOG_NORMAL);
|
|
|
|
|
|
|
|
if (plugins.get(i).lastmodified!=lastModifiedDate) { |
|
|
|
//This plugin is different! Update the hash for it. Prepare for a restart of the server!
|
|
|
|
//This plugin is different! Update the hash for it. Prepare for a restart of the server!
|
|
|
|
final int ii=i; |
|
|
|
final int ii=i; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
FileUtils.copyURLToFile(new URL(plugins.get(i).url), new File(AutoPluginUpdate.datafolder,"updates/"+plugins.get(i).name)); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//After that's done, check the hash.
|
|
|
|
|
|
|
|
FileInputStream file = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
file = new FileInputStream(new File(AutoPluginUpdate.datafolder,"updates/"+plugins.get(i).name)); |
|
|
|
|
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String md5 = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(file); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
file.close(); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!md5.equalsIgnoreCase(plugins.get(i).hash)) { |
|
|
|
|
|
|
|
//AutoPluginUpdate.log("Last Modified Date Comparison: "+plugins.get(i).lastmodified+","+lastModifiedDate, AutoPluginUpdate.LOG_NORMAL);
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("AutoPluginUpdate"), new Runnable() { |
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("AutoPluginUpdate"), new Runnable() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
@ -79,7 +126,9 @@ public class PluginManager implements Runnable{ |
|
|
|
AutoPluginUpdate.updateServer(); |
|
|
|
AutoPluginUpdate.updateServer(); |
|
|
|
} |
|
|
|
} |
|
|
|
}},1); |
|
|
|
}},1); |
|
|
|
|
|
|
|
} |
|
|
|
plugins.get(i).hash = md5; |
|
|
|
plugins.get(i).hash = md5; |
|
|
|
|
|
|
|
plugins.get(i).lastmodified = lastModifiedDate; |
|
|
|
SaveHash(plugins.get(i)); |
|
|
|
SaveHash(plugins.get(i)); |
|
|
|
|
|
|
|
|
|
|
|
//Move the file to the new location.
|
|
|
|
//Move the file to the new location.
|
|
|
@ -92,6 +141,8 @@ public class PluginManager implements Runnable{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void AddPlugin(String name, String url) { |
|
|
|
public void AddPlugin(String name, String url) { |
|
|
|
plugins.add(new Plugin(name,url)); |
|
|
|
plugins.add(new Plugin(name,url)); |
|
|
@ -102,11 +153,13 @@ public class PluginManager implements Runnable{ |
|
|
|
File config = new File(AutoPluginUpdate.datafolder,"hashes.data"); |
|
|
|
File config = new File(AutoPluginUpdate.datafolder,"hashes.data"); |
|
|
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config); |
|
|
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config); |
|
|
|
pluginname.hash = workable.getString(pluginname.name+"/HASH"); |
|
|
|
pluginname.hash = workable.getString(pluginname.name+"/HASH"); |
|
|
|
|
|
|
|
pluginname.lastmodified = workable.getLong(pluginname.name+"/HASHMOD"); |
|
|
|
} |
|
|
|
} |
|
|
|
public void SaveHash(Plugin pluginname) { |
|
|
|
public void SaveHash(Plugin pluginname) { |
|
|
|
File config = new File(AutoPluginUpdate.datafolder,"hashes.data"); |
|
|
|
File config = new File(AutoPluginUpdate.datafolder,"hashes.data"); |
|
|
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config); |
|
|
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config); |
|
|
|
workable.set(pluginname.name+"/HASH",pluginname.hash); |
|
|
|
workable.set(pluginname.name+"/HASH",pluginname.hash); |
|
|
|
|
|
|
|
workable.set(pluginname.name+"/HASHMOD",pluginname.lastmodified); |
|
|
|
try { |
|
|
|
try { |
|
|
|
workable.save(config); |
|
|
|
workable.save(config); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
@ -118,6 +171,7 @@ public class PluginManager implements Runnable{ |
|
|
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config); |
|
|
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config); |
|
|
|
for (int i=0;i<pluginlist.size();i++) { |
|
|
|
for (int i=0;i<pluginlist.size();i++) { |
|
|
|
workable.set(pluginlist.get(i).name+"/HASH",pluginlist.get(i).hash); |
|
|
|
workable.set(pluginlist.get(i).name+"/HASH",pluginlist.get(i).hash); |
|
|
|
|
|
|
|
workable.set(pluginlist.get(i).name+"/HASHMOD",pluginlist.get(i).lastmodified); |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
workable.save(config); |
|
|
|
workable.save(config); |
|
|
@ -131,17 +185,20 @@ class Plugin { |
|
|
|
String name; |
|
|
|
String name; |
|
|
|
String hash; |
|
|
|
String hash; |
|
|
|
String url; |
|
|
|
String url; |
|
|
|
|
|
|
|
long lastmodified=0; |
|
|
|
|
|
|
|
|
|
|
|
public Plugin(String name,String url) { |
|
|
|
public Plugin(String name,String url) { |
|
|
|
this.name=name; |
|
|
|
this.name=name; |
|
|
|
this.url=url; |
|
|
|
this.url=url; |
|
|
|
this.hash=FetchHash(); //Try to fetch the hash.
|
|
|
|
this.hash=FetchHash(); //Try to fetch the hash.
|
|
|
|
|
|
|
|
this.lastmodified=FetchLastModified(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Plugin(String name,String hash,String url) { |
|
|
|
public Plugin(String name,String hash,long lastmodified,String url) { |
|
|
|
this.name=name; |
|
|
|
this.name=name; |
|
|
|
this.url=url; |
|
|
|
this.url=url; |
|
|
|
this.hash=hash; |
|
|
|
this.hash=hash; |
|
|
|
|
|
|
|
this.lastmodified=lastmodified; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String FetchHash() { |
|
|
|
public String FetchHash() { |
|
|
@ -149,4 +206,10 @@ class Plugin { |
|
|
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config); |
|
|
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config); |
|
|
|
return workable.getString(this.name+"/HASH"); |
|
|
|
return workable.getString(this.name+"/HASH"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public long FetchLastModified() { |
|
|
|
|
|
|
|
File config = new File(AutoPluginUpdate.datafolder,"hashes.data"); |
|
|
|
|
|
|
|
FileConfiguration workable = YamlConfiguration.loadConfiguration(config); |
|
|
|
|
|
|
|
return workable.getLong(this.name+"/HASHMOD"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|