Skip to content

Commit

Permalink
Revert to .zip
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Jun 29, 2021
1 parent 1427ff0 commit ee82ec3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 45 deletions.
12 changes: 0 additions & 12 deletions SubServers.Bungee/pom.xml
Expand Up @@ -43,18 +43,6 @@
<version>1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.kamranzafar</groupId>
<artifactId>jtar</artifactId>
<version>2.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.tukaani</groupId>
<artifactId>xz</artifactId>
<version>1.9</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -12,18 +12,12 @@
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
import net.ME1312.SubServers.Bungee.SubProxy;

import org.kamranzafar.jtar.TarEntry;
import org.kamranzafar.jtar.TarOutputStream;
import org.tukaani.xz.LZMA2Options;
import org.tukaani.xz.XZOutputStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.util.HashMap;

import static org.tukaani.xz.LZMA2Options.MODE_FAST;
import static org.tukaani.xz.XZ.CHECK_SHA256;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
* External Host Template Download Packet
Expand Down Expand Up @@ -52,26 +46,26 @@ public void send(SubDataClient client, OutputStream stream) throws Throwable {
try {
if (client.getBlockSize() < DataSize.MBB) client.tempBlockSize(DataSize.MBB);
HashMap<String, ServerTemplate> map = Util.getDespiteException(() -> Util.reflect(ExternalSubCreator.class.getDeclaredField("templates"), ((ExternalHost) client.getHandler()).getCreator()), new HashMap<>());
TarOutputStream tar = new TarOutputStream(new XZOutputStream(stream, new LZMA2Options(MODE_FAST), CHECK_SHA256));
File dir = new UniversalFile(plugin.dir, "SubServers:Templates");
ZipOutputStream zip = new ZipOutputStream(stream);

byte[] buffer = new byte[4096];
for (String file : Util.searchDirectory(dir)) {
int index = file.indexOf(File.separatorChar);
if (index != -1 && !map.containsKey(file.substring(0, index).toLowerCase())) {

tar.putNextEntry(new TarEntry(new File(dir, file), file.replace(File.separatorChar, '/')));
zip.putNextEntry(new ZipEntry(file.replace(File.separatorChar, '/')));
FileInputStream in = new FileInputStream(dir.getAbsolutePath() + File.separator + file);

int len;
while ((len = in.read(buffer)) != -1) {
tar.write(buffer, 0, len);
zip.write(buffer, 0, len);
}

in.close();
}
}
tar.close();
zip.close();

Util.isException(() -> Util.reflect(ExternalSubCreator.class.getDeclaredField("enableRT"), host.getCreator(), true));
} catch (Exception e) {
Expand Down
12 changes: 0 additions & 12 deletions SubServers.Host/pom.xml
Expand Up @@ -51,18 +51,6 @@
<version>1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.kamranzafar</groupId>
<artifactId>jtar</artifactId>
<version>2.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.tukaani</groupId>
<artifactId>xz</artifactId>
<version>1.9</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -9,13 +9,11 @@
import net.ME1312.SubServers.Host.ExHost;
import net.ME1312.SubServers.Host.SubAPI;

import org.kamranzafar.jtar.TarEntry;
import org.kamranzafar.jtar.TarInputStream;
import org.tukaani.xz.XZInputStream;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
* External Host Template Download Packet
Expand Down Expand Up @@ -48,11 +46,11 @@ public void receive(SubDataSender client, InputStream stream) {

try {
dir.mkdirs();
TarInputStream tar = new TarInputStream(new XZInputStream(stream));
ZipInputStream zip = new ZipInputStream(stream);

byte[] buffer = new byte[4096];
TarEntry entry;
while ((entry = tar.getNextEntry()) != null) {
ZipEntry entry;
while ((entry = zip.getNextEntry()) != null) {
File newFile = new File(dir + File.separator + entry.getName().replace('/', File.separatorChar));
if (newFile.exists()) {
if (newFile.isDirectory()) {
Expand All @@ -71,12 +69,12 @@ public void receive(SubDataSender client, InputStream stream) {

FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = tar.read(buffer)) != -1) {
while ((len = zip.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.close();
}
tar.close();
zip.close();

host.creator.load(true);
host.log.info.println(((first)?"":"New ") + "Remote Template Files Downloaded");
Expand Down

0 comments on commit ee82ec3

Please sign in to comment.