/*
 * @(#)LoadProject.java
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 2001-2004 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDcreator.java for details.
 *
 * Jörg Haeger, 11.05.2001
 */

/**
 * Load a project from the server.
 *
 * @version 20040302
 * @author Jörg P. M. Haeger
 */
class LoadProject extends Command {
	private java.util.Vector commands = new java.util.Vector(100);

	void processHint(String str) {
//		System.out.println(str);
		commands.add(str);
	}

	void execute(String str) {
		String str1 = "", str2 = "", str3 = "";
		int i = str.indexOf(" ");
		if (i < 0)
				str1 = str;
		else {
			str1 = str.substring(0, i);
			str = str.substring(i + 1);
			i = str.indexOf(" ");
			if (i < 0)
				str2 = str;
			else {
				str2 = str.substring(0, i);
				str3 = str.substring(i + 1);
			}
		}

		str2 = removeEscChars(str2);
		str3 = removeEscChars(str3);
//		System.out.println(str2);
//		System.out.println(str3);

		if (str1.equals("add"))
			Project.add(str2, str3);
		else
		if (str1.equals("boot")) {
			if (CDcreator.model != null)
				CDcreator.model.setBootImage(str2);
		}
		else
		if (str1.equals("down"))
			Project.moveDown(str2);
		else
		if (str1.equals("medium")) {
			if (str3.length() > 0)
				str2 = str2 + " " + str3;
			Mode.setMedium(str2);
		}
		else
		if (str1.equals("mkdir"))
			Project.mkdir(str2);
		else
		if (str1.equals("mv"))
			Project.rename(str2, str3);
		else
		if (str1.equals("rm"))
			Project.remove(str2);
		else
		if (str1.equals("type")) {
			if (str2.equals("audio"))
				Mode.setTypeAudio();
			else
			if (str2.equals("image")) {
				Mode.makeImage = false;
				Mode.type = Mode.data;
			}
			else
			if (str2.equals("data")) {
				Mode.makeImage = true;
				Mode.type = Mode.data;
			}
		}
		else
		if (str1.equals("up"))
			Project.moveUp(str2);
	}

	public void run() {
		execCommand("loadProject " + spaceToEsc(State.sessionID));

		for (int i = 0; i < commands.size(); i++)
			execute((String) commands.get(i));

		super.run();
	}
}
