Skip to content

Commit

Permalink
original 1.6.3 source code
Browse files Browse the repository at this point in the history
  • Loading branch information
mixa3607 committed May 12, 2024
1 parent f723d55 commit 48ebf07
Show file tree
Hide file tree
Showing 38 changed files with 380 additions and 178 deletions.
12 changes: 5 additions & 7 deletions source/README
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
Make sure to read and understand the license for this program, found in the file LICENSE or at http://www.gnu.org/licenses/gpl.txt, before you start playing with it.

In order to build Hentai@Home, you need the following:
In order to build Hentai@Home, you just need OpenJDK 8 or newer.

- The sqlite-jdbc-3.7.2 SQLiteJDBC library, placed in this directory (obtainable from http://g.e-hentai.org/hentaiathome.php or http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC)
In a Windows build environment, run make.bat and makejar.bat in order. On Linux, do make then make jar (or make all).

- The Java(TM) SE JDK, version 6 or greater
This will produce two .jar files, HentaiAtHome.jar and HentaiAtHomeGUI.jar, in the current directory. Move these .jar files to a location of your choice - this is where H@H will store all its files by default.

In a Windows build environment, run make.bat and makejar.bat in order. On Linux, do make then make jar (or make all). This will produce two .jar files, HentaiAtHome.jar and HentaiAtHomeGUI.jar, in the current directory. These two files along with sqlite-jdbc-3.7.2 constitutes the entire program.
In a GUI environment you can usually just double-click HentaiAtHomeGUI.jar to start it. Alternatively, from a command-line, use java -jar HentaiAtHome.jar for the CLI version or java -jar HentaiAtHomeGUI.jar for the GUI version.

Move the three .jar files to a location of your choice (this is where H@H will store all its files), and run java -jar HentaiAtHome.jar for the CLI version or java -jar HentaiAtHomeGUI.jar for the GUI version.

Note that this package only contains the Hentai@Home Client, which is coded specifically for E-Hentai Galleries. The server-side systems are highly dependent on the setup of a given site, and must be coded specially if it's to be used for other sites.
This package only contains the Hentai@Home Client, which is coded specifically for E-Hentai Galleries. The server-side systems are highly dependent on the setup of a given site, and must be coded specially if it is to be used for other sites.
4 changes: 2 additions & 2 deletions source/src/hath/base/CacheHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2008-2023 E-Hentai.org
Copyright 2008-2024 E-Hentai.org
https://forums.e-hentai.org/
tenboro@e-hentai.org
Expand All @@ -17,7 +17,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hentai@Home. If not, see <http://www.gnu.org/licenses/>.
along with Hentai@Home. If not, see <https://www.gnu.org/licenses/>.
*/

Expand Down
4 changes: 2 additions & 2 deletions source/src/hath/base/CakeSphere.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2008-2023 E-Hentai.org
Copyright 2008-2024 E-Hentai.org
https://forums.e-hentai.org/
tenboro@e-hentai.org
Expand All @@ -17,7 +17,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hentai@Home. If not, see <http://www.gnu.org/licenses/>.
along with Hentai@Home. If not, see <https://www.gnu.org/licenses/>.
*/

Expand Down
4 changes: 2 additions & 2 deletions source/src/hath/base/ClientAPI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2008-2023 E-Hentai.org
Copyright 2008-2024 E-Hentai.org
https://forums.e-hentai.org/
tenboro@e-hentai.org
Expand All @@ -17,7 +17,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hentai@Home. If not, see <http://www.gnu.org/licenses/>.
along with Hentai@Home. If not, see <https://www.gnu.org/licenses/>.
*/

Expand Down
4 changes: 2 additions & 2 deletions source/src/hath/base/ClientAPIResult.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2008-2023 E-Hentai.org
Copyright 2008-2024 E-Hentai.org
https://forums.e-hentai.org/
tenboro@e-hentai.org
Expand All @@ -17,7 +17,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hentai@Home. If not, see <http://www.gnu.org/licenses/>.
along with Hentai@Home. If not, see <https://www.gnu.org/licenses/>.
*/

Expand Down
30 changes: 22 additions & 8 deletions source/src/hath/base/FileDownloader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2008-2023 E-Hentai.org
Copyright 2008-2024 E-Hentai.org
https://forums.e-hentai.org/
tenboro@e-hentai.org
Expand All @@ -17,7 +17,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hentai@Home. If not, see <http://www.gnu.org/licenses/>.
along with Hentai@Home. If not, see <https://www.gnu.org/licenses/>.
*/

Expand All @@ -31,15 +31,15 @@
import javax.net.ssl.HttpsURLConnection;

public class FileDownloader implements Runnable {
private int timeout = 30000, maxDLTime = Integer.MAX_VALUE, retries = 3;
private int timeout = 30000, maxDLTime = Integer.MAX_VALUE, retries = 3, contentLength = 0;
private long timeDownloadStart = 0, timeFirstByte = 0, timeDownloadFinish = 0;
private ByteBuffer byteBuffer = null;
private HTTPBandwidthMonitor downloadLimiter = null;
private Path outputPath = null;
private URL source;
private Thread myThread;
private Object downloadLock = new Object();
private boolean started = false, discardData = false, successful = false;
private boolean started = false, discardData = false, successful = false, allowProxy = false;

public FileDownloader(URL source, int timeout, int maxDLTime) {
// everything will be written to a ByteBuffer
Expand All @@ -56,12 +56,13 @@ public FileDownloader(URL source, int timeout, int maxDLTime, boolean discardDat
this.discardData = discardData;
}

public FileDownloader(URL source, int timeout, int maxDLTime, Path outputPath) {
public FileDownloader(URL source, int timeout, int maxDLTime, Path outputPath, boolean allowProxy) {
// in this case, the data will be written directly to a channel specified by outputPath
this.source = source;
this.timeout = timeout;
this.maxDLTime = maxDLTime;
this.outputPath = outputPath;
this.allowProxy = allowProxy;
}

public void setDownloadLimiter(HTTPBandwidthMonitor limiter) {
Expand Down Expand Up @@ -129,6 +130,10 @@ public String getResponseAsString(String charset) {
public long getDownloadTimeMillis() {
return timeFirstByte > 0 ? timeDownloadFinish - timeFirstByte : 0;
}

public int getContentLength() {
return contentLength;
}

public void run() {
synchronized(downloadLock) {
Expand All @@ -145,8 +150,17 @@ public void run() {
try {
Out.debug("Connecting to " + source.getHost() + "...");

Proxy proxy = allowProxy ? Settings.getImageProxy() : null;

// should return a HttpURLConnection for http and HttpsURLConnection for https
URLConnection connection = source.openConnection();
URLConnection connection = null;

if(proxy != null) {
connection = source.openConnection(proxy);
}
else {
connection = source.openConnection();
}

connection.setConnectTimeout(5000);
connection.setReadTimeout(timeout);
Expand All @@ -161,7 +175,7 @@ public void run() {
}
*/

int contentLength = connection.getContentLength();
contentLength = connection.getContentLength();

if(contentLength < 0) {
// since we control all systems in this case, we'll demand that clients and servers always send the Content-Length
Expand Down Expand Up @@ -313,7 +327,7 @@ public static void main(String[] args) {
// savey
URL testurl = new URL("https://ehgt.org/b/2019-10/1.jpg");
File testfile = new File("testfile.jpg");
FileDownloader testdl = new FileDownloader(testurl, 30000, 30000, testfile.toPath());
FileDownloader testdl = new FileDownloader(testurl, 30000, 30000, testfile.toPath(), false);
testdl.downloadFile();
*/

Expand Down
4 changes: 2 additions & 2 deletions source/src/hath/base/FileValidator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2008-2023 E-Hentai.org
Copyright 2008-2024 E-Hentai.org
https://forums.e-hentai.org/
tenboro@e-hentai.org
Expand All @@ -17,7 +17,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hentai@Home. If not, see <http://www.gnu.org/licenses/>.
along with Hentai@Home. If not, see <https://www.gnu.org/licenses/>.
*/

Expand Down
59 changes: 38 additions & 21 deletions source/src/hath/base/GalleryDownloader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2008-2023 E-Hentai.org
Copyright 2008-2024 E-Hentai.org
https://forums.e-hentai.org/
tenboro@e-hentai.org
Expand All @@ -17,7 +17,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hentai@Home. If not, see <http://www.gnu.org/licenses/>.
along with Hentai@Home. If not, see <https://www.gnu.org/licenses/>.
*/

Expand Down Expand Up @@ -67,10 +67,10 @@ public void run() {

Out.info("GalleryDownloader: Starting download of gallery: " + title);

int galleryretry = 0;
int galleryretry = 0, totalFailedFiles = 0;
boolean success = false;

while(!success && ++galleryretry < 10) {
while(!success && ++galleryretry < 10 && totalFailedFiles < filecount * 2) {
int successfulFiles = 0;

for(GalleryFile gFile : galleryFiles) {
Expand Down Expand Up @@ -98,6 +98,7 @@ else if(downloadState == GalleryFile.STATE_ALREADY_DOWNLOADED) {
++successfulFiles;
}
else if(downloadState == GalleryFile.STATE_DOWNLOAD_FAILED) {
++totalFailedFiles;
sleepTime = 5000;
}
}
Expand Down Expand Up @@ -243,10 +244,22 @@ else if(split[0].equals("TITLE")) {
// MINXRES must be passed before TITLE for this to work. the only purpose is to make distinct titles
String xresTitle = minxres.equals("org") ? "" : "-" + minxres + "x";

if(title.length() > 100) {
todir = new File(Settings.getDownloadDir(), title.substring(0, 97) + "... [" + gid + xresTitle + "]");
} else {
todir = new File(Settings.getDownloadDir(), title + " [" + gid + xresTitle + "]");
String postfix = " [" + gid + xresTitle + "]";

int titleLength = title.length();
int postfixLength = postfix.length();
int maxFilenameLength = Settings.getMaxFilenameLength();

// many filesystems have a maximum file length of 255 *bytes*. title.length() calculates the length in UTF-16 code units (16-bit unicode). we therefore default to a maxFilenameLength of 125 UTF-16 chars, since this should be safe on all systems
if(titleLength + postfixLength > maxFilenameLength) {
// we need to count code points to avoid splitting any UTF-16 surrogate pairs representing surrogate characters
int codePointLength = title.codePointCount(0, maxFilenameLength - postfixLength - 3);
String truncatedTitle = title.substring(0, title.offsetByCodePoints(0, codePointLength));
Out.debug("Truncated title with titleLength=" + titleLength + " postfixLength=" + postfixLength + " codePointLength=" + codePointLength + " truncatedTitle=" + truncatedTitle);
todir = new File(Settings.getDownloadDir(), truncatedTitle + "..." + postfix);
}
else {
todir = new File(Settings.getDownloadDir(), title + postfix);
}

// just in case, check for directory traversal
Expand All @@ -259,7 +272,9 @@ else if(split[0].equals("TITLE")) {
try {
Tools.checkAndCreateDir(todir);
}
catch(Exception e) {}
catch(Exception e) {
e.printStackTrace();
}

if(!todir.exists()) {
Out.warning("GalleryDownloader: Could not create gallery download directory \"" + todir.getName() + "\". Your filesystem may not support Unicode. Attempting fallback.");
Expand Down Expand Up @@ -354,8 +369,8 @@ else if(validator.validateFile(tofile.toPath(), expectedSHA1Hash)) {
Out.debug("GalleryDownloader: Verified SHA-1 hash for " + this + ": " + expectedSHA1Hash);
}
}
catch(java.io.IOException e) {
Out.warning("GalleryDownloader: Encountered I/O error while validating " + tofile);
catch(Exception e) {
Out.warning("GalleryDownloader: Encountered error while validating " + tofile);
e.printStackTrace();
}
}
Expand All @@ -371,30 +386,28 @@ else if(validator.validateFile(tofile.toPath(), expectedSHA1Hash)) {

// if this turns out to be a file that can be handled by this client, the returned link will be to localhost, which will trigger a static range fetch using the standard mechanism
// we don't have enough information at this point to initiate a ProxyFileDownload directly, so while the extra roundtrip might seem wasteful, it is necessary (and usually fairly rare)
URL source = client.getServerHandler().getDownloaderFetchURL(gid, page, fileindex, xres, ++fileretry > 1);

if(source != null) {
FileDownloader dler = new FileDownloader(source, 10000, 300000, tofile.toPath());
dler.setDownloadLimiter(downloadLimiter);
fileComplete = dler.downloadFile();
URL source = client.getServerHandler().getDownloaderFetchURL(gid, page, fileindex, xres, ++fileretry);

if(source != null) {
try {
FileDownloader dler = new FileDownloader(source, 10000, 300000, tofile.toPath(), fileretry > 1);
dler.setDownloadLimiter(downloadLimiter);
fileComplete = dler.downloadFile();

if(fileComplete && expectedSHA1Hash != null) {
if(!validator.validateFile(tofile.toPath(), expectedSHA1Hash)) {
fileComplete = false;
tofile.delete();
Out.debug("GalleryDownloader: Corrupted download for " + this + ", forcing retry");
}
else {
Out.debug("GalleryDownloader: Verified SHA-1 hash for " + this + ": " + expectedSHA1Hash);
}
}
}
catch(java.io.IOException e) {
Out.warning("GalleryDownloader: Encountered I/O error while validating " + tofile);
catch(Exception e) {
Out.warning("GalleryDownloader: Encountered error while downloading " + tofile);
e.printStackTrace();
fileComplete = false;
tofile.delete();
}

Out.debug("GalleryDownloader: Download of " + this + " " + (fileComplete ? "successful" : "FAILED") + " (attempt=" + fileretry + ")");
Expand All @@ -408,6 +421,10 @@ else if(validator.validateFile(tofile.toPath(), expectedSHA1Hash)) {
}
}

if(!fileComplete && tofile.isFile()) {
tofile.delete();
}

return fileComplete ? STATE_DOWNLOAD_SUCCESSFUL : STATE_DOWNLOAD_FAILED;
}

Expand Down
4 changes: 2 additions & 2 deletions source/src/hath/base/HTTPBandwidthMonitor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2008-2023 E-Hentai.org
Copyright 2008-2024 E-Hentai.org
https://forums.e-hentai.org/
tenboro@e-hentai.org
Expand All @@ -17,7 +17,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hentai@Home. If not, see <http://www.gnu.org/licenses/>.
along with Hentai@Home. If not, see <https://www.gnu.org/licenses/>.
*/

Expand Down
Loading

0 comments on commit 48ebf07

Please sign in to comment.