mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
[FEATURE] Storing provider version locally and clear cache when outdated
This commit is contained in:
@@ -182,4 +182,32 @@ public class ServerProviderInfo {
|
||||
// Will never return null, unless the BDN URL is changed. It shouldn't be.
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is a temporary method until the bdn gets updated
|
||||
* @param serverName
|
||||
* @return
|
||||
*/
|
||||
public static String getProviderVersion(String serverName) {
|
||||
try {
|
||||
serverName = serverName.toLowerCase();
|
||||
String providerInfo = String.format("http://v3.bdn.parabot.org/api/bot/list/%s-provider?latest=true", serverName);
|
||||
String response = WebUtil.getContents(providerInfo);
|
||||
|
||||
if (response.length() > 0) {
|
||||
JSONObject jsonObject = (JSONObject) WebUtil.getJsonParser().parse(response);
|
||||
|
||||
if (jsonObject.get("version") != null) {
|
||||
return jsonObject.get("version").toString();
|
||||
}
|
||||
} else if (response.equals("")) {
|
||||
return getProviderVersion("default");
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.forum.AccountManagerAccess;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
import org.parabot.environment.api.utils.PBLocalPreferences;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
import org.parabot.environment.servers.loader.ServerLoader;
|
||||
@@ -37,6 +38,9 @@ public class PublicServerExecuter extends ServerExecuter {
|
||||
};
|
||||
private String serverName;
|
||||
|
||||
private PBLocalPreferences settings;
|
||||
private final String CACHE_VERSION_KEY = "cachedProviderVersion";
|
||||
|
||||
public PublicServerExecuter(final String serverName) {
|
||||
this.serverName = serverName;
|
||||
}
|
||||
@@ -53,6 +57,24 @@ public class PublicServerExecuter extends ServerExecuter {
|
||||
|
||||
Core.verbose("Downloading: " + jarUrl + " ...");
|
||||
|
||||
String providerVersion = ServerProviderInfo.getProviderVersion(serverName);
|
||||
if(providerVersion == null) {
|
||||
providerVersion = "error";
|
||||
}
|
||||
|
||||
settings = new PBLocalPreferences(serverProviderInfo.getClientCRC32()+".json");
|
||||
if(settings.getSetting(CACHE_VERSION_KEY) != null) {
|
||||
Core.verbose(String.format("Latest provider version: %s, local provider version: %s", settings.getSetting(CACHE_VERSION_KEY), providerVersion));
|
||||
if(!settings.getSetting(CACHE_VERSION_KEY).equals(providerVersion)) {
|
||||
Core.verbose("Local provider outdated, clearing cache.");
|
||||
Directories.clearCache();
|
||||
}
|
||||
} else {
|
||||
Core.verbose("No local provider version in settings, adding to settings file");
|
||||
}
|
||||
|
||||
settings.addSetting(CACHE_VERSION_KEY, providerVersion);
|
||||
|
||||
if (destination.exists()) {
|
||||
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user