Skip to content

Commit

Permalink
Create UpdateCheck Function
Browse files Browse the repository at this point in the history
  • Loading branch information
layou233 committed Jan 2, 2021
1 parent 917c8ec commit e65c453
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/main/java/lau/NovelDL/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static void main(String[] args) throws InterruptedException {
"| | \\ | | |_| | | |/ / | |___ | |___ | |_| | | |___ \n" +
"|_| \\_| \\_____/ |___/ |_____| |_____| |_____/ |_____| "
);
UpdateCheck.updateCheck();
System.out.print("Enter the first page URL of the novel: ");
firstPageURL = KotlinFunctionsKt.readln().trim();
try {
Expand Down Expand Up @@ -65,7 +66,7 @@ public static void main(String[] args) throws InterruptedException {
try { // First dumping
String s = replacer(Weber.getWebString(currentPageURL, "UTF-8"));
charset = NovelInfosKt.getCharset(s);
if (charset != "UTF.8")
if (!charset.equals("UTF.8"))
s = replacer(Weber.getWebString(currentPageURL, charset));
String chapter = NovelInfosKt.getChapterTitle(s);
fileOutputStream.write(chapter.getBytes(StandardCharsets.UTF_8));
Expand All @@ -77,7 +78,7 @@ public static void main(String[] args) throws InterruptedException {
} catch (IOException e) {
System.out.println(e.getMessage());
} catch (HTTPException e) {
System.out.println(dumpCount + " FAILED:Target website responsed Code " + e.getStatusCode());
System.out.println(dumpCount + " FAILED:Target website responded Code " + e.getStatusCode());
} catch (NullPointerException e) {
System.out.println("It doesn't seem to be a novel. Do your IP got banned?");
return;
Expand All @@ -98,7 +99,7 @@ public static void main(String[] args) throws InterruptedException {
} catch (IOException e) {
System.out.println(e.getMessage());
} catch (HTTPException e) {
System.out.println(dumpCount + " FAILED:Target website responsed Code " + e.getStatusCode());
System.out.println(dumpCount + " FAILED:Target website responded Code " + e.getStatusCode());
} catch (NullPointerException e) {
System.out.println(dumpCount + " FAILED:It doesn't seem to be a novel. REDUMPING IN 10 SECONDS...");
Thread.sleep(10000);
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/lau/NovelDL/UpdateCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package lau.NovelDL;

import java.io.IOException;

/**
* NovelDL, the best application for Chinese readers
*
* @author layou233
*/

public class UpdateCheck {
public static String version = "1.0";

public static void updateCheck() {
System.out.println("Version " + version);
String remoteVersion;
try {
remoteVersion = Weber.getWebString("https://raw.githubusercontent.com/layou233/NovelDL/master/src/main/resources/version.txt", "UTF-8");
} catch (
IOException e) {
System.out.println("FAILED TO CHECK FOR UPDATES.\n" +
"You can check it yourself at https://github.com/layou233/NovelDL/releases\n");
return;
}
if (version.equals(remoteVersion))
System.out.println("Nice! You are using the latest version!\n");
else System.out.println("THE NovelDL YOU ARE CURRENTLY USING HAS BEEN OUTDATED!\n" +
"Check out newer versions at https://github.com/layou233/NovelDL/releases\n");
}
}
2 changes: 1 addition & 1 deletion src/main/java/lau/NovelDL/Weber.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static String getWebString(String url, String charset) throws IOException
InputStream is = connection.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[10485760]; // 10MiB Buffer
int len = 0;
int len;
while ((len = is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/lau/NovelDL/KotlinFunctions.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package lau.NovelDL

import java.net.URL
import java.nio.charset.Charset

/**
* NovelDL, the best application for Chinese readers
*
Expand Down

0 comments on commit e65c453

Please sign in to comment.