aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/qcommon
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-10-08 10:44:05 +0200
committerSven Gothel <[email protected]>2012-10-08 10:44:05 +0200
commitf5612e7dfc635359f15b402c2ee9022a5e703a9d (patch)
tree0b54287f72b87a2693f38ed308195e928311a093 /src/jake2/qcommon
parent3119458b32c8620f971ba44488389ddf03b2d705 (diff)
Simple NEWT port: Remove AWT dependencies in Jake2 / JOGL / Fast (default mode) - Prepare for ES2NEWT
- Removed AWT init dialog, replaced w/ UI less auto install if n/a @ default location: $HOME/Jake2/baseq2 - JOGL GL2 Renderer 'joglgl2' - JOGL ES2 Renderer 'jogles2' (TBD) - Replaced JOGLKBD (AWT) w/ NEWTKBD - JOGL* Renderer using NEWT
Diffstat (limited to 'src/jake2/qcommon')
-rw-r--r--src/jake2/qcommon/Q2DataDialog.java3
-rw-r--r--src/jake2/qcommon/Q2DataTool.java191
-rw-r--r--src/jake2/qcommon/Qcommon.java39
3 files changed, 214 insertions, 19 deletions
diff --git a/src/jake2/qcommon/Q2DataDialog.java b/src/jake2/qcommon/Q2DataDialog.java
index ffb5842..9e3b318 100644
--- a/src/jake2/qcommon/Q2DataDialog.java
+++ b/src/jake2/qcommon/Q2DataDialog.java
@@ -309,9 +309,6 @@ public class Q2DataDialog extends javax.swing.JDialog {
}
- /* (non-Javadoc)
- * @see java.awt.Component#paint(java.awt.Graphics)
- */
public void paint(Graphics g) {
g.drawImage(image, 0, 0, null);
}
diff --git a/src/jake2/qcommon/Q2DataTool.java b/src/jake2/qcommon/Q2DataTool.java
new file mode 100644
index 0000000..b12acfc
--- /dev/null
+++ b/src/jake2/qcommon/Q2DataTool.java
@@ -0,0 +1,191 @@
+/*
+ * Q2DataDialog.java
+ * Copyright (C) 2003
+ */
+package jake2.qcommon;
+
+import java.io.*;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Enumeration;
+import java.util.Vector;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+public class Q2DataTool {
+ static final String home = System.getProperty("user.home");
+ static final String sep = System.getProperty("file.separator");
+ static final String dataDir = home + sep + "Jake2";
+ static final String baseq2Dir = dataDir + sep + "baseq2";
+
+ private Vector<String> mirrorNames = new Vector<String>();
+ private Vector<String> mirrorLinks = new Vector<String>();
+ private byte[] buf = new byte[8192];
+
+ public void testQ2Data() {
+ initMirrors();
+ for(int i=0; !isAvail() && i<mirrorNames.size(); i++) {
+ try {
+ install(i);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ void destroy() {
+
+ }
+
+ void setStatus(String text) {
+ System.err.println(text);
+ System.err.println();
+ }
+
+ boolean isAvail() {
+ Cvar.Set("cddir", baseq2Dir);
+ FS.setCDDir();
+ return null != FS.LoadFile("pics/colormap.pcx");
+ }
+
+ void initMirrors() {
+ InputStream in = getClass().getResourceAsStream("/mirrors");
+ BufferedReader r = new BufferedReader(new InputStreamReader(in));
+ try {
+ 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) {}
+ }
+ }
+
+ void install(int mirrorIdx) {
+ final String mirrorName = mirrorNames.get(mirrorIdx);
+ final String mirror = mirrorLinks.get(mirrorIdx);
+ InputStream in = null;
+ OutputStream out = null;
+ File outFile = null;
+
+ setStatus("downloading from "+mirrorName+": <"+mirror+">");
+
+ File dir = null;
+ try {
+ dir = new File(dataDir);
+ dir.mkdirs();
+ }
+ catch (Exception e) {}
+ try {
+ if (!dir.isDirectory() || !dir.canWrite()) {
+ setStatus("can't write to " + dataDir);
+ return;
+ }
+ }
+ catch (Exception e) {
+ setStatus(e.getMessage());
+ return;
+ }
+
+ try {
+ URL url = new URL(mirror);
+ URLConnection conn = url.openConnection();
+ // int length = conn.getContentLength();
+
+ in = conn.getInputStream();
+
+ outFile = File.createTempFile("Jake2Data", ".zip");
+ outFile.deleteOnExit();
+ out = new FileOutputStream(outFile);
+
+ copyStream(in, out);
+ } catch (Exception e) {
+ setStatus(e.getMessage());
+ return;
+ } finally {
+ try {
+ in.close();
+ } catch (Exception e) {}
+ try {
+ out.close();
+ } catch (Exception e) {}
+ }
+
+ try {
+ installData(outFile.getCanonicalPath());
+ } catch (Exception e) {
+ setStatus(e.getMessage());
+ return;
+ }
+
+
+ try {
+ if (outFile != null) outFile.delete();
+ } catch (Exception e) {}
+
+ setStatus("installation successful from "+mirrorName+": <"+mirror+">");
+ }
+
+
+ void installData(String filename) throws Exception {
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ ZipFile f = new ZipFile(filename);
+ Enumeration<? extends ZipEntry> 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 = dataDir + name.substring(i);
+ File outFile = new File(name);
+ if (entry.isDirectory()) {
+ outFile.mkdirs();
+ } else {
+ setStatus("installing " + outFile.getName());
+ 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 copyStream(InputStream in, OutputStream out) throws Exception {
+ try {
+ // int c = 0;
+ int l;
+ while ((l = in.read(buf)) > 0) {
+ out.write(buf, 0, l);
+ // c += l;
+ }
+ } catch (Exception e) {
+ throw e;
+ } finally {
+ try {
+ in.close();
+ } catch (Exception e) {}
+ try {
+ out.close();
+ } catch (Exception e) {}
+ }
+ }
+
+}
diff --git a/src/jake2/qcommon/Qcommon.java b/src/jake2/qcommon/Qcommon.java
index bd4ca88..79f6f29 100644
--- a/src/jake2/qcommon/Qcommon.java
+++ b/src/jake2/qcommon/Qcommon.java
@@ -74,21 +74,24 @@ public final class Qcommon extends Globals {
Cbuf.AddEarlyCommands(false);
Cbuf.Execute();
- if (Globals.dedicated.value != 1.0f)
- Jake2.Q2Dialog.setStatus("initializing filesystem...");
+ if (Globals.dedicated.value != 1.0f) {
+ Jake2.q2DataTool.setStatus("initializing filesystem...");
+ }
FS.InitFilesystem();
- if (Globals.dedicated.value != 1.0f)
- Jake2.Q2Dialog.setStatus("loading config...");
+ if (Globals.dedicated.value != 1.0f) {
+ Jake2.q2DataTool.setStatus("loading config...");
+ }
reconfigure(false);
FS.setCDDir(); // use cddir from config.cfg
FS.markBaseSearchPaths(); // mark the default search paths
-
- if (Globals.dedicated.value != 1.0f)
- Jake2.Q2Dialog.testQ2Data(); // test for valid baseq2
+
+ if (Globals.dedicated.value != 1.0f) {
+ Jake2.q2DataTool.testQ2Data(); // test for valid baseq2
+ }
reconfigure(true); // reload default.cfg and config.cfg
@@ -114,18 +117,21 @@ public final class Qcommon extends Globals {
Cvar.Get("version", s, CVAR_SERVERINFO | CVAR_NOSET);
- if (Globals.dedicated.value != 1.0f)
- Jake2.Q2Dialog.setStatus("initializing network subsystem...");
+ if (Globals.dedicated.value != 1.0f) {
+ Jake2.q2DataTool.setStatus("initializing network subsystem...");
+ }
NET.Init(); //ok
Netchan.Netchan_Init(); //ok
- if (Globals.dedicated.value != 1.0f)
- Jake2.Q2Dialog.setStatus("initializing server subsystem...");
+ if (Globals.dedicated.value != 1.0f) {
+ Jake2.q2DataTool.setStatus("initializing server subsystem...");
+ }
SV_MAIN.SV_Init(); //ok
- if (Globals.dedicated.value != 1.0f)
- Jake2.Q2Dialog.setStatus("initializing client subsystem...");
+ if (Globals.dedicated.value != 1.0f) {
+ Jake2.q2DataTool.setStatus("initializing client subsystem...");
+ }
CL.Init();
@@ -148,9 +154,10 @@ public final class Qcommon extends Globals {
// save config when configuration is completed
CL.WriteConfiguration();
-
- if (Globals.dedicated.value != 1.0f)
- Jake2.Q2Dialog.dispose();
+
+ if (Globals.dedicated.value != 1.0f) {
+ Jake2.q2DataTool.destroy();
+ }
} catch (longjmpException e) {
Sys.Error("Error during initialization");