2 // CustomizableFileSettingsProvider.cs
5 // Noriaki Okimoto <seara@ojk.sppd.ne.jp>
6 // Atsushi Enomoto <atsushi@ximian.com>
8 // (C)2007 Noriaki Okimoto
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 extern alias PrebuiltSystem;
35 using System.Collections;
36 using System.Collections.Generic;
37 using System.Configuration;
38 using System.Globalization;
40 using System.Reflection;
41 using System.Security.Cryptography;
45 using NameValueCollection = PrebuiltSystem.System.Collections.Specialized.NameValueCollection;
47 namespace System.Configuration
49 // location to store user configuration settings.
50 internal enum UserConfigLocationOption : uint
53 Product_VersionMajor = 0x21,
54 Product_VersionMinor = 0x22,
55 Product_VersionBuild = 0x24,
56 Product_VersionRevision = 0x28,
57 Company_Product = 0x30,
58 Company_Product_VersionMajor = 0x31,
59 Company_Product_VersionMinor = 0x32,
60 Company_Product_VersionBuild = 0x34,
61 Company_Product_VersionRevision = 0x38,
66 internal class CustomizableFileSettingsProvider : SettingsProvider, IApplicationSettingsProvider
70 // This is used from within System.Web to allow mapping of the ExeConfigFilename to
71 // the correct Web.config for the current request. Otherwise web applications will
72 // not be able to access settings from Web.config. The type assigned to this
73 // variable must descend from the ConfigurationFileMap class and its
74 // MachineConfigFilename will be used to set the ExeConfigFilename.
76 // This is necessary to fix bug #491531
77 #pragma warning disable 649
78 private static Type webConfigurationFileMapType;
79 #pragma warning restore 649
81 private static string userRoamingPath = "";
82 private static string userLocalPath = "";
83 private static string userRoamingPathPrevVersion = "";
84 private static string userLocalPathPrevVersion = "";
85 private static string userRoamingName = "user.config";
86 private static string userLocalName = "user.config";
87 private static string userRoamingBasePath = "";
88 private static string userLocalBasePath = "";
89 private static string CompanyName = "";
90 private static string ProductName = "";
91 private static string ForceVersion = "";
92 private static string[] ProductVersion;
94 // whether to include parts in the folder name or not:
95 private static bool isVersionMajor = false; // 0x0001 major version
96 private static bool isVersionMinor = false; // 0x0002 minor version
97 private static bool isVersionBuild = false; // 0x0004 build version
98 private static bool isVersionRevision = false; // 0x0008 revision
99 private static bool isCompany = true; // 0x0010 corporate name
100 private static bool isProduct = true; // 0x0020 product name
101 private static bool isEvidence = false; // 0x0040 evidence hash
103 private static bool userDefine = false; // 0x8000 ignore all above and use user definition
105 private static UserConfigLocationOption userConfig = UserConfigLocationOption.Company_Product;
107 public override void Initialize (string name, NameValueCollection config)
109 base.Initialize (name, config);
112 // full path to roaming user.config
113 internal static string UserRoamingFullPath {
114 get { return Path.Combine (userRoamingPath, userRoamingName); }
117 // full path to local user.config
118 internal static string UserLocalFullPath {
119 get { return Path.Combine (userLocalPath, userLocalName); }
122 // previous full path to roaming user.config
123 public static string PrevUserRoamingFullPath {
124 get { return Path.Combine (userRoamingPathPrevVersion, userRoamingName); }
127 // previous full path to local user.config
128 public static string PrevUserLocalFullPath {
129 get { return Path.Combine (userLocalPathPrevVersion, userLocalName); }
132 // path to roaming user.config
133 public static string UserRoamingPath {
134 get { return userRoamingPath; }
137 // path to local user.config
138 public static string UserLocalPath {
139 get { return userLocalPath; }
142 // file name which is equivalent to user.config, for roaming user
143 public static string UserRoamingName {
144 get { return userRoamingName; }
147 // file name which is equivalent to user.config, for local user
148 public static string UserLocalName {
149 get { return userLocalName; }
152 public static UserConfigLocationOption UserConfigSelector
154 get { return userConfig; }
158 if (((uint) userConfig & 0x8000) != 0) {
159 isVersionMajor = false;
160 isVersionMinor = false;
161 isVersionBuild = false;
162 isVersionRevision = false;
167 isVersionRevision = ((uint) userConfig & 0x0008) != 0;
168 isVersionBuild = isVersionRevision | ((uint)userConfig & 0x0004) != 0;
169 isVersionMinor = isVersionBuild | ((uint)userConfig & 0x0002) != 0;
170 isVersionMajor = IsVersionMinor | ((uint)userConfig & 0x0001) != 0;
172 isCompany = ((uint) userConfig & 0x0010) != 0;
173 isProduct = ((uint) userConfig & 0x0020) != 0;
177 // whether the path to include the major version.
178 public static bool IsVersionMajor
180 get { return isVersionMajor; }
183 isVersionMajor = value;
184 isVersionMinor = false;
185 isVersionBuild = false;
186 isVersionRevision = false;
190 // whether the path to include minor version.
191 public static bool IsVersionMinor
193 get { return isVersionMinor; }
196 isVersionMinor = value;
198 isVersionMajor = true;
199 isVersionBuild = false;
200 isVersionRevision = false;
204 // whether the path to include build version.
205 public static bool IsVersionBuild
207 get { return isVersionBuild; }
210 isVersionBuild = value;
211 if (isVersionBuild) {
212 isVersionMajor = true;
213 isVersionMinor = true;
215 isVersionRevision = false;
219 // whether the path to include revision.
220 public static bool IsVersionRevision
222 get { return isVersionRevision; }
225 isVersionRevision = value;
226 if (isVersionRevision) {
227 isVersionMajor = true;
228 isVersionMinor = true;
229 isVersionBuild = true;
234 // whether the path to include company name.
235 public static bool IsCompany
237 get { return isCompany; }
238 set { isCompany = value; }
241 // whether the path to include evidence hash.
242 public static bool IsEvidence
244 get { return isEvidence; }
245 set { isEvidence = value; }
248 // AssemblyCompanyAttribute->Namespace->"Program"
249 private static string GetCompanyName ()
251 Assembly assembly = Assembly.GetEntryAssembly ();
252 if (assembly == null)
253 assembly = Assembly.GetCallingAssembly ();
255 AssemblyCompanyAttribute [] attrs = (AssemblyCompanyAttribute []) assembly.GetCustomAttributes (typeof (AssemblyCompanyAttribute), true);
257 if ((attrs != null) && attrs.Length > 0) {
258 return attrs [0].Company;
261 MethodInfo entryPoint = assembly.EntryPoint;
262 Type entryType = entryPoint != null ? entryPoint.DeclaringType : null;
263 if (entryType != null && !String.IsNullOrEmpty (entryType.Namespace)) {
264 int end = entryType.Namespace.IndexOf ('.');
265 return end < 0 ? entryType.Namespace : entryType.Namespace.Substring (0, end);
270 private static string GetProductName ()
272 Assembly assembly = Assembly.GetEntryAssembly ();
273 if (assembly == null)
274 assembly = Assembly.GetCallingAssembly ();
276 byte [] pkt = assembly.GetName ().GetPublicKeyToken ();
277 return String.Format ("{0}_{1}_{2}",
278 AppDomain.CurrentDomain.FriendlyName,
279 pkt != null && pkt.Length > 0 ? "StrongName" : "Url",
283 // Note: Changed from base64() to hex output to avoid unexpected chars like '\' or '/' with filesystem meaning.
284 // Otherwise eventually filenames, which are invalid on linux or windows, might be created.
285 // Signed-off-by: Carsten Schlote <schlote@vahanus.net>
286 // TODO: Compare with .NET. It might be also, that their way isn't suitable for Unix OS derivates (slahes in output)
287 private static string GetEvidenceHash ()
289 Assembly assembly = Assembly.GetEntryAssembly ();
290 if (assembly == null)
291 assembly = Assembly.GetCallingAssembly ();
293 byte [] pkt = assembly.GetName ().GetPublicKeyToken ();
294 byte [] hash = SHA1.Create ().ComputeHash (pkt != null && pkt.Length >0 ? pkt : Encoding.UTF8.GetBytes (assembly.EscapedCodeBase));
295 System.Text.StringBuilder evidence_string = new System.Text.StringBuilder();
296 foreach (byte b in hash)
297 evidence_string.AppendFormat("{0:x2}",b);
298 return evidence_string.ToString ();
301 private static string GetProductVersion ()
303 Assembly assembly = Assembly.GetEntryAssembly ();
304 if (assembly == null)
305 assembly = Assembly.GetCallingAssembly ();
306 if (assembly == null)
309 return assembly.GetName ().Version.ToString ();
312 private static void CreateUserConfigPath ()
317 if (ProductName == "")
318 ProductName = GetProductName ();
319 if (CompanyName == "")
320 CompanyName = GetCompanyName ();
321 if (ForceVersion == "")
322 ProductVersion = GetProductVersion ().Split('.');
324 // C:\Documents and Settings\(user)\Application Data
325 if (userRoamingBasePath == "")
326 userRoamingPath = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
328 userRoamingPath = userRoamingBasePath;
330 // C:\Documents and Settings\(user)\Local Settings\Application Data (on Windows)
331 if (userLocalBasePath == "")
332 userLocalPath = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
334 userLocalPath = userLocalBasePath;
337 userRoamingPath = Path.Combine (userRoamingPath, CompanyName);
338 userLocalPath = Path.Combine (userLocalPath, CompanyName);
343 Assembly assembly = Assembly.GetEntryAssembly ();
344 if (assembly == null)
345 assembly = Assembly.GetCallingAssembly ();
346 byte [] pkt = assembly.GetName ().GetPublicKeyToken ();
347 ProductName = String.Format ("{0}_{1}_{2}",
349 pkt != null ? "StrongName" : "Url",
352 userRoamingPath = Path.Combine (userRoamingPath, ProductName);
353 userLocalPath = Path.Combine (userLocalPath, ProductName);
359 if (ForceVersion == "") {
360 if (isVersionRevision)
361 versionName = String.Format ("{0}.{1}.{2}.{3}", ProductVersion [0], ProductVersion [1], ProductVersion [2], ProductVersion [3]);
362 else if (isVersionBuild)
363 versionName = String.Format ("{0}.{1}.{2}", ProductVersion [0], ProductVersion [1], ProductVersion [2]);
364 else if (isVersionMinor)
365 versionName = String.Format ("{0}.{1}", ProductVersion [0], ProductVersion [1]);
366 else if (isVersionMajor)
367 versionName = ProductVersion [0];
372 versionName = ForceVersion;
374 string prevVersionRoaming = PrevVersionPath (userRoamingPath, versionName);
375 string prevVersionLocal = PrevVersionPath (userLocalPath, versionName);
377 userRoamingPath = Path.Combine (userRoamingPath, versionName);
378 userLocalPath = Path.Combine (userLocalPath, versionName);
379 if (prevVersionRoaming != "")
380 userRoamingPathPrevVersion = Path.Combine(userRoamingPath, prevVersionRoaming);
381 if (prevVersionLocal != "")
382 userLocalPathPrevVersion = Path.Combine(userLocalPath, prevVersionLocal);
385 // string for the previous version. It ignores newer ones.
386 private static string PrevVersionPath (string dirName, string currentVersion)
388 string prevVersionString = "";
390 if (!Directory.Exists(dirName))
391 return prevVersionString;
392 DirectoryInfo currentDir = new DirectoryInfo (dirName);
393 foreach (DirectoryInfo dirInfo in currentDir.GetDirectories ())
394 if (String.Compare (currentVersion, dirInfo.Name, StringComparison.Ordinal) > 0)
395 if (String.Compare (prevVersionString, dirInfo.Name, StringComparison.Ordinal) < 0)
396 prevVersionString = dirInfo.Name;
398 return prevVersionString;
401 // sets the explicit path to store roaming user.config or equivalent.
402 // (returns the path validity.)
403 public static bool SetUserRoamingPath (string configPath)
405 if (CheckPath (configPath))
407 userRoamingBasePath = configPath;
414 // sets the explicit path to store local user.config or equivalent.
415 // (returns the path validity.)
416 public static bool SetUserLocalPath (string configPath)
418 if (CheckPath (configPath))
420 userLocalBasePath = configPath;
427 private static bool CheckFileName (string configFile)
430 char[] invalidFileChars = Path.GetInvalidFileNameChars();
432 foreach (char invalidChar in invalidFileChars)
434 if (configFile.Contains(invalidChar.ToString()))
441 return configFile.IndexOfAny (Path.GetInvalidFileNameChars ()) < 0;
444 // sets the explicit roaming file name which is user.config equivalent.
445 // (returns the file name validity.)
446 public static bool SetUserRoamingFileName (string configFile)
448 if (CheckFileName (configFile))
450 userRoamingName = configFile;
457 // sets the explicit local file name which is user.config equivalent.
458 // (returns the file name validity.)
459 public static bool SetUserLocalFileName (string configFile)
461 if (CheckFileName (configFile))
463 userLocalName = configFile;
470 // sets the explicit company name for folder.
471 // (returns the file name validity.)
472 public static bool SetCompanyName (string companyName)
474 if (CheckFileName (companyName))
476 CompanyName = companyName;
483 // sets the explicit product name for folder.
484 // (returns the file name validity.)
485 public static bool SetProductName (string productName)
487 if (CheckFileName (productName))
489 ProductName = productName;
496 // sets the explicit major version for folder.
497 public static bool SetVersion (int major)
499 ForceVersion = string.Format ("{0}", major);
503 // sets the explicit major and minor versions for folder.
504 public static bool SetVersion (int major, int minor)
506 ForceVersion = string.Format ("{0}.{1}", major, minor);
510 // sets the explicit major/minor/build numbers for folder.
511 public static bool SetVersion (int major, int minor, int build)
513 ForceVersion = string.Format ("{0}.{1}.{2}", major, minor, build);
517 // sets the explicit major/minor/build/revision numbers for folder.
518 public static bool SetVersion (int major, int minor, int build, int revision)
520 ForceVersion = string.Format ("{0}.{1}.{2}.{3}", major, minor, build, revision);
524 // sets the explicit version number string for folder.
525 public static bool SetVersion (string forceVersion)
527 if (CheckFileName (forceVersion))
529 ForceVersion = forceVersion;
536 private static bool CheckPath (string configPath)
538 char[] invalidPathChars = Path.GetInvalidPathChars ();
541 foreach (char invalidChar in invalidPathChars)
543 if (configPath.Contains (invalidChar.ToString()))
549 if (configPath.IndexOfAny (invalidPathChars) >= 0)
552 string folder = configPath;
554 while ((fileName = Path.GetFileName (folder)) != "")
556 if (!CheckFileName (fileName))
560 folder = Path.GetDirectoryName (folder);
567 public override string Name {
568 get { return base.Name; }
571 string app_name = String.Empty;//"OJK.CustomSetting.CustomizableLocalFileSettingsProvider";
572 public override string ApplicationName {
573 get { return app_name; }
574 set { app_name = value; }
577 private ExeConfigurationFileMap exeMapCurrent = null;
578 private ExeConfigurationFileMap exeMapPrev = null;
579 private SettingsPropertyValueCollection values = null;
581 private void SaveProperties (ExeConfigurationFileMap exeMap, SettingsPropertyValueCollection collection, ConfigurationUserLevel level, SettingsContext context, bool checkUserLevel)
583 Configuration config = ConfigurationManager.OpenMappedExeConfiguration (exeMap, level);
585 UserSettingsGroup userGroup = config.GetSectionGroup ("userSettings") as UserSettingsGroup;
586 bool isRoaming = (level == ConfigurationUserLevel.PerUserRoaming);
588 #if true // my reimplementation
590 if (userGroup == null) {
591 userGroup = new UserSettingsGroup ();
592 config.SectionGroups.Add ("userSettings", userGroup);
594 ApplicationSettingsBase asb = context.CurrentSettings;
595 string class_name = NormalizeInvalidXmlChars ((asb != null ? asb.GetType () : typeof (ApplicationSettingsBase)).FullName);
596 ClientSettingsSection userSection = null;
597 ConfigurationSection cnf = userGroup.Sections.Get (class_name);
598 userSection = cnf as ClientSettingsSection;
599 if (userSection == null) {
600 userSection = new ClientSettingsSection ();
601 userGroup.Sections.Add (class_name, userSection);
604 bool hasChanges = false;
606 if (userSection == null)
609 foreach (SettingsPropertyValue value in collection) {
610 if (checkUserLevel && value.Property.Attributes.Contains (typeof (SettingsManageabilityAttribute)) != isRoaming)
612 // The default impl does not save the ApplicationScopedSetting properties
613 if (value.Property.Attributes.Contains (typeof (ApplicationScopedSettingAttribute)))
617 SettingElement element = userSection.Settings.Get (value.Name);
618 if (element == null) {
619 element = new SettingElement (value.Name, value.Property.SerializeAs);
620 userSection.Settings.Add (element);
622 if (element.Value.ValueXml == null)
623 element.Value.ValueXml = new XmlDocument ().CreateElement ("value");
624 switch (value.Property.SerializeAs) {
625 case SettingsSerializeAs.Xml:
626 element.Value.ValueXml.InnerXml = (value.SerializedValue as string) ?? string.Empty;
628 case SettingsSerializeAs.String:
629 element.Value.ValueXml.InnerText = value.SerializedValue as string;
631 case SettingsSerializeAs.Binary:
632 element.Value.ValueXml.InnerText = value.SerializedValue != null ? Convert.ToBase64String (value.SerializedValue as byte []) : string.Empty;
635 throw new NotImplementedException ();
639 config.Save (ConfigurationSaveMode.Minimal, true);
641 #else // original impl. - likely buggy to miss some properties to save
643 foreach (ConfigurationSection configSection in userGroup.Sections)
645 ClientSettingsSection userSection = configSection as ClientSettingsSection;
646 if (userSection != null)
649 userSection.Settings.Clear();
651 foreach (SettingsPropertyValue propertyValue in collection)
653 if (propertyValue.IsDirty)
655 SettingElement element = new SettingElement(propertyValue.Name, SettingsSerializeAs.String);
656 element.Value.ValueXml = new XmlDocument();
657 element.Value.ValueXml.InnerXml = (string)propertyValue.SerializedValue;
658 userSection.Settings.Add(element);
662 foreach (SettingElement element in userSection.Settings)
664 if (collection [element.Name] != null) {
665 if (collection [element.Name].Property.Attributes.Contains (typeof (SettingsManageabilityAttribute)) != isRoaming)
668 element.SerializeAs = SettingsSerializeAs.String;
669 element.Value.ValueXml.InnerXml = (string) collection [element.Name].SerializedValue; ///Value = XmlElement
675 config.Save (ConfigurationSaveMode.Minimal, true);
679 // NOTE: We should add here all the chars that are valid in a name of a class (Ecma-wise),
680 // but invalid in an xml element name, and provide a better impl if we get too many of them.
681 string NormalizeInvalidXmlChars (string str)
683 char [] invalid_chars = new char [] { '+' };
685 if (str == null || str.IndexOfAny (invalid_chars) == -1)
688 // Replace with its hexadecimal values.
689 str = str.Replace ("+", "_x002B_");
693 private void LoadPropertyValue (SettingsPropertyCollection collection, SettingElement element, bool allowOverwrite)
695 SettingsProperty prop = collection [element.Name];
696 if (prop == null) { // see bug #343459
697 prop = new SettingsProperty (element.Name);
698 collection.Add (prop);
701 SettingsPropertyValue value = new SettingsPropertyValue (prop);
702 value.IsDirty = false;
703 if (element.Value.ValueXml != null) {
704 switch (value.Property.SerializeAs) {
705 case SettingsSerializeAs.Xml:
706 value.SerializedValue = element.Value.ValueXml.InnerXml;
708 case SettingsSerializeAs.String:
709 value.SerializedValue = element.Value.ValueXml.InnerText.Trim ();
711 case SettingsSerializeAs.Binary:
712 value.SerializedValue = Convert.FromBase64String (element.Value.ValueXml.InnerText);
717 value.SerializedValue = prop.DefaultValue;
721 values.Remove (element.Name);
723 } catch (ArgumentException ex) {
724 throw new ConfigurationErrorsException (string.Format (
725 CultureInfo.InvariantCulture,
726 "Failed to load value for '{0}'.",
731 private void LoadProperties (ExeConfigurationFileMap exeMap, SettingsPropertyCollection collection, ConfigurationUserLevel level, string sectionGroupName, bool allowOverwrite, string groupName)
733 Configuration config = ConfigurationManager.OpenMappedExeConfiguration (exeMap,level);
735 ConfigurationSectionGroup sectionGroup = config.GetSectionGroup (sectionGroupName);
736 if (sectionGroup != null) {
737 foreach (ConfigurationSection configSection in sectionGroup.Sections) {
738 if (configSection.SectionInformation.Name != groupName)
741 ClientSettingsSection clientSection = configSection as ClientSettingsSection;
742 if (clientSection == null)
745 foreach (SettingElement element in clientSection.Settings) {
746 LoadPropertyValue(collection, element, allowOverwrite);
748 // Only the first one seems to be processed by MS
755 public override void SetPropertyValues (SettingsContext context, SettingsPropertyValueCollection collection)
759 if (UserLocalFullPath == UserRoamingFullPath)
761 SaveProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, context, false);
763 SaveProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, context, true);
764 SaveProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoamingAndLocal, context, true);
768 public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context, SettingsPropertyCollection collection)
772 values = new SettingsPropertyValueCollection ();
773 string groupName = context ["GroupName"] as string;
774 groupName = NormalizeInvalidXmlChars (groupName); // we likely saved the element removing the non valid xml chars.
775 LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.None, "applicationSettings", false, groupName);
776 LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.None, "userSettings", false, groupName);
778 LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, "userSettings", true, groupName);
779 LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoamingAndLocal, "userSettings", true, groupName);
781 // create default values if not exist
782 foreach (SettingsProperty p in collection)
783 if (values [p.Name] == null)
784 values.Add (new SettingsPropertyValue (p));
788 /// creates an ExeConfigurationFileMap
789 private void CreateExeMap ()
791 if (exeMapCurrent == null) {
792 CreateUserConfigPath ();
795 exeMapCurrent = new ExeConfigurationFileMap ();
797 // exeMapCurrent.ExeConfigFilename = System.Windows.Forms.Application.ExecutablePath + ".config";
798 Assembly entry = Assembly.GetEntryAssembly () ?? Assembly.GetExecutingAssembly ();
799 exeMapCurrent.ExeConfigFilename = entry.Location + ".config";
800 exeMapCurrent.LocalUserConfigFilename = UserLocalFullPath;
801 exeMapCurrent.RoamingUserConfigFilename = UserRoamingFullPath;
803 if (webConfigurationFileMapType != null && typeof (ConfigurationFileMap).IsAssignableFrom (webConfigurationFileMapType)) {
805 ConfigurationFileMap cfgFileMap = Activator.CreateInstance (webConfigurationFileMapType) as ConfigurationFileMap;
806 if (cfgFileMap != null) {
807 string fpath = cfgFileMap.MachineConfigFilename;
808 if (!String.IsNullOrEmpty (fpath))
809 exeMapCurrent.ExeConfigFilename = fpath;
817 if ((PrevUserLocalFullPath != "") && (PrevUserRoamingFullPath != ""))
819 exeMapPrev = new ExeConfigurationFileMap();
820 // exeMapPrev.ExeConfigFilename = System.Windows.Forms.Application.ExecutablePath + ".config";
821 exeMapPrev.ExeConfigFilename = entry.Location + ".config";
822 exeMapPrev.LocalUserConfigFilename = PrevUserLocalFullPath;
823 exeMapPrev.RoamingUserConfigFilename = PrevUserRoamingFullPath;
829 public SettingsPropertyValue GetPreviousVersion (SettingsContext context, SettingsProperty property)
834 public void Reset (SettingsContext context)
836 if (values != null) {
837 foreach (SettingsPropertyValue propertyValue in values) {
838 // Can't use propertyValue.Property.DefaultValue
839 // as it may cause InvalidCastException (see bug# 532180)
840 values[propertyValue.Name].PropertyValue = propertyValue.Reset ();
846 public void Upgrade (SettingsContext context, SettingsPropertyCollection properties)
850 public static void setCreate ()
852 CreateUserConfigPath();