Skip to content

Commit 7e8356f

Browse files
committed
Remove zip functionality from the updater
I don't upload zip files anyways
1 parent 72b8c4c commit 7e8356f

File tree

1 file changed

+5
-127
lines changed

1 file changed

+5
-127
lines changed

modules/ProtocolLib/src/main/java/com/comphenix/protocol/updater/BukkitUpdater.java

Lines changed: 5 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,20 @@
77
// Somewhat modified by aadnk.
88
package com.comphenix.protocol.updater;
99

10-
import java.io.BufferedInputStream;
11-
import java.io.BufferedOutputStream;
12-
import java.io.BufferedReader;
13-
import java.io.File;
14-
import java.io.FileOutputStream;
15-
import java.io.IOException;
16-
import java.io.InputStreamReader;
10+
import java.io.*;
1711
import java.net.MalformedURLException;
1812
import java.net.URL;
1913
import java.net.URLConnection;
20-
import java.util.Enumeration;
21-
import java.util.zip.ZipEntry;
22-
import java.util.zip.ZipFile;
14+
15+
import com.comphenix.protocol.ProtocolLibrary;
16+
import com.comphenix.protocol.error.Report;
2317

2418
import org.bukkit.configuration.file.YamlConfiguration;
2519
import org.bukkit.plugin.Plugin;
2620
import org.json.simple.JSONArray;
2721
import org.json.simple.JSONObject;
2822
import org.json.simple.JSONValue;
2923

30-
import com.comphenix.protocol.ProtocolLibrary;
31-
import com.comphenix.protocol.error.Report;
32-
3324
/**
3425
* Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed.
3526
* <p/>
@@ -60,7 +51,7 @@ public class BukkitUpdater extends Updater {
6051
private static final String VERSION_VALUE = "gameVersion"; // Gets remote file's build version
6152
private static final Object FILE_NAME = "fileName"; // Gets remote file's name
6253
private static final String QUERY = "/servermods/files?projectIds="; // Path to GET
63-
private static final String HOST = "https://api.curseforge.com"; // Slugs will be appended to this to get to the project's RSS feed
54+
private static final String HOST = "https://servermods.forgesvc.net"; // Formerly api.curseforge.net
6455

6556
// private static final String[] NO_UPDATE_TAG = { "-DEV", "-PRE", "-SNAPSHOT" }; // If the version number contains one of these, don't update.
6657
private static final int BYTE_SIZE = 1024; // Used for downloading files
@@ -186,18 +177,6 @@ private void saveFile(File folder, String file, String u) {
186177
this.plugin.getLogger().info("Downloading update: " + percent + "% of " + fileLength + " bytes.");
187178
}
188179
}
189-
//Just a quick check to make sure we didn't leave any files from last time...
190-
for (final File xFile : new File(this.plugin.getDataFolder().getParent(), this.updateFolder).listFiles()) {
191-
if (xFile.getName().endsWith(".zip")) {
192-
xFile.delete();
193-
}
194-
}
195-
// Check to see if it's a zip file, if it is, unzip it.
196-
final File dFile = new File(folder.getAbsolutePath() + "/" + file);
197-
if (dFile.getName().endsWith(".zip")) {
198-
// Unzip
199-
this.unzip(dFile.getCanonicalPath());
200-
}
201180
if (this.announce) {
202181
this.plugin.getLogger().info("Finished updating.");
203182
}
@@ -217,107 +196,6 @@ private void saveFile(File folder, String file, String u) {
217196
}
218197
}
219198

220-
/**
221-
* Part of Zip-File-Extractor, modified by Gravity for use with Bukkit
222-
*/
223-
private void unzip(String file) {
224-
try {
225-
final File fSourceZip = new File(file);
226-
final String zipPath = file.substring(0, file.length() - 4);
227-
ZipFile zipFile = new ZipFile(fSourceZip);
228-
Enumeration<? extends ZipEntry> e = zipFile.entries();
229-
while (e.hasMoreElements()) {
230-
ZipEntry entry = e.nextElement();
231-
File destinationFilePath = new File(zipPath, entry.getName());
232-
destinationFilePath.getParentFile().mkdirs();
233-
if (entry.isDirectory()) {
234-
continue;
235-
} else {
236-
final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
237-
int b;
238-
final byte buffer[] = new byte[BukkitUpdater.BYTE_SIZE];
239-
final FileOutputStream fos = new FileOutputStream(destinationFilePath);
240-
final BufferedOutputStream bos = new BufferedOutputStream(fos, BukkitUpdater.BYTE_SIZE);
241-
while ((b = bis.read(buffer, 0, BukkitUpdater.BYTE_SIZE)) != -1) {
242-
bos.write(buffer, 0, b);
243-
}
244-
bos.flush();
245-
bos.close();
246-
bis.close();
247-
final String name = destinationFilePath.getName();
248-
if (name.endsWith(".jar") && this.pluginFile(name)) {
249-
destinationFilePath.renameTo(new File(this.plugin.getDataFolder().getParent(), this.updateFolder + "/" + name));
250-
}
251-
}
252-
entry = null;
253-
destinationFilePath = null;
254-
}
255-
e = null;
256-
zipFile.close();
257-
zipFile = null;
258-
259-
// Move any plugin data folders that were included to the right place, Bukkit won't do this for us.
260-
for (final File dFile : new File(zipPath).listFiles()) {
261-
if (dFile.isDirectory()) {
262-
if (this.pluginFile(dFile.getName())) {
263-
final File oFile = new File(this.plugin.getDataFolder().getParent(), dFile.getName()); // Get current dir
264-
final File[] contents = oFile.listFiles(); // List of existing files in the current dir
265-
for (final File cFile : dFile.listFiles()) // Loop through all the files in the new dir
266-
{
267-
boolean found = false;
268-
for (final File xFile : contents) // Loop through contents to see if it exists
269-
{
270-
if (xFile.getName().equals(cFile.getName())) {
271-
found = true;
272-
break;
273-
}
274-
}
275-
if (!found) {
276-
// Move the new file into the current dir
277-
cFile.renameTo(new File(oFile.getCanonicalFile() + "/" + cFile.getName()));
278-
} else {
279-
// This file already exists, so we don't need it anymore.
280-
cFile.delete();
281-
}
282-
}
283-
}
284-
}
285-
dFile.delete();
286-
}
287-
new File(zipPath).delete();
288-
fSourceZip.delete();
289-
} catch (final IOException ex) {
290-
this.plugin.getLogger().warning("The auto-updater tried to unzip a new update file, but was unsuccessful.");
291-
this.result = BukkitUpdater.UpdateResult.FAIL_DOWNLOAD;
292-
ex.printStackTrace();
293-
}
294-
new File(file).delete();
295-
}
296-
297-
/**
298-
* Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip.
299-
*/
300-
private boolean pluginFile(String name) {
301-
for (final File file : new File("plugins").listFiles()) {
302-
if (file.getName().equals(name)) {
303-
return true;
304-
}
305-
}
306-
return false;
307-
}
308-
309-
/**
310-
* Evaluate whether the version number is marked showing that it should not be updated by this program
311-
*/
312-
/* private boolean hasTag(String version) {
313-
for (final String string : BukkitUpdater.NO_UPDATE_TAG) {
314-
if (version.contains(string)) {
315-
return true;
316-
}
317-
}
318-
return false;
319-
} */
320-
321199
public boolean read() {
322200
try {
323201
final URLConnection conn = this.url.openConnection();

0 commit comments

Comments
 (0)