This commit is contained in:
marc barbier
2021-07-08 15:07:11 +02:00
parent 77a3cdec7e
commit 2a3c112b67
6 changed files with 18 additions and 13 deletions
Binary file not shown.
+1 -1
View File
@@ -4,7 +4,7 @@ cd src
javac \ javac \
-d ../objs\ -d ../objs\
-cp ../lib/commons-compress-1.20.jar:../lib/gson-2.8.7.jar:../lib/gson-2.8.6.jar\ -cp ../lib/commons-compress-1.20.jar:../lib/gson-2.8.7.jar:../lib/gson-2.8.6.jar:../lib/sqlite-jdbc-3.32.3.2.jar\
downloader/*.java downloader/forgeSvc/*.java downloader/helper/*.java downloader/*.java downloader/forgeSvc/*.java downloader/helper/*.java
cd .. cd ..
@@ -18,6 +18,10 @@ public class Database {
Gson gson; Gson gson;
public Database() { public Database() {
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e1) {} //it will crash anyway
this.connector = new DBConnector(); this.connector = new DBConnector();
try { try {
this.connector.connect((new File("database.dat")).getAbsolutePath()); this.connector.connect((new File("database.dat")).getAbsolutePath());
@@ -30,7 +34,7 @@ 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");
@@ -13,7 +13,7 @@ import downloader.helper.HttpHelper;
public class DatabaseVersionManager { public class DatabaseVersionManager {
private String version; private String version;
private static final String Iam = "DBUpdater"; private static final String ME = "DBUpdater";
public DatabaseVersionManager() { public DatabaseVersionManager() {
try { try {
@@ -26,32 +26,32 @@ public class DatabaseVersionManager {
public void updateIfNeeded() { public void updateIfNeeded() {
String latestVersion = fetchLatestVersion(); String latestVersion = fetchLatestVersion();
if( !version.equals(latestVersion) ) { if( version == null || !latestVersion.equals(version) ) {
Log.i(Iam, "new dbVersion avaliable downloading..."); Log.i(ME, "new dbVersion avaliable downloading...");
downloadDatabase(latestVersion); downloadDatabase(latestVersion);
} else { } else {
Log.i(Iam, "update to Date"); Log.i(ME, "update to Date");
} }
} }
private void downloadDatabase(String dbVersion) { private void downloadDatabase(String dbVersion) {
Log.i(Iam, "fetching=" + "http://files.mcdex.net/data/mcdex-v5-" + dbVersion + ".dat.bz2"); Log.i(ME, "fetching=" + "http://files.mcdex.net/data/mcdex-v5-" + dbVersion + ".dat.bz2");
File archive; File archive;
try { try {
archive = HttpHelper.readFileFromUrl("http://files.mcdex.net/data/mcdex-v5-" + dbVersion + ".dat.bz2"); archive = HttpHelper.readFileFromUrl("http://files.mcdex.net/data/mcdex-v5-" + dbVersion + ".dat.bz2");
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
Log.e(Iam, "Error invalid database download url"); Log.e(ME, "Error invalid database download url");
System.exit(1); System.exit(1);
//utile pour le lint //utile pour le lint
return; return;
} }
Log.i(Iam, "download finished"); Log.i(ME, "download finished");
Log.i(Iam, "decompressing db"); Log.i(ME, "decompressing db");
try { try {
ArchiveHelper.decompressBz2(archive, "database.dat"); ArchiveHelper.decompressBz2(archive, "database.dat");
archive.delete(); archive.delete();
} catch (IOException e) { } catch (IOException e) {
Log.e(Iam, "[ERROR]cannot extract database"); Log.e(ME, "[ERROR]cannot extract database");
if(archive.exists()) archive.delete(); if(archive.exists()) archive.delete();
System.exit(1); System.exit(1);
} }
+1 -1
View File
@@ -43,7 +43,7 @@ public class Main {
String cmd = it.next(); String cmd = it.next();
switch (cmd) { switch (cmd) {
case "--check": case "--check":
System.out.println("--check is not avaliable") System.out.println("--check is not avaliable");
checkingonly = true; checkingonly = true;
continue; continue;
case "-t": case "-t":
@@ -23,13 +23,14 @@ public class ModUpdater {
public void update() { public void update() {
File modsList = new File("modpack.txt"); File modsList = new File("modpack.txt");
if(modsList.exists() && modsList.isFile()) { if(!(modsList.exists() && modsList.isFile())) {
Log.e("Updater", "[ERROR]no mod file found exiting..."); Log.e("Updater", "[ERROR]no mod file found exiting...");
System.exit(1); System.exit(1);
} }
//parse and download //parse and download
try { try {
//TODO: add threads
BufferedReader in = new BufferedReader(new FileReader(modsList)); BufferedReader in = new BufferedReader(new FileReader(modsList));
while (in.ready()) { while (in.ready()) {
String line = in.readLine(); String line = in.readLine();