mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-06 00:49:14 +07:00
Fixed class loader not closing when deleting mods
This commit is contained in:
parent
fac26032aa
commit
9e2350be03
13
core/src/mindustry/mod/ClassLoaderCloser.java
Normal file
13
core/src/mindustry/mod/ClassLoaderCloser.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user