Author: jpobst Date: 2008-02-20 11:42:02 -0500 (Wed, 20 Feb 2008) New Revision: 96268
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog Log: 2008-02-20 Jonathan Pobst <[EMAIL PROTECTED]> * Application.cs: For the app data paths and the registry key paths, ensure they are created before returning them to the user. [Fixes bug #361709] Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs =================================================================== --- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs 2008-02-20 16:37:39 UTC (rev 96267) +++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs 2008-02-20 16:42:02 UTC (rev 96268) @@ -195,15 +195,15 @@ public static string CommonAppDataPath { get { - return Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData); + return CreateDataPath (Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData)); } } public static RegistryKey CommonAppDataRegistry { get { - return Registry.LocalMachine.OpenSubKey ("Software\\" + - Application.CompanyName + "\\" + Application.ProductName + - "\\" + Application.ProductVersion, true); + string key = string.Format ("Software\\{0}\\{1}\\{2}", CompanyName, ProductName, ProductVersion); + + return Registry.LocalMachine.CreateSubKey (key); } } @@ -262,9 +262,7 @@ public static string LocalUserAppDataPath { get { - return Path.Combine (Path.Combine (Path.Combine ( - Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), - CompanyName), ProductName), ProductVersion); + return CreateDataPath (Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData)); } } @@ -342,17 +340,15 @@ public static string UserAppDataPath { get { - return Path.Combine (Path.Combine (Path.Combine ( - Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), - CompanyName), ProductName), ProductVersion); + return CreateDataPath (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData)); } } public static RegistryKey UserAppDataRegistry { get { - return Registry.CurrentUser.OpenSubKey ("Software\\" + - Application.CompanyName + "\\" + Application.ProductName + - "\\" + Application.ProductVersion, true); + string key = string.Format ("Software\\{0}\\{1}\\{2}", CompanyName, ProductName, ProductVersion); + + return Registry.CurrentUser.CreateSubKey (key); } } @@ -994,6 +990,22 @@ return false; } #endif + + // Takes a starting path, appends company name, product name, and + // product version. If the directory doesn't exist, create it + private static string CreateDataPath (string basePath) + { + string path; + + path = Path.Combine (basePath, CompanyName); + path = Path.Combine (path, ProductName); + path = Path.Combine (path, ProductVersion); + + if (!Directory.Exists (path)) + Directory.CreateDirectory (path); + + return path; + } #endregion } } Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog =================================================================== --- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog 2008-02-20 16:37:39 UTC (rev 96267) +++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog 2008-02-20 16:42:02 UTC (rev 96268) @@ -1,5 +1,11 @@ 2008-02-20 Jonathan Pobst <[EMAIL PROTECTED]> + * Application.cs: For the app data paths and the registry key paths, + ensure they are created before returning them to the user. + [Fixes bug #361709] + +2008-02-20 Jonathan Pobst <[EMAIL PROTECTED]> + * Application.cs: Guard against an NRE in CompanyName and ProductName. _______________________________________________ Mono-patches maillist - Mono-patches@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-patches