Fixed class loader not closing when deleting mods

This commit is contained in:
Anuken 2024-11-04 10:51:10 -05:00
parent fac26032aa
commit 9e2350be03
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package mindustry.mod;
import java.net.*;
public class ClassLoaderCloser{
/** Workaround for the close() method not being available on Android. */
public static void close(ClassLoader loader) throws Exception{
if(loader instanceof URLClassLoader u){
u.close();
}
}
}

View File

@ -412,6 +412,14 @@ 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);
}
}
if(mod.root instanceof ZipFi){
mod.root.delete();
}
@ -958,6 +966,12 @@ public class Mods implements Loadable{
if(other != null){
//steam mods can't really be deleted, they need to be unsubscribed
if(overwrite && !other.hasSteamID()){
//close the classloader for jar mods
if(!android){
ClassLoaderCloser.close(other.loader);
}
//close zip file
if(other.root instanceof ZipFi){
other.root.delete();