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 wrap: on
line diff
--- a/Constants.cs	Sun Aug 07 19:13:19 2011 +0000
+++ b/Constants.cs	Sat Aug 13 10:42:57 2011 +0000
@@ -18,20 +18,10 @@
 
 		static Constants()
 		{
-            string exe = Environment.GetCommandLineArgs()[0];
-            int slash = exe.LastIndexOf(DirectoryChar) + 1;
-            int dot = exe.LastIndexOf('.');
-
-            if (dot > slash)
-            {
-                exe = exe.Substring(slash, dot - slash);
-            }
-            else
-            {
-                exe = exe.Substring(slash);
-            }
-
-            userDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).TrimEnd(DirectoryChar) + DirectoryChar + "IBBoard" + DirectoryChar + exe;
+            string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
+			string exe = Environment.GetCommandLineArgs()[0];
+			exe = Path.GetFileNameWithoutExtension(exe);
+            userDataPath = Path.Combine(Path.Combine(appDataDir, "IBBoard"), exe);
 		}
 
 		public static string ExecutablePath
@@ -45,13 +35,5 @@
 		{
 			get { return userDataPath; }
 		}
-		
-		/*public static void RecreateUserDataPath(string path)
-		{
-			if (path!=null && path!="")
-			{
-				userDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+DirectoryChar+path.Trim(DirectoryChar);
-			}
-		}*/
 	}
 }
--- a/Logging/FileLogger.cs	Sun Aug 07 19:13:19 2011 +0000
+++ b/Logging/FileLogger.cs	Sat Aug 13 10:42:57 2011 +0000
@@ -32,7 +32,7 @@
 		
 		public static string MakeLogFilePath(string path)
 		{
-			return path.TrimEnd(IBBoard.Constants.DirectoryChar) + IBBoard.Constants.DirectoryChar + "logs" + IBBoard.Constants.DirectoryChar + String.Format("{0:yyyy-MM-dd-HHmmss}", DateTime.Now)+".log";
+			return Path.Combine(Path.Combine(path, "logs"), String.Format("{0:yyyy-MM-dd-HHmmss}.log", DateTime.Now));
 		}
 		
 		public static FileStream CreateDefaultLogFileStream()
--- a/Preferences.cs	Sun Aug 07 19:13:19 2011 +0000
+++ b/Preferences.cs	Sat Aug 13 10:42:57 2011 +0000
@@ -32,22 +32,12 @@
 			LoadPreferences();
 		}
 
-		/*public Preferences(string appExecPath, string appName, string fullUserDataDir)
-		{
-			LoadPreferences(appExecPath.TrimEnd(Constants.DirectoryChar) + Constants.DirectoryChar + appName + "Pref.xml", fullUserDataDir.TrimEnd(Constants.DirectoryChar));
-		}
-
-		public Preferences(string filepath, string appDir)
-		{
-			LoadPreferences(filepath, appDir);
-		}*/
-
 		private void LoadPreferences()
 		{
 			htGlobal = new Hashtable();
 			htLocal = new Hashtable();
 			
-			string globalPath = Constants.ExecutablePath + Constants.DirectoryChar + app + "Pref.xml";
+			string globalPath = Path.Combine(Constants.ExecutablePath, app + "Pref.xml");
 			
 			if (File.Exists(globalPath))
 			{
@@ -113,7 +103,7 @@
 		
 		private void LoadLocalPreferences()
 		{
-			string path = Constants.UserDataPath + Constants.DirectoryString + "preferences.xml";
+			string path = Path.Combine(Constants.UserDataPath, "preferences.xml");
 
 			if (File.Exists(path))
 			{
@@ -287,6 +277,8 @@
 
 		public void Save()
 		{
+			string prefPath = Path.Combine(Constants.UserDataPath, "preferences.xml");
+
 			if (htLocal.Count>0)
 			{
 				XmlDocument xmld = new XmlDocument();
@@ -354,12 +346,12 @@
 				{
 					Directory.CreateDirectory(Constants.UserDataPath);
 				}
-				
-				xmld.Save(Constants.UserDataPath + Constants.DirectoryString + "preferences.xml");
+
+				xmld.Save(prefPath);
 			}
-			else if (File.Exists(Constants.UserDataPath + Constants.DirectoryString + "preferences.xml"))
+			else if (File.Exists(prefPath))
 			{
-				File.Delete(Constants.UserDataPath + Constants.DirectoryString + "preferences.xml");
+				File.Delete(prefPath);
 			}
 
 			modified = false;
--- a/Xml/IBBXmlResolver.cs	Sun Aug 07 19:13:19 2011 +0000
+++ b/Xml/IBBXmlResolver.cs	Sat Aug 13 10:42:57 2011 +0000
@@ -24,7 +24,7 @@
 			if (relativeUri.StartsWith("dtds/"))
 			{
 				//Uri uri = base.ResolveUri(baseUri, relativeUri);
-				return new Uri(Uri.UriSchemeFile + "://" + baseFilePath + Constants.DirectoryString + relativeUri);
+				return new Uri(Uri.UriSchemeFile + "://" + baseFilePath + "/" + relativeUri);
 			}
 			else
 			{