Mercurial > repos > IBBoard.WarFoundry.API
changeset 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 | 81e130f3b85e |
children | e4e2a85604b6 |
files | API/AbstractWarFoundryLoader.cs API/WarFoundryHacks.cs API/WarFoundryLoader.cs |
diffstat | 3 files changed, 24 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/API/AbstractWarFoundryLoader.cs Tue May 15 20:57:29 2012 +0100 +++ b/API/AbstractWarFoundryLoader.cs Sat May 19 14:38:15 2012 +0100 @@ -29,6 +29,7 @@ protected AbstractWarFoundryLoader() { directories = new List<DirectoryInfo>(); + directories.Add(new DirectoryInfo(WarFoundryLoader.DEFAULT_USER_DATA_DIR)); factories = new List<INativeWarFoundryFactory>(); nonNativeFactories = new List<INonNativeWarFoundryFactory>(); loadedObjects = new Dictionary<IWarFoundryFactory,SimpleSet<IWarFoundryObject>>();
--- a/API/WarFoundryHacks.cs Tue May 15 20:57:29 2012 +0100 +++ b/API/WarFoundryHacks.cs Sat May 19 14:38:15 2012 +0100 @@ -16,12 +16,10 @@ /// </summary> public class WarFoundryHacks { - public static readonly string dataPath = Path.Combine(Constants.ExecutablePath, "data"); - public static void Initialise() { //Set default data path - should be a preference - WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(dataPath)); + WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Path.Combine(Constants.ExecutablePath, "data"))); //Make sure we have at least one loader - should be controlled by plugins WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); //Make sure we have a way to save files - should be controlled by plugins
--- 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); + } } }