Skip to content

Commit

Permalink
Make assets tree builder use hardlinks if available
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgehog1029 committed May 3, 2022
1 parent debd822 commit 39487dd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions launcher/src/main/java/com/skcraft/launcher/AssetsRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<String, Asset> entry : index.getObjects().entrySet()) {
File objectPath = getObjectPath(entry.getValue());
File virtualPath = new File(destDir, entry.getKey());
Expand All @@ -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++;
}
Expand Down

0 comments on commit 39487dd

Please sign in to comment.