From 39487dda3ea302a94427433fe2e083620dd94a24 Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Tue, 3 May 2022 21:49:26 +0100 Subject: [PATCH] Make assets tree builder use hardlinks if available --- .../java/com/skcraft/launcher/AssetsRoot.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/launcher/src/main/java/com/skcraft/launcher/AssetsRoot.java b/launcher/src/main/java/com/skcraft/launcher/AssetsRoot.java index 2bf64c798..247188f8e 100644 --- a/launcher/src/main/java/com/skcraft/launcher/AssetsRoot.java +++ b/launcher/src/main/java/com/skcraft/launcher/AssetsRoot.java @@ -6,7 +6,6 @@ package com.skcraft.launcher; -import com.google.common.io.Files; import com.skcraft.concurrency.ProgressObservable; import com.skcraft.launcher.model.minecraft.Asset; import com.skcraft.launcher.model.minecraft.AssetsIndex; @@ -18,6 +17,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.util.Map; import java.util.logging.Level; @@ -101,6 +101,7 @@ public AssetsTreeBuilder(AssetsIndex index, File destDir) { public File build() throws IOException, LauncherException { AssetsRoot.log.info("Building asset virtual tree at '" + destDir.getAbsolutePath() + "'..."); + boolean supportsLinks = true; for (Map.Entry entry : index.getObjects().entrySet()) { File objectPath = getObjectPath(entry.getValue()); File virtualPath = new File(destDir, entry.getKey()); @@ -114,7 +115,17 @@ public File build() throws IOException, LauncherException { throw new LauncherException("Missing object " + objectPath.getAbsolutePath(), message); } - Files.copy(objectPath, virtualPath); + if (supportsLinks) { + try { + Files.createLink(virtualPath.toPath(), objectPath.toPath()); + } catch (UnsupportedOperationException e) { + supportsLinks = false; + } + } + + if (!supportsLinks) { + Files.copy(objectPath.toPath(), virtualPath.toPath()); + } } processed++; }