Compare commits
5 Commits
v0.4
...
47d9e8e392
| Author | SHA1 | Date | |
|---|---|---|---|
| 47d9e8e392 | |||
| c64ddd90c5 | |||
| 2f1ecef3d6 | |||
| 0cfe34d152 | |||
| d9d868050f |
@@ -0,0 +1,24 @@
|
|||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <https://unlicense.org>
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -4,25 +4,21 @@ public class CurseForgeModFile extends ProjectInfo {
|
|||||||
private int projectID;
|
private int projectID;
|
||||||
private int fileID;
|
private int fileID;
|
||||||
private boolean clientOnly;
|
private boolean clientOnly;
|
||||||
|
|
||||||
public CurseForgeModFile(ProjectInfo pj, int projectID, int fileID, boolean clientOnly) {
|
public CurseForgeModFile(ProjectInfo pj, int projectID, int fileID, boolean clientOnly) {
|
||||||
this(pj.getSlug(), pj.getName(), pj.getDesc(), projectID, fileID, clientOnly);
|
this(pj.getSlug(), pj.getName(), pj.getDesc(), projectID, fileID, clientOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurseForgeModFile(String slug, String name, String desc, int projectID, int fileID, boolean clientOnly) {
|
public CurseForgeModFile(String slug, String name, String desc, int projectID, int fileID, boolean clientOnly) {
|
||||||
super(slug, name, desc);
|
super(slug, name, desc);
|
||||||
this.projectID = projectID;
|
this.projectID = projectID;
|
||||||
this.fileID = fileID;
|
this.fileID = fileID;
|
||||||
this.clientOnly = clientOnly;
|
this.clientOnly = clientOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFileID() {
|
public int getFileID() {
|
||||||
return this.fileID;
|
return this.fileID;
|
||||||
}
|
}
|
||||||
public int getProjectID() {
|
public int getProjectID() {
|
||||||
return this.projectID;
|
return this.projectID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClientOnly() {
|
public boolean isClientOnly() {
|
||||||
return this.clientOnly;
|
return this.clientOnly;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,14 +13,20 @@ import downloader.forgeSvc.ForgeSvcFile;
|
|||||||
import downloader.helper.HttpHelper;
|
import downloader.helper.HttpHelper;
|
||||||
|
|
||||||
public class Database {
|
public class Database {
|
||||||
DBConnector connector;
|
private DBConnector connector;
|
||||||
|
|
||||||
Gson gson;
|
private Gson gson;
|
||||||
|
|
||||||
|
private static final String ME = "Db";
|
||||||
|
|
||||||
public Database() {
|
public Database() {
|
||||||
try {
|
try {
|
||||||
|
//work around to avoid
|
||||||
Class.forName("org.sqlite.JDBC");
|
Class.forName("org.sqlite.JDBC");
|
||||||
} catch (ClassNotFoundException e1) {} //it will crash anyway
|
} catch (ClassNotFoundException e1) {
|
||||||
|
Log.e(ME, "Error sqLite was not found");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
this.connector = new DBConnector();
|
this.connector = new DBConnector();
|
||||||
try {
|
try {
|
||||||
@@ -34,12 +40,12 @@ public class Database {
|
|||||||
|
|
||||||
private int findProjectBySlug(String slug, int ptype) {
|
private int findProjectBySlug(String slug, int ptype) {
|
||||||
int pjId = -1;
|
int pjId = -1;
|
||||||
ResultSet rs = this.connector.executeRequest("select projectid from projects where type =" + ptype + " and slug LIKE \"%" + slug.trim().toLowerCase() + "%\"");
|
ResultSet rs = this.connector.executeRequest("select projectid from projects where type =" + ptype + " and slug LIKE \"" + slug.trim().toLowerCase() + "\"");
|
||||||
try {
|
try {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
pjId = rs.getInt("projectid");
|
pjId = rs.getInt("projectid");
|
||||||
} else {
|
} else {
|
||||||
Log.e("DB", "not found " + slug);
|
Log.e(ME, "not found " + slug);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package downloader;
|
package downloader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import downloader.helper.ArchiveHelper;
|
import downloader.helper.ArchiveHelper;
|
||||||
import downloader.helper.SlugHelper;
|
import downloader.helper.SlugHelper;
|
||||||
|
|||||||
@@ -1,13 +1,30 @@
|
|||||||
package downloader;
|
package downloader;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
public class Log {
|
public class Log {
|
||||||
private Log() {}
|
private Log() {}
|
||||||
|
private static String staticLine = "";
|
||||||
|
private static PrintStream lastStream = System.out;
|
||||||
|
|
||||||
public static void e(String who, String msg) {
|
public static void e(String who, String msg) {
|
||||||
System.out.println(String.valueOf(who) + " : " + msg);
|
printNonStatic(String.valueOf(who) + " : " + msg, System.err);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void i(String who, String msg) {
|
public static void i(String who, String msg) {
|
||||||
if(Main.verbose)System.out.println(String.valueOf(who) + " : " + msg);
|
if(Main.verbose) printNonStatic(String.valueOf(who) + " : " + msg, System.out);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printNonStatic(String line, PrintStream stream) {
|
||||||
|
//erase last stream since we used \r
|
||||||
|
lastStream.print("");
|
||||||
|
stream.println(line);
|
||||||
|
stream.print(staticLine + "\r");
|
||||||
|
lastStream = stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setStaticPrint(String staticString) {
|
||||||
|
staticLine = staticString;
|
||||||
|
System.out.print(staticString + "\r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import java.io.IOException;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import downloader.forgeSvc.ForgeSvcFile;
|
import downloader.forgeSvc.ForgeSvcFile;
|
||||||
import downloader.helper.HttpHelper;
|
import downloader.helper.HttpHelper;
|
||||||
@@ -59,7 +58,7 @@ public class ModUpdater {
|
|||||||
//on attend la fin des threads
|
//on attend la fin des threads
|
||||||
while( !threads.isEmpty() ) {
|
while( !threads.isEmpty() ) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
Log.i(ME, "finished");
|
Log.i(ME, "finished");
|
||||||
@@ -82,7 +81,7 @@ final class UpdaterThread extends Thread {
|
|||||||
private static final String ME = "ModUpdaterThread";
|
private static final String ME = "ModUpdaterThread";
|
||||||
|
|
||||||
public UpdaterThread(String line, Database db, DirectUpdateManager directUpdateManager, CurseUpdateManager curseUpdateManager, List<Thread> threads) {
|
public UpdaterThread(String line, Database db, DirectUpdateManager directUpdateManager, CurseUpdateManager curseUpdateManager, List<Thread> threads) {
|
||||||
super();
|
super(line);
|
||||||
this.line = line;
|
this.line = line;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.directUpdateManager = directUpdateManager;
|
this.directUpdateManager = directUpdateManager;
|
||||||
@@ -118,7 +117,6 @@ final class UpdaterThread extends Thread {
|
|||||||
//le slug est une nom de mods qui se trouve dans le nom du fichier
|
//le slug est une nom de mods qui se trouve dans le nom du fichier
|
||||||
String slug = extractSlugFromLink(line);
|
String slug = extractSlugFromLink(line);
|
||||||
//on check si le mods est pas déja installé et si il est a jours
|
//on check si le mods est pas déja installé et si il est a jours
|
||||||
Log.e("who",slug);
|
|
||||||
boolean upToDate = directUpdateManager.checkAndDelete(filename, slug);
|
boolean upToDate = directUpdateManager.checkAndDelete(filename, slug);
|
||||||
if(!upToDate)
|
if(!upToDate)
|
||||||
{
|
{
|
||||||
@@ -152,13 +150,13 @@ final class UpdaterThread extends Thread {
|
|||||||
Log.i("DB", "NEW MOD DETECTED " + modID);
|
Log.i("DB", "NEW MOD DETECTED " + modID);
|
||||||
upToDate = this.curseUpdateManager.checkAndDelete(new File("mods/" + HttpHelper.getFileNameFromURL(downloadUrl)), pj.getSlug());
|
upToDate = this.curseUpdateManager.checkAndDelete(new File("mods/" + HttpHelper.getFileNameFromURL(downloadUrl)), pj.getSlug());
|
||||||
if(upToDate) {
|
if(upToDate) {
|
||||||
|
Log.i("who", "file found");
|
||||||
this.curseUpdateManager.addModsToTheList("mods/" + HttpHelper.getFileNameFromURL(downloadUrl), modID);
|
this.curseUpdateManager.addModsToTheList("mods/" + HttpHelper.getFileNameFromURL(downloadUrl), modID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!upToDate) {
|
if (!upToDate) {
|
||||||
Log.i("MOD", "downloading " + pj.getName().replace(" ", "-"));
|
Log.i("MOD", "downloading " + pj.getName().replace(" ", "-"));
|
||||||
|
|
||||||
HttpHelper.readFileFromUrlToFolder(downloadUrl, "mods");
|
HttpHelper.readFileFromUrlToFolder(downloadUrl, "mods");
|
||||||
|
|
||||||
Log.i("MOD", "download finished");
|
Log.i("MOD", "download finished");
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import downloader.Log;
|
import downloader.Log;
|
||||||
|
|
||||||
@@ -111,6 +112,7 @@ public class HttpHelper {
|
|||||||
// imposible vu qu'on l'a crée precedament
|
// imposible vu qu'on l'a crée precedament
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double start = System.currentTimeMillis();
|
||||||
try (InputStream in = con.getInputStream()) {
|
try (InputStream in = con.getInputStream()) {
|
||||||
// on lit par tranche de 4mo
|
// on lit par tranche de 4mo
|
||||||
byte[] buffer = new byte[4096];
|
byte[] buffer = new byte[4096];
|
||||||
@@ -119,6 +121,15 @@ public class HttpHelper {
|
|||||||
int bytesRead = in.read(buffer);
|
int bytesRead = in.read(buffer);
|
||||||
if (bytesRead < 0)
|
if (bytesRead < 0)
|
||||||
break;
|
break;
|
||||||
|
{
|
||||||
|
double elapsed = ( System.currentTimeMillis() - start ) / 1000;
|
||||||
|
if(elapsed != 0) {
|
||||||
|
long estimatedBandwith = (long) (bytesRead / elapsed);
|
||||||
|
//display the estimate
|
||||||
|
Log.setStaticPrint(formatBandwidth(estimatedBandwith));
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}
|
||||||
downloadingWriter.write(buffer, 0, bytesRead);
|
downloadingWriter.write(buffer, 0, bytesRead);
|
||||||
}
|
}
|
||||||
downloadingWriter.close();
|
downloadingWriter.close();
|
||||||
@@ -128,6 +139,35 @@ public class HttpHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param estimatedBandwith in o/s
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String formatBandwidth(long estimatedBandwith) {
|
||||||
|
//is ko/s
|
||||||
|
if(estimatedBandwith > 1000) {
|
||||||
|
//is mo/s
|
||||||
|
if(estimatedBandwith > 1000 * 1000) {
|
||||||
|
return String.valueOf(estimatedBandwith/ (1000 * 1000)) + "M" + getLocalizedByte() + "/s";
|
||||||
|
} else {
|
||||||
|
return String.valueOf(estimatedBandwith/ 1000) + "K" + getLocalizedByte() + "/s";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return String.valueOf(estimatedBandwith) + getLocalizedByte() + "/s";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getLocalizedByte() {
|
||||||
|
Locale l = Locale.getDefault();
|
||||||
|
|
||||||
|
if (l.equals(Locale.FRANCE) | l.equals(Locale.FRENCH)) {
|
||||||
|
return "O";
|
||||||
|
} else {
|
||||||
|
return "B";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getFileNameFromURL(String url)
|
public static String getFileNameFromURL(String url)
|
||||||
{
|
{
|
||||||
String[] urlsplit = url.split("/");
|
String[] urlsplit = url.split("/");
|
||||||
|
|||||||
Reference in New Issue
Block a user