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.*; import java.util.ArrayList; import java.util.List; public class Main { public static List<String> getAvailableTitaniumSdkVersions() { String basePath = getTitaniumBaseSdkPath(); if (basePath == null) { return null; } File baseFolder = new File(basePath); File[] files = baseFolder.listFiles(); if (files != null && files.length > 0) { List<String> versions = new ArrayList<String>(); for (File f : files) { if (f.isDirectory()) { versions.add(f.getName()); } } if (!versions.isEmpty()) { return versions; } } return null; } public static String getTitaniumBaseSdkPath() { final String homeFolder = System.getProperty("user.home"); String sdkPath = null; File sdkFile = null; if (isMac()) { sdkPath = homeFolder + "/Library/Application Support/Titanium/mobilesdk/osx/"; sdkFile = new File(sdkPath); if (!sdkFile.exists()) { sdkPath = "/Library/Application Support/Titanium/mobilesdk/osx/"; sdkFile = new File(sdkPath); if (!sdkFile.exists()) { sdkPath = null; } } } else if (isWindows()) { final String userProfileFolder = System.getenv("ALLUSERSPROFILE"); sdkPath = userProfileFolder + "\\Titanium\\mobilesdk\\win32\\"; sdkFile = new File(sdkPath); if (!sdkFile.exists()) { sdkPath = "C:\\Documents and Settings\\All Users\\Application Data\\Titanium\\mobilesdk\\win32\\"; sdkFile = new File(sdkPath); if (!sdkFile.exists()) { sdkPath = null; } } } else if (isUnix()) { sdkPath = homeFolder + "/.titanium/mobilesdk/linux/"; 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); } }