mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-17 07:47:57 -04:00
parent
1a772e8c65
commit
192c90816b
@ -25,6 +25,7 @@ import org.jackhuang.hmcl.task.FileDownloadTask;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.util.gson.JsonUtils;
|
||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||
import org.jackhuang.hmcl.util.io.NetworkUtils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@ -35,6 +36,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
||||
|
||||
@ -120,7 +122,9 @@ public class ModrinthCompletionTask extends Task<Void> {
|
||||
if (modsDirectory.equals(filePath.getParent()) && this.modManager.hasSimpleMod(FileUtils.getName(filePath)))
|
||||
continue;
|
||||
|
||||
var task = new FileDownloadTask(file.getDownloads(), filePath);
|
||||
var task = new FileDownloadTask(
|
||||
file.getDownloads().stream().map(NetworkUtils::toURI).collect(Collectors.toList()),
|
||||
filePath);
|
||||
task.setCacheRepository(dependency.getCacheRepository());
|
||||
task.setCaching(true);
|
||||
dependencies.add(task.withCounter("hmcl.modpack.download"));
|
||||
|
@ -24,7 +24,6 @@ import org.jackhuang.hmcl.util.gson.TolerableValidationException;
|
||||
import org.jackhuang.hmcl.util.gson.Validation;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -98,10 +97,10 @@ public class ModrinthManifest implements ModpackManifest, Validation {
|
||||
private final String path;
|
||||
private final Map<String, String> hashes;
|
||||
private final Map<String, String> env;
|
||||
private final List<URI> downloads;
|
||||
private final List<String> downloads;
|
||||
private final int fileSize;
|
||||
|
||||
public File(String path, Map<String, String> hashes, Map<String, String> env, List<URI> downloads, int fileSize) {
|
||||
public File(String path, Map<String, String> hashes, Map<String, String> env, List<String> downloads, int fileSize) {
|
||||
this.path = path;
|
||||
this.hashes = hashes;
|
||||
this.env = env;
|
||||
@ -121,7 +120,7 @@ public class ModrinthManifest implements ModpackManifest, Validation {
|
||||
return env;
|
||||
}
|
||||
|
||||
public List<URI> getDownloads() {
|
||||
public List<String> getDownloads() {
|
||||
return downloads;
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,11 @@ package org.jackhuang.hmcl.mod.modrinth;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
||||
import org.jackhuang.hmcl.download.LibraryAnalyzer;
|
||||
import org.jackhuang.hmcl.game.DefaultGameRepository;
|
||||
import org.jackhuang.hmcl.mod.ModAdviser;
|
||||
@ -68,7 +68,7 @@ public class ModrinthModpackExportTask extends Task<Void> {
|
||||
}
|
||||
}
|
||||
|
||||
if (!modrinthVersion.isPresent() && !curseForgeVersion.isPresent()) {
|
||||
if (modrinthVersion.isEmpty() && curseForgeVersion.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -82,22 +82,22 @@ public class ModrinthModpackExportTask extends Task<Void> {
|
||||
env.put("client", "optional");
|
||||
}
|
||||
|
||||
List<URL> downloads = new ArrayList<>();
|
||||
List<String> downloads = new ArrayList<>();
|
||||
if (modrinthVersion.isPresent())
|
||||
downloads.add(new URL(modrinthVersion.get().getFile().getUrl()));
|
||||
downloads.add(modrinthVersion.get().getFile().getUrl());
|
||||
if (curseForgeVersion.isPresent())
|
||||
downloads.add(new URL(curseForgeVersion.get().getFile().getUrl()));
|
||||
downloads.add(curseForgeVersion.get().getFile().getUrl());
|
||||
|
||||
long fileSize = Files.size(file);
|
||||
if (fileSize > Integer.MAX_VALUE) {
|
||||
LOG.warning("File " + relativePath + " is too large (size: " + fileSize + " bytes), precision may be lost when converting to int");
|
||||
}
|
||||
return new ModrinthManifest.File(
|
||||
relativePath,
|
||||
hashes,
|
||||
env,
|
||||
downloads,
|
||||
(int) fileSize
|
||||
relativePath,
|
||||
hashes,
|
||||
env,
|
||||
downloads,
|
||||
(int) fileSize
|
||||
);
|
||||
}
|
||||
|
||||
@ -117,24 +117,24 @@ public class ModrinthModpackExportTask extends Task<Void> {
|
||||
Path dirPath = runDirectory.resolve(dir);
|
||||
if (Files.exists(dirPath)) {
|
||||
Files.walk(dirPath)
|
||||
.filter(Files::isRegularFile)
|
||||
.forEach(file -> {
|
||||
try {
|
||||
String relativePath = runDirectory.relativize(file).normalize().toString().replace(File.separatorChar, '/');
|
||||
|
||||
if (!info.getWhitelist().contains(relativePath)) {
|
||||
return;
|
||||
.filter(Files::isRegularFile)
|
||||
.forEach(file -> {
|
||||
try {
|
||||
String relativePath = runDirectory.relativize(file).normalize().toString().replace(File.separatorChar, '/');
|
||||
|
||||
if (!info.getWhitelist().contains(relativePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ModrinthManifest.File fileEntry = tryGetRemoteFile(file, relativePath);
|
||||
if (fileEntry != null) {
|
||||
files.add(fileEntry);
|
||||
filesInManifest.add(relativePath);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.warning("Failed to process file: " + file, e);
|
||||
}
|
||||
|
||||
ModrinthManifest.File fileEntry = tryGetRemoteFile(file, relativePath);
|
||||
if (fileEntry != null) {
|
||||
files.add(fileEntry);
|
||||
filesInManifest.add(relativePath);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.warning("Failed to process file: " + file, e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ public class ModrinthModpackExportTask extends Task<Void> {
|
||||
|
||||
Map<String, String> dependencies = new HashMap<>();
|
||||
dependencies.put("minecraft", gameVersion);
|
||||
|
||||
|
||||
analyzer.getVersion(FORGE).ifPresent(forgeVersion ->
|
||||
dependencies.put("forge", forgeVersion));
|
||||
analyzer.getVersion(NEO_FORGE).ifPresent(neoForgeVersion ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user