build.xml
Improved update procedure for servers with plugin already installed - only unzips newer files
This commit is contained in:
parent
438ec92342
commit
24f7b594dd
1 changed files with 35 additions and 22 deletions
|
@ -38,8 +38,8 @@ public class ScriptCraftPlugin extends JavaPlugin
|
||||||
{
|
{
|
||||||
getLogger().finest("Directory " + JS_PLUGINS_DIR + " does not exist.");
|
getLogger().finest("Directory " + JS_PLUGINS_DIR + " does not exist.");
|
||||||
getLogger().finest("Initializing " + JS_PLUGINS_DIR + " directory with contents from plugin archive.");
|
getLogger().finest("Initializing " + JS_PLUGINS_DIR + " directory with contents from plugin archive.");
|
||||||
|
|
||||||
jsPlugins.mkdir();
|
jsPlugins.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
ZipInputStream zis = new ZipInputStream(getResource(JS_PLUGINS_DIR + ".zip"));
|
ZipInputStream zis = new ZipInputStream(getResource(JS_PLUGINS_DIR + ".zip"));
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
|
@ -47,7 +47,6 @@ public class ScriptCraftPlugin extends JavaPlugin
|
||||||
while ( ( entry = zis.getNextEntry() ) != null)
|
while ( ( entry = zis.getNextEntry() ) != null)
|
||||||
{
|
{
|
||||||
String filename = entry.getName();
|
String filename = entry.getName();
|
||||||
getLogger().finest("Unzipping " + filename);
|
|
||||||
File newFile = new File(jsPlugins.getName() + File.separator + filename);
|
File newFile = new File(jsPlugins.getName() + File.separator + filename);
|
||||||
|
|
||||||
//create all non exists folders
|
//create all non exists folders
|
||||||
|
@ -55,11 +54,26 @@ public class ScriptCraftPlugin extends JavaPlugin
|
||||||
if (entry.isDirectory()){
|
if (entry.isDirectory()){
|
||||||
newFile.mkdirs();
|
newFile.mkdirs();
|
||||||
}else{
|
}else{
|
||||||
|
//
|
||||||
|
// only write out to file if zip entry is newer than file
|
||||||
|
//
|
||||||
|
long zTime = entry.getTime();
|
||||||
|
boolean unzip = false;
|
||||||
|
if (!newFile.exists())
|
||||||
|
unzip = true;
|
||||||
|
else{
|
||||||
|
long fTime = newFile.lastModified();
|
||||||
|
if (zTime > fTime)
|
||||||
|
unzip = true;
|
||||||
|
}
|
||||||
|
if (unzip){
|
||||||
|
getLogger().info("Unzipping " + filename);
|
||||||
FileOutputStream fout = new FileOutputStream(newFile);
|
FileOutputStream fout = new FileOutputStream(newFile);
|
||||||
for (int c = zis.read(); c != -1; c = zis.read()) {
|
for (int c = zis.read(); c != -1; c = zis.read()) {
|
||||||
fout.write(c);
|
fout.write(c);
|
||||||
}
|
}
|
||||||
fout.close();
|
fout.close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
zis.closeEntry();
|
zis.closeEntry();
|
||||||
|
@ -70,7 +84,6 @@ public class ScriptCraftPlugin extends JavaPlugin
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
|
|
Reference in a new issue