Skip to content

Commit

Permalink
fix: improvements to downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalsin committed Oct 15, 2024
1 parent 498957e commit 14828e3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public Skidfuscator(SkidfuscatorSession session) {
public void run() {
LOGGER.setDebug(session.isDebug());
LOGGER.post("Beginning Skidfuscator Community...");
_verifyEnvironment();
if (session.isAnalytics()) {
_runAnalytics();
}
Expand Down Expand Up @@ -392,6 +393,27 @@ private void _runAnalytics() {
}
}

protected void _verifyEnvironment() {
Path local = Paths.get("");

// If config is defined, it should be in workspace
if (session.getConfig() != null) {
LOGGER.debug(String.format("Config path: %s", session.getConfig().toPath().toString()));
final Path path = local.resolve(session.getConfig().getName());

if (path.toFile().getAbsolutePath().equals(session.getConfig().getAbsolutePath())) {
LOGGER.debug("Config is in workspace");
} else {
LOGGER.warn("-----------------------------------------------------\n"
+ "Config is not in workspace\n"
+ "Your current working directory is: " + local.toAbsolutePath() + "\n"
+ "Your current config path is: " + session.getConfig().getAbsolutePath() + "\n"
+ "Please execute Skidfuscator in the same directory as your config for best compatibility!!\n"
+ "----------------------------------------------------- \n");
}
}
}

protected void _importConfig() {
LOGGER.post("Loading config...");

Expand Down Expand Up @@ -719,11 +741,10 @@ private void _verify() {
commonDependencies.forEach(e -> {
LOGGER.warn("Found common dependency: " + e.name() + "...\n");
dependencyDownloader.download(e);
LOGGER.warn("Downloaded " + e.name() + "...\n");
});


final Path mappingsDir = Paths.get("mappings");
final Path mappingsDir = Paths.get("mappings-cloud");
this.importMappingFolder(mappingsDir.toFile());

LOGGER.warn(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.SneakyThrows;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
Expand All @@ -20,10 +21,16 @@ public void download(final CommonDependency dependency) {
final String url = dependency.getUrl();

// Resolve path
Path mappingsDir = Paths.get("mappings");
Path mappingsDir = Paths.get("mappings-cloud");
Files.createDirectories(mappingsDir);

Path zipFilePath = mappingsDir.resolve(dependency.name().toLowerCase() + ".zip");
if (Files.exists(mappingsDir.resolve(dependency.name().toLowerCase()))) {
Skidfuscator.LOGGER.style(String.format("Dependency %s already exists\n", dependency.name()));
return;
}

Path zipFilePath = mappingsDir.resolve(dependency.name().toLowerCase() + "/download.zip");
Files.createDirectories(zipFilePath.getParent());

// Download the zip file
Skidfuscator.LOGGER.style(String.format("Downloading dependency %s from %s\n", dependency.name(), url));
Expand Down Expand Up @@ -64,8 +71,8 @@ public void download(final CommonDependency dependency) {
zipInputStream.closeEntry();
}
}
Skidfuscator.LOGGER.style(String.format("Extracted dependency %s to %s\n", dependency.name(), mappingsDir.toFile().getAbsolutePath()));
Files.delete(zipFilePath);
Skidfuscator.LOGGER.style(String.format("Extracted dependency %s to %s\n", dependency.name(), mappingsDir.toFile().getAbsolutePath()));
} else {
Skidfuscator.LOGGER.style(String.format("Unsupported file type for %s\n", url));
}
Expand Down

0 comments on commit 14828e3

Please sign in to comment.