ajout checkadv + patch dl
This commit is contained in:
@@ -1,18 +1,77 @@
|
||||
package downloader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class IntegrityChecker {
|
||||
public static String[] fileList;
|
||||
public String[] fileList;
|
||||
public SortedMap<Integer, String> installedMods;
|
||||
public File modsMap;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public IntegrityChecker()
|
||||
{
|
||||
fileList = new File("mods").list();
|
||||
modsMap = new File("mods/modsMap.sav");
|
||||
if(modsMap.exists())
|
||||
{
|
||||
try {
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(modsMap));
|
||||
installedMods = (SortedMap<Integer, String>) ois.readObject();
|
||||
if(installedMods == null)installedMods = new TreeMap<>();
|
||||
ois.close();
|
||||
} catch (Exception e) {
|
||||
installedMods = new TreeMap<>();
|
||||
modsMap.delete();
|
||||
}
|
||||
}
|
||||
try {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(modsMap));
|
||||
oos.writeObject(installedMods);
|
||||
oos.close();
|
||||
} catch (IOException e) {
|
||||
Log.e("SAV", "erreur pas de sauvegarde");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkAndDelete(File modToDownload, String slug) {
|
||||
public boolean checkAndDelete(File modToDownload, int modid) {
|
||||
File alredyInstalledMods = new File("mods/"+installedMods.get(modid));
|
||||
if (alredyInstalledMods.exists()) {
|
||||
try {
|
||||
//si sa balance une exception sa veut dire que le jar n'est pas lisible
|
||||
new ZipFile(alredyInstalledMods).close();
|
||||
} catch (IOException e) {
|
||||
Log.i("integrityChecker","Corruption detected redownloading");
|
||||
alredyInstalledMods.delete();
|
||||
return false;
|
||||
}
|
||||
if(!modToDownload.getAbsolutePath().equals(alredyInstalledMods.getAbsolutePath()))
|
||||
{
|
||||
alredyInstalledMods.delete();
|
||||
Log.i("integrityChecker","Corruption detected redownloading");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}else {
|
||||
if(modToDownload.exists())
|
||||
{
|
||||
modToDownload.delete();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean checkAndDelete(File modToDownload, String slug) {
|
||||
if (modToDownload.exists()) {
|
||||
try {
|
||||
//si sa balance une exception sa veut dire que le jar n'est pas lisible
|
||||
@@ -20,7 +79,7 @@ public class IntegrityChecker {
|
||||
} catch (IOException e) {
|
||||
Log.i("integrityChecker","Corruption detected redownloading");
|
||||
modToDownload.delete();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String s : fileList) {
|
||||
@@ -28,12 +87,37 @@ public class IntegrityChecker {
|
||||
if (!modToDownload.getName().contains(s)) {
|
||||
new File(s).delete();
|
||||
Log.i("integrityChecker","Corruption detected redownloading");
|
||||
return false;
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addModsToTheList(String fileName,int modID)
|
||||
{
|
||||
installedMods.put(modID, fileName);
|
||||
updateFile();
|
||||
}
|
||||
|
||||
public boolean isModIdKnown(int modId)
|
||||
{
|
||||
return installedMods.get(modId) != null;
|
||||
}
|
||||
|
||||
private void updateFile()
|
||||
{
|
||||
try {
|
||||
modsMap.delete();
|
||||
//modsMap.createNewFile();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(modsMap));
|
||||
oos.writeObject(installedMods);
|
||||
oos.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user