package NET.worlds.scape; import NET.worlds.console.Console; import NET.worlds.network.URL; import java.io.File; import java.io.IOException; public class MultiManifestAction extends Action implements LoadedURLSelf { private String _directory; private static Object classCookie = new Object(); private String[] _files; private File _dir; private int _curFile; private String _file; @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, "Directory")); } else if (mode == 1) { if (this._directory == null) { this._directory = new String(); } ret = new String(this._directory); } else if (mode == 2) { this._directory = ((String)value).trim(); } break; default: ret = super.properties(index, offset + 1, mode, value); } return ret; } @Override public void saveState(Saver s) throws IOException { s.saveVersion(0, classCookie); super.saveState(s); s.saveString(this._directory); } @Override public void restoreState(Restorer r) throws IOException, TooNewException { switch (r.restoreVersion(classCookie)) { case 0: super.restoreState(r); this._directory = r.restoreString(); return; default: throw new TooNewException(); } } @Override public Persister trigger(Event e, Persister seqId) { if (seqId == null) { System.out.println("MMAState:starting"); this._dir = new File(this._directory); this._files = this._dir.list(new ExtensionFilter(".world")); this._curFile = 0; this.startFile(); } return this._curFile >= this._files.length ? null : this; } public void startFile() { if (this._curFile >= this._files.length) { System.out.println("MMAState:Done"); } else { this._file = new File(this._dir, this._files[this._curFile]).getAbsolutePath(); System.out.println("MMAState:Loading: " + this._file); World.load(URL.make(this._file), this); } } @Override public void loadedURLSelf(URLSelf o, URL url, String err) { if (err == null && o instanceof World) { World w = (World)o; String mftname = this._file.substring(0, this._file.lastIndexOf(".world")) + ".mft"; System.out.println("MMAState:Manifesting: " + mftname); try { Manifest mft = new Manifest(mftname); mft.saveProps(w); mft.done(); } catch (Exception var7) { var7.printStackTrace(System.out); } if (w != Pilot.getActive().getWorld()) { w.discard(); } } else { if (err == null) { err = Console.message("No-contain-world"); o.decRef(); } Console.println(Console.message("Cant-load-remote") + url + "' "); } this._curFile++; this.startFile(); } }