package NET.worlds.scape; import NET.worlds.console.Main; import NET.worlds.console.MainCallback; import NET.worlds.console.MainTerminalCallback; import java.io.IOException; public class CDPlayerAction extends Action implements Runnable, MainCallback, MainTerminalCallback { private static final boolean DISABLE_ALL = true; private static final int STATE_INITIAL = 0; private static final int STATE_WAITING = 1; private static final int STATE_DONE = 2; private static int numDrives = -1; private static CDPlayerAction active; private String artist; private String title; private String hash; private int start; private int stop; private boolean isStopper; private boolean cancel; private int state = 0; private static Object classCookie = new Object(); private boolean same(String str1, String str2) { if (str1 == null) { return str2 == null; } else { return str2 == null ? false : str1.equals(str2); } } private boolean same(CDPlayerAction other) { return other != null && this.same(this.artist, other.artist) && this.same(this.title, other.title) && this.same(this.hash, other.hash) && this.start == other.start && this.stop == other.stop; } @Override public Persister trigger(Event e, Persister seqID) { return null; } @Override public void run() { if (numDrives == -1) { numDrives = getNumDrives(); } for (int i = 0; i < numDrives; i++) { try { CDTrackInfo trackInfo = getTrackList(i); String curHash = null; if (trackInfo != null) { curHash = CDDBHash.hashString(trackInfo); if (curHash.equals(this.hash)) { this.play(i); break; } } if (this.cancel) { break; } } catch (IOException var4) { } } this.state = 2; } @Override public void mainCallback() { } @Override public void terminalCallback() { this.cancel = true; if (this.state == 2) { Main.unregister(this); } } private void play(int drive) throws IOException { int driveID; if ((driveID = openDrive(drive)) != 0) { playAudio(driveID, this.start, this.stop); while (isPlaying(driveID)) { try { Thread.sleep(1000L); } catch (InterruptedException var4) { } if (this.cancel) { stopAudio(driveID); break; } } closeDrive(driveID); } } public static CDTrackInfo getTrackList(int drive) throws IOException { CDTrackInfo ret = null; int driveID; if ((driveID = openDrive(drive)) != 0) { ret = getDriveTrackList(driveID); closeDrive(driveID); } return ret; } public static native int getNumDrives(); public static native int getDriveLetterOffset(int var0); public static native int openDrive(int var0) throws IOException; public static native void closeDrive(int var0) throws IOException; public static native void checkDrive(int var0) throws IOException; public static native CDTrackInfo getDriveTrackList(int var0) throws IOException; public static native void playAudio(int var0, int var1, int var2) throws IOException; public static native void stopAudio(int var0) throws IOException; public static native void pauseAudio(int var0) throws IOException; public static native void resumeAudio(int var0) throws IOException; public static native boolean isPlaying(int var0) throws IOException; public static native int getPosition(int var0) throws IOException; public static native void setNTAutoPlayCode(int var0); public static native boolean launchVolumeControlApp(); @Override public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException { Object ret = null; switch (index - offset) { case 0: if (mode == 0) { ret = StringPropertyEditor.make(new Property(this, index, "Artist")); } else if (mode == 1) { ret = this.artist; } else if (mode == 2) { this.artist = (String)value; } break; case 1: if (mode == 0) { ret = StringPropertyEditor.make(new Property(this, index, "Title")); } else if (mode == 1) { ret = this.title; } else if (mode == 2) { this.title = (String)value; } break; case 2: if (mode == 0) { ret = StringPropertyEditor.make(new Property(this, index, "Disk ID (Edit or Delete to read CD)").allowSetNull()); } else if (mode == 1) { if (this.hash == null) { try { CDTrackInfo trackList = getTrackList(0); if (trackList != null) { this.hash = CDDBHash.hashString(trackList); } } catch (IOException var7) { } } ret = this.hash; } else if (mode == 2) { this.hash = (String)value; } break; case 3: if (mode == 0) { ret = CDPositionPropertyEditor.make(new Property(this, index, "Start (75ths of a second)"), false); } else if (mode == 1) { ret = new Integer(this.start); } else if (mode == 2) { this.start = (Integer)value; } break; case 4: if (mode == 0) { ret = CDPositionPropertyEditor.make(new Property(this, index, "Stop (75ths of a second)"), true); } else if (mode == 1) { ret = new Integer(this.stop); } else if (mode == 2) { this.stop = (Integer)value; } break; case 5: if (mode == 0) { ret = BooleanPropertyEditor.make(new Property(this, index, "Stop identical CDPlayerAction"), "No", "Yes"); } else if (mode == 1) { ret = new Boolean(this.isStopper); } else if (mode == 2) { this.isStopper = (Boolean)value; } break; default: ret = super.properties(index, offset + 6, mode, value); } return ret; } @Override public void saveState(Saver s) throws IOException { s.saveVersion(2, classCookie); super.saveState(s); s.saveString(this.artist); s.saveString(this.title); s.saveString(this.hash); s.saveInt(this.start); s.saveInt(this.stop); s.saveBoolean(this.isStopper); } @Override public void restoreState(Restorer r) throws IOException, TooNewException { switch (r.restoreVersion(classCookie)) { case 1: super.restoreState(r); this.artist = r.restoreString(); this.title = r.restoreString(); this.hash = r.restoreString(); this.start = r.restoreInt(); this.stop = r.restoreInt(); break; case 2: super.restoreState(r); this.artist = r.restoreString(); this.title = r.restoreString(); this.hash = r.restoreString(); this.start = r.restoreInt(); this.stop = r.restoreInt(); this.isStopper = r.restoreBoolean(); break; default: throw new TooNewException(); } } }