mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-11-15 10:55:20 +01:00
Allow url redirect
Bukkit changed download urls from http to https so this fix is needed
This commit is contained in:
parent
d95816eddb
commit
75624ac624
@ -36,12 +36,9 @@ public InventorySerializer()
|
||||
String[] version = name.substring(name.lastIndexOf('.') + 2).split("_");
|
||||
try
|
||||
{
|
||||
if(version[0].equals("1"))
|
||||
if(version[0].equals("1") && Integer.parseInt(version[1]) > 7)
|
||||
{
|
||||
if(Integer.parseInt(version[1]) > 7)
|
||||
{
|
||||
serializer = new NBTItemStackSerializer();
|
||||
}
|
||||
serializer = new NBTItemStackSerializer();
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
|
@ -26,6 +26,7 @@
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
@ -181,6 +182,11 @@ protected boolean versionCheck(String remoteVersion)
|
||||
//endregion
|
||||
|
||||
protected void download(URL url, String fileName) // Saves file into servers update directory
|
||||
{
|
||||
download(url, fileName, 0);
|
||||
}
|
||||
|
||||
protected void download(URL url, String fileName, int movedCount) // Saves file into servers update directory
|
||||
{
|
||||
if(!updateFolder.exists())
|
||||
{
|
||||
@ -189,10 +195,29 @@ protected void download(URL url, String fileName) // Saves file into servers upd
|
||||
}
|
||||
try
|
||||
{
|
||||
int fileLength = url.openConnection().getContentLength(), count, percent, percentHelper = -1;
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setInstanceFollowRedirects(false);
|
||||
connection.setConnectTimeout(15000);
|
||||
connection.setReadTimeout(15000);
|
||||
switch (connection.getResponseCode())
|
||||
{
|
||||
case HttpURLConnection.HTTP_MOVED_PERM:
|
||||
case HttpURLConnection.HTTP_MOVED_TEMP:
|
||||
if(movedCount == 5)
|
||||
{
|
||||
logger.warning("Target url moved more than 5 times. Abort.");
|
||||
result = UpdateResult.FAIL_DOWNLOAD;
|
||||
return;
|
||||
}
|
||||
download(new URL(url, connection.getHeaderField("Location")), fileName, ++movedCount);
|
||||
return;
|
||||
}
|
||||
//endregion
|
||||
long fileLength = connection.getContentLengthLong();
|
||||
int count, percent, percentHelper = -1;
|
||||
File downloadFile = new File(updateFolder.getAbsolutePath() + File.separator + fileName);
|
||||
MessageDigest md5HashGenerator = updateProvider.provideMD5Checksum() ? MessageDigest.getInstance("MD5") : null;
|
||||
try(InputStream inputStream = (md5HashGenerator != null) ? new DigestInputStream(new BufferedInputStream(url.openStream()), md5HashGenerator) : new BufferedInputStream(url.openStream());
|
||||
try(InputStream inputStream = (md5HashGenerator != null) ? new DigestInputStream(new BufferedInputStream(connection.getInputStream()), md5HashGenerator) : new BufferedInputStream(url.openStream());
|
||||
FileOutputStream outputStream = new FileOutputStream(downloadFile))
|
||||
{
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
@ -214,6 +239,7 @@ protected void download(URL url, String fileName) // Saves file into servers upd
|
||||
}
|
||||
outputStream.flush();
|
||||
}
|
||||
connection.disconnect();
|
||||
if(md5HashGenerator != null)
|
||||
{
|
||||
String MD5Download = byteArrayToHex(md5HashGenerator.digest()).toLowerCase(), MD5Target = updateProvider.getLatestChecksum().toLowerCase();
|
||||
|
Loading…
Reference in New Issue
Block a user