changeset 107:0f88d32b22cc

* Swap to built-in .Net methods (listed on http://www.ironshay.com/post/Use-NET-Built-in-Methods-to-Save-Time-and-Headaches.aspx) no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sat, 13 Aug 2011 10:42:57 +0000
parents a78efc8b2119
children 27b6aa1e98e8
files Constants.cs Logging/FileLogger.cs Preferences.cs Xml/IBBXmlResolver.cs
diffstat 4 files changed, 14 insertions(+), 40 deletions(-) [+]
line diff
     1.1 --- a/Constants.cs	Sun Aug 07 19:13:19 2011 +0000
     1.2 +++ b/Constants.cs	Sat Aug 13 10:42:57 2011 +0000
     1.3 @@ -18,20 +18,10 @@
     1.4  
     1.5  		static Constants()
     1.6  		{
     1.7 -            string exe = Environment.GetCommandLineArgs()[0];
     1.8 -            int slash = exe.LastIndexOf(DirectoryChar) + 1;
     1.9 -            int dot = exe.LastIndexOf('.');
    1.10 -
    1.11 -            if (dot > slash)
    1.12 -            {
    1.13 -                exe = exe.Substring(slash, dot - slash);
    1.14 -            }
    1.15 -            else
    1.16 -            {
    1.17 -                exe = exe.Substring(slash);
    1.18 -            }
    1.19 -
    1.20 -            userDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).TrimEnd(DirectoryChar) + DirectoryChar + "IBBoard" + DirectoryChar + exe;
    1.21 +            string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
    1.22 +			string exe = Environment.GetCommandLineArgs()[0];
    1.23 +			exe = Path.GetFileNameWithoutExtension(exe);
    1.24 +            userDataPath = Path.Combine(Path.Combine(appDataDir, "IBBoard"), exe);
    1.25  		}
    1.26  
    1.27  		public static string ExecutablePath
    1.28 @@ -45,13 +35,5 @@
    1.29  		{
    1.30  			get { return userDataPath; }
    1.31  		}
    1.32 -		
    1.33 -		/*public static void RecreateUserDataPath(string path)
    1.34 -		{
    1.35 -			if (path!=null && path!="")
    1.36 -			{
    1.37 -				userDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+DirectoryChar+path.Trim(DirectoryChar);
    1.38 -			}
    1.39 -		}*/
    1.40  	}
    1.41  }
     2.1 --- a/Logging/FileLogger.cs	Sun Aug 07 19:13:19 2011 +0000
     2.2 +++ b/Logging/FileLogger.cs	Sat Aug 13 10:42:57 2011 +0000
     2.3 @@ -32,7 +32,7 @@
     2.4  		
     2.5  		public static string MakeLogFilePath(string path)
     2.6  		{
     2.7 -			return path.TrimEnd(IBBoard.Constants.DirectoryChar) + IBBoard.Constants.DirectoryChar + "logs" + IBBoard.Constants.DirectoryChar + String.Format("{0:yyyy-MM-dd-HHmmss}", DateTime.Now)+".log";
     2.8 +			return Path.Combine(Path.Combine(path, "logs"), String.Format("{0:yyyy-MM-dd-HHmmss}.log", DateTime.Now));
     2.9  		}
    2.10  		
    2.11  		public static FileStream CreateDefaultLogFileStream()
     3.1 --- a/Preferences.cs	Sun Aug 07 19:13:19 2011 +0000
     3.2 +++ b/Preferences.cs	Sat Aug 13 10:42:57 2011 +0000
     3.3 @@ -32,22 +32,12 @@
     3.4  			LoadPreferences();
     3.5  		}
     3.6  
     3.7 -		/*public Preferences(string appExecPath, string appName, string fullUserDataDir)
     3.8 -		{
     3.9 -			LoadPreferences(appExecPath.TrimEnd(Constants.DirectoryChar) + Constants.DirectoryChar + appName + "Pref.xml", fullUserDataDir.TrimEnd(Constants.DirectoryChar));
    3.10 -		}
    3.11 -
    3.12 -		public Preferences(string filepath, string appDir)
    3.13 -		{
    3.14 -			LoadPreferences(filepath, appDir);
    3.15 -		}*/
    3.16 -
    3.17  		private void LoadPreferences()
    3.18  		{
    3.19  			htGlobal = new Hashtable();
    3.20  			htLocal = new Hashtable();
    3.21  			
    3.22 -			string globalPath = Constants.ExecutablePath + Constants.DirectoryChar + app + "Pref.xml";
    3.23 +			string globalPath = Path.Combine(Constants.ExecutablePath, app + "Pref.xml");
    3.24  			
    3.25  			if (File.Exists(globalPath))
    3.26  			{
    3.27 @@ -113,7 +103,7 @@
    3.28  		
    3.29  		private void LoadLocalPreferences()
    3.30  		{
    3.31 -			string path = Constants.UserDataPath + Constants.DirectoryString + "preferences.xml";
    3.32 +			string path = Path.Combine(Constants.UserDataPath, "preferences.xml");
    3.33  
    3.34  			if (File.Exists(path))
    3.35  			{
    3.36 @@ -287,6 +277,8 @@
    3.37  
    3.38  		public void Save()
    3.39  		{
    3.40 +			string prefPath = Path.Combine(Constants.UserDataPath, "preferences.xml");
    3.41 +
    3.42  			if (htLocal.Count>0)
    3.43  			{
    3.44  				XmlDocument xmld = new XmlDocument();
    3.45 @@ -354,12 +346,12 @@
    3.46  				{
    3.47  					Directory.CreateDirectory(Constants.UserDataPath);
    3.48  				}
    3.49 -				
    3.50 -				xmld.Save(Constants.UserDataPath + Constants.DirectoryString + "preferences.xml");
    3.51 +
    3.52 +				xmld.Save(prefPath);
    3.53  			}
    3.54 -			else if (File.Exists(Constants.UserDataPath + Constants.DirectoryString + "preferences.xml"))
    3.55 +			else if (File.Exists(prefPath))
    3.56  			{
    3.57 -				File.Delete(Constants.UserDataPath + Constants.DirectoryString + "preferences.xml");
    3.58 +				File.Delete(prefPath);
    3.59  			}
    3.60  
    3.61  			modified = false;
     4.1 --- a/Xml/IBBXmlResolver.cs	Sun Aug 07 19:13:19 2011 +0000
     4.2 +++ b/Xml/IBBXmlResolver.cs	Sat Aug 13 10:42:57 2011 +0000
     4.3 @@ -24,7 +24,7 @@
     4.4  			if (relativeUri.StartsWith("dtds/"))
     4.5  			{
     4.6  				//Uri uri = base.ResolveUri(baseUri, relativeUri);
     4.7 -				return new Uri(Uri.UriSchemeFile + "://" + baseFilePath + Constants.DirectoryString + relativeUri);
     4.8 +				return new Uri(Uri.UriSchemeFile + "://" + baseFilePath + "/" + relativeUri);
     4.9  			}
    4.10  			else
    4.11  			{