|
| 1 | +using Microsoft.Data.Sqlite; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.IO; |
| 5 | +using System.Linq; |
| 6 | + |
| 7 | +namespace DynmapFilesToSQLite.Converter.Reader.impl { |
| 8 | + public class MapTypesReader : DynReader { |
| 9 | + public List<MapType> mapTypes = new List<MapType>(); |
| 10 | + |
| 11 | + public MapTypesReader(DirectoryInfo myDir) : base(myDir) { } |
| 12 | + |
| 13 | + public override void ExecuteSqliteCommands(SqliteTransaction transaction) { |
| 14 | + List<DirectoryInfo> worldNames = new List<DirectoryInfo>(); |
| 15 | + worldNames.AddRange(myDir.EnumerateDirectories().Where(dir => { |
| 16 | + return !dir.Name.Equals("_markers_") && !dir.Name.Equals("faces"); |
| 17 | + })); |
| 18 | + |
| 19 | + foreach(DirectoryInfo world in worldNames) { |
| 20 | + foreach(DirectoryInfo mapId in world.EnumerateDirectories()) { |
| 21 | + MapType type; |
| 22 | + mapTypes.Add(type = new MapType { |
| 23 | + mapId = mapId.Name, |
| 24 | + worldName = world.Name, |
| 25 | + variant = "STANDARD" |
| 26 | + }); |
| 27 | + |
| 28 | + SqliteCommand cmd = new SqliteCommand(); |
| 29 | + cmd.CommandText = "INSERT INTO Maps VALUES (@ID, @WorldID, @MapID, @Variant);"; |
| 30 | + |
| 31 | + cmd.Parameters.AddWithValue("@ID", mapTypes.Count); |
| 32 | + cmd.Parameters.AddWithValue("@WorldID", type.worldName); |
| 33 | + cmd.Parameters.AddWithValue("@MapID", type.mapId); |
| 34 | + cmd.Parameters.AddWithValue("@Variant", type.variant); |
| 35 | + |
| 36 | + cmd.Transaction = transaction; |
| 37 | + cmd.Connection = transaction.Connection; |
| 38 | + cmd.ExecuteNonQuery(); |
| 39 | + |
| 40 | + Console.WriteLine("Added new map type: " + mapTypes.Count); |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + public struct MapType { |
| 46 | + public string worldName, mapId, variant; |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments