mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-27 12:46:22 +01:00
Add support for URL download override.
This commit is contained in:
parent
883eaf63eb
commit
8cdf50ff77
@ -17,6 +17,7 @@ import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* Walks a path and adds hashed path versions to the given
|
||||
@ -25,6 +26,8 @@ import java.io.IOException;
|
||||
@Log
|
||||
public class ClientFileCollector extends DirectoryWalker {
|
||||
|
||||
public static final String URL_FILE_SUFFIX = ".url.txt";
|
||||
|
||||
private final Manifest manifest;
|
||||
private final PropertiesApplicator applicator;
|
||||
private final File destDir;
|
||||
@ -51,17 +54,26 @@ public class ClientFileCollector extends DirectoryWalker {
|
||||
|
||||
@Override
|
||||
protected void onFile(File file, String relPath) throws IOException {
|
||||
if (file.getName().endsWith(FileInfoScanner.FILE_SUFFIX)) {
|
||||
if (file.getName().endsWith(FileInfoScanner.FILE_SUFFIX) || file.getName().endsWith(URL_FILE_SUFFIX)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// url.txt override file
|
||||
File urlFile = new File(file.getAbsoluteFile().getParentFile(), file.getName() + URL_FILE_SUFFIX);
|
||||
String to;
|
||||
if (urlFile.exists()) {
|
||||
to = Files.readFirstLine(urlFile, Charset.defaultCharset());
|
||||
} else {
|
||||
to = FilenameUtils.separatorsToUnix(FilenameUtils.normalize(relPath));
|
||||
}
|
||||
|
||||
FileInstall entry = new FileInstall();
|
||||
String hash = Files.hash(file, hf).toString();
|
||||
String hashedPath = hash.substring(0, 2) + "/" + hash.substring(2, 4) + "/" + hash;
|
||||
File destPath = new File(destDir, hashedPath);
|
||||
entry.setHash(hash);
|
||||
entry.setLocation(hashedPath);
|
||||
entry.setTo(FilenameUtils.separatorsToUnix(FilenameUtils.normalize(relPath)));
|
||||
entry.setTo(to);
|
||||
entry.setSize(file.length());
|
||||
applicator.apply(entry);
|
||||
destPath.getParentFile().mkdirs();
|
||||
|
Loading…
Reference in New Issue
Block a user