import b;
import f;
import h;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Vector;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
public class VNC extends MIDlet
implements CommandListener, Runnable {
public RecordStore x;
public RecordStore p;
public Vector g;
public Display o;
public f a;
public h s;
public StreamConnection j;
public Thread t;
private Form r;
private Form q;
private TextField i;
private TextField k;
private Command v;
private Command l;
private Command w;
private Command m;
private Command n;
private ChoiceGroup e;
private String h;
private int f;
private Gauge c;
private ChoiceGroup u;
public int d;
public Image b;
public int y;
public void b() {
d++;
c.setValue(d);
}
public void run() {
if(i.getString() == null || i.getString() != null && i.getString().length() < 1) {
Alert alert = new Alert("No Host!", "The host box is blank\nSo many problems it will cause\nPlease fill it in", null, AlertType.ERROR);
Alert _tmp = alert;
alert.setTimeout(-2);
o.setCurrent(alert, r);
return;
}
if(k.getString() != null && k.getString().length() < 6 && k.getString().length() != 0) {
Alert alert1 = new Alert("Password Problem", "Password is too short\nGreater than six letter it must\nPlease write some more.", null, AlertType.ERROR);
Alert _tmp1 = alert1;
alert1.setTimeout(-2);
o.setCurrent(alert1, r);
return;
}
Thread.currentThread();
Thread.yield();
b();
h = i.getString();
if(h.indexOf(":") >= 0) {
try {
f = Integer.parseInt(h.substring(h.indexOf(":") + 1, h.length()));
}
catch(NumberFormatException numberformatexception) {
Alert alert2 = new Alert("Problem Connecting", "The format is wrong\nI don't know where to connect\n" + h.substring(h.indexOf(":") + 1, h.length()) + "is not a number", null, AlertType.ERROR);
Alert _tmp2 = alert2;
alert2.setTimeout(-2);
o.setCurrent(alert2, r);
return;
}
h = h.substring(0, h.indexOf(":"));
}
if(f < 5900)
f += 5900;
try {
j = (StreamConnection)Connector.open("socket://" + h + ":" + f, 3);
b();
}
catch(IllegalArgumentException illegalargumentexception) {
Alert alert3 = new Alert("Problem Connecting", "#format_is_wrongPlease double check\n" + illegalargumentexception.toString(), null, AlertType.ERROR);
Alert _tmp3 = alert3;
alert3.setTimeout(-2);
o.setCurrent(alert3, r);
return;
}
catch(ConnectionNotFoundException connectionnotfoundexception) {
Alert alert4 = new Alert("Problem Connecting", "Unable to connect\n" + (connectionnotfoundexception.getMessage() != null ? connectionnotfoundexception.getMessage() : "Is the host correct?") + "?", null, AlertType.ERROR);
Alert _tmp4 = alert4;
alert4.setTimeout(-2);
o.setCurrent(alert4, r);
return;
}
catch(IOException ioexception) {
Alert alert5 = new Alert("Problem Connecting", "Unknown problem\n" + ioexception.toString(), null, AlertType.ERROR);
Alert _tmp5 = alert5;
alert5.setTimeout(-2);
o.setCurrent(alert5, r);
return;
}
catch(Throwable throwable) {
Alert alert6 = new Alert("Problem Connecting", "Unknown problem\n" + throwable.toString(), null, AlertType.ERROR);
Alert _tmp6 = alert6;
alert6.setTimeout(-2);
o.setCurrent(alert6, r);
return;
}
byte abyte0[] = k.getString().getBytes();
byte abyte1[] = new byte[abyte0.length + 1 <= 8 ? 8 : abyte0.length + 1];
System.arraycopy(abyte0, 0, abyte1, 0, abyte0.length);
a = new f(this);
b();
try {
s = new h(j.openDataInputStream(), j.openOutputStream(), abyte1, a, u.isSelected(0), u.isSelected(1));
}
catch(IOException ioexception1) {
Alert alert7 = new Alert("Problem Connecting", "Unknown problem\n" + ioexception1.toString(), null, AlertType.ERROR);
Alert _tmp7 = alert7;
alert7.setTimeout(-2);
o.setCurrent(alert7, r);
return;
}
catch(Throwable throwable1) {
Alert alert8 = new Alert("Problem Connecting", "Unknown problem\n" + throwable1.toString(), null, AlertType.ERROR);
Alert _tmp8 = alert8;
alert8.setTimeout(-2);
o.setCurrent(alert8, r);
return;
}
t = new Thread(s);
t.start();
a();
b();
try {
x.closeRecordStore();
}
catch(Throwable throwable2) { }
}
public void commandAction(Command command, Displayable displayable) {
if(command == v) {
o.setCurrent(q);
(new Thread(this)).start();
} else
if(command == l)
try {
String s1 = i.getString() + "|" + k.getString();
b b2 = new b(i.getString(), 8, 10, x.addRecord(s1.getBytes(), 0, s1.length()));
g.addElement(b2);
r.addCommand(b2);
}
catch(Throwable throwable) {
System.err.println("Save: " + throwable);
}
else
if(command == w) {
Form form = new Form("Manage Hosts");
e = new ChoiceGroup("Host:", 1);
try {
int i1 = g.size();
for(int k1 = 0; k1 < i1; k1++) {
b b3 = (b)g.elementAt(k1);
e.append(b3.a + " " + b3.getLabel(), null);
}
}
catch(Throwable throwable2) {
System.err.println(throwable2);
}
form.setCommandListener(this);
form.append(e);
form.addCommand(m);
form.addCommand(n);
o.setCurrent(form);
} else
if(command == m) {
String s2 = e.getString(e.getSelectedIndex());
int j1 = Integer.parseInt(s2.substring(0, s2.indexOf(" ")));
e.delete(e.getSelectedIndex());
try {
x.deleteRecord(j1);
}
catch(Throwable throwable3) {
System.err.println("delete" + throwable3);
}
for(int l1 = g.size() - 1; l1 >= 0; l1--)
if(((b)g.elementAt(l1)).a == j1) {
r.removeCommand((b)g.elementAt(l1));
g.removeElementAt(l1);
}
} else
if(command == n)
o.setCurrent(r);
else
if(command instanceof b)
try {
o.setCurrent(q);
b b1 = (b)command;
String s3 = new String(x.getRecord(b1.a));
i.setString(s3.substring(0, s3.indexOf("|")));
k.setString(s3.substring(s3.indexOf("|") + 1, s3.length()));
(new Thread(this)).start();
}
catch(Throwable throwable1) {
System.err.println(throwable1);
}
}
public VNC() {
x = null;
p = null;
g = new Vector();
r = new Form("VNC");
q = new Form("VNC - Connecting");
i = new TextField("Host", "", 25, 0);
k = new TextField("Password", "", 14, 0x10000);
v = new Command("Connect", 4, 0);
l = new Command("Add", 8, 9);
w = new Command("Manage", 8, 11);
m = new Command("Delete", 4, 0);
n = new Command("Back", 2, 1);
e = null;
h = "";
f = 5900;
c = new Gauge("Connecting", false, 5, 0);
u = new ChoiceGroup("", 2);
d = 0;
b = null;
y = 0;
o = Display.getDisplay(this);
r.append(i);
r.append(k);
r.append(u);
r.addCommand(v);
r.addCommand(l);
r.addCommand(w);
r.setCommandListener(this);
u.append("Share Desktop", null);
u.append("NCM", null);
try {
x = RecordStore.openRecordStore("hosts", true);
b b1;
for(RecordEnumeration recordenumeration = x.enumerateRecords(null, null, false); recordenumeration.hasNextElement(); g.addElement(b1)) {
int i1 = recordenumeration.nextRecordId();
String s1 = new String(x.getRecord(i1));
String s2 = s1;
if(s1.indexOf("|") > 0)
s2 = s1.substring(0, s1.indexOf("|"));
b1 = new b(s2, 8, 10, i1);
r.addCommand(b1);
}
p = RecordStore.openRecordStore("options", true);
RecordEnumeration recordenumeration1 = p.enumerateRecords(null, null, false);
if(recordenumeration1.hasNextElement()) {
y = recordenumeration1.nextRecordId();
byte abyte0[] = p.getRecord(y);
if(abyte0 != null && abyte0.length > 0) {
System.out.println(abyte0.length);
u.setSelectedIndex(0, (abyte0[0] & 1) == 1);
u.setSelectedIndex(1, (abyte0[0] & 2) == 2);
}
} else {
y = -100;
}
b = Image.createImage("/about.png");
q.setCommandListener(this);
q.append(b);
q.append(c);
}
catch(Throwable throwable) {
System.err.println("VNC() : t " + throwable.toString());
throwable.printStackTrace();
}
}
public void pauseApp() {
}
public void destroyApp(boolean flag) throws MIDletStateChangeException {
if(a != null)
a.a();
try {
byte abyte0[] = new byte[1];
abyte0[0] = (byte)((u.isSelected(0) ? 1 : 0) + (u.isSelected(1) ? 2 : 0));
System.out.println(abyte0[0]);
if(y != -100) {
p.setRecord(y, abyte0, 0, 1);
System.out.println("hi");
} else {
p.addRecord(abyte0, 0, 1);
}
x.closeRecordStore();
p.closeRecordStore();
}
catch(Throwable throwable) {
System.err.println(throwable.toString());
}
}
public void startApp() throws MIDletStateChangeException {
if(a == null)
o.setCurrent(r);
else
o.setCurrent(a);
}
private void a() {
r = null;
q = null;
i = null;
k = null;
v = null;
l = null;
w = null;
m = null;
n = null;
e = null;
h = "";
System.gc();
}
}