SF.net SVN: tuotoo: [4] trunk/src/org/tuotoo/tor/Config.java
Status: Pre-Alpha
Brought to you by:
hanru
|
From: <ha...@us...> - 2007-11-22 12:29:14
|
Revision: 4
http://tuotoo.svn.sourceforge.net/tuotoo/?rev=4&view=rev
Author: hanru
Date: 2007-11-22 04:29:19 -0800 (Thu, 22 Nov 2007)
Log Message:
-----------
A simple config class for holding all future config items.
Added Paths:
-----------
trunk/src/org/tuotoo/tor/Config.java
Added: trunk/src/org/tuotoo/tor/Config.java
===================================================================
--- trunk/src/org/tuotoo/tor/Config.java (rev 0)
+++ trunk/src/org/tuotoo/tor/Config.java 2007-11-22 12:29:19 UTC (rev 4)
@@ -0,0 +1,96 @@
+package org.tuotoo.tor;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.util.Properties;
+
+import org.tuotoo.logging.LogHolder;
+import org.tuotoo.logging.LogLevel;
+import org.tuotoo.logging.LogType;
+
+public class Config {
+
+ private static Config ms_instance = null;
+
+ private Properties m_props;
+
+ private String confFile;
+
+ public static String[] defaultDirServers = {
+ "moria1 128.31.0.34 9031 FFCB46DB1339DA84674C70D7CB586434C4370441",
+ "moria2 128.31.0.34 9032 719BE45DE224B607C53707D0E2143E2D423E74CF",
+ "tor26 86.59.21.38 80 847B1F850344D7876491A54892F904934E4EB85D",
+ "lefkada 140.247.60.64 80 38D4F5FCF7B1023228B895EA56EDE7D5CCDCAF32",
+ "dizum 194.109.206.212 80 7EA6EAD6FD83083C538F44038BBFA077587DD755",
+ };
+
+ private Config() {
+ this(getDefaultConfigLocation());
+ }
+
+ private Config(String conf) {
+ confFile = conf;
+ Properties defProps = new Properties();
+
+ // initialize default properties
+ defProps.setProperty("proxy.SocksPort", "9150");
+ // ...
+
+ m_props = new Properties(defProps);
+ load();
+ }
+
+ public static Config getInstance() {
+ if (ms_instance == null)
+ ms_instance = new Config();
+ return ms_instance;
+ }
+
+ public String getConfig(String key) {
+ return m_props.getProperty(key);
+ }
+
+ public void setConfig(String key, String value) {
+ m_props.setProperty(key, value);
+ }
+
+ private void load() {
+ try {
+ FileInputStream in = new FileInputStream(confFile);
+ m_props.load(in);
+ in.close();
+ } catch (FileNotFoundException e) {
+ // 'confFile' not exists, create an empty one
+ try {
+ LogHolder.log(LogLevel.NOTICE, LogType.TOR, confFile
+ + " not exists, creating an empty one.");
+ File f = new File(confFile);
+ File pf = f.getParentFile();
+ pf.mkdirs();
+ f.createNewFile();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void save() {
+ try {
+ FileOutputStream out = new FileOutputStream(confFile);
+ m_props.store(out, "");
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static String getDefaultConfigLocation() {
+ return System.getProperty("user.home")
+ + System.getProperty("file.separator") + ".tuotoo"
+ + System.getProperty("file.separator") + "tuotoo.conf";
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|