BootCheck Cleanup

This commit is contained in:
Konloch 2021-06-27 14:15:08 -07:00
parent b0f5e938db
commit 3be7d457c6

View file

@ -15,61 +15,84 @@ import java.util.List;
import static the.bytecode.club.bytecodeviewer.Constants.nl; import static the.bytecode.club.bytecodeviewer.Constants.nl;
/** /**
* Loads the libraries on boot.
*
* This broke with maven so now only FatJar builds will work.
*
* To get this system working again for smaller binaries/automatic updating libraries maven support will need to be added.
*
* @author Konloch * @author Konloch
* @author Bibl (don't ban me pls)
* @since 6/21/2021 * @since 6/21/2021
*/ */
public class BootCheck implements Runnable public class BootCheck implements Runnable
{ {
boolean finished = false;
@Override @Override
@SuppressWarnings({"rawtypes", "unchecked"}) public void run()
public void run() { {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
while (!finished) { //7 second failsafe
if (System.currentTimeMillis() - start >= 7000) { //7 second failsafe while (System.currentTimeMillis() - start < 7000)
if (!Boot.completedboot && !Boot.downloading) { {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) { }
}
//if it's failed to boot and it's not downloading attempt to load the libraries
failSafeLoadLibraries();
}
@SuppressWarnings({"rawtypes", "unchecked"})
public void failSafeLoadLibraries()
{
if (!Boot.completedboot && !Boot.downloading)
{
File libsDir = Boot.libsDir(); File libsDir = Boot.libsDir();
File[] listFiles = libsDir.listFiles(); File[] listFiles = libsDir.listFiles();
if (listFiles == null || listFiles.length <= 0) {
//first boot failed to download libraries
if (listFiles == null || listFiles.length <= 0)
{
BytecodeViewer.showMessage( BytecodeViewer.showMessage(
"Github is loading extremely slow, BCV needs to download libraries from github in" "Github is loading extremely slow, BCV needs to download libraries from github in order"
+ " order" + nl + + nl + "to work, please try adjusting your network settings or manually downloading these libraries"
"to work, please try adjusting your network settings or manually " + nl + "if this error persists.");
+ "downloading these libraries" + nl +
"if this error persists.");
finished = true;
return; return;
} }
Boot.setState("Bytecode Viewer Boot Screen (OFFLINE MODE) - Unable to connect to github, " Boot.setState("Bytecode Viewer Boot Screen (OFFLINE MODE) - Unable to connect to github, force booting...");
+ "force booting...");
System.out.println("Unable to connect to github, force booting..."); System.out.println("Unable to connect to github, force booting...");
List<String> libsFileList = new ArrayList<>(); List<String> libsFileList = new ArrayList<>();
for (File f : listFiles) { for (File f : listFiles)
libsFileList.add(f.getAbsolutePath()); libsFileList.add(f.getAbsolutePath());
}
ILoader<?> loader = Boot.findLoader(); ILoader<?> loader = Boot.findLoader();
for (String s : libsFileList)
for (String s : libsFileList) { {
if (s.endsWith(".jar")) { if (s.endsWith(".jar"))
{
File f = new File(s); File f = new File(s);
if (f.exists()) { if (f.exists())
Boot.setState("Bytecode Viewer Boot Screen (OFFLINE MODE) - Force Loading Library" {
+ " " + f.getName()); Boot.setState("Bytecode Viewer Boot Screen (OFFLINE MODE) - Force Loading Library "
+ f.getName());
System.out.println("Force loading library " + f.getName()); System.out.println("Force loading library " + f.getName());
try { try
{
ExternalResource res = new EmptyExternalResource<>(f.toURI().toURL()); ExternalResource res = new EmptyExternalResource<>(f.toURI().toURL());
loader.bind(res); loader.bind(res);
System.out.println("Successfully loaded " + f.getName()); System.out.println("Successfully loaded " + f.getName());
} catch (Exception e) { }
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
f.delete(); f.delete();
JOptionPane.showMessageDialog(null, "Error, Library " + f.getName() + " is " JOptionPane.showMessageDialog(null,
+ "corrupt, please restart to redownload it.", "Error, Library " + f.getName() + " is corrupt, please restart to re-download it.",
"Error", JOptionPane.ERROR_MESSAGE); "Error", JOptionPane.ERROR_MESSAGE);
} }
} }
@ -89,12 +112,5 @@ public class BootCheck implements Runnable
CommandLineInput.executeCommandLine(BytecodeViewer.args); CommandLineInput.executeCommandLine(BytecodeViewer.args);
} }
} }
finished = true;
}
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
}
} }
} }