Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate API/WarFoundryLoader.cs @ 491:a41c2bc1683a
Re #410: M units for N parent models requirement
* Fix text string for requirement failure
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 02 Aug 2012 21:02:23 +0100 |
parents | 1a632b133606 |
children |
rev | line source |
---|---|
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (WarFoundryLoader.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // 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. |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System; |
477
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
5 using System.IO; |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using ICSharpCode.SharpZipLib.Zip; |
379
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
7 using System.Collections.Generic; |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
8 using IBBoard.WarFoundry.API.Factories.Requirement; |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
9 using IBBoard.WarFoundry.API.Objects.Requirement; |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 namespace IBBoard.WarFoundry.API |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 public class WarFoundryLoader |
477
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
14 { |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
15 public static readonly string DEFAULT_USER_DATA_DIR = Path.Combine(Constants.UserDataPath, "data"); |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 private static AbstractWarFoundryLoader loader; |
379
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
17 private static Dictionary<string, IRequirementFactory> requirementFactories = new Dictionary<string, IRequirementFactory>(); |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
18 |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 /// <summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 /// Gets the default <see cref="WarFoundryLoader"/> used to load WarFoundry data files. |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 /// </summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 /// <returns> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 /// The default <see cref="WarFoundryLoader"/> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 /// </returns> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 public static AbstractWarFoundryLoader GetDefault() |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 if (loader == null) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 loader = new DefaultWarFoundryLoader(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 return loader; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 public static void SetDefault(AbstractWarFoundryLoader newLoader) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 { |
379
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
37 loader = newLoader; |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 } |
379
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
39 |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 private WarFoundryLoader() |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 //Hide constructor |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 } |
379
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
44 |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
45 public static void RegisterRequirementFactory(IRequirementFactory factory) |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
46 { |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
47 requirementFactories[factory.AppliesToID] = factory; |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
48 } |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
49 |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
50 public static IRequirementFactory GetRequirementFactory(string requirementID) |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
51 { |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
52 return DictionaryUtils.GetValue(requirementFactories, requirementID); |
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
53 } |
477
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
54 |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
55 /// <summary> |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
56 /// Adds the new data file to the default data directory. Once added, the loader will need to be refreshed to |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
57 /// force it to load the new file. |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
58 /// </summary> |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
59 /// <param name='filePath'> |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
60 /// The path of the file to copy to the default data directory |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
61 /// </param> |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
62 public static void AddNewDataFile(string filePath) |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
63 { |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
64 string newFilePath = System.IO.Path.Combine(WarFoundryLoader.DEFAULT_USER_DATA_DIR, System.IO.Path.GetFileName(filePath)); |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
65 |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
66 if (!Directory.Exists(WarFoundryLoader.DEFAULT_USER_DATA_DIR)) |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
67 { |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
68 Directory.CreateDirectory(WarFoundryLoader.DEFAULT_USER_DATA_DIR); |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
69 } |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
70 |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
71 File.Copy(filePath, newFilePath); |
1a632b133606
Re #417: Improve WarFoundry installation experience
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
72 } |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 } |