mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-16 18:58:01 +07:00
Fixed class loader not closing when deleting mods
This commit is contained in:
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. */
|
/** Removes a mod file and marks it for requiring a restart. */
|
||||||
public void removeMod(LoadedMod mod){
|
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){
|
if(mod.root instanceof ZipFi){
|
||||||
mod.root.delete();
|
mod.root.delete();
|
||||||
}
|
}
|
||||||
@ -958,6 +966,12 @@ public class Mods implements Loadable{
|
|||||||
if(other != null){
|
if(other != null){
|
||||||
//steam mods can't really be deleted, they need to be unsubscribed
|
//steam mods can't really be deleted, they need to be unsubscribed
|
||||||
if(overwrite && !other.hasSteamID()){
|
if(overwrite && !other.hasSteamID()){
|
||||||
|
|
||||||
|
//close the classloader for jar mods
|
||||||
|
if(!android){
|
||||||
|
ClassLoaderCloser.close(other.loader);
|
||||||
|
}
|
||||||
|
|
||||||
//close zip file
|
//close zip file
|
||||||
if(other.root instanceof ZipFi){
|
if(other.root instanceof ZipFi){
|
||||||
other.root.delete();
|
other.root.delete();
|
||||||
|
Reference in New Issue
Block a user