public static List <ScenarioModel> ReadScenariosFromDisk(string assetsDirectory, string routeGuid, bool inGame, bool inArchive) { var scenarioList = new List <ScenarioModel>(); int routeId = RoutesCollectionDataAccess.GetRouteId(routeGuid); if (routeId <= 0) { Log.Trace($"Cannot find RouteId for {routeGuid} No scenarios retrieved {Converters.LocationToString(inGame,inArchive)}", LogEventType.Message); return(scenarioList); } DirectoryInfo path = new DirectoryInfo($"{assetsDirectory}{routeGuid}\\Scenarios\\"); if (Directory.Exists(path.FullName)) { DirectoryInfo[] scenarioPathList = path.GetDirectories("*", SearchOption.TopDirectoryOnly); foreach (var scenarioDir in scenarioPathList) { var scenario = new ScenarioModel(); scenario.ScenarioGuid = scenarioDir.Name; scenario.RouteId = routeId; var scenarioPropertiesPath = $"{scenarioDir}\\ScenarioProperties.xml"; if (File.Exists(scenarioPropertiesPath)) { if (inGame) { scenario.IsValidInGame = true; } if (inArchive) { scenario.IsValidInArchive = true; } var properties = ScenarioPropertiesDataAccess.ReadScenarioNameAndClass(scenarioPropertiesPath, scenario.ScenarioGuid); scenario.ScenarioTitle = properties.ScenarioTitle; scenario.ScenarioClass = properties.ScenarioClass; } else { scenario.ScenarioTitle = ScenarioPropertiesDataAccess.GetInvalidScenarioTitle(scenario.ScenarioGuid); if (inGame) { scenario.IsValidInGame = false; } if (inArchive) { scenario.IsValidInArchive = false; } } scenarioList.Add(scenario); } } return(scenarioList); }
public static List <ScenarioModel> ReadScenariosFromDatabase(string routeGuid) { var routeId = RoutesCollectionDataAccess.GetRouteId(routeGuid); using IDbConnection Db = new SQLiteConnection(AssetDatabaseAccess.GetConnectionString()); var output = Db.Query <ScenarioModel>("SELECT * FROM Scenarios WHERE RouteId=@routeId", new { routeId }); return(output.ToList()); }
public static List <ScenarioModel> ReadPackedListScenariosFromDisk(string assetsDirectory, string routeGuid, bool inGame, bool inArchive) { var scenarioList = new List <ScenarioModel>(); int routeId = RoutesCollectionDataAccess.GetRouteId(routeGuid); if (routeId <= 0) { Log.Trace($"Cannot find RouteId for {routeGuid} No scenarios retrieved {Converters.LocationToString(inGame,inArchive)}", LogEventType.Message); return(scenarioList); } DirectoryInfo path = new DirectoryInfo($"{assetsDirectory}{routeGuid}\\"); if (Directory.Exists(path.FullName)) { FileInfo[] apFiles = path.GetFiles("*.ap", SearchOption.TopDirectoryOnly); foreach (var file in apFiles) { // We cannot use the ZipAccess method here, because all logic but be in scope of the using statement for the archive using (ZipArchive archive = ZipFile.OpenRead(file.FullName)) { var entries = archive.Entries; var filteredEntries = entries.Where(x => x.FullName.EndsWith("ScenarioProperties.xml")).ToList(); foreach (var entry in filteredEntries) { var scenario = new ScenarioModel(); scenario.IsPacked = true; scenario.Pack = file.Name; scenario.RouteId = routeId; if (inGame) { scenario.IsValidInGame = true; } if (inArchive) { scenario.IsValidInArchive = true; } scenario.ScenarioGuid = entry.FullName.Substring(10, 36); var scenarioProperties = ScenarioPropertiesDataAccess.ReadPackedScenarioNameAndClass(entry, scenario.ScenarioGuid); scenario.ScenarioTitle = scenarioProperties.ScenarioTitle; scenario.ScenarioClass = scenarioProperties.ScenarioClass; scenarioList.Add(scenario); } } } } return(scenarioList); }