Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a52c650c5 | |||
| 098f6876ed | |||
| 22727988fb |
@@ -6,14 +6,13 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.SortedMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import downloader.helper.ArchiveHelper;
|
import downloader.helper.ArchiveHelper;
|
||||||
import downloader.helper.SlugHelper;
|
import downloader.helper.SlugHelper;
|
||||||
|
|
||||||
public class CurseUpdateManager {
|
public class CurseUpdateManager {
|
||||||
private SortedMap<Integer, String> installedMods;
|
private ConcurrentHashMap<Integer, String> installedMods;
|
||||||
|
|
||||||
public CurseUpdateManager()
|
public CurseUpdateManager()
|
||||||
{
|
{
|
||||||
@@ -27,18 +26,18 @@ public class CurseUpdateManager {
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(modsMapFile));
|
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(modsMapFile));
|
||||||
installedMods = (SortedMap<Integer, String>) ois.readObject();
|
installedMods = (ConcurrentHashMap<Integer, String>) ois.readObject();
|
||||||
ois.close();
|
ois.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
modsMapFile.delete();
|
modsMapFile.delete();
|
||||||
}
|
}
|
||||||
if(installedMods == null)installedMods = new TreeMap<>();
|
|
||||||
}
|
}
|
||||||
|
if(installedMods == null)installedMods = new ConcurrentHashMap<>();
|
||||||
this.updateFile();
|
this.updateFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkAndDelete(File modToDownload, int modid) {
|
public boolean checkAndDelete(File modToDownload, int modid) {
|
||||||
String alredyInstalledName = installedMods.get(modid).toLowerCase();
|
String alredyInstalledName = installedMods.get(modid).toLowerCase();
|
||||||
File alredyInstalledMods= null;
|
File alredyInstalledMods= null;
|
||||||
|
|
||||||
//on cherche le fichier local affin de ne pas voir d'erreur avec la casse
|
//on cherche le fichier local affin de ne pas voir d'erreur avec la casse
|
||||||
@@ -61,7 +60,7 @@ public class CurseUpdateManager {
|
|||||||
|
|
||||||
if (alredyInstalledMods.exists()) {
|
if (alredyInstalledMods.exists()) {
|
||||||
//we only check if the jar file still works
|
//we only check if the jar file still works
|
||||||
if(ArchiveHelper.checkJarIntegrity(alredyInstalledMods)) {
|
if(!ArchiveHelper.checkJarIntegrity(alredyInstalledMods)) {
|
||||||
alredyInstalledMods.delete();
|
alredyInstalledMods.delete();
|
||||||
installedMods.remove(modid);
|
installedMods.remove(modid);
|
||||||
updateFile();
|
updateFile();
|
||||||
@@ -110,18 +109,17 @@ public class CurseUpdateManager {
|
|||||||
* @param fileName
|
* @param fileName
|
||||||
* @param modID
|
* @param modID
|
||||||
*/
|
*/
|
||||||
public void addModsToTheList(String fileName,int modID)
|
public synchronized void addModsToTheList(String fileName,int modID)
|
||||||
{
|
{
|
||||||
installedMods.put(modID, fileName);
|
installedMods.put(modID, fileName);
|
||||||
updateFile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isModIdKnown(int modId)
|
public synchronized boolean isModIdKnown(int modId)
|
||||||
{
|
{
|
||||||
return installedMods.get(modId) != null;
|
return installedMods.get(modId) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFile()
|
public synchronized void updateFile()
|
||||||
{
|
{
|
||||||
File modsMap = new File("mods/modsMap.sav");
|
File modsMap = new File("mods/modsMap.sav");
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import java.io.BufferedReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
import downloader.helper.ArchiveHelper;
|
import downloader.helper.ArchiveHelper;
|
||||||
@@ -29,11 +31,22 @@ public class DatabaseVersionManager {
|
|||||||
if( version == null || !latestVersion.equals(version) ) {
|
if( version == null || !latestVersion.equals(version) ) {
|
||||||
Log.i(ME, "new dbVersion avaliable downloading...");
|
Log.i(ME, "new dbVersion avaliable downloading...");
|
||||||
downloadDatabase(latestVersion);
|
downloadDatabase(latestVersion);
|
||||||
|
saveDbVersion(latestVersion);
|
||||||
} else {
|
} else {
|
||||||
Log.i(ME, "update to Date");
|
Log.i(ME, "update to Date");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveDbVersion(String latestVersion) {
|
||||||
|
File versionFile = new File("dbVersion");
|
||||||
|
PrintWriter out;
|
||||||
|
try {
|
||||||
|
out = new PrintWriter(new FileWriter(versionFile));
|
||||||
|
out.println(latestVersion);
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e) {}
|
||||||
|
}
|
||||||
|
|
||||||
private void downloadDatabase(String dbVersion) {
|
private void downloadDatabase(String dbVersion) {
|
||||||
Log.i(ME, "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;
|
||||||
@@ -81,8 +94,7 @@ public class DatabaseVersionManager {
|
|||||||
versionFile.delete();
|
versionFile.delete();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new FileNotFoundException();
|
|
||||||
}
|
}
|
||||||
|
throw new FileNotFoundException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
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;
|
||||||
@@ -13,13 +14,8 @@ public class DirectUpdateManager {
|
|||||||
* @return upToDate
|
* @return upToDate
|
||||||
*/
|
*/
|
||||||
public boolean checkAndDelete(String filename, String slug) {
|
public boolean checkAndDelete(String filename, String slug) {
|
||||||
File mod = new File("mods/"+filename);
|
File mod = new File("mods/"+filename.toLowerCase());
|
||||||
|
|
||||||
if (!mod.isFile()) {
|
|
||||||
mod.delete();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mod.exists()) {
|
if (!mod.exists()) {
|
||||||
SlugHelper.deleteBySlug(slug);
|
SlugHelper.deleteBySlug(slug);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ public class Log {
|
|||||||
private Log() {}
|
private Log() {}
|
||||||
|
|
||||||
public static void e(String who, String msg) {
|
public static void e(String who, String msg) {
|
||||||
System.err.println(String.valueOf(who) + " : " + msg);
|
System.out.println(String.valueOf(who) + " : " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void i(String who, String msg) {
|
public static void i(String who, String msg) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ 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";
|
||||||
|
|
||||||
public ModUpdater() {
|
public ModUpdater() {
|
||||||
this.db = new Database();
|
this.db = new Database();
|
||||||
@@ -27,7 +28,7 @@ public class ModUpdater {
|
|||||||
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(ME, "[ERROR]no mod file found exiting...");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +51,19 @@ public class ModUpdater {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
Log.i("Main", "finished");
|
|
||||||
|
|
||||||
} catch( IOException e ) {
|
} catch( IOException e ) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//on attend la fin des threads
|
||||||
|
while( !threads.isEmpty() ) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch (InterruptedException e) {}
|
||||||
|
}
|
||||||
|
Log.i(ME, "finished");
|
||||||
|
curseUpdateManager.updateFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAComment(String line)
|
public static boolean isAComment(String line)
|
||||||
@@ -71,6 +79,7 @@ final class UpdaterThread extends Thread {
|
|||||||
private final DirectUpdateManager directUpdateManager;
|
private final DirectUpdateManager directUpdateManager;
|
||||||
private final CurseUpdateManager curseUpdateManager;
|
private final CurseUpdateManager curseUpdateManager;
|
||||||
private final List<Thread> threads;
|
private final List<Thread> threads;
|
||||||
|
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();
|
||||||
@@ -88,7 +97,9 @@ final class UpdaterThread extends Thread {
|
|||||||
handleDirectDownload(line);
|
handleDirectDownload(line);
|
||||||
} else if (line.startsWith("del=")) {
|
} else if (line.startsWith("del=")) {
|
||||||
String[] delete = line.split("del=");
|
String[] delete = line.split("del=");
|
||||||
new File(delete[1]).delete();
|
if(new File("mods/" + delete[1]).delete()) {
|
||||||
|
Log.i(ME, "Successfully removed " + delete[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (line.split("/").length >= 5) {
|
if (line.split("/").length >= 5) {
|
||||||
@@ -107,15 +118,16 @@ 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)
|
||||||
{
|
{
|
||||||
Log.i("main","downloading "+ filename);
|
Log.i(ME,"downloading "+ filename);
|
||||||
try {
|
try {
|
||||||
HttpHelper.readFileFromUrlToFolder(url,"mods",filename);
|
HttpHelper.readFileFromUrlToFolder(url,"mods",filename);
|
||||||
Log.i("main","done");
|
Log.i(ME,"done");
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
Log.e("ModUpdater", "could not update mod, error while downloading");
|
Log.e(ME, "could not update mod, error while downloading");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,6 +151,9 @@ final class UpdaterThread extends Thread {
|
|||||||
else {
|
else {
|
||||||
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) {
|
||||||
|
this.curseUpdateManager.addModsToTheList("mods/" + HttpHelper.getFileNameFromURL(downloadUrl), modID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!upToDate) {
|
if (!upToDate) {
|
||||||
|
|||||||
@@ -90,13 +90,11 @@ public class HttpHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
File downloadingFile = destination;
|
File downloadingFile = destination;
|
||||||
System.out.println(downloadingFile.getAbsolutePath());
|
|
||||||
|
|
||||||
if (downloadingFile.exists()) {
|
if (downloadingFile.exists()) {
|
||||||
return downloadingFile;
|
return downloadingFile;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
System.out.println(downloadingFile);
|
|
||||||
downloadingFile.createNewFile();
|
downloadingFile.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e("HTTPHelper","permission error could not write file");
|
Log.e("HTTPHelper","permission error could not write file");
|
||||||
|
|||||||
Reference in New Issue
Block a user