diff API/WarFoundryLoader.cs @ 477:1a632b133606

Re #417: Improve WarFoundry installation experience * Make the original "hack" something that is core
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 May 2012 14:38:15 +0100
parents 04f4c2fea356
children
line wrap: on
line diff
--- a/API/WarFoundryLoader.cs	Tue May 15 20:57:29 2012 +0100
+++ b/API/WarFoundryLoader.cs	Sat May 19 14:38:15 2012 +0100
@@ -2,6 +2,7 @@
 //
 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
 using System;
+using System.IO;
 using ICSharpCode.SharpZipLib.Zip;
 using System.Collections.Generic;
 using IBBoard.WarFoundry.API.Factories.Requirement;
@@ -10,7 +11,8 @@
 namespace IBBoard.WarFoundry.API
 {
 	public class WarFoundryLoader
-	{		
+	{
+		public static readonly string DEFAULT_USER_DATA_DIR = Path.Combine(Constants.UserDataPath, "data");
 		private static AbstractWarFoundryLoader loader;
 		private static Dictionary<string, IRequirementFactory> requirementFactories = new Dictionary<string, IRequirementFactory>();
 
@@ -49,5 +51,24 @@
 		{
 			return DictionaryUtils.GetValue(requirementFactories, requirementID);
 		}
+
+		/// <summary>
+		/// Adds the new data file to the default data directory. Once added, the loader will need to be refreshed to
+		/// force it to load the new file.
+		/// </summary>
+		/// <param name='filePath'>
+		/// The path of the file to copy to the default data directory
+		/// </param>
+		public static void AddNewDataFile(string filePath)
+		{
+			string newFilePath = System.IO.Path.Combine(WarFoundryLoader.DEFAULT_USER_DATA_DIR, System.IO.Path.GetFileName(filePath));
+
+			if (!Directory.Exists(WarFoundryLoader.DEFAULT_USER_DATA_DIR))
+			{
+				Directory.CreateDirectory(WarFoundryLoader.DEFAULT_USER_DATA_DIR);
+			}
+
+			File.Copy(filePath, newFilePath);
+		}
 	}
 }