mirror of
https://github.com/SKCraft/Launcher.git
synced 2025-02-26 03:21:51 +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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Walks a path and adds hashed path versions to the given
|
* Walks a path and adds hashed path versions to the given
|
||||||
@ -25,6 +26,8 @@ import java.io.IOException;
|
|||||||
@Log
|
@Log
|
||||||
public class ClientFileCollector extends DirectoryWalker {
|
public class ClientFileCollector extends DirectoryWalker {
|
||||||
|
|
||||||
|
public static final String URL_FILE_SUFFIX = ".url.txt";
|
||||||
|
|
||||||
private final Manifest manifest;
|
private final Manifest manifest;
|
||||||
private final PropertiesApplicator applicator;
|
private final PropertiesApplicator applicator;
|
||||||
private final File destDir;
|
private final File destDir;
|
||||||
@ -51,17 +54,26 @@ public class ClientFileCollector extends DirectoryWalker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFile(File file, String relPath) throws IOException {
|
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;
|
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();
|
FileInstall entry = new FileInstall();
|
||||||
String hash = Files.hash(file, hf).toString();
|
String hash = Files.hash(file, hf).toString();
|
||||||
String hashedPath = hash.substring(0, 2) + "/" + hash.substring(2, 4) + "/" + hash;
|
String hashedPath = hash.substring(0, 2) + "/" + hash.substring(2, 4) + "/" + hash;
|
||||||
File destPath = new File(destDir, hashedPath);
|
File destPath = new File(destDir, hashedPath);
|
||||||
entry.setHash(hash);
|
entry.setHash(hash);
|
||||||
entry.setLocation(hashedPath);
|
entry.setLocation(hashedPath);
|
||||||
entry.setTo(FilenameUtils.separatorsToUnix(FilenameUtils.normalize(relPath)));
|
entry.setTo(to);
|
||||||
entry.setSize(file.length());
|
entry.setSize(file.length());
|
||||||
applicator.apply(entry);
|
applicator.apply(entry);
|
||||||
destPath.getParentFile().mkdirs();
|
destPath.getParentFile().mkdirs();
|
||||||
|
Loading…
Reference in New Issue
Block a user