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.ui.util.FrameHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
@ -10,6 +11,7 @@ import java.io.*;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLStreamHandlerFactory;
|
||||
import java.util.Date;
|
||||
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
|
||||
public static URLClassLoader getClassLoaderByJar(String jar) throws MalformedURLException {
|
||||
final URL jarURL = new File( jar ).toURI().toURL();
|
||||
dynamicResourcesLoader.addURL( jarURL );
|
||||
return new URLClassLoader(
|
||||
new URL[]{new File(jar).toURI().toURL()},
|
||||
AutoupdateUtil.class.getClassLoader()
|
||||
new URL[]{ new File( jar ).toURI().toURL() },
|
||||
dynamicResourcesLoader
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -73,12 +106,12 @@ public class AutoupdateUtil {
|
|||
return file.length() == completeFileSize && file.lastModified() == lastModified;
|
||||
}
|
||||
|
||||
public static ImageIcon loadIcon(String strPath) {
|
||||
URL imgURL = AutoupdateUtil.class.getResource(strPath);
|
||||
public static ImageIcon loadIcon( String strPath ) {
|
||||
URL imgURL = dynamicResourcesLoader.getResource( strPath );
|
||||
if (imgURL != null) {
|
||||
return new ImageIcon(imgURL);
|
||||
} else {
|
||||
imgURL = AutoupdateUtil.class.getResource("/com/rusefi/" + strPath);
|
||||
imgURL = dynamicResourcesLoader.getResource("/com/rusefi/" + strPath);
|
||||
if (imgURL != null) {
|
||||
return new ImageIcon(imgURL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue