/JTacticalSim.API/InfoObjects/DataFileInfoBase.cs
C# | 101 lines | 89 code | 11 blank | 1 comment | 1 complexity | c8e7f4d6330a0a5eb8eac1f0eceb8f64 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Configuration;
- using System.Xml.Linq;
- using JTacticalSim.API.Data;
- using JTacticalSim.Utility;
-
- namespace JTacticalSim.API.InfoObjects
- {
- public abstract class DataFileInfoBase<fileType> : IDataFileInfo<fileType>
- {
- protected string RootFilePath { get; set; }
- protected string FilePathGameSave { get; set; }
- protected string FilePathScenario { get; set; }
- protected string FilePathComponentData { get; set; }
-
- protected string _scenarioDataFilePath;
- protected string _savedGameDataFilePath;
- protected string _componentDataFilePath;
- protected string _lookupDataFilePath;
- protected string _gameDataFilePath;
- protected string _boardDataFilePath;
- protected string _unitDataFilePath;
-
- public string ScenarioDataFilePath { get { return _scenarioDataFilePath; }}
- public string SavedGameDataFilePath { get { return _savedGameDataFilePath; } }
- public string ComponentDataFilePath { get { return _componentDataFilePath; } }
- public string LookupDataFilePath { get { return _lookupDataFilePath; } }
- public string GameDataFilePath { get { return _gameDataFilePath; } }
- public string BoardDataFilePath { get { return _boardDataFilePath; } }
- public string UnitDataFilePath { get { return _unitDataFilePath; } }
-
- public XDocument SavedGameDataFile { get { return XDocument.Load(_savedGameDataFilePath); } }
- public XDocument ScenarioDataFile {get { return XDocument.Load(_scenarioDataFilePath); }}
-
- public abstract fileType ComponentDataFile { get; }
- public abstract fileType LookupDataFile { get; }
- public abstract fileType GameDataFile { get; }
- public abstract fileType BoardDataFile { get; }
- public abstract fileType UnitDataFile { get; }
- public abstract string GameSaveRootDirectory { get; }
- public abstract string GameSaveDirectory { get; }
- public abstract string ScenarioDirectory { get; }
- public abstract string ComponentDirectory { get; }
-
- public List<String> ScenarioFilePaths
- {
- get
- {
- return new List<string>()
- {
- GameDataFilePath,
- BoardDataFilePath,
- UnitDataFilePath
- };
- }
- }
-
- public List<fileType> ScenarioFiles
- {
- get
- {
- return new List<fileType>()
- {
- GameDataFile,
- BoardDataFile,
- UnitDataFile
- };
- }
- }
-
- public DataFileInfoBase()
- {
- // Get the data from the configured component set
- var componentSet = ConfigurationManager.AppSettings["component_set"];
- var componentSetPath = string.Empty;
-
- switch (componentSet)
- {
- case "modern" :
- componentSetPath = "\\Modern";
- break;
- case "Fantasy" :
- componentSetPath = "\\Fantasy";
- break;
- }
-
- var curDrive = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory());
- RootFilePath = "{0}{1}".F(curDrive, ConfigurationManager.AppSettings["datafilepathDefault"]);
- FilePathComponentData = "{0}{1}".F(RootFilePath, componentSetPath);
- FilePathGameSave = "{0}{1}".F(curDrive, ConfigurationManager.AppSettings["datafilepathGameSaveDefault"]);
- FilePathScenario = "{0}{1}".F(curDrive, ConfigurationManager.AppSettings["datafilepathScenarioDefault"]);
-
- _savedGameDataFilePath = "{0}\\010_SavedGames.xml".F(RootFilePath);
- _scenarioDataFilePath = "{0}\\005_Scenarios.xml".F(RootFilePath);
- }
- }
- }