fDownInfo = null;
final ProgressBar downloadBar = new ProgressBar(new Vector2f(340, 32), new Color(20, 44, 48), HOVER);
StartScene.this.addChild(downloadBar.position(new Vector2f(60, 115)));
final TextEntity downloadText = new TextEntity("Please wait while Dizgruntled downloads\nrequired resources", TextEntity.ALIGN_LEFT, fFont);
StartScene.this.addChild(downloadText.position(new Vector2f(60, 200)));
// Download the resources
final Thread downloader = new Thread() {
private DownloadExtractor fVrzDown;
private DownloadExtractor fRezDown;
@Override
public void run() {
try {
URL url = new URL("http://pointcliki.com/gruntz/download.txt");
Scanner s = new Scanner(url.openStream());
final String rez = s.nextLine();
final String vrz = s.nextLine();
s.close();
// Download the VRZ
fVrzDown = new DownloadExtractor(new URL(vrz), new File("lib/vrz.zip"), new File("lib/GRUNTZ.VRZ")) {
@Override
public void onError(Exception e) {
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(frame, "Sorry, Dizgruntled can't download the files at this time. Please try again later", "Download Error", 0);
frame.dispose();
fVrzDown.cancel();
fRezDown.cancel();
// Clean up
removeChild(fBack);
downloadBar.cleanup();
downloadText.cleanup();
showDownloadPage();
}
@Override
public void onExtracting() {
downloadText.text("Extracting resources...");
}
@Override
public void onProgress(float f) {
downloadBar.percent(f / 2 + fRezDown.progress() / 2);
}
@Override
public void onDone() {
done.set(done.get() + 1);
}
};
// Download the REZ
fRezDown = new DownloadExtractor(new URL(rez), new File("lib/rez.zip"), new File("lib/GRUNTZ.REZ")) {
@Override
public void onError(Exception e) {
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(frame, "Sorry, Dizgruntled can't download the files at this time. Please try again later", "Download Error", 0);
frame.dispose();
fVrzDown.cancel();
fRezDown.cancel();
// Clean up
removeChild(fBack);
downloadBar.cleanup();
downloadText.cleanup();
showDownloadPage();
}
@Override
public void onExtracting() {
downloadText.text("Extracting resources...");
}
@Override
public void onProgress(float f) {
downloadBar.percent(f / 2 + fVrzDown.progress() / 2);
}
@Override
public void onDone() {
done.set(done.get() + 1);
}
};
final HyperlinkText cancelText = new HyperlinkText("Cancel Download", TextEntity.ALIGN_LEFT, fFont, Color.white, HOVER) {
/**
* Serial key
*/
private static final long serialVersionUID = 896122497881495986L;
@Override
public void click() {
fVrzDown.cancel();
fRezDown.cancel();
// Clean up
removeChild(fBack);
downloadBar.cleanup();
downloadText.cleanup();
showDownloadPage();
}
};
StartScene.this.addChild(cancelText.position(new Vector2f(60, 450)));
fVrzDown.start();
fRezDown.start();
} catch (Exception e) {
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(frame, "Sorry, Dizgruntled can't download the files at this time. Please try again later", "Download Error", 0);
frame.dispose();
// Clean up
removeChild(fBack);
downloadBar.cleanup();
downloadText.cleanup();
showDownloadPage();
}
fFinishedDownload = new Minion<FrameEvent>() {
@Override
public long run(Dispatcher<FrameEvent> dispatcher, String type, FrameEvent event) {
if (done.get() < 2) {
return Minion.CONTINUE;
} else {
// Clean up
removeChild(fBack);
downloadBar.cleanup();
downloadText.cleanup();
showMenuPage();
return Minion.FINISH;
}
}