📄 systemresources.java
字号:
/* * SystemResources.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */package org.executequery.util;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.util.Properties;import java.util.StringTokenizer;import java.util.Vector;import javax.swing.JOptionPane;import org.executequery.Constants;import org.executequery.GUIUtilities;import org.executequery.SystemUtilities;import org.underworldlabs.util.FileUtils;import org.underworldlabs.util.MiscUtils;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the * release of version 3.0.0beta1 has meant a * resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * This object acts as a utility class for file input * and output. All open file and save file requests are * propagated via the relevant methods to this class. * This object is also responsible for user and default * system properties and handles all read and write methods * for these. System version information and SQL keywords * are also retrieved and maintained here. * * @author Takis Diakoumis * @version $Revision: 1.8 $ * @date $Date: 2006/06/25 12:45:19 $ */public class SystemResources { public static void resetLog(String log) { try { String path = SystemUtilities.getUserLogsPath() + log; FileUtils.writeFile(path, Constants.EMPTY, false); } catch (IOException e) { GUIUtilities.displayErrorMessage("Error resetting log file:\n" + log); } } public static Vector<String> getDatabaseNameList() { try { String path = "org/executequery/database.name.list"; String values = FileUtils.loadResource(path); Vector<String> v = new Vector<String>(); StringTokenizer st = new StringTokenizer(values, "|"); while (st.hasMoreTokens()) { v.add(st.nextToken()); } return v; } catch (IOException e) { e.printStackTrace(); GUIUtilities.displayErrorMessage("Error opening database list"); return null; } } public static Properties getEqSystemProperties() { Properties properties = null; try { String path = "org/executequery/eq.system.properties"; properties = FileUtils.loadPropertiesResource(path); } catch (IOException e) { System.err.println("Could not find version."); properties = new Properties(); properties.setProperty("eq.version","-1"); properties.setProperty("eq.build","-1"); properties.setProperty("help.version","-1"); } return properties; } public static Properties getUserActionShortcuts() { try { String fileName = SystemUtilities.getUserPropertiesPath() + "eq.shortcuts.properties"; File file = new File(fileName); if (!file.exists()) { return null; } return FileUtils.loadProperties(file); } catch (IOException e) { e.printStackTrace(); return null; } } public static void setUserActionShortcuts(Properties properties) { try { String path = SystemUtilities.getUserPropertiesPath() + "eq.shortcuts.properties"; FileUtils.storeProperties(path, properties, "Execute Query - User Defined System Shortcuts"); } catch (IOException e) { e.printStackTrace(); GUIUtilities.displayErrorMessage("Error saving shortcuts"); } } public static synchronized void setUserPreferences(Properties properties) { try { String path = SystemUtilities.getUserPropertiesPath() + "eq.user.properties"; FileUtils.storeProperties(path, properties, "Execute Query - User Defined System Properties"); } catch (IOException e) { e.printStackTrace(); GUIUtilities.displayErrorMessage("Error saving preferences:\n"+ e.getMessage()); } } public static Properties getConsoleProperties() { Properties properties = null; try { String path = "org/executequery/console.properties"; properties = FileUtils.loadPropertiesResource(path); } catch (IOException e) { e.printStackTrace(); GUIUtilities.displayErrorMessage( "Error opening system console properties"); } return properties; } public static Properties getDefaultProperties() { Properties properties = null; try { String path = "org/executequery/eq.default.properties"; properties = FileUtils.loadPropertiesResource(path); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog( GUIUtilities.getParentFrame(), "Error opening default\nsystem properties", "Error", JOptionPane.ERROR_MESSAGE); System.exit(0); } return properties; } public static Properties getUserProperties() { try { String path = SystemUtilities.getUserPropertiesPath() + "eq.user.properties"; Properties defaults = getDefaultProperties(); Properties properties = FileUtils.loadProperties(path, defaults); return properties; } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(GUIUtilities.getParentFrame(), "Error opening user\nsystem properties", "Error", JOptionPane.ERROR_MESSAGE); return null; } } /** * Creates the eq system home directory structure in ~/.executequery. */ public static boolean createUserHomeDirSettings() { String fileSeparator = System.getProperty("file.separator"); String eqUserHomeDir = System.getProperty("user.home") + fileSeparator + System.getProperty("executequery.user.home.dir"); File equeryDir = new File(eqUserHomeDir); File confDir = new File(SystemUtilities.getUserPropertiesPath()); File logsDir = new File(SystemUtilities.getUserLogsPath()); try { // whether the equery base dir exists
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -