Skip to content

Commit

Permalink
Bugfix: 403 error on download
Browse files Browse the repository at this point in the history
  • Loading branch information
dhohmann committed Dec 16, 2022
1 parent 4f436d0 commit 5434c44
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# arcdps_downloader_gw2
Small Java program to download latest Arcdps to Guild Wars 2
Fork of [jani-e/arcdps_downloader_gw2](https://github.com/jani-e/arcdps_downloader_gw2)

## Requirements
Java 8+
Expand Down
26 changes: 26 additions & 0 deletions launch4j.config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<jar>.\target\ArcdpsDownloaderGW2-1.1.2.jar</jar>
<outfile>.\target\ArcdpsDownloaderGW2-1.1.2.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>false</stayAlive>
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon>.\src\main\resources\assets\download.ico</icon>
<jre>
<path></path>
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.8</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
</launch4jConfig>
37 changes: 32 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,49 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gw2.arcdpsdownloadergw2</groupId>
<artifactId>ArcdpsDownloaderGW2</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<exec.mainClass>com.gw2.arcdpsdownloadergw2.ArcdpsDownloaderGW2</exec.mainClass>
</properties>
<profiles>
<profile>
<id>java11</id>
<activation>
<jdk>[1.11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>HelloFX</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.1</version>
</dependency>
</dependencies>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</resources>
<plugins>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/com/gw2/arcdpsdownloadergw2/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
Expand All @@ -32,6 +33,15 @@ public class Downloader {
private URL url;
private String filePath;

private InputStream getStream(URL url) throws IOException {
URLConnection urlConnection = url.openConnection();
urlConnection.addRequestProperty("User-Agent", "java");
urlConnection.setReadTimeout(5000);
urlConnection.setConnectTimeout(5000);
urlConnection.connect();
return urlConnection.getInputStream();
}

public Downloader() {
try {
this.url = new URL("https://www.deltaconnected.com/arcdps/x64/d3d11.dll");
Expand All @@ -48,7 +58,7 @@ public boolean downloadFile() {
System.out.println(String.format("Using DirectX%d version. If needed, change it in configuration.",
ArcdpsDownloaderGW2.getConfig().getDirectXVersion()));

InputStream inputStream = this.url.openStream();
InputStream inputStream = getStream(this.url);
Files.copy(inputStream, Paths.get(this.filePath), StandardCopyOption.REPLACE_EXISTING);
return true;
} catch (IOException ex) {
Expand All @@ -66,7 +76,8 @@ public Date getLastModification() {
try {
StringBuilder output = new StringBuilder();
URL url = new URL("https://www.deltaconnected.com/arcdps/x64/");
InputStreamReader reader = new InputStreamReader(url.openStream());

InputStreamReader reader = new InputStreamReader(getStream(url));
char[] buffer = new char[256];
int length = -1;
while ((length = reader.read(buffer)) > 0) {
Expand All @@ -76,13 +87,12 @@ public Date getLastModification() {
int i = output.indexOf("<a href=\"d3d11.dll\">d3d11.dll</a>");
i = output.indexOf("indexcollastmod\">", i) + 17;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return format.parse(output.substring(i, output.indexOf("</td>", i)));
String p = output.substring(i, output.indexOf("</td>", i));
return format.parse(p);
} catch (IOException ex) {
Logger.getLogger(Downloader.class.getName()).log(Level.SEVERE, "Could not retrieve last modification date",
ex);
System.out.println("Could not retrieve last modification date: " + ex.getMessage());
} catch (ParseException ex) {
Logger.getLogger(Downloader.class.getName()).log(Level.SEVERE, "Could not parse last modification date",
ex);
System.out.println("Could not parse last modification date: " + ex.getMessage());
}
return null;
}
Expand All @@ -106,12 +116,13 @@ public boolean checkUpdateAvailable() {
}
Date updateVersion = getLastModification();
if (updateVersion == null) {
System.out.println("sdgsdgdsdgsdgsgd");
return false;
}
return currentVersion.before(updateVersion);
}

public static void main(String[] args) {
new Downloader().checkUpdateAvailable();
System.out.println(new Downloader().checkUpdateAvailable());
}
}
12 changes: 3 additions & 9 deletions src/main/java/com/gw2/arcdpsdownloadergw2/ui/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.io.PrintStream;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
Expand All @@ -28,6 +30,7 @@ public class Window {

public Window() {
frame = new JFrame("ArcDPSDownloader GW2");
frame.setIconImage(new ImageIcon(getClass().getResource("/assets/download.png")).getImage());
frame.setLayout(new BorderLayout());
frame.setMinimumSize(new Dimension(500, 400));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Expand Down Expand Up @@ -128,13 +131,4 @@ public void close() {
private void performAction(String action) {
ArcdpsDownloaderGW2.getActionManager().execute(action);
}

public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.out.println(e.getMessage());
}
new Window().show();
}
}
Binary file added src/main/resources/assets/download.ico
Binary file not shown.
Binary file added src/main/resources/assets/download.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5434c44

Please sign in to comment.