Fix Android loadJar (#10867)

* Fix Android loadJar

* Using another way

* Code formating

* Fix mod update
This commit is contained in:
Wxp
2025-06-03 02:32:24 +08:00
committed by GitHub
parent 18d852b5c1
commit 7076d1bf97
3 changed files with 70 additions and 24 deletions

View File

@@ -413,11 +413,22 @@ public class Mods implements Loadable{
/** Removes a mod file and marks it for requiring a restart. */
public void removeMod(LoadedMod mod){
if(!android && mod.loader != null){
try{
ClassLoaderCloser.close(mod.loader);
}catch(Exception e){
Log.err(e);
boolean deleted = true;
if(mod.loader != null){
if(android){
//Try to remove cache for Android 14 security problem
Fi cacheDir = new Fi(Core.files.getCachePath()).child("mods");
Fi modCacheDir = cacheDir.child(mod.file.nameWithoutExtension());
if(modCacheDir.exists()){
deleted = modCacheDir.deleteDirectory();
}
}else{
try{
ClassLoaderCloser.close(mod.loader);
}catch(Exception e){
Log.err(e);
}
}
}
@@ -425,7 +436,7 @@ public class Mods implements Loadable{
mod.root.delete();
}
boolean deleted = mod.file.isDirectory() ? mod.file.deleteDirectory() : mod.file.delete();
deleted &= mod.file.isDirectory() ? mod.file.deleteDirectory() : mod.file.delete();
if(!deleted){
ui.showErrorMessage("@mod.delete.error");
@@ -1112,6 +1123,11 @@ public class Mods implements Loadable{
//close the classloader for jar mods
if(!android){
ClassLoaderCloser.close(other.loader);
}else if(other.loader != null){
//Try to remove cache for Android 14 security problem
Fi cacheDir = new Fi(Core.files.getCachePath()).child("mods");
Fi modCacheDir = cacheDir.child(other.file.nameWithoutExtension());
modCacheDir.deleteDirectory();
}
//close zip file