package org.bench4q.monitor;

import java.io.File;

public class Main {
	static {
		loadLibraries();
	}

	private static void loadLibraries() {
		String osName = System.getProperty("os.name").toLowerCase();
		if (osName.contains("windows")) {
			String directory = Main.class.getProtectionDomain().getCodeSource()
					.getLocation().getFile().replace("\\", "/");
			File file = new File(directory);
			if (!file.isDirectory()) {
				directory = directory.substring(0, directory.lastIndexOf("/"));
				if (!directory.endsWith("/")) {
					directory += "/";
				}
				int arch = Integer.parseInt(System
						.getProperty("sun.arch.data.model"));
				if (arch == 64) {
					System.load(directory + "lib/x64/Monitor.dll");
					System.load(directory + "lib/x64/Native.dll");
				} else {
					System.load(directory + "lib/x86/Monitor.dll");
					System.load(directory + "lib/x86/Native.dll");
				}
			} else {
				// In IDE
				String userDir = System.getProperty("user.dir").replace("\\",
						"/");
				userDir += "/WindowsMonitor";
				int arch = Integer.parseInt(System
						.getProperty("sun.arch.data.model"));
				if (arch == 64) {
					System.load(userDir + "/x64/Release/Monitor.dll");
					System.load(userDir + "/x64/Release/Native.dll");
				} else {
					System.load(userDir + "/Release/Monitor.dll");
					System.load(userDir + "/Release/Native.dll");
				}
			}
		}
	}

	public static void main(String[] args) {

		if (System.getProperty("os.name").toLowerCase().contains("windows"))
			loadLibraries();
		MonitorServer monitorServer = new MonitorServer(5556);
		monitorServer.start();
	}

}
