
package net.kmate.craftpackager.util;

import java.io.File;

import net.kmate.craftpackager.Constants;

public class PlatformHelper {
	public static final String platformName;
	public static final String platformVersion;
	public static final String platformArch;
	public static final String platformDataModel;
	
	public enum BasePlatform {
		WINDOWS,
		OSX,
		LINUX,
		UNKNOWN;
		
		@Override
		public String toString() {
			return super.toString().toLowerCase();
		}
	}
	
	public static final BasePlatform basePlatform;
	
	static {
		platformName = System.getProperty("os.name");
		platformVersion = System.getProperty("os.version");
		platformArch = System.getProperty("os.arch");
		platformDataModel = System.getProperty("sun.arch.data.model");
		
		// Determine the base platform
		String platformNameLower = platformName.toLowerCase();
		if (platformNameLower.startsWith("windows")) {
			basePlatform = BasePlatform.WINDOWS;
		} else if (platformNameLower.startsWith("osx")) {
			basePlatform = BasePlatform.OSX;
		} else if (platformNameLower.startsWith("linux")) {
			basePlatform = BasePlatform.LINUX;
		} else {
			basePlatform = BasePlatform.UNKNOWN;
		}
	}

	public static String getJvmPath() {
		String javaBin = System.getProperty("java.home") + File.separator + "bin";
		if (basePlatform == BasePlatform.WINDOWS) {
			return javaBin + File.separator + "javaw.exe";
		} else {
			return javaBin + File.separator + "java";
		}
	}
	
	public static String getLauncherDirectory() {
		if (basePlatform == BasePlatform.WINDOWS) {
			return System.getenv("appdata") + File.separator + Constants.GAME_DIRECTORY_NAME;
		} else {
			return System.getProperty("user.home") + File.separator + Constants.GAME_DIRECTORY_NAME;
		}
	}
}
