Skip to content

Commit 14828e3

Browse files
committed
fix: improvements to downloader
1 parent 498957e commit 14828e3

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/Skidfuscator.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public Skidfuscator(SkidfuscatorSession session) {
143143
public void run() {
144144
LOGGER.setDebug(session.isDebug());
145145
LOGGER.post("Beginning Skidfuscator Community...");
146+
_verifyEnvironment();
146147
if (session.isAnalytics()) {
147148
_runAnalytics();
148149
}
@@ -392,6 +393,27 @@ private void _runAnalytics() {
392393
}
393394
}
394395

396+
protected void _verifyEnvironment() {
397+
Path local = Paths.get("");
398+
399+
// If config is defined, it should be in workspace
400+
if (session.getConfig() != null) {
401+
LOGGER.debug(String.format("Config path: %s", session.getConfig().toPath().toString()));
402+
final Path path = local.resolve(session.getConfig().getName());
403+
404+
if (path.toFile().getAbsolutePath().equals(session.getConfig().getAbsolutePath())) {
405+
LOGGER.debug("Config is in workspace");
406+
} else {
407+
LOGGER.warn("-----------------------------------------------------\n"
408+
+ "Config is not in workspace\n"
409+
+ "Your current working directory is: " + local.toAbsolutePath() + "\n"
410+
+ "Your current config path is: " + session.getConfig().getAbsolutePath() + "\n"
411+
+ "Please execute Skidfuscator in the same directory as your config for best compatibility!!\n"
412+
+ "----------------------------------------------------- \n");
413+
}
414+
}
415+
}
416+
395417
protected void _importConfig() {
396418
LOGGER.post("Loading config...");
397419

@@ -719,11 +741,10 @@ private void _verify() {
719741
commonDependencies.forEach(e -> {
720742
LOGGER.warn("Found common dependency: " + e.name() + "...\n");
721743
dependencyDownloader.download(e);
722-
LOGGER.warn("Downloaded " + e.name() + "...\n");
723744
});
724745

725746

726-
final Path mappingsDir = Paths.get("mappings");
747+
final Path mappingsDir = Paths.get("mappings-cloud");
727748
this.importMappingFolder(mappingsDir.toFile());
728749

729750
LOGGER.warn(String.format(

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/dependency/DependencyDownloader.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import lombok.SneakyThrows;
55

66
import java.io.BufferedInputStream;
7+
import java.io.File;
78
import java.io.FileOutputStream;
89
import java.io.IOException;
910
import java.net.URL;
@@ -20,10 +21,16 @@ public void download(final CommonDependency dependency) {
2021
final String url = dependency.getUrl();
2122

2223
// Resolve path
23-
Path mappingsDir = Paths.get("mappings");
24+
Path mappingsDir = Paths.get("mappings-cloud");
2425
Files.createDirectories(mappingsDir);
2526

26-
Path zipFilePath = mappingsDir.resolve(dependency.name().toLowerCase() + ".zip");
27+
if (Files.exists(mappingsDir.resolve(dependency.name().toLowerCase()))) {
28+
Skidfuscator.LOGGER.style(String.format("Dependency %s already exists\n", dependency.name()));
29+
return;
30+
}
31+
32+
Path zipFilePath = mappingsDir.resolve(dependency.name().toLowerCase() + "/download.zip");
33+
Files.createDirectories(zipFilePath.getParent());
2734

2835
// Download the zip file
2936
Skidfuscator.LOGGER.style(String.format("Downloading dependency %s from %s\n", dependency.name(), url));
@@ -64,8 +71,8 @@ public void download(final CommonDependency dependency) {
6471
zipInputStream.closeEntry();
6572
}
6673
}
67-
Skidfuscator.LOGGER.style(String.format("Extracted dependency %s to %s\n", dependency.name(), mappingsDir.toFile().getAbsolutePath()));
6874
Files.delete(zipFilePath);
75+
Skidfuscator.LOGGER.style(String.format("Extracted dependency %s to %s\n", dependency.name(), mappingsDir.toFile().getAbsolutePath()));
6976
} else {
7077
Skidfuscator.LOGGER.style(String.format("Unsupported file type for %s\n", url));
7178
}

0 commit comments

Comments
 (0)