/* * Moonlight|3D Copyright (C) 2006 The Moonlight|3D team * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Jan 1, 2006 */ package ml.core.preferences; /** * \package ml.core.preferences * * This is the preferences system for Moonlight|3D. It * is responsible for loading, accessing and storing * user preferences. * * This package is part of the core program. */ import java.io.File; public class Manager { private Preferences systemPreferences; private Preferences userPreferences; private Preferences currentPreferences; public Manager() { currentPreferences=new Preferences(); systemPreferences=new Preferences(); userPreferences=new Preferences(); } public void updatePreferenceFiles() { currentPreferences.saveToFile(getUserPreferencesPath() + "preferences.xml"); } private String getSystemPreferencesPath() { // use the installation directory for now - maybe there is a better solution return ml.core.State.getInstance().getInstallationDirectory() + System.getProperty("file.separator"); } private String getUserPreferencesPath() { String moonlightDirectory=""; File directory; if(System.getProperty("os.name").length()>=7) { if(System.getProperty("os.name").substring(0,7).equals("Windows")) { moonlightDirectory=System.getenv().get("APPDATA"); moonlightDirectory+= System.getProperty("file.separator") + "Moonlight3D" + System.getProperty("file.separator"); } } else { moonlightDirectory=System.getProperty("user.home") + System.getProperty("file.separator"); moonlightDirectory+=".moonlight3d" + System.getProperty("file.separator"); } directory=new File(moonlightDirectory); if(!directory.exists()) { if(!directory.mkdirs()) { return null; } } return moonlightDirectory; } public void loadPreferences() { try { systemPreferences.loadFromFile(getSystemPreferencesPath() + "preferences.xml"); } catch(Exception e) { // ignore exception; it means file is missing and this isn't bad. } try { userPreferences.loadFromFile(getUserPreferencesPath() + "preferences.xml"); } catch(Exception e) { // ignore exception; it means file is missing and this isn't bad. e.printStackTrace(); } } public void applyLoadedPreferences() { currentPreferences.setFrom(systemPreferences); currentPreferences.setFrom(userPreferences); } public Preferences getUserPreferences() { return userPreferences; } public Preferences getCurrentPreferences() { return currentPreferences; } }