From 07849371b8bcd465caff245810ef3d8320adb57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Tue, 25 Dec 2018 12:55:43 +0100 Subject: [PATCH 1/2] Allow .url.txt files only inside src/mods/ --- .../launcher/builder/ClientFileCollector.java | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/launcher-builder/src/main/java/com/skcraft/launcher/builder/ClientFileCollector.java b/launcher-builder/src/main/java/com/skcraft/launcher/builder/ClientFileCollector.java index 02805a341..2d0319fff 100644 --- a/launcher-builder/src/main/java/com/skcraft/launcher/builder/ClientFileCollector.java +++ b/launcher-builder/src/main/java/com/skcraft/launcher/builder/ClientFileCollector.java @@ -11,12 +11,14 @@ import com.google.common.io.Files; import com.skcraft.launcher.model.modpack.FileInstall; import com.skcraft.launcher.model.modpack.Manifest; +import com.skcraft.launcher.util.HttpRequest; import lombok.NonNull; import lombok.extern.java.Log; import org.apache.commons.io.FilenameUtils; import java.io.File; import java.io.IOException; +import java.net.URL; import java.nio.charset.Charset; /** @@ -54,24 +56,57 @@ protected DirectoryBehavior getBehavior(@NonNull String name) { @Override protected void onFile(File file, String relPath) throws IOException { - if (file.getName().endsWith(FileInfoScanner.FILE_SUFFIX) || file.getName().endsWith(URL_FILE_SUFFIX)) { + ClientFileCollector.log.info(String.format("Get %s from %s...", relPath, file.getAbsolutePath())); + if ( + (file.getName().endsWith(FileInfoScanner.FILE_SUFFIX) || file.getName().endsWith(URL_FILE_SUFFIX)) + && new File(file.getAbsoluteFile().getParentFile(), file.getName().replace(URL_FILE_SUFFIX, "")).exists() + ) { + ClientFileCollector.log.info(String.format("Get %s ignored ...", relPath)); return; } - FileInstall entry = new FileInstall(); - String hash = Files.hash(file, hf).toString(); - String to = FilenameUtils.separatorsToUnix(FilenameUtils.normalize(relPath)); + File urlFile; + if(file.getName().endsWith(URL_FILE_SUFFIX)) + { + relPath = relPath.replace(URL_FILE_SUFFIX, ""); + urlFile = file; + } + else + { + urlFile = new File(file.getAbsoluteFile().getParentFile(), file.getName() + URL_FILE_SUFFIX); + } // url.txt override file - File urlFile = new File(file.getAbsoluteFile().getParentFile(), file.getName() + URL_FILE_SUFFIX); - String location; + String location, hash; boolean copy = true; if (urlFile.exists() && !System.getProperty("com.skcraft.builder.ignoreURLOverrides", "false").equalsIgnoreCase("true")) { location = Files.readFirstLine(urlFile, Charset.defaultCharset()); copy = false; + + ClientFileCollector.log.info(String.format("Download %s from %s...", relPath, location)); + File tempFile = File.createTempFile("com.skcraft.builder", null); + URL url = HttpRequest.url(location.trim()); + try { + HttpRequest.get(url) + .execute() + .expectResponseCode(200) + .saveContent(tempFile); + hash = Files.hash(tempFile, hf).toString(); + } catch (InterruptedException e) { + ClientFileCollector.log.warning(String.format("Download from %s failed! ", location)); + throw new IOException(e); + } finally { + if(!tempFile.delete()) { + ClientFileCollector.log.warning(String.format("Unable to delete %s! ", tempFile.getAbsolutePath())); + } + } } else { + hash = Files.hash(file, hf).toString(); location = hash.substring(0, 2) + "/" + hash.substring(2, 4) + "/" + hash; } + + FileInstall entry = new FileInstall(); + String to = FilenameUtils.separatorsToUnix(FilenameUtils.normalize(relPath)); File destPath = new File(destDir, location); entry.setHash(hash); From 66a19cfbf4fa74890c0a2c9a1274aa6ac1798ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Tue, 25 Dec 2018 15:54:06 +0100 Subject: [PATCH 2/2] Allow to test modpacks --- .../launcher/builder/ClientFileCollector.java | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/launcher-builder/src/main/java/com/skcraft/launcher/builder/ClientFileCollector.java b/launcher-builder/src/main/java/com/skcraft/launcher/builder/ClientFileCollector.java index 2d0319fff..1356a6cad 100644 --- a/launcher-builder/src/main/java/com/skcraft/launcher/builder/ClientFileCollector.java +++ b/launcher-builder/src/main/java/com/skcraft/launcher/builder/ClientFileCollector.java @@ -68,8 +68,9 @@ && new File(file.getAbsoluteFile().getParentFile(), file.getName().replace(URL_F File urlFile; if(file.getName().endsWith(URL_FILE_SUFFIX)) { - relPath = relPath.replace(URL_FILE_SUFFIX, ""); urlFile = file; + file = new File(file.getAbsoluteFile().getParentFile(), file.getName().replace(URL_FILE_SUFFIX, "")); + relPath = relPath.replace(URL_FILE_SUFFIX, ""); } else { @@ -79,25 +80,37 @@ && new File(file.getAbsoluteFile().getParentFile(), file.getName().replace(URL_F // url.txt override file String location, hash; boolean copy = true; - if (urlFile.exists() && !System.getProperty("com.skcraft.builder.ignoreURLOverrides", "false").equalsIgnoreCase("true")) { + if (urlFile.exists() && + ( + !file.exists() || !System.getProperty("com.skcraft.builder.ignoreURLOverrides", "false") + .equalsIgnoreCase("true") + ) + ) { location = Files.readFirstLine(urlFile, Charset.defaultCharset()); copy = false; - ClientFileCollector.log.info(String.format("Download %s from %s...", relPath, location)); - File tempFile = File.createTempFile("com.skcraft.builder", null); - URL url = HttpRequest.url(location.trim()); - try { - HttpRequest.get(url) - .execute() - .expectResponseCode(200) - .saveContent(tempFile); - hash = Files.hash(tempFile, hf).toString(); - } catch (InterruptedException e) { - ClientFileCollector.log.warning(String.format("Download from %s failed! ", location)); - throw new IOException(e); - } finally { - if(!tempFile.delete()) { - ClientFileCollector.log.warning(String.format("Unable to delete %s! ", tempFile.getAbsolutePath())); + if (file.exists()) + { + hash = Files.hash(file, hf).toString(); + } + else + { + ClientFileCollector.log.info(String.format("Download %s from %s...", relPath, location)); + File tempFile = File.createTempFile("com.skcraft.builder", null); + URL url = HttpRequest.url(location.trim()); + try { + HttpRequest.get(url) + .execute() + .expectResponseCode(200) + .saveContent(tempFile); + hash = Files.hash(tempFile, hf).toString(); + } catch (InterruptedException e) { + ClientFileCollector.log.warning(String.format("Download from %s failed! ", location)); + throw new IOException(e); + } finally { + if(!tempFile.delete()) { + ClientFileCollector.log.warning(String.format("Unable to delete %s! ", tempFile.getAbsolutePath())); + } } } } else {