package org.openmhp.system;

import java.net.*;
import java.lang.Runtime;
import java.io.*;
import javax.swing.*;
import java.util.*;

import java.awt.*;
import java.applet.Applet;

import org.openmhp.appman.*;

import libopenmhp.Grabber;         // miknov
import libopenmhp.InterfaceServer; // miknov
import org.dvb.event.EventManager; // miknov


/*
* 30.3.2005 Creates persistent directories and sets dvb.persistent.storage /tejopa
*/

public class RunXlet extends Applet {


    static { org.dvb.event.EventManager.getInstance(); } // miknov


/*
	public static void main(String[] args) {

		new MainFrame(new RunXlet(args),720,576);
	}

	public RunXlet(String[] args) {
		org.openmhp.system.Constants.setRootPath(args[4]);
		setLayout(new BorderLayout());
		add("Center",new TVScreen(new Output()));

		EmulatorRemote remote = new EmulatorRemote();
		remote.setLocation(0,0);
		URL path = null;
		try {
			path = new URL("file:\\\\\\"+args[0]);
		} catch (Exception e) { System.out.println(e.toString()); }
		new org.openmhp.system.XletManager(path,args[1],new Integer(args[2]).intValue(),new Integer(args[3]).intValue());

	}
*/


    public static void main(String[] args) throws Exception { // miknov: exception

		org.openmhp.system.Constants.setRootPath(args[4]);

		String root = args[4];

		int oid = new Integer(args[2]).intValue();
		int aid = new Integer(args[3]).intValue();


		/* tejopa 5.4.2005 */
		String FS = File.separator;
		Properties p = Configuration.loadProperties(root+FS+"static"+FS+"openmhp.properties");

		Properties sysprops = System.getProperties();
		sysprops.put("base_dir",root);
		sysprops.put("dvb.persistent.root",root+File.separator+"persistent");
		sysprops.putAll(p);
		System.setProperties(sysprops);

		String dir = (String)(System.getProperty("dvb.persistent.root")+File.separator+oid+File.separator+aid);
		File persfile = new File(dir);
		persfile.mkdirs();


		TVScreen screen = new TVScreen(); // miknov: stripped argument

		/* miknov: remote removed
		EmulatorRemote remote = new EmulatorRemote();
		remote.setLocation(screen.getX()+screen.getWidth(),screen.getY());
		*/
		URL path = null;
		try {
			path = new URL("file:\\\\\\"+args[0]);
		} catch (Exception e) { System.out.println(e.toString()); }
		new org.openmhp.system.XletManager(path,args[1],new Integer(args[2]).intValue(),new Integer(args[3]).intValue());

                // miknov: start communication with client
                InterfaceServer is = InterfaceServer.getInstance();
                is.startServer();
	}

}
