aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Zickner <[email protected]>2004-10-24 20:40:07 +0000
committerHolger Zickner <[email protected]>2004-10-24 20:40:07 +0000
commite42d98bb00b020862eca8e2b8089028a6147739c (patch)
treea404e56667cc86abf73fac40ac789d7b4a0f64fa
parentfa1f6ac360a891685ca446ae3bbd081ad44c979c (diff)
standalone installer
-rw-r--r--build.xml16
-rw-r--r--install.xml72
-rw-r--r--lib/izpack/standalone-compiler.jarbin0 -> 1993406 bytes
-rw-r--r--src/jake2/install/Q2DataInstaller.java748
4 files changed, 836 insertions, 0 deletions
diff --git a/build.xml b/build.xml
index 83b3a1c..71306e7 100644
--- a/build.xml
+++ b/build.xml
@@ -7,6 +7,10 @@
</classpath>
</taskdef>
+
+ <taskdef name="izpack" classpath="lib/izpack/standalone-compiler.jar"
+ classname="com.izforge.izpack.ant.IzPackTask"/>
+
<!-- properties -->
<property name="version" value="cvs"/>
<property name="src" location="src"/>
@@ -120,6 +124,9 @@
<keep access="public" name="jake2.Jake2">
<method name="main(java.lang.String[])"/>
</keep>
+ <keep access="public" name="jake2.install.Q2DataInstaller">
+ <method name="main(java.lang.String[])"/>
+ </keep>
</proguard>
</target>
@@ -183,6 +190,15 @@
</zip>
</target>
+ <!-- standalone installer -->
+ <target name="installer" depends="dist">
+ <izpack input="${basedir}/install.xml"
+ output="${basedir}/Jake2-install.jar"
+ installerType="standard"
+ basedir="${dist}"
+ izPackDir="${basedir}/lib/izpack"/>
+ </target>
+
<!-- webstart -->
<target name="webstart" depends="dist">
<mkdir dir="webstart/lib"/>
diff --git a/install.xml b/install.xml
new file mode 100644
index 0000000..d21d469
--- /dev/null
+++ b/install.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
+
+
+<installation version="1.0">
+
+ <info>
+ <appname>Jake2</appname>
+ <appversion>cvs</appversion>
+ <authors>
+ <author name="Bytonic Software" email="[email protected]"/>
+ </authors>
+ <url>http://www.bytonic.de</url>
+ </info>
+
+ <guiprefs width="640" height="480" resizable="no"/>
+
+ <locale>
+ <langpack iso3="eng"/>
+ </locale>
+
+ <resources>
+ <res id="LicencePanel.licence" src="LICENSE"/>
+ <res id="InfoPanel.info" src="README"/>
+ <!-- res id="Installer.image" src="../resources/icon.png"/ -->
+ </resources>
+
+ <panels>
+ <panel classname="HelloPanel"/>
+ <panel classname="InfoPanel"/>
+ <panel classname="LicencePanel"/>
+ <panel classname="TargetPanel"/>
+ <panel classname="PacksPanel"/>
+ <panel classname="InstallPanel"/>
+ <panel classname="SimpleFinishPanel"/>
+ </panels>
+
+ <packs>
+ <pack name="Jake2" required="yes">
+ <description>Jake2 files</description>
+ <fileset dir="." targetdir="$INSTALL_PATH">
+ <include name="*"/>
+ <include name="lib/*.jar"/>
+ <exclude name="*.bat"/>
+ <exclude name="*.sh"/>
+ </fileset>
+ <executable type="jar"
+ targetfile="$INSTALL_PATH/lib/jake2.jar"
+ class="jake2.install.Q2DataInstaller"
+ stage="postinstall"
+ keep="true">
+ <args>
+ <arg value="$INSTALL_PATH"/>
+ </args>
+ </executable>
+ </pack>
+ <pack name="Linux libraries and scripts" required="yes">
+ <os name="Linux" arch="i386"/>
+ <description>jogl and joal libraries for Linux</description>
+ <file src="lib/linux" targetdir="$INSTALL_PATH/lib"/>
+ <file src="Jake2.sh" targetdir="$INSTALL_PATH"/>
+ <executable targetfile="$INSTALL_PATH/Jake2.sh" stage="never"/>
+ </pack>
+ <pack name="Windows libraries and scripts" required="yes">
+ <os family="windows" arch="i386"/>
+ <description>jogl and joal libraries for Windows</description>
+ <file src="lib/windows" targetdir="$INSTALL_PATH/lib"/>
+ <file src="Jake2.bat" targetdir="$INSTALL_PATH"/>
+ <executable targetfile="$INSTALL_PATH/Jake2.bat" stage="never"/>
+ </pack>
+ </packs>
+
+</installation>
diff --git a/lib/izpack/standalone-compiler.jar b/lib/izpack/standalone-compiler.jar
new file mode 100644
index 0000000..0ef515d
--- /dev/null
+++ b/lib/izpack/standalone-compiler.jar
Binary files differ
diff --git a/src/jake2/install/Q2DataInstaller.java b/src/jake2/install/Q2DataInstaller.java
new file mode 100644
index 0000000..d1c5764
--- /dev/null
+++ b/src/jake2/install/Q2DataInstaller.java
@@ -0,0 +1,748 @@
+/*
+ * Q2DataDialog.java
+ * Copyright (C) 2003
+ *
+ * $Id: Q2DataInstaller.java,v 1.1 2004-10-24 20:40:07 hzi Exp $
+ */
+
+package jake2.install;
+
+import jake2.Globals;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import java.util.Enumeration;
+import java.util.Vector;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import javax.imageio.ImageIO;
+import javax.swing.*;
+
+
+public class Q2DataInstaller extends javax.swing.JDialog {
+
+ static final String home = System.getProperty("user.home");
+ static final String sep = System.getProperty("file.separator");
+ String destdir;
+
+ public Q2DataInstaller(String dir) {
+ super();
+ destdir = dir;
+ initComponents();
+
+ DisplayMode mode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();
+ int x = (mode.getWidth() - getWidth()) / 2;
+ int y = (mode.getHeight() - getHeight()) / 2;
+ setLocation(x, y);
+ dir = home + sep + "jake2" + sep + "baseq2";
+ jTextField1.setText(dir);
+ }
+
+ private void initComponents() {//GEN-BEGIN:initComponents
+ java.awt.GridBagConstraints gridBagConstraints;
+
+ choosePanel = new javax.swing.JPanel();
+ statusPanel = new JPanel();
+ status = new JLabel("initializing Jake2...");
+ jTextField1 = new javax.swing.JTextField();
+ changeButton = new javax.swing.JButton();
+ cancelButton = new javax.swing.JButton();
+ exitButton = new javax.swing.JButton();
+ okButton = new javax.swing.JButton();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
+ setTitle("Jake2 - Bytonic Software");
+
+ setResizable(false);
+ addWindowListener(new java.awt.event.WindowAdapter() {
+ public void windowClosing(java.awt.event.WindowEvent evt) {
+ formWindowClosing(evt);
+ }
+ });
+
+ choosePanel.setLayout(new java.awt.GridBagLayout());
+ choosePanel.setMaximumSize(new java.awt.Dimension(400, 100));
+ choosePanel.setMinimumSize(new java.awt.Dimension(400, 100));
+ choosePanel.setPreferredSize(new java.awt.Dimension(400, 100));
+
+
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 0;
+ gridBagConstraints.gridwidth = 1;
+ gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
+ gridBagConstraints.weightx = 0;
+ gridBagConstraints.anchor = GridBagConstraints.SOUTHWEST;
+ choosePanel.add(new JLabel("baseq2 directory"),gridBagConstraints);
+
+ gridBagConstraints.gridx = 1;
+ gridBagConstraints.gridy = 0;
+ gridBagConstraints.gridwidth = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+ gridBagConstraints.insets = new java.awt.Insets(5, 2, 5, 2);
+ gridBagConstraints.weightx = 1;
+ choosePanel.add(jTextField1, gridBagConstraints);
+
+ changeButton.setText("...");
+ changeButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ changeButtonActionPerformed(evt);
+ }
+ });
+ gridBagConstraints.gridx = 3;
+ gridBagConstraints.gridy = 0;
+ gridBagConstraints.gridwidth = 1;
+ gridBagConstraints.weightx = 0;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.NONE;
+ gridBagConstraints.insets = new java.awt.Insets(5, 2, 5, 5);
+ gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
+ choosePanel.add(changeButton, gridBagConstraints);
+
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.gridwidth = 4;
+ gridBagConstraints.weightx = 0;
+ gridBagConstraints.weighty = 1;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
+ choosePanel.add(new JPanel(), gridBagConstraints);
+
+ cancelButton.setText("Cancel");
+ cancelButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ cancelButtonActionPerformed(evt);
+ }
+ });
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 2;
+ gridBagConstraints.gridwidth = 4;
+ gridBagConstraints.weighty = 0;
+ gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
+ gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
+ choosePanel.add(cancelButton, gridBagConstraints);
+
+ exitButton.setText("Exit");
+ exitButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ exitButtonActionPerformed(evt);
+ }
+ });
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 2;
+ gridBagConstraints.gridwidth = 1;
+ gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
+ choosePanel.add(exitButton, gridBagConstraints);
+
+ okButton.setText("OK");
+ okButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ okButtonActionPerformed(evt);
+ }
+ });
+ gridBagConstraints.gridx = 2;
+ gridBagConstraints.gridy = 2;
+ gridBagConstraints.gridwidth = 2;
+ gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
+ choosePanel.add(okButton, gridBagConstraints);
+
+
+ Jake2Canvas c = new Jake2Canvas();
+ getContentPane().add(c, BorderLayout.CENTER);
+
+ statusPanel.setLayout(new java.awt.GridBagLayout());
+ statusPanel.setMaximumSize(new java.awt.Dimension(400, 100));
+ statusPanel.setMinimumSize(new java.awt.Dimension(400, 100));
+ statusPanel.setPreferredSize(new java.awt.Dimension(400, 100));
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 0;
+ gridBagConstraints.gridwidth = 1;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
+ gridBagConstraints.weightx = 1.0;
+ statusPanel.add(status, gridBagConstraints);
+ getContentPane().add(statusPanel, java.awt.BorderLayout.SOUTH);
+
+ progressPanel = new ProgressPanel(this);
+ installPanel = new InstallPanel(this);
+ notFoundPanel = new NotFoundPanel(this);
+
+ pack();
+ }
+
+ private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
+ showNotFoundPanel();
+ }
+
+ private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {
+ System.exit(1);
+ dispose();
+ }
+
+ private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
+
+ synchronized(this) {
+ notifyAll();
+ }
+ }
+
+ private void changeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeButtonActionPerformed
+ JFileChooser chooser = new JFileChooser();
+ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
+ chooser.setMultiSelectionEnabled(false);
+ chooser.setDialogTitle("choose a valid baseq2 directory");
+ chooser.showDialog(this, "OK");
+
+ dir = null;
+ try {
+ dir = chooser.getSelectedFile().getCanonicalPath();
+ } catch (Exception e) {}
+ if (dir != null) jTextField1.setText(dir);
+ else dir = jTextField1.getText();
+
+ }//GEN-LAST:event_changeButtonActionPerformed
+
+ private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
+ System.exit(1);
+ dispose();
+ }//GEN-LAST:event_formWindowClosing
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton changeButton;
+ private javax.swing.JButton exitButton;
+ private javax.swing.JButton cancelButton;
+ private Jake2Canvas canvas;
+ private javax.swing.JPanel choosePanel;
+ private JPanel statusPanel;
+ private ProgressPanel progressPanel;
+ private InstallPanel installPanel;
+ private NotFoundPanel notFoundPanel;
+ private JLabel status;
+ private javax.swing.JTextField jTextField1;
+ private javax.swing.JButton okButton;
+ // End of variables declaration//GEN-END:variables
+
+ private String dir;
+
+ void showChooseDialog() {
+ getContentPane().remove(statusPanel);
+ getContentPane().remove(progressPanel);
+ getContentPane().remove(installPanel);
+ getContentPane().remove(notFoundPanel);
+ getContentPane().add(choosePanel, BorderLayout.SOUTH);
+ validate();
+ repaint();
+ }
+
+ void showStatus() {
+ getContentPane().remove(choosePanel);
+ getContentPane().remove(installPanel);
+ getContentPane().add(statusPanel, BorderLayout.SOUTH);
+ validate();
+ repaint();
+ }
+
+ void showProgressPanel() {
+ getContentPane().remove(choosePanel);
+ getContentPane().remove(installPanel);
+ getContentPane().remove(notFoundPanel);
+ getContentPane().add(progressPanel, BorderLayout.SOUTH);
+ validate();
+ repaint();
+ }
+
+ void showInstallPanel() {
+ getContentPane().remove(choosePanel);
+ getContentPane().remove(statusPanel);
+ getContentPane().remove(notFoundPanel);
+ getContentPane().add(installPanel, BorderLayout.SOUTH);
+ validate();
+ repaint();
+ }
+
+ void showNotFoundPanel() {
+ getContentPane().remove(choosePanel);
+ getContentPane().remove(installPanel);
+ getContentPane().remove(statusPanel);
+ getContentPane().add(notFoundPanel, BorderLayout.SOUTH);
+ validate();
+ repaint();
+ }
+
+ void setStatus(String text) {
+ status.setText(text);
+ }
+
+ void installQ2Data() {
+ showNotFoundPanel();
+ synchronized(this) {
+ try {
+ wait();
+ } catch (Exception e) {}
+ }
+ setVisible(false);
+ dispose();
+
+ }
+
+ static class Jake2Canvas extends Canvas {
+ private Image image;
+ Jake2Canvas() {
+ setSize(400, 200);
+ try {
+ image = ImageIO.read(getClass().getResource("/splash.png"));
+ } catch (Exception e) {}
+
+ }
+
+
+ /* (non-Javadoc)
+ * @see java.awt.Component#paint(java.awt.Graphics)
+ */
+ public void paint(Graphics g) {
+ g.drawImage(image, 0, 0, null);
+ }
+
+ }
+
+ static class NotFoundPanel extends JPanel {
+
+ private Q2DataInstaller parent;
+ private JCheckBox install;
+ private JButton exit;
+ private JButton ok;
+ private JLabel message;
+
+ NotFoundPanel(Q2DataInstaller d) {
+ parent = d;
+ initComponents();
+ }
+
+ private void initComponents() {
+ GridBagConstraints constraints = new GridBagConstraints();
+ setLayout(new GridBagLayout());
+ Dimension d = new Dimension(400, 100);
+ setMinimumSize(d);
+ setMaximumSize(d);
+ setPreferredSize(d);
+
+ message = new JLabel(" ");
+ message.setForeground(Color.RED);
+ constraints.gridx = 0;
+ constraints.gridy = 0;
+ constraints.gridwidth = 2;
+ constraints.insets = new Insets(5, 5, 2, 5);
+ constraints.anchor = GridBagConstraints.CENTER;
+ add(message, constraints);
+
+ constraints.gridx = 1;
+ constraints.gridy = 1;
+ constraints.gridwidth = 2;
+ constraints.weightx = 1;
+ constraints.fill = GridBagConstraints.HORIZONTAL;
+ constraints.insets = new Insets(0, 2, 0, 5);
+ constraints.anchor = GridBagConstraints.WEST;
+
+
+ constraints.gridx = 1;
+ constraints.gridy = 2;
+ JLabel label = new JLabel("install Quake2 demo data");
+ label.addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ install.setSelected(!install.isSelected());
+ }
+ });
+ add(label, constraints);
+
+
+ install = new JCheckBox();
+ install.setSelected(true);
+
+ constraints.gridx = 0;
+ constraints.gridy = 1;
+ constraints.gridwidth = 1;
+ constraints.weightx = 0;
+ constraints.insets = new Insets(0, 5, 0, 2);
+ constraints.fill = GridBagConstraints.NONE;
+ constraints.anchor = GridBagConstraints.EAST;
+
+
+ constraints.gridx = 0;
+ constraints.gridy = 2;
+ add(install, constraints);
+
+ constraints.gridx = 0;
+ constraints.gridy = 3;
+ constraints.gridwidth = 2;
+ constraints.weighty = 1;
+ constraints.insets = new Insets(5, 5, 5, 5);
+ constraints.fill = GridBagConstraints.NONE;
+ constraints.anchor = GridBagConstraints.SOUTHWEST;
+ exit = new JButton("Exit");
+ exit.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ System.exit(0);
+ }});
+ add(exit, constraints);
+
+ constraints.gridx = 2;
+ constraints.gridy = 3;
+ constraints.gridwidth = 1;
+ constraints.anchor = GridBagConstraints.SOUTHEAST;
+ ok = new JButton("OK");
+ ok.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ ok();
+ }});
+ add(ok, constraints);
+ }
+
+ private void ok() {
+ if (!install.isSelected()) System.exit(0);
+ parent.progressPanel.destDir = parent.destdir;
+ parent.progressPanel.mirror = "q2-314-demo-x86.exe";
+ parent.showProgressPanel();
+ new Thread(parent.progressPanel).start();
+ }
+ }
+
+ static class InstallPanel extends JPanel {
+
+ private Vector mirrorNames = new Vector();
+ private Vector mirrorLinks = new Vector();
+ private Q2DataInstaller parent;
+ private JComboBox mirrorBox;
+ private JTextField destDir;
+ private JButton cancel;
+ private JButton exit;
+ private JButton install;
+ private JButton choose;
+
+ public InstallPanel(Q2DataInstaller d) {
+ initComponents();
+ String dir = Q2DataInstaller.home + Q2DataInstaller.sep + "jake2";
+ destDir.setText(dir);
+ initMirrors();
+ parent = d;
+ }
+
+ private void initComponents() {
+ GridBagConstraints constraints = new GridBagConstraints();
+ setLayout(new GridBagLayout());
+ Dimension d = new Dimension(400, 100);
+ setMinimumSize(d);
+ setMaximumSize(d);
+ setPreferredSize(d);
+
+ constraints.gridx = 0;
+ constraints.gridy = 0;
+ constraints.insets = new Insets(5, 5, 0, 5);
+ constraints.anchor = GridBagConstraints.SOUTHWEST;
+ add(new JLabel("download mirror"), constraints);
+
+ constraints.gridx = 0;
+ constraints.gridy = 1;
+ constraints.insets = new Insets(5, 5, 5, 5);
+ add(new JLabel("destination directory"), constraints);
+
+ constraints.gridx = 1;
+ constraints.gridy = 0;
+ constraints.weightx = 1;
+ constraints.gridwidth = 3;
+ constraints.insets = new Insets(5, 5, 0, 5);
+ constraints.fill = GridBagConstraints.HORIZONTAL;
+ mirrorBox = new JComboBox();
+ add(mirrorBox, constraints);
+
+ constraints.gridx = 1;
+ constraints.gridy = 1;
+ constraints.gridwidth = 2;
+ constraints.fill = GridBagConstraints.BOTH;
+ constraints.insets = new Insets(5, 5, 5, 5);
+ destDir = new JTextField();
+ add(destDir, constraints);
+
+ constraints.gridx = 3;
+ constraints.gridy = 1;
+ constraints.weightx = 0;
+ constraints.gridwidth = 1;
+ constraints.fill = GridBagConstraints.NONE;
+ choose = new JButton("...");
+ choose.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ choose();
+ }});
+ add(choose, constraints);
+
+ constraints.gridx = 0;
+ constraints.gridy = 2;
+ constraints.gridwidth = 1;
+ constraints.weighty = 1;
+ constraints.fill = GridBagConstraints.NONE;
+ exit = new JButton("Exit");
+ exit.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ exit();
+ }});
+ add(exit, constraints);
+
+ constraints.gridx = 0;
+ constraints.gridy = 2;
+ constraints.gridwidth = 4;
+ constraints.anchor = GridBagConstraints.SOUTH;
+ cancel = new JButton("Cancel");
+ cancel.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ cancel();
+ }});
+ add(cancel, constraints);
+
+ constraints.gridx = 2;
+ constraints.gridy = 2;
+ constraints.gridwidth = 2;
+ constraints.anchor = GridBagConstraints.SOUTHEAST;
+ install = new JButton("Install");
+ install.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ install();
+ }});
+ add(install, constraints);
+ }
+
+ private void readMirrors() {
+ InputStream in = getClass().getResourceAsStream("/mirrors");
+ BufferedReader r = new BufferedReader(new InputStreamReader(in));
+ try {
+ int i = 0;
+ while (true) {
+ String name = r.readLine();
+ String value = r.readLine();
+ if (name == null || value == null) break;
+ mirrorNames.add(name);
+ mirrorLinks.add(value);
+ }
+ } catch (Exception e) {}
+ finally {
+ try {
+ r.close();
+ } catch (Exception e1) {}
+ try {
+ in.close();
+ } catch (Exception e1) {}
+ }
+ }
+
+ private void initMirrors() {
+ readMirrors();
+ for (int i = 0; i < mirrorNames.size(); i++) {
+ mirrorBox.addItem(mirrorNames.get(i));
+ }
+ int i = Globals.rnd.nextInt(mirrorNames.size());
+ mirrorBox.setSelectedIndex(i);
+ }
+
+ private void cancel() {
+ parent.showNotFoundPanel();
+ }
+
+ private void install() {
+ parent.progressPanel.destDir = destDir.getText();
+ parent.progressPanel.mirror = (String)mirrorLinks.get(mirrorBox.getSelectedIndex());
+ parent.showProgressPanel();
+ new Thread(parent.progressPanel).start();
+ }
+
+ private void exit() {
+ System.exit(0);
+ }
+
+ private void choose() {
+ JFileChooser chooser = new JFileChooser();
+ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
+ chooser.setMultiSelectionEnabled(false);
+ chooser.setDialogTitle("choose destination directory");
+ chooser.showDialog(this, "OK");
+
+ String dir = null;
+ try {
+ dir = chooser.getSelectedFile().getCanonicalPath();
+ } catch (Exception e) {}
+ if (dir != null) destDir.setText(dir);
+ }
+ }
+
+ static class ProgressPanel extends JPanel implements Runnable {
+
+ static byte[] buf = new byte[8192];
+ String destDir;
+ String mirror;
+
+ JProgressBar progress = new JProgressBar();
+ JLabel label = new JLabel("");
+ JButton cancel = new JButton("Cancel");
+ Q2DataInstaller parent;
+ boolean running;
+
+ public ProgressPanel(Q2DataInstaller d) {
+ initComponents();
+ parent = d;
+ }
+
+ void initComponents() {
+ progress.setMinimum(0);
+ progress.setMaximum(100);
+ progress.setStringPainted(true);
+ setLayout(new GridBagLayout());
+ GridBagConstraints gridBagConstraints = new GridBagConstraints();
+
+ gridBagConstraints = new GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 0;
+ gridBagConstraints.gridwidth = 1;
+ gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
+ gridBagConstraints.insets = new Insets(5, 10, 5, 10);
+ gridBagConstraints.weightx = 1.0;
+ gridBagConstraints.anchor = GridBagConstraints.SOUTH;
+ add(label, gridBagConstraints);
+
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.anchor = GridBagConstraints.NORTH;
+ add(progress, gridBagConstraints);
+
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.anchor = GridBagConstraints.SOUTH;
+ gridBagConstraints.fill = GridBagConstraints.NONE;
+ gridBagConstraints.weighty = 1;
+ gridBagConstraints.weightx = 0;
+ cancel.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ cancel();
+ }});
+ add(cancel, gridBagConstraints);
+
+ Dimension d = new Dimension(400, 100);
+ setMinimumSize(d);
+ setMaximumSize(d);
+ setPreferredSize(d);
+ }
+
+ void cancel() {
+ synchronized(this) {
+ running = false;
+ }
+ }
+
+ public void run() {
+ synchronized(this) {
+ running = true;
+ }
+
+ File dir = null;
+ try {
+ dir = new File(destDir);
+ dir.mkdirs();
+ }
+ catch (Exception e) {}
+ try {
+ if (!dir.isDirectory() || !dir.canWrite()) {
+ endInstall("can't write to " + destDir);
+ return;
+ }
+ }
+ catch (Exception e) {
+ endInstall(e.getMessage());
+ return;
+ }
+
+ try {
+ installData(mirror);
+ } catch (Exception e) {
+ endInstall(e.getMessage());
+ return;
+ }
+
+ endInstall("installation successful");
+ }
+
+
+ void installData(String filename) throws Exception {
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ ZipFile f = new ZipFile(filename);
+ Enumeration e = f.entries();
+ while (e.hasMoreElements()) {
+ ZipEntry entry = (ZipEntry)e.nextElement();
+ String name = entry.getName();
+ int i;
+ if ((i = name.indexOf("/baseq2")) > -1 && name.indexOf(".dll") == -1) {
+ name = destDir + name.substring(i);
+ File outFile = new File(name);
+ if (entry.isDirectory()) {
+ outFile.mkdirs();
+ } else {
+ label.setText("installing " + outFile.getName());
+ progress.setMaximum((int)entry.getSize()/1024);
+ progress.setValue(0);
+ outFile.getParentFile().mkdirs();
+ out = new FileOutputStream(outFile);
+ in = f.getInputStream(entry);
+ copyStream(in, out);
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw e;
+ } finally {
+ try {in.close();} catch (Exception e1) {}
+ try {out.close();} catch (Exception e1) {}
+ }
+ }
+
+ void endInstall(String message) {
+ parent.notFoundPanel.message.setText(message);
+ parent.dir = destDir + "/baseq2";
+ parent.showChooseDialog();
+ parent.okButtonActionPerformed(null);
+ }
+
+ void copyStream(InputStream in, OutputStream out) throws Exception {
+ try {
+ int c = 0;
+ int l;
+ while ((l = in.read(buf)) > 0) {
+ if (!running) throw new Exception("installation canceled");
+ out.write(buf, 0, l);
+ c += l;
+ int k = c / 1024;
+ progress.setValue(k);
+ progress.setString(k + "/" + progress.getMaximum() + " KB");
+ }
+ } catch (Exception e) {
+ throw e;
+ } finally {
+ try {
+ in.close();
+ } catch (Exception e) {}
+ try {
+ out.close();
+ } catch (Exception e) {}
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+
+ if (args.length != 1) System.exit(1);
+
+ Q2DataInstaller installer = new Q2DataInstaller(args[0]);
+ installer.setVisible(true);
+ installer.installQ2Data();
+
+ System.exit(0);
+ }
+}