reindent + add error

This commit is contained in:
Marc BARBIER
2021-07-09 15:09:12 +02:00
parent 2f1ecef3d6
commit c64ddd90c5
5 changed files with 69 additions and 64 deletions
+5
View File
@@ -0,0 +1,5 @@
{
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
@@ -1,29 +1,25 @@
package downloader; package downloader;
public class CurseForgeModFile extends ProjectInfo { 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) {
super(slug, name, desc);
public CurseForgeModFile(String slug, String name, String desc, int projectID, int fileID, boolean clientOnly) { this.projectID = projectID;
super(slug, name, desc); this.fileID = fileID;
this.projectID = projectID; this.clientOnly = clientOnly;
this.fileID = fileID; }
this.clientOnly = clientOnly; public int getFileID() {
} return this.fileID;
}
public int getFileID() { public int getProjectID() {
return this.fileID; return this.projectID;
} }
public int getProjectID() { public boolean isClientOnly() {
return this.projectID; return this.clientOnly;
} }
public boolean isClientOnly() {
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;
private Gson gson;
private static final String ME = "Db";
Gson gson;
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 {
@@ -39,7 +45,7 @@ public class Database {
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;
@@ -7,24 +7,23 @@ 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;
public class ModUpdater { public class ModUpdater {
private DirectUpdateManager directUpdateManager; private DirectUpdateManager directUpdateManager;
private CurseUpdateManager curseUpdateManager; private CurseUpdateManager curseUpdateManager;
private Database db; private Database db;
private final String ME = "ModUpdater"; private final String ME = "ModUpdater";
public ModUpdater() {
this.db = new Database();
this.directUpdateManager = new DirectUpdateManager();
this.curseUpdateManager = new CurseUpdateManager();
}
public void update() { public ModUpdater() {
this.db = new Database();
this.directUpdateManager = new DirectUpdateManager();
this.curseUpdateManager = new CurseUpdateManager();
}
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())) {
@@ -35,8 +34,8 @@ public class ModUpdater {
//parse and download //parse and download
List<Thread> threads = new ArrayList<>(Main.threadNb); List<Thread> threads = new ArrayList<>(Main.threadNb);
try { try {
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();
if (!isAComment(line)) { if (!isAComment(line)) {
Thread t = new UpdaterThread(line, db, directUpdateManager, curseUpdateManager, threads); Thread t = new UpdaterThread(line, db, directUpdateManager, curseUpdateManager, threads);
@@ -49,13 +48,13 @@ public class ModUpdater {
Thread.sleep(10); Thread.sleep(10);
} catch (InterruptedException e) {} } catch (InterruptedException e) {}
} }
} }
in.close(); in.close();
} catch( IOException e ) { } catch( IOException e ) {
e.printStackTrace(); e.printStackTrace();
System.exit(1); System.exit(1);
} }
//on attend la fin des threads //on attend la fin des threads
while( !threads.isEmpty() ) { while( !threads.isEmpty() ) {
try { try {
@@ -64,9 +63,9 @@ public class ModUpdater {
} }
Log.i(ME, "finished"); Log.i(ME, "finished");
curseUpdateManager.updateFile(); curseUpdateManager.updateFile();
} }
public static boolean isAComment(String line) public static boolean isAComment(String line)
{ {
return line.startsWith("//"); return line.startsWith("//");
} }
@@ -112,7 +111,7 @@ final class UpdaterThread extends Thread {
} }
private void handleDirectDownload(String line) { private void handleDirectDownload(String line) {
String url = line.replaceFirst("direct=.*@", ""); String url = line.replaceFirst("direct=.*@", "");
String filename=extractNameFromLink(line); String filename=extractNameFromLink(line);
//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
@@ -123,19 +122,19 @@ final class UpdaterThread extends Thread {
{ {
Log.i(ME,"downloading "+ filename); Log.i(ME,"downloading "+ filename);
try { try {
HttpHelper.readFileFromUrlToFolder(url,"mods",filename); HttpHelper.readFileFromUrlToFolder(url,"mods",filename);
Log.i(ME,"done"); Log.i(ME,"done");
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
Log.e(ME, "could not update mod, error while downloading"); Log.e(ME, "could not update mod, error while downloading");
} }
} }
} }
private void handleCurseDownload(String line) { private void handleCurseDownload(String line) {
String name = line.split("/")[5]; String name = line.split("/")[5];
int modID = db.findModBySlug(name); int modID = db.findModBySlug(name);
ProjectInfo pj = db.getProjectInfo(modID); ProjectInfo pj = db.getProjectInfo(modID);
ForgeSvcFile svc = db.fetchMod(pj, modID); ForgeSvcFile svc = db.fetchMod(pj, modID);
if (svc != null) { if (svc != null) {
try { try {