5 // Joel Reed (joelwreed@gmail.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System
.Collections
.Generic
;
34 using Microsoft
.TeamFoundation
.Client
;
35 using Microsoft
.TeamFoundation
.VersionControl
.Common
;
36 using Microsoft
.TeamFoundation
.VersionControl
.Client
;
38 public class Settings
: SortedList
<string, string>
40 private readonly string ConfigFile
= "TfClient.config";
41 private bool initialized
= false;
42 private static Settings current
= new Settings();
44 public static Settings Current
46 get { return current; }
53 private void InitializeAsNeeded()
55 if (initialized
) return;
57 Add("Checkin.Validate", "false");
58 Add("Checkout.Latest", "false");
59 Add("Credentials.Save", "false");
60 Add("File.Excludes", "");
61 Add("File.ReadWrite", "false");
62 Add("Get.Recursive", "false");
63 Add("History.DefaultToCwd", "false");
64 Add("History.Detailed", "false");
65 Add("History.Recursive", "false");
66 Add("History.StopAfter", "256");
67 Add("Online.Recursive", "false");
71 string configFilePath
= GetConfigPath();
72 if (!File
.Exists(configFilePath
)) return;
74 using (XmlTextReader reader
= new XmlTextReader(configFilePath
))
78 if (reader
.NodeType
== XmlNodeType
.Element
&& reader
.Name
== "add")
80 string key
= reader
.GetAttribute("key");
81 string value = reader
.GetAttribute("value");
88 public string GetConfigPath()
90 return Path
.Combine(TeamFoundationServer
.ClientSettingsDirectory
, ConfigFile
);
97 XmlDocument doc
= new XmlDocument();
99 XmlElement root
= doc
.CreateElement("configuration");
100 doc
.AppendChild(root
);
102 XmlElement appSettings
= doc
.CreateElement("appSettings");
103 root
.AppendChild(appSettings
);
105 foreach (string key
in Keys
)
107 XmlElement
add = doc
.CreateElement("add");
108 add.SetAttributeNode("key", "").Value
= key
;
109 add.SetAttributeNode("value", "").Value
= this[key
];
110 appSettings
.AppendChild(add);
113 string configFilePath
= Path
.Combine(TeamFoundationServer
.ClientSettingsDirectory
, ConfigFile
);
114 using (XmlTextWriter writer
= new XmlTextWriter(configFilePath
, null))
116 writer
.Formatting
= Formatting
.Indented
;
121 public string Get(string key
)
123 InitializeAsNeeded();
125 string value = String
.Empty
;
126 TryGetValue(key
, out value);
131 public bool GetAsBool(string key
)
133 InitializeAsNeeded();
135 string value = String
.Empty
;
136 if (TryGetValue(key
, out value))
138 return Convert
.ToBoolean(value);
144 public int GetAsInt(string key
)
146 InitializeAsNeeded();
148 string value = String
.Empty
;
149 if (TryGetValue(key
, out value))
151 return Convert
.ToInt32(value);