Compare commits

...
Author SHA1 Message Date
Glavo 1187ae4f04 Fix #2938: 修复 DefaultLauncher 会多次添加包装命令的问题 (#2939) 2024-03-16 11:08:17 +08:00
Glavo 8efdc536ee Fix #2934: 修复无法读取远古版本版本号的问题 (#2936)
* update

* update
2024-03-15 20:57:45 +08:00
Glavo 78f080b6cc Fix #2784: 离线账户选择 Steve/Alex 皮肤时强制使用本地 Yggdrasil 服务器 (#2933) 2024-03-15 13:39:50 +08:00
Glavo cc8bcfd924 Fix i18n (#2931)
* Fix i18n

* update
2024-03-15 12:56:29 +08:00
Glavo 806ca3f64a 更新 Modrinth 翻译 (#2929)
* update

* update

* update

* update

* update

* update
2024-03-15 12:24:43 +08:00
lyuxc_ 4a16fa13ee Update ModpackInfoPage.java (#2928) 2024-03-14 21:23:06 +08:00
Glavo b88d7c4fd2 修复 saveETagIndex 可能写入不全的问题 (#2926) 2024-03-14 19:24:30 +08:00
Burning_TNTandGlavo c0838468b1 Close #2911: 下载失败时打印重定向链 (#2912)
* Support #2911.

* update

* update

* update

* update

* update

---------

Co-authored-by: Glavo <[email protected]>
2024-03-14 13:50:25 +08:00
Glavo 90cfe3d0b7 加载网络背景时设置超时 (#2856) 2024-03-13 16:25:55 +08:00
Burning_TNT baf1d22bc4 Fix bugs. (#2920)
* Always sort the results while searching in CurseForge.

* Fix bugs.
2024-03-12 22:14:32 +08:00
Glavo 7ca5744559 允许使用系统属性禁用系统代理 (#2921) 2024-03-12 21:44:08 +08:00
Glavo 57e728991b Fix #1938: 正确处理 map_to_resources (#2919)
* Fix #1938: 正确处理 map_to_resources

* fix checkstyle
2024-03-12 20:01:30 +08:00
Glavo e08ba4d421 不再尝试下载 .pack.xz 文件 (#2917)
* 不再尝试下载 .pack.xz 文件

* update
2024-03-11 20:21:17 +08:00
19 changed files with 161 additions and 119 deletions

No files matched your search

@@ -55,8 +55,8 @@ public final class Main {
}
public static void main(String[] args) {
System.setProperty("java.net.useSystemProxies", "true");
System.setProperty("javafx.autoproxy.disable", "true");
System.getProperties().putIfAbsent("java.net.useSystemProxies", "true");
System.getProperties().putIfAbsent("javafx.autoproxy.disable", "true");
System.getProperties().putIfAbsent("http.agent", "HMCL/" + Metadata.VERSION);
checkDirectoryPath();
@@ -333,7 +333,8 @@ public final class LauncherHelper {
}
private static Task<JavaVersion> checkGameState(Profile profile, VersionSetting setting, Version version) {
GameVersionNumber gameVersion = GameVersionNumber.asGameVersion(profile.getRepository().getGameVersion(version));
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(version, profile.getRepository().getGameVersion(version).orElse(null));
GameVersionNumber gameVersion = GameVersionNumber.asGameVersion(analyzer.getVersion(LibraryAnalyzer.LibraryType.MINECRAFT));
if (setting.isNotCheckJVM()) {
return Task.composeAsync(() -> setting.getJavaVersion(gameVersion, version))
@@ -417,7 +418,6 @@ public final class LauncherHelper {
JavaVersionConstraint violatedMandatoryConstraint = null;
List<JavaVersionConstraint> violatedSuggestedConstraints = null;
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(version, gameVersion.toString());
for (JavaVersionConstraint constraint : JavaVersionConstraint.ALL) {
if (constraint.appliesToVersion(gameVersion, version, javaVersion, analyzer)) {
if (!constraint.checkJava(gameVersion, version, javaVersion)) {
@@ -50,6 +50,10 @@ import org.jackhuang.hmcl.ui.wizard.WizardProvider;
import org.jackhuang.hmcl.util.io.NetworkUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -168,8 +172,23 @@ public class DecoratorController {
break;
case NETWORK:
String backgroundImageUrl = config().getBackgroundImageUrl();
if (backgroundImageUrl != null && NetworkUtils.isURL(backgroundImageUrl))
image = tryLoadImage(backgroundImageUrl).orElse(null);
if (backgroundImageUrl != null) {
try {
URLConnection connection = NetworkUtils.createConnection(new URL(backgroundImageUrl));
if (connection instanceof HttpURLConnection) {
connection = NetworkUtils.resolveConnection((HttpURLConnection) connection);
}
try (InputStream input = connection.getInputStream()) {
image = new Image(input);
if (image.isError()) {
throw image.getException();
}
}
} catch (Exception e) {
LOG.log(WARNING, "Couldn't load background image", e);
}
}
break;
case CLASSIC:
image = newBuiltinImage("/assets/img/background-classic.jpg");
@@ -179,7 +179,7 @@ public final class ModpackInfoPage extends Control implements WizardPage {
if (skinnable.controller.getSettings().get(MODPACK_TYPE) == MODPACK_TYPE_SERVER) {
Hyperlink hyperlink = new Hyperlink(i18n("modpack.wizard.step.initialization.server"));
hyperlink.setOnMouseClicked(e -> {
FXUtils.openLink("https://docs.hmcl.net/modpack/serverpack.htm");
FXUtils.openLink("https://docs.hmcl.net/modpack/serverpack.html");
});
borderPane.setTop(hyperlink);
} else {
@@ -21,7 +21,12 @@ import org.jackhuang.hmcl.game.LocalizedRemoteModRepository;
import org.jackhuang.hmcl.mod.RemoteModRepository;
import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository;
import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository;
import org.jackhuang.hmcl.util.i18n.I18n;
import java.util.MissingResourceException;
import java.util.logging.Level;
import static org.jackhuang.hmcl.util.Logging.LOG;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public class ResourcePackDownloadListPage extends DownloadListPage {
@@ -66,10 +71,18 @@ public class ResourcePackDownloadListPage extends DownloadListPage {
@Override
protected String getLocalizedCategory(String category) {
String key;
if ("mods.modrinth".equals(downloadSource.get())) {
return i18n("modrinth.category." + category);
key = "modrinth.category." + category;
} else {
return i18n("curse.category." + category);
key = "curse.category." + category;
}
try {
return I18n.getResourceBundle().getString(key);
} catch (MissingResourceException e) {
LOG.log(Level.WARNING, "Cannot find key " + key + " in resource bundle", e);
return category;
}
}
@@ -164,7 +164,9 @@ public class VersionPage extends DecoratorAnimatedPage implements DecoratorPage
}
private void clearAssets() {
FileUtils.deleteDirectoryQuietly(new File(getProfile().getRepository().getBaseDirectory(), "assets"));
File baseDirectory = getProfile().getRepository().getBaseDirectory();
FileUtils.deleteDirectoryQuietly(new File(baseDirectory, "assets"));
FileUtils.deleteDirectoryQuietly(new File(baseDirectory, "resources"));
}
private void clearJunkFiles() {
@@ -827,26 +827,39 @@ Keep in mind that you are not allowed to add mods and resource packs that are ex
modpack.wizard.step.initialization.server=Click here for more tutorials for making a server modpack that can be automatically updated.
modrinth.category.adventure=Adventure
modrinth.category.audio=Audio
modrinth.category.blocks=Blocks
modrinth.category.bukkit=Bukkit
modrinth.category.bungeecord=BungeeCord
modrinth.category.challenging=Challenging
modrinth.category.core-shaders=Core Shaders
modrinth.category.combat=Combat
modrinth.category.cursed=Cursed
modrinth.category.decoration=Decoration
modrinth.category.economy=Economy
modrinth.category.entities=Entities
modrinth.category.environment=Environment
modrinth.category.equipment=Equipment
modrinth.category.fabric=Fabric
modrinth.category.fonts=Fonts
modrinth.category.food=Food
modrinth.category.forge=Forge
modrinth.category.game-mechanics=Game Mechanics
modrinth.category.gui=GUI
modrinth.category.items=Items
modrinth.category.kitchen-sink=Kitchen-Sink
modrinth.category.library=Library
modrinth.category.lightweight=Lightweight
modrinth.category.liteloader=LiteLoader
modrinth.category.locale=Locale
modrinth.category.magic=Magic
modrinth.category.management=Management
modrinth.category.minecraft=Minecraft
modrinth.category.minigame=Minigame
modrinth.category.misc=Misc
modrinth.category.mobs=Mobs
modrinth.category.modded=Modded
modrinth.category.models=Models
modrinth.category.modloader=Modloader
modrinth.category.multiplayer=Multiplayer
modrinth.category.neoforge=NeoForge
@@ -855,19 +868,32 @@ modrinth.category.paper=Paper
modrinth.category.purpur=Purpur
modrinth.category.quests=Quests
modrinth.category.quilt=Quilt
modrinth.category.realistic=Realistic
modrinth.category.rift=Rift
modrinth.category.simplistic=Simplistic
modrinth.category.social=Social
modrinth.category.spigot=Spigot
modrinth.category.sponge=Sponge
modrinth.category.storage=Storage
modrinth.category.technology=Technology
modrinth.category.themed=Themed
modrinth.category.transportation=Transportation
modrinth.category.tweaks=Tweaks
modrinth.category.utility=Utility
modrinth.category.vanilla-like=Vanilla-like
modrinth.category.velocity=Velocity
modrinth.category.waterfall=Waterfall
modrinth.category.worldgen=Worldgen
modrinth.category.datapack=Datapack
modrinth.category.folia=Folia
modrinth.category.8x-=8x-
modrinth.category.16x=16x
modrinth.category.32x=32x
modrinth.category.48x=48x
modrinth.category.64x=64x
modrinth.category.128x=128x
modrinth.category.256x=256x
modrinth.category.512x+=512x+
mods=Mods
mods.add=Add Mods
@@ -511,7 +511,7 @@ install.installer.forge=Forge
install.installer.neoforge=NeoForge
install.installer.game=Minecraft
install.installer.incompatible=與 %s 不相容
install.installer.install=安裝%s
install.installer.install=安裝 %s
install.installer.install_offline=從本機檔案安裝或升級
install.installer.install_offline.extension=Forge/OptiFine 安裝器
install.installer.install_offline.tooltip=支援匯入已經下載好的 Forge/OptiFine 安裝器
@@ -703,26 +703,39 @@ modpack.wizard.step.initialization.warning=在製作模組包前,請您確認
modpack.wizard.step.initialization.server=點選此處查看有關伺服器自動更新模組包的製作教學
modrinth.category.adventure=冒險
modrinth.category.audio=聲音
modrinth.category.blocks=方塊
modrinth.category.bukkit=Bukkit
modrinth.category.bungeecord=BungeeCord
modrinth.category.challenging=高難度
modrinth.category.core-shaders=覈心著色器
modrinth.category.combat=戰鬥
modrinth.category.cursed=Cursed
modrinth.category.decoration=裝飾
modrinth.category.economy=經濟
modrinth.category.entities=實體
modrinth.category.environment=環境
modrinth.category.equipment=裝備
modrinth.category.fabric=Fabric
modrinth.category.fonts=字體
modrinth.category.food=食物
modrinth.category.forge=Forge
modrinth.category.game-mechanics=遊戲機制
modrinth.category.gui=GUI
modrinth.category.items=物品
modrinth.category.kitchen-sink=大雜燴
modrinth.category.library=支持庫
modrinth.category.lightweight=輕量
modrinth.category.liteloader=LiteLoader
modrinth.category.locale=在地化
modrinth.category.magic=魔法
modrinth.category.management=管理
modrinth.category.minecraft=Minecraft
modrinth.category.minigame=小遊戲
modrinth.category.misc=其他
modrinth.category.mobs=生物
modrinth.category.modded=Modded
modrinth.category.models=模型
modrinth.category.modloader=Modloader
modrinth.category.multiplayer=多人
modrinth.category.neoforge=NeoForge
@@ -731,14 +744,19 @@ modrinth.category.paper=Paper
modrinth.category.purpur=Purpur
modrinth.category.quests=任務
modrinth.category.quilt=Quilt
modrinth.category.realistic=寫實
modrinth.category.rift=Rift
modrinth.category.simplistic=簡單
modrinth.category.social=社交
modrinth.category.spigot=Spigot
modrinth.category.sponge=Sponge
modrinth.category.storage=儲存
modrinth.category.technology=科技
modrinth.category.themed=主題
modrinth.category.transportation=運輸
modrinth.category.tweaks=優化
modrinth.category.utility=實用
modrinth.category.vanilla-like=類原生
modrinth.category.velocity=Velocity
modrinth.category.waterfall=Waterfall
modrinth.category.worldgen=世界生成
@@ -702,26 +702,39 @@ modpack.wizard.step.initialization.warning=在制作整合包前,请您确认
modpack.wizard.step.initialization.server=点击此处查看有关服务器自动更新整合包的制作教程
modrinth.category.adventure=冒险
modrinth.category.audio=声音
modrinth.category.blocks=方块
modrinth.category.bukkit=Bukkit
modrinth.category.bungeecord=BungeeCord
modrinth.category.challenging=高难度
modrinth.category.core-shaders=核心着色器
modrinth.category.combat=战斗
modrinth.category.cursed=Cursed
modrinth.category.decoration=装饰
modrinth.category.economy=经济
modrinth.category.entities=实体
modrinth.category.environment=环境
modrinth.category.equipment=装备
modrinth.category.fabric=Fabric
modrinth.category.fonts=字体
modrinth.category.food=食物
modrinth.category.forge=Forge
modrinth.category.game-mechanics=游戏机制
modrinth.category.gui=GUI
modrinth.category.items=物品
modrinth.category.kitchen-sink=大杂烩
modrinth.category.library=支持库
modrinth.category.lightweight=轻量
modrinth.category.liteloader=LiteLoader
modrinth.category.locale=本地化
modrinth.category.magic=魔法
modrinth.category.management=管理
modrinth.category.minecraft=Minecraft
modrinth.category.minigame=小游戏
modrinth.category.misc=其他
modrinth.category.mobs=生物
modrinth.category.modded=Modded
modrinth.category.models=模型
modrinth.category.modloader=Modloader
modrinth.category.multiplayer=多人
modrinth.category.neoforge=NeoForge
@@ -730,14 +743,19 @@ modrinth.category.paper=Paper
modrinth.category.purpur=Purpur
modrinth.category.quests=任务
modrinth.category.quilt=Quilt
modrinth.category.realistic=写实
modrinth.category.rift=Rift
modrinth.category.simplistic=简单
modrinth.category.social=社交
modrinth.category.spigot=Spigot
modrinth.category.sponge=Sponge
modrinth.category.storage=存储
modrinth.category.technology=科技
modrinth.category.themed=主题
modrinth.category.transportation=运输
modrinth.category.tweaks=优化
modrinth.category.utility=实用
modrinth.category.vanilla-like=类原生
modrinth.category.velocity=Velocity
modrinth.category.waterfall=Waterfall
modrinth.category.worldgen=世界生成
@@ -25,7 +25,6 @@ import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorArtifactInfo;
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorArtifactProvider;
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorDownloadException;
import org.jackhuang.hmcl.auth.yggdrasil.Texture;
import org.jackhuang.hmcl.auth.yggdrasil.TextureModel;
import org.jackhuang.hmcl.auth.yggdrasil.TextureType;
import org.jackhuang.hmcl.game.Arguments;
import org.jackhuang.hmcl.game.LaunchOptions;
@@ -101,14 +100,7 @@ public class OfflineAccount extends Account {
}
protected boolean loadAuthlibInjector(Skin skin) {
if (skin == null) return false;
if (skin.getType() == Skin.Type.DEFAULT) return false;
TextureModel defaultModel = TextureModel.detectUUID(getUUID());
if (skin.getType() == Skin.Type.ALEX && defaultModel == TextureModel.ALEX ||
skin.getType() == Skin.Type.STEVE && defaultModel == TextureModel.STEVE) {
return false;
}
return true;
return skin != null && skin.getType() != Skin.Type.DEFAULT;
}
@Override
@@ -18,7 +18,6 @@
package org.jackhuang.hmcl.download.game;
import org.jackhuang.hmcl.download.AbstractDependencyManager;
import org.jackhuang.hmcl.download.ArtifactMalformedException;
import org.jackhuang.hmcl.download.DefaultCacheRepository;
import org.jackhuang.hmcl.game.Library;
import org.jackhuang.hmcl.task.DownloadException;
@@ -26,13 +25,12 @@ import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.task.FileDownloadTask.IntegrityCheck;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.util.DigestUtils;
import org.jackhuang.hmcl.util.Pack200Utils;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.io.IOUtils;
import org.jackhuang.hmcl.util.io.NetworkUtils;
import org.tukaani.xz.XZInputStream;
import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -41,7 +39,6 @@ import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import java.util.jar.JarOutputStream;
import java.util.logging.Level;
import static org.jackhuang.hmcl.util.Logging.LOG;
@@ -51,10 +48,8 @@ public class LibraryDownloadTask extends Task<Void> {
protected final File jar;
protected final DefaultCacheRepository cacheRepository;
protected final AbstractDependencyManager dependencyManager;
private final File xzFile;
protected final Library library;
protected final String url;
protected boolean xz;
private final Library originalLibrary;
private boolean cached = false;
@@ -72,8 +67,6 @@ public class LibraryDownloadTask extends Task<Void> {
url = library.getDownload().getUrl();
jar = file;
xzFile = new File(file.getAbsoluteFile().getParentFile(), file.getName() + ".pack.xz");
}
@Override
@@ -101,8 +94,6 @@ public class LibraryDownloadTask extends Task<Void> {
throw new CancellationException();
else
throw new LibraryDownloadException(library, t);
} else {
if (xz) unpackLibrary(jar, Files.readAllBytes(xzFile.toPath()));
}
}
@@ -126,36 +117,13 @@ public class LibraryDownloadTask extends Task<Void> {
}
}
if (Pack200Utils.isSupported() && testURLExistence(url)) {
List<URL> urls = dependencyManager.getDownloadProvider().injectURLWithCandidates(url + ".pack.xz");
task = new FileDownloadTask(urls, xzFile, null);
task.setCacheRepository(cacheRepository);
task.setCaching(true);
xz = true;
} else {
List<URL> urls = dependencyManager.getDownloadProvider().injectURLWithCandidates(url);
task = new FileDownloadTask(urls, jar,
library.getDownload().getSha1() != null ? new IntegrityCheck("SHA-1", library.getDownload().getSha1()) : null);
task.setCacheRepository(cacheRepository);
task.setCaching(true);
task.addIntegrityCheckHandler(FileDownloadTask.ZIP_INTEGRITY_CHECK_HANDLER);
xz = false;
}
}
private boolean testURLExistence(String rawUrl) {
List<URL> urls = dependencyManager.getDownloadProvider().injectURLWithCandidates(rawUrl);
for (URL url : urls) {
URL xzURL = NetworkUtils.toURL(url.toString() + ".pack.xz");
for (int retry = 0; retry < 3; retry++) {
try {
return NetworkUtils.urlExists(xzURL);
} catch (IOException e) {
LOG.log(Level.WARNING, "Failed to test for url existence: " + url + ".pack.xz", e);
}
}
}
return false; // maybe some ugly implementation will give timeout for not existent url.
List<URL> urls = dependencyManager.getDownloadProvider().injectURLWithCandidates(url);
task = new FileDownloadTask(urls, jar,
library.getDownload().getSha1() != null ? new IntegrityCheck("SHA-1", library.getDownload().getSha1()) : null);
task.setCacheRepository(cacheRepository);
task.setCaching(true);
task.addIntegrityCheckHandler(FileDownloadTask.ZIP_INTEGRITY_CHECK_HANDLER);
}
@Override
@@ -167,7 +135,7 @@ public class LibraryDownloadTask extends Task<Void> {
public void postExecute() throws Exception {
if (!cached) {
try {
cacheRepository.cacheLibrary(library, jar.toPath(), xz);
cacheRepository.cacheLibrary(library, jar.toPath(), false);
} catch (IOException e) {
LOG.log(Level.WARNING, "Failed to cache downloaded library " + library, e);
}
@@ -232,44 +200,4 @@ public class LibraryDownloadTask extends Task<Void> {
}
return false;
}
private static void unpackLibrary(File dest, byte[] src) throws IOException {
if (dest.exists())
if (!dest.delete())
throw new IOException("Unable to delete file " + dest);
byte[] decompressed;
try {
decompressed = IOUtils.readFullyAsByteArray(new XZInputStream(new ByteArrayInputStream(src)));
} catch (IOException e) {
throw new ArtifactMalformedException("Library " + dest + " is malformed");
}
String end = new String(decompressed, decompressed.length - 4, 4);
if (!end.equals("SIGN"))
throw new IOException("Unpacking failed, signature missing " + end);
int x = decompressed.length;
int len = decompressed[(x - 8)] & 0xFF | (decompressed[(x - 7)] & 0xFF) << 8 | (decompressed[(x - 6)] & 0xFF) << 16 | (decompressed[(x - 5)] & 0xFF) << 24;
Path temp = Files.createTempFile("minecraft", ".pack");
byte[] checksums = Arrays.copyOfRange(decompressed, decompressed.length - len - 8, decompressed.length - 8);
try (OutputStream out = Files.newOutputStream(temp)) {
out.write(decompressed, 0, decompressed.length - len - 8);
}
try (FileOutputStream jarBytes = new FileOutputStream(dest); JarOutputStream jos = new JarOutputStream(jarBytes)) {
Pack200Utils.unpack(temp.toFile(), jos);
JarEntry checksumsFile = new JarEntry("checksums.sha1");
checksumsFile.setTime(0L);
jos.putNextEntry(checksumsFile);
jos.write(checksums);
jos.closeEntry();
}
Files.delete(temp);
}
}
@@ -52,6 +52,10 @@ public final class AssetIndex {
return virtual || mapToResources;
}
public boolean needMapToResources() {
return mapToResources;
}
public Map<String, AssetObject> getObjects() {
return Collections.unmodifiableMap(objects);
}
@@ -459,6 +459,8 @@ public class DefaultGameRepository implements GameRepository {
return assetsDir;
if (index.isVirtual()) {
Path resourcesDir = getBaseDirectory().toPath().resolve("resources");
int cnt = 0;
int tot = index.getObjects().entrySet().size();
for (Map.Entry<String, AssetObject> entry : index.getObjects().entrySet()) {
@@ -468,6 +470,12 @@ public class DefaultGameRepository implements GameRepository {
cnt++;
if (!Files.isRegularFile(target))
FileUtils.copyFile(original, target);
if (index.needMapToResources()) {
target = resourcesDir.resolve(entry.getKey());
if (!Files.isRegularFile(target))
FileUtils.copyFile(original, target);
}
}
}
@@ -104,8 +104,13 @@ final class GameVersion {
if (minecraft != null) {
try (InputStream is = gameJar.getInputStream(minecraft)) {
Optional<String> result = getVersionOfClassMinecraft(is);
if (result.isPresent())
if (result.isPresent()) {
String version = result.get();
if (version.startsWith("Beta ")) {
result = Optional.of("b" + version.substring("Beta ".length()));
}
return result;
}
}
}
@@ -102,7 +102,7 @@ public class DefaultLauncher extends Launcher {
// Executable
if (StringUtils.isNotBlank(options.getWrapper()))
res.addAllWithoutParsing(StringUtils.tokenize(options.getWrapper()));
res.addAllWithoutParsing(StringUtils.tokenize(options.getWrapper(), getEnvVars()));
res.add(options.getJava().getBinary().toString());
@@ -429,9 +429,6 @@ public class DefaultLauncher extends Launcher {
// To guarantee that when failed to generate launch command line, we will not call pre-launch command
List<String> rawCommandLine = command.commandLine.asList();
if (StringUtils.isNotBlank(options.getWrapper())) {
rawCommandLine.addAll(0, StringUtils.tokenize(options.getWrapper(), getEnvVars()));
}
if (command.tempNativeFolder != null) {
Files.deleteIfExists(command.tempNativeFolder);
@@ -111,9 +111,8 @@ public final class CurseForgeRemoteModRepository implements RemoteModRepository
.header("X-API-KEY", apiKey)
.getJson(new TypeToken<Response<List<CurseAddon>>>() {
}.getType());
Stream<RemoteMod> res = response.getData().stream().map(CurseAddon::toMod);
if (searchFilter.isEmpty()) {
return new SearchResult(res, (int)Math.ceil((double)response.pagination.totalCount / pageSize));
return new SearchResult(response.getData().stream().map(CurseAddon::toMod), (int)Math.ceil((double)response.pagination.totalCount / pageSize));
}
// https://github.com/HMCL-dev/HMCL/issues/1549
@@ -125,7 +124,7 @@ public final class CurseForgeRemoteModRepository implements RemoteModRepository
StringUtils.LevCalculator levCalculator = new StringUtils.LevCalculator();
return new SearchResult(res.map(remoteMod -> {
return new SearchResult(response.getData().stream().map(CurseAddon::toMod).map(remoteMod -> {
String lowerCaseResult = remoteMod.getTitle().toLowerCase();
int diff = levCalculator.calc(lowerCaseSearchFilter, lowerCaseResult);
@@ -136,7 +135,7 @@ public final class CurseForgeRemoteModRepository implements RemoteModRepository
}
return pair(remoteMod, diff);
}).sorted(Comparator.comparingInt(Pair::getValue)).map(Pair::getKey), res, response.pagination.totalCount);
}).sorted(Comparator.comparingInt(Pair::getValue)).map(Pair::getKey), response.getData().stream().map(CurseAddon::toMod), response.pagination.totalCount);
}
@Override
@@ -94,6 +94,7 @@ public abstract class FetchTask<T> extends Task<T> {
break download;
}
List<String> redirects = null;
try {
beforeDownload(url);
@@ -103,7 +104,9 @@ public abstract class FetchTask<T> extends Task<T> {
if (checkETag) repository.injectConnection(conn);
if (conn instanceof HttpURLConnection) {
conn = NetworkUtils.resolveConnection((HttpURLConnection) conn);
redirects = new ArrayList<>();
conn = NetworkUtils.resolveConnection((HttpURLConnection) conn, redirects);
int responseCode = ((HttpURLConnection) conn).getResponseCode();
if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED) {
@@ -164,13 +167,13 @@ public abstract class FetchTask<T> extends Task<T> {
} catch (FileNotFoundException ex) {
failedURL = url;
exception = ex;
Logging.LOG.log(Level.WARNING, "Failed to download " + url + ", not found", ex);
Logging.LOG.log(Level.WARNING, "Failed to download " + url + ", not found" + ((redirects == null || redirects.isEmpty()) ? "" : ", redirects: " + redirects), ex);
break; // we will not try this URL again
} catch (IOException ex) {
failedURL = url;
exception = ex;
Logging.LOG.log(Level.WARNING, "Failed to download " + url + ", repeat times: " + (++repeat), ex);
Logging.LOG.log(Level.WARNING, "Failed to download " + url + ", repeat times: " + (++repeat) + ((redirects == null || redirects.isEmpty()) ? "" : ", redirects: " + redirects), ex);
}
}
}
@@ -293,8 +293,12 @@ public class CacheRepository {
ETagIndex indexOnDisk = JsonUtils.fromMaybeMalformedJson(new String(IOUtils.readFullyWithoutClosing(Channels.newInputStream(channel)), UTF_8), ETagIndex.class);
Map<String, ETagItem> newIndex = joinETagIndexes(indexOnDisk == null ? null : indexOnDisk.eTag, index.values());
channel.truncate(0);
ETagIndex writeTo = new ETagIndex(newIndex.values());
channel.write(ByteBuffer.wrap(JsonUtils.GSON.toJson(writeTo).getBytes(UTF_8)));
ByteBuffer writeTo = ByteBuffer.wrap(JsonUtils.GSON.toJson(new ETagIndex(newIndex.values())).getBytes(UTF_8));
while (writeTo.hasRemaining()) {
if (channel.write(writeTo) == 0) {
throw new IOException("No value is written");
}
}
this.index = newIndex;
} finally {
lock.release();
@@ -29,7 +29,6 @@ import static org.jackhuang.hmcl.util.Pair.pair;
import static org.jackhuang.hmcl.util.StringUtils.*;
/**
*
* @author huangyuhui
*/
public final class NetworkUtils {
@@ -131,16 +130,20 @@ public final class NetworkUtils {
return sb.toString();
}
public static HttpURLConnection resolveConnection(HttpURLConnection conn) throws IOException {
return resolveConnection(conn, null);
}
/**
* This method is a work-around that aims to solve problem when "Location" in
* stupid server's response is not encoded.
*
*
* @see <a href="https://github.com/curl/curl/issues/473">Issue with libcurl</a>
* @param conn the stupid http connection.
* @return manually redirected http connection.
* @throws IOException if an I/O error occurs.
*/
public static HttpURLConnection resolveConnection(HttpURLConnection conn) throws IOException {
public static HttpURLConnection resolveConnection(HttpURLConnection conn, List<String> redirects) throws IOException {
int redirect = 0;
while (true) {
conn.setUseCaches(false);
@@ -154,6 +157,9 @@ public final class NetworkUtils {
String newURL = conn.getHeaderField("Location");
conn.disconnect();
if (redirects != null) {
redirects.add(newURL);
}
if (redirect > 20) {
throw new IOException("Too much redirects");
}