Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Allow .url.txt files only inside src/mods/ #273

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -54,24 +56,70 @@ 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))
{
urlFile = file;
file = new File(file.getAbsoluteFile().getParentFile(), file.getName().replace(URL_FILE_SUFFIX, ""));
relPath = relPath.replace(URL_FILE_SUFFIX, "");
}
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")) {
if (urlFile.exists() &&
(
!file.exists() || !System.getProperty("com.skcraft.builder.ignoreURLOverrides", "false")
.equalsIgnoreCase("true")
)
) {
location = Files.readFirstLine(urlFile, Charset.defaultCharset());
copy = false;

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 {
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);
Expand Down