PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/JTacticalSim.API/InfoObjects/DataFileInfoBase.cs

https://github.com/Queztionmark/JTacticalSim
C# | 101 lines | 89 code | 11 blank | 1 comment | 1 complexity | c8e7f4d6330a0a5eb8eac1f0eceb8f64 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Configuration;
  7. using System.Xml.Linq;
  8. using JTacticalSim.API.Data;
  9. using JTacticalSim.Utility;
  10. namespace JTacticalSim.API.InfoObjects
  11. {
  12. public abstract class DataFileInfoBase<fileType> : IDataFileInfo<fileType>
  13. {
  14. protected string RootFilePath { get; set; }
  15. protected string FilePathGameSave { get; set; }
  16. protected string FilePathScenario { get; set; }
  17. protected string FilePathComponentData { get; set; }
  18. protected string _scenarioDataFilePath;
  19. protected string _savedGameDataFilePath;
  20. protected string _componentDataFilePath;
  21. protected string _lookupDataFilePath;
  22. protected string _gameDataFilePath;
  23. protected string _boardDataFilePath;
  24. protected string _unitDataFilePath;
  25. public string ScenarioDataFilePath { get { return _scenarioDataFilePath; }}
  26. public string SavedGameDataFilePath { get { return _savedGameDataFilePath; } }
  27. public string ComponentDataFilePath { get { return _componentDataFilePath; } }
  28. public string LookupDataFilePath { get { return _lookupDataFilePath; } }
  29. public string GameDataFilePath { get { return _gameDataFilePath; } }
  30. public string BoardDataFilePath { get { return _boardDataFilePath; } }
  31. public string UnitDataFilePath { get { return _unitDataFilePath; } }
  32. public XDocument SavedGameDataFile { get { return XDocument.Load(_savedGameDataFilePath); } }
  33. public XDocument ScenarioDataFile {get { return XDocument.Load(_scenarioDataFilePath); }}
  34. public abstract fileType ComponentDataFile { get; }
  35. public abstract fileType LookupDataFile { get; }
  36. public abstract fileType GameDataFile { get; }
  37. public abstract fileType BoardDataFile { get; }
  38. public abstract fileType UnitDataFile { get; }
  39. public abstract string GameSaveRootDirectory { get; }
  40. public abstract string GameSaveDirectory { get; }
  41. public abstract string ScenarioDirectory { get; }
  42. public abstract string ComponentDirectory { get; }
  43. public List<String> ScenarioFilePaths
  44. {
  45. get
  46. {
  47. return new List<string>()
  48. {
  49. GameDataFilePath,
  50. BoardDataFilePath,
  51. UnitDataFilePath
  52. };
  53. }
  54. }
  55. public List<fileType> ScenarioFiles
  56. {
  57. get
  58. {
  59. return new List<fileType>()
  60. {
  61. GameDataFile,
  62. BoardDataFile,
  63. UnitDataFile
  64. };
  65. }
  66. }
  67. public DataFileInfoBase()
  68. {
  69. // Get the data from the configured component set
  70. var componentSet = ConfigurationManager.AppSettings["component_set"];
  71. var componentSetPath = string.Empty;
  72. switch (componentSet)
  73. {
  74. case "modern" :
  75. componentSetPath = "\\Modern";
  76. break;
  77. case "Fantasy" :
  78. componentSetPath = "\\Fantasy";
  79. break;
  80. }
  81. var curDrive = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory());
  82. RootFilePath = "{0}{1}".F(curDrive, ConfigurationManager.AppSettings["datafilepathDefault"]);
  83. FilePathComponentData = "{0}{1}".F(RootFilePath, componentSetPath);
  84. FilePathGameSave = "{0}{1}".F(curDrive, ConfigurationManager.AppSettings["datafilepathGameSaveDefault"]);
  85. FilePathScenario = "{0}{1}".F(curDrive, ConfigurationManager.AppSettings["datafilepathScenarioDefault"]);
  86. _savedGameDataFilePath = "{0}\\010_SavedGames.xml".F(RootFilePath);
  87. _scenarioDataFilePath = "{0}\\005_Scenarios.xml".F(RootFilePath);
  88. }
  89. }
  90. }