Skip to content

Commit

Permalink
allow to use proxy when downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
GlodBlock committed Mar 11, 2023
1 parent 5c96fe7 commit b6d4781
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/com/hrudyplayz/mcinstanceloader/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class Config {
public static boolean disableCache;
public static boolean disableAutomaticZipCreation;
public static int connectionTimeout;
public static boolean useHttpProxy;
public static String proxyHttpHost;
public static int proxyHttpPort;

public static String curseforgeURL;
public static String curseforgeAPIKey;
Expand Down Expand Up @@ -48,6 +51,10 @@ public static void createConfigFile() {
disableStopModRepostsCheck = config.getBoolean("Disable StopModReposts check", CATEGORY_BEHAVIOR, false, "Whether to disable the StopModReposts check, used to prevent the use of malware sites. It's recommended to keep it enabled.");
disableCache = config.getBoolean("Disable the cache system", CATEGORY_BEHAVIOR, false, "Whether to disable the cache system, forcing every resource to be downloaded regardless of the cached value.");

useHttpProxy = config.getBoolean("Use proxy", CATEGORY_BEHAVIOR, false, "This will enable proxy when downing files.");
proxyHttpHost = config.getString("Proxy host address", CATEGORY_BEHAVIOR, "127.0.0.1", "The proxy host address.");
proxyHttpPort = config.getInt("Proxy host port", CATEGORY_BEHAVIOR, 0, 0, 65535, "The proxy host port.");

disableAutomaticZipCreation = config.getBoolean("Disable the automatic zipping system for the pack folder", CATEGORY_BEHAVIOR, false, "Whether to disable the automatic creation of the pack.mcinstance file from the pack folder.");
if (deleteInsteadOfRenaming && !disableAutomaticZipCreation) disableAutomaticZipCreation = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ private static boolean downloadFile(String fileURL, String savePath, boolean don
}

try {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
HttpURLConnection connection;
if (Config.useHttpProxy) {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(Config.proxyHttpHost, Config.proxyHttpPort));
connection = (HttpURLConnection) url.openConnection(proxy);
} else {
connection = (HttpURLConnection) url.openConnection();
}
connection.setRequestMethod("GET");
connection.setInstanceFollowRedirects(true);

Expand Down

0 comments on commit b6d4781

Please sign in to comment.