This commit is contained in:
marc barbier
2021-07-08 22:42:14 +02:00
parent 098f6876ed
commit 1a52c650c5
3 changed files with 7 additions and 13 deletions
@@ -1,6 +1,7 @@
package downloader;
import java.io.File;
import java.io.IOException;
import downloader.helper.ArchiveHelper;
import downloader.helper.SlugHelper;
@@ -13,13 +14,8 @@ public class DirectUpdateManager {
* @return upToDate
*/
public boolean checkAndDelete(String filename, String slug) {
File mod = new File("mods/"+filename);
if (!mod.isFile()) {
mod.delete();
return false;
}
File mod = new File("mods/"+filename.toLowerCase());
if (!mod.exists()) {
SlugHelper.deleteBySlug(slug);
return false;
@@ -118,15 +118,16 @@ final class UpdaterThread extends Thread {
//le slug est une nom de mods qui se trouve dans le nom du fichier
String slug = extractSlugFromLink(line);
//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);
if(!upToDate)
{
Log.i("main","downloading "+ filename);
Log.i(ME,"downloading "+ filename);
try {
HttpHelper.readFileFromUrlToFolder(url,"mods",filename);
Log.i("main","done");
Log.i(ME,"done");
} catch (MalformedURLException e) {
Log.e("ModUpdater", "could not update mod, error while downloading");
Log.e(ME, "could not update mod, error while downloading");
}
}
}
@@ -79,7 +79,6 @@ public class HttpHelper {
return readFileFromUrl(urlToFetch, new File((folder + name.toLowerCase()).trim()));
}
//TODO: debug
private static File readFileFromUrl(String urlToFetch, File destination) throws MalformedURLException {
URL url = new URL(urlToFetch);
HttpURLConnection con;
@@ -91,13 +90,11 @@ public class HttpHelper {
}
File downloadingFile = destination;
System.out.println(downloadingFile.getAbsolutePath());
if (downloadingFile.exists()) {
return downloadingFile;
} else {
try {
System.out.println(downloadingFile);
downloadingFile.createNewFile();
} catch (IOException e) {
Log.e("HTTPHelper","permission error could not write file");