mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-25 21:40:08 +00:00
Working ZIP file loading
This commit is contained in:
1 parent
1c0954d0cf
commit
78acf59f98
5 files changed
+33
-19
No files matched your search
@@ -105,17 +105,15 @@ public class ConfigPack {
|
|||||||
long l = System.nanoTime();
|
long l = System.nanoTime();
|
||||||
|
|
||||||
InputStream stream = null;
|
InputStream stream = null;
|
||||||
Enumeration<? extends ZipEntry> entries = file.entries();
|
|
||||||
|
|
||||||
while(entries.hasMoreElements()) {
|
try {
|
||||||
ZipEntry entry = entries.nextElement();
|
Enumeration<? extends ZipEntry> entries = file.entries();
|
||||||
if(entry.getName().equals("pack.yml")) {
|
while(entries.hasMoreElements()) {
|
||||||
try {
|
ZipEntry entry = entries.nextElement();
|
||||||
stream = file.getInputStream(entry);
|
if(entry.getName().equals("pack.yml")) stream = file.getInputStream(entry);
|
||||||
} catch(IOException e) {
|
|
||||||
throw new LoadException("Unable to load pack.yml from ZIP file", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} catch(IOException e) {
|
||||||
|
throw new LoadException("Unable to load pack.yml from ZIP file", e);
|
||||||
}
|
}
|
||||||
if(stream == null) throw new FileMissingException("No pack.yml file found in " + file.getName());
|
if(stream == null) throw new FileMissingException("No pack.yml file found in " + file.getName());
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ public class FolderLoader extends Loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader open(String directory) {
|
protected void load(String directory) {
|
||||||
if(streams.size() != 0) throw new IllegalStateException("Attempted to load folder before closing InputStreams");
|
|
||||||
File newPath = new File(path.toFile(), directory);
|
File newPath = new File(path.toFile(), directory);
|
||||||
newPath.mkdirs();
|
newPath.mkdirs();
|
||||||
try(Stream<Path> paths = Files.walk(newPath.toPath())) {
|
try(Stream<Path> paths = Files.walk(newPath.toPath())) {
|
||||||
@@ -34,6 +33,5 @@ public class FolderLoader extends Loader {
|
|||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,10 +23,15 @@ public abstract class Loader {
|
|||||||
/**
|
/**
|
||||||
* Open a subdirectory.
|
* Open a subdirectory.
|
||||||
*
|
*
|
||||||
* @param directory
|
* @param directory Directory to open
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public abstract Loader open(String directory);
|
public Loader open(String directory) {
|
||||||
|
if(streams.size() != 0) throw new IllegalStateException("Attempted to load new directory before closing existing InputStreams");
|
||||||
|
load(directory);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void load(String directory);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close all InputStreams opened.
|
* Close all InputStreams opened.
|
||||||
|
|||||||
@@ -13,10 +13,8 @@ public class ZIPLoader extends Loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader open(String directory) {
|
protected void load(String directory) {
|
||||||
if(streams.size() != 0) throw new IllegalStateException("Attempted to load folder before closing InputStreams");
|
|
||||||
Enumeration<? extends ZipEntry> entries = file.entries();
|
Enumeration<? extends ZipEntry> entries = file.entries();
|
||||||
|
|
||||||
while(entries.hasMoreElements()) {
|
while(entries.hasMoreElements()) {
|
||||||
ZipEntry entry = entries.nextElement();
|
ZipEntry entry = entries.nextElement();
|
||||||
if(!entry.isDirectory() && entry.getName().startsWith(directory) && entry.getName().endsWith(".yml")) {
|
if(!entry.isDirectory() && entry.getName().startsWith(directory) && entry.getName().endsWith(".yml")) {
|
||||||
@@ -27,6 +25,5 @@ public class ZIPLoader extends Loader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
package com.dfsek.terra.registry;
|
package com.dfsek.terra.registry;
|
||||||
|
|
||||||
import com.dfsek.tectonic.exception.ConfigException;
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
|
import com.dfsek.terra.Debug;
|
||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to hold config packs
|
* Class to hold config packs
|
||||||
@@ -35,5 +38,18 @@ public class ConfigRegistry extends TerraRegistry<ConfigPack> {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".jar") || file.getName().endsWith(".terra"))) {
|
||||||
|
try {
|
||||||
|
Debug.info("Loading ZIP archive: " + zip.getName());
|
||||||
|
getRegistry().load(new ZipFile(zip));
|
||||||
|
} catch(IOException | ConfigException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(ZipFile file) throws ConfigException {
|
||||||
|
ConfigPack pack = new ConfigPack(file);
|
||||||
|
add(pack.getTemplate().getID(), pack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user