Show bootstrap statuses on splash frame.

This commit is contained in:
CalDescent 2021-10-03 15:01:50 +01:00
parent 35718f6215
commit 7e5dd62a92
2 changed files with 44 additions and 15 deletions

View File

@ -16,6 +16,7 @@ public class SplashFrame {
private static SplashFrame instance;
private JFrame splashDialog;
private SplashPanel splashPanel;
@SuppressWarnings("serial")
public static class SplashPanel extends JPanel {
@ -23,22 +24,39 @@ public class SplashFrame {
private String defaultSplash = "Qlogo_512.png";
private JLabel statusLabel;
public SplashPanel() {
image = Gui.loadImage(defaultSplash);
setOpaque(false);
setLayout(new GridBagLayout());
}
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBorder(null);
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
// Add logo
JLabel imageLabel = new JLabel(new ImageIcon(image));
imageLabel.setSize(new Dimension(300, 300));
add(imageLabel);
// Add status label
statusLabel = new JLabel("Starting Qortal Core...", JLabel.CENTER);
statusLabel.setMaximumSize(new Dimension(500, 50));
statusLabel.setFont(new Font("Verdana", Font.PLAIN, 22));
statusLabel.setBackground(new Color(255, 255, 255));
statusLabel.setOpaque(true);
statusLabel.setBorder(null);
add(statusLabel);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(500, 500);
return new Dimension(500, 550);
}
public void updateStatus(String text) {
if (statusLabel != null) {
statusLabel.setText(text);
}
}
}
@ -55,7 +73,8 @@ public class SplashFrame {
icons.add(Gui.loadImage("icons/Qlogo_128.png"));
this.splashDialog.setIconImages(icons);
this.splashDialog.getContentPane().add(new SplashPanel());
this.splashPanel = new SplashPanel();
this.splashDialog.getContentPane().add(this.splashPanel);
this.splashDialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.splashDialog.setUndecorated(true);
this.splashDialog.pack();
@ -79,4 +98,8 @@ public class SplashFrame {
this.splashDialog.dispose();
}
public void updateStatus(String text) {
this.splashPanel.updateStatus(text);
}
}

View File

@ -8,6 +8,7 @@ import org.qortal.controller.Controller;
import org.qortal.data.account.MintingAccountData;
import org.qortal.data.block.BlockData;
import org.qortal.data.crosschain.TradeBotData;
import org.qortal.gui.SplashFrame;
import org.qortal.repository.hsqldb.HSQLDBImportExport;
import org.qortal.repository.hsqldb.HSQLDBRepositoryFactory;
import org.qortal.settings.Settings;
@ -302,14 +303,14 @@ public class Bootstrap {
try (final Repository repository = RepositoryManager.getRepository()) {
this.repository = repository;
LOGGER.info("Starting import of bootstrap...");
this.updateStatus("Starting import of bootstrap...");
this.doImport();
break;
} catch (DataException e) {
LOGGER.info("Bootstrap import failed: {}", e.getMessage());
LOGGER.info("Retrying in 5 minutes");
this.updateStatus("Bootstrapping failed. Retrying in 5 minutes");
Thread.sleep(5 * 60 * 1000L);
}
}
@ -363,7 +364,7 @@ public class Bootstrap {
String bootstrapFilename = this.getFilename();
try {
LOGGER.info("Downloading bootstrap...");
this.updateStatus("Downloading bootstrap...");
String bootstrapUrl = String.format("%s/%s", bootstrapHost, bootstrapFilename);
InputStream in = new URL(bootstrapUrl).openStream();
Files.copy(in, path, REPLACE_EXISTING);
@ -379,12 +380,12 @@ public class Bootstrap {
blockchainLock.lockInterruptibly();
try {
LOGGER.info("Extracting bootstrap...");
this.updateStatus("Extracting bootstrap...");
Path input = path.toAbsolutePath();
Path output = path.toAbsolutePath().getParent().toAbsolutePath();
SevenZ.decompress(input.toString(), output.toFile());
LOGGER.info("Stopping repository...");
this.updateStatus("Stopping repository...");
// Close the repository while we are still able to
// Otherwise, the caller will run into difficulties when it tries to close it
repository.discardChanges();
@ -399,11 +400,11 @@ public class Bootstrap {
}
// Move the "bootstrap" folder in place of the "db" folder
LOGGER.info("Moving files to output directory...");
this.updateStatus("Moving files to output directory...");
FileUtils.deleteDirectory(outputPath.toFile());
Files.move(inputPath, outputPath);
LOGGER.info("Starting repository from bootstrap...");
this.updateStatus("Starting repository from bootstrap...");
RepositoryFactory repositoryFactory = new HSQLDBRepositoryFactory(Controller.getRepositoryUrl());
RepositoryManager.setRepositoryFactory(repositoryFactory);
@ -413,4 +414,9 @@ public class Bootstrap {
}
}
private void updateStatus(String text) {
LOGGER.info(text);
SplashFrame.getInstance().updateStatus(text);
}
}