/* * CUserSettings.java * * Created on 31 May 2007, 01:46 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package aflobby; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.HashMap; import java.util.Iterator; import java.util.Scanner; import java.util.Set; /** * * @author Tom */ public class CUserSettings { public LMain LM; /** Creates a new instance of CUserSettings */ public CUserSettings (LMain L) { LM =L; } public String GetStartScript (String user){ // String s; if(Misc.isLinux ()==true){ // s = System.getenv ("HOME")+"/.aflobby/startupscript.txt"; }else{ s = "lobby/aflobby/startupscript.txt"; } Scanner read_in; try { String t = ""; read_in = new Scanner (new File (s)); read_in.useDelimiter (System.getProperty ("line.separator")); while(read_in.hasNext ()){ t += new String (read_in.next ()); } read_in.close (); return t; } catch (FileNotFoundException e) { return "";//e.printStackTrace (); } //return ""; } public void SaveStartScript (String user, String script){ String s; if(Misc.isLinux ()==true){ s = System.getenv ("HOME")+"/.aflobby/startupscript.txt"; }else{ s = "lobby\\aflobby\\startupscript.txt"; } PrintStream write_out; try { // Create new file write_out = new PrintStream (new File (s)); write_out.print (script); write_out.close (); } catch (FileNotFoundException e) { e.printStackTrace (); } } private HashMap values = new HashMap(); String GetValue (String key){ // if(values.isEmpty ()){ Load (); } return values.get (key); } void PutValue (String key, String value){ values.put (key,value); Save (); } public void Load (){ String f; if(Misc.isLinux ()==true){ // f = System.getenv ("HOME")+"/.aflobby/settings.tdf"; }else{ f = "lobby/aflobby/settings.tdf"; } String s = ""; Scanner read_in; try { String t = ""; read_in = new Scanner (new File (f)); read_in.useDelimiter (System.getProperty ("line.separator")); while(read_in.hasNext ()){ s += new String (read_in.next ()); } read_in.close (); } catch (FileNotFoundException e) { return; } TdfParser t = new TdfParser (s); //System.out.println("values:"+t.RootSection.Values.size ()); //TdfParser.Section sec = t.RootSection.SubSection ("mainsettings"); values = t/*sec*/.RootSection.Values; } public void Save (){ // String s = "";// = "[mainsettings]{\n"; Set keys = values.keySet (); Iterator i = keys.iterator (); while(i.hasNext ()){ String k = i.next (); String v = values.get (k); s+= "\t"+k+"="+v+";"+System.getProperty ("line.separator"); } //s += "}"; String f; if(Misc.isLinux ()==true){ f = System.getenv ("HOME")+"/.aflobby/settings.tdf"; }else{ f = "lobby/aflobby/settings.tdf"; } PrintStream write_out; try { // Create new file write_out = new PrintStream (new File (f)); write_out.print (s); write_out.close (); } catch (FileNotFoundException e) { e.printStackTrace (); } } }