fDownInfo = new Sprite("downinfo");
addChild(fDownInfo.position(new Vector2f(60, 115)));
final SyncObject<Integer> done = new SyncObject<Integer>(0);
fDownYes = new HyperlinkText("I have already installed Gruntz", TextEntity.ALIGN_LEFT, fFont, Color.white, HOVER) {
/**
* Serial key
*/
private static final long serialVersionUID = 3255208115397490201L;
@Override
public void click() {
// Locate Gruntz
JFileChooser loader = new JFileChooser();
loader.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
loader.setDialogTitle("Locate Gruntz game folder");
int r = loader.showOpenDialog(null);
if (r == JFileChooser.APPROVE_OPTION) {
File f = loader.getSelectedFile();
File rez = new File(f.getAbsolutePath() + "/GRUNTZ.REZ");
File vrz = new File(f.getAbsolutePath() + "/GRUNTZ.VRZ");
// TODO: use zzz file
//File zzz = new File(f.getAbsolutePath() + "/GRUNTZ.ZZZ");
boolean copy = false;
if (!rez.exists() || !vrz.exists()) {
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(frame, "Sorry, the folder selected doesn't appear to have the resources\nrequired to play Dizgruntled. Please try again or select the\noption to download the resources.", "Resources Not Found", 0);
frame.dispose();
}/* else if (!zzz.exists()) {
r = JOptionPane.showConfirmDialog(null, "Dizgruntled couldn't find the Gruntz 1.01 patch with your game. Please note that\nwhile you can play Dizgruntled without this patch, a few of the original levels\nare incorrect. Would you like to continue without the patch?", "Patch Not Found", JOptionPane.YES_NO_OPTION);
if (r == 0) copy = true;
} */else {
copy = true;
}
if (copy) {
try {
copyFile(rez, new File("lib/GRUNTZ.REZ"));
copyFile(vrz, new File("lib/GRUNTZ.VRZ"));
// Remove Hyperlinks
fDownYes.cleanup();
fDownYes = null;
fDownNo.cleanup();
fDownNo = null;
fDownInfo.cleanup();
fDownInfo = null;
// Continue
removeChild(fBack);
showMenuPage();
} catch (IOException e) {
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(frame, "Sorry, Dizgruntled couldn't copy over the required resource files GRUNTZ.REZ and GRUNTZ.VRZ. Please check they exist and are not in use.", "Copy Error", 0);
frame.dispose();
}
}
}
}
};
addChild(fDownYes.position(new Vector2f(65, 450)));
fDownNo = new HyperlinkText("I haven't previously installed Gruntz", TextEntity.ALIGN_LEFT, fFont, Color.white, HOVER) {
/**
* Serial key
*/
private static final long serialVersionUID = -4682660357282196588L;
@Override
public void click() {
// Remove Hyperlinks
fDownYes.cleanup();
fDownYes = null;
fDownNo.cleanup();
fDownNo = null;
fDownInfo.cleanup();
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) {