hotfix 2944: broken icon paths in rusefi_autoupdate (#3043)
* fix: successfully replaced standard resources loader to custom dynamic resources loader * fix: successfully replaced standard resources loader to custom dynamic resources loader
This commit is contained in:
parent
d52c6d12ce
commit
c18583e45b
|
@ -3,6 +3,7 @@ package com.rusefi.autoupdate;
|
||||||
import com.rusefi.shared.ConnectionAndMeta;
|
import com.rusefi.shared.ConnectionAndMeta;
|
||||||
import com.rusefi.ui.util.FrameHelper;
|
import com.rusefi.ui.util.FrameHelper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -10,6 +11,7 @@ import java.io.*;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.net.URLStreamHandlerFactory;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
@ -51,11 +53,42 @@ public class AutoupdateUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class DynamicForResourcesURLClassLoader extends URLClassLoader {
|
||||||
|
|
||||||
|
public DynamicForResourcesURLClassLoader( URL[] urls, ClassLoader parent ) { super( urls, parent ); }
|
||||||
|
|
||||||
|
public DynamicForResourcesURLClassLoader( URL[] urls ) { super( urls ); }
|
||||||
|
|
||||||
|
public DynamicForResourcesURLClassLoader( URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory ) { super( urls, parent, factory ); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addURL( URL url ) {
|
||||||
|
super.addURL( url );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Let's here emulate Class.getResource() logic
|
||||||
|
* @param name resource name
|
||||||
|
* @return resource url
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public URL getResource( String name ) {
|
||||||
|
if ( name.startsWith( "/" ) )
|
||||||
|
name = name.substring( 1 );
|
||||||
|
return super.getResource( name );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final DynamicForResourcesURLClassLoader dynamicResourcesLoader = new DynamicForResourcesURLClassLoader( new URL[ 0 ], AutoupdateUtil.class.getClassLoader() );
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static URLClassLoader getClassLoaderByJar(String jar) throws MalformedURLException {
|
public static URLClassLoader getClassLoaderByJar(String jar) throws MalformedURLException {
|
||||||
|
final URL jarURL = new File( jar ).toURI().toURL();
|
||||||
|
dynamicResourcesLoader.addURL( jarURL );
|
||||||
return new URLClassLoader(
|
return new URLClassLoader(
|
||||||
new URL[]{ new File( jar ).toURI().toURL() },
|
new URL[]{ new File( jar ).toURI().toURL() },
|
||||||
AutoupdateUtil.class.getClassLoader()
|
dynamicResourcesLoader
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,11 +107,11 @@ public class AutoupdateUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImageIcon loadIcon( String strPath ) {
|
public static ImageIcon loadIcon( String strPath ) {
|
||||||
URL imgURL = AutoupdateUtil.class.getResource(strPath);
|
URL imgURL = dynamicResourcesLoader.getResource( strPath );
|
||||||
if (imgURL != null) {
|
if (imgURL != null) {
|
||||||
return new ImageIcon(imgURL);
|
return new ImageIcon(imgURL);
|
||||||
} else {
|
} else {
|
||||||
imgURL = AutoupdateUtil.class.getResource("/com/rusefi/" + strPath);
|
imgURL = dynamicResourcesLoader.getResource("/com/rusefi/" + strPath);
|
||||||
if (imgURL != null) {
|
if (imgURL != null) {
|
||||||
return new ImageIcon(imgURL);
|
return new ImageIcon(imgURL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue