Java tutorial
//package com.java2s; /* * Copyright 2011 SOFTEC sa. All rights reserved. * * This source code is licensed under the Creative Commons * Attribution-NonCommercial-NoDerivs 3.0 Luxembourg * License. * * To view a copy of this license, visit * http://creativecommons.org/licenses/by-nc-nd/3.0/lu/ * or send a letter to Creative Commons, 171 Second Street, * Suite 300, San Francisco, California, 94105, USA. */ import java.io.*; public class Main { public static String getTitaniumSdkPath(String version) { final String homeFolder = System.getProperty("user.home"); String sdkPath = null; File sdkFile = null; if (isMac()) { sdkPath = homeFolder + "/Library/Application Support/Titanium/mobilesdk/osx/" + version + "/"; sdkFile = new File(sdkPath); if (!sdkFile.exists()) { sdkPath = "/Library/Application Support/Titanium/mobilesdk/osx/" + version + "/"; sdkFile = new File(sdkPath); if (!sdkFile.exists()) { sdkPath = null; } } } else if (isWindows()) { final String userProfileFolder = System.getenv("ALLUSERSPROFILE"); sdkPath = userProfileFolder + "\\Titanium\\mobilesdk\\win32\\" + version + "\\"; sdkFile = new File(sdkPath); if (!sdkFile.exists()) { sdkPath = "C:\\Documents and Settings\\All Users\\Application Data\\Titanium\\mobilesdk\\win32\\" + version + "\\"; sdkFile = new File(sdkPath); if (!sdkFile.exists()) { sdkPath = null; } } } else if (isUnix()) { sdkPath = homeFolder + "/.titanium/mobilesdk/linux/" + version + "/"; sdkFile = new File(sdkPath); if (!sdkFile.exists()) { sdkPath = null; } } return sdkPath; } private static boolean isMac() { return isOs("mac"); } private static boolean isWindows() { return isOs("win"); } private static boolean isUnix() { return (isOs("nix") || isOs("nux")); } private static boolean isOs(final String osName) { final String os = System.getProperty("os.name").toLowerCase(); return (os.indexOf(osName) >= 0); } }