/*========================================================================= Program: FusionViewer Module: $RCSfile: Env.java,v $ Language: Java Date: $Date: 2006/10/13 18:35:13 $ Version: $Revision: 1.2 $ Copyright (c) Insightful Corporation. All rights reserved. See Copyright.txt for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ package org.fusionviewer.io; import java.io.File; import org.fusionviewer.ui.PlatformUtility; /**\class Env *\brief Static class containing platform-dependent file and directory names and locations. */ public class Env { /** * Home directory */ public final static File PREFERENCES_DIRECTORY; /** * Application configuration file */ public final static String CONFIG = "fusionviewer.config"; /** * Application data directory */ public final static File DATA; /** * True if we are running on a Macintosh. */ public final static boolean isMac; /** * True if we are running on Windows. */ public final static boolean isWindows; static { final String APPLICATION_NAME = "FusionViewer"; final String VIEWER_HOME_DIRECTORY = ".fusionviewer"; final String USER_HOME = "user.home"; String os = System.getProperty("os.name").toLowerCase(); String home; if (os.startsWith("mac")) { // If this is a Mac, go to the user's preferences directory home = System.getProperty(USER_HOME) + "/Library/Preferences/Insightful"; isMac = true; isWindows = false; } else if (os.startsWith("windows")) { File appData = new File(System.getProperty(USER_HOME) + File.separator + "Application Data"); if (appData.exists() && appData.isDirectory()) { StringBuffer sb = new StringBuffer(); sb.append(System.getProperty(USER_HOME)).append(File.separator); sb.append("Application Data").append(File.separator); sb.append("Insightful").append(File.separator); sb.append(APPLICATION_NAME); home = sb.toString(); } else { home = System.getProperty(USER_HOME) + File.separator + VIEWER_HOME_DIRECTORY; } isMac = false; isWindows = true; } else { home = System.getProperty(USER_HOME) + File.separator + VIEWER_HOME_DIRECTORY; isMac = false; isWindows = false; } File jarDirectory = new PlatformUtility().getJarFilePath(); if (jarDirectory != null) { File testDir = new File(jarDirectory, "Data"); File colormapsFile = new File(testDir, "Colormaps.xml"); if (colormapsFile.exists()) DATA = new File(jarDirectory, "Data"); else DATA = new File("Data"); } else { DATA = new File("Data"); } PREFERENCES_DIRECTORY = new File(home); if (!PREFERENCES_DIRECTORY.exists()) PREFERENCES_DIRECTORY.mkdirs(); } }