Skip to content

Commit 9d1ac7d

Browse files
committed
Added more readers
1 parent a631475 commit 9d1ac7d

File tree

5 files changed

+110
-0
lines changed

5 files changed

+110
-0
lines changed

DynmapFilesToSQLite/Converter/Converter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
namespace DynmapFilesToSQLite.Converter {
99
public class Converter {
1010
public static void Convert(DirectoryInfo tilesFolder, DirectoryInfo markersFolder, FileInfo outputFile, bool useJPG) {
11+
MapTypesReader mapTypesReader = new MapTypesReader(tilesFolder);
12+
1113
List<DynReader> readers = new List<DynReader>();
1214
readers.Add(new MarkerIconsReader(markersFolder));
15+
readers.Add(new MarkerFilesReader(markersFolder));
1316
readers.Add(new FacesReader(new DirectoryInfo(Path.Combine(tilesFolder.FullName, "faces"))));
17+
readers.Add(new SchemaVersionWriter(null));
18+
readers.Add(mapTypesReader);
1419

1520
SQLiteWriter writer = new SQLiteWriter(outputFile);
1621
writer.CreateTables();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.Data.Sqlite;
2+
using System;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace DynmapFilesToSQLite.Converter.Reader.impl {
8+
public class MarkerFilesReader : DynReader {
9+
public MarkerFilesReader(DirectoryInfo myDir) : base(myDir) { }
10+
11+
public override void ExecuteSqliteCommands(SqliteTransaction transaction) {
12+
var markers = myDir.EnumerateFiles().Where(file => file.Name.EndsWith(".json"));
13+
14+
foreach (FileInfo markerInfo in markers) {
15+
SqliteCommand cmd = new SqliteCommand();
16+
cmd.CommandText = "INSERT INTO MarkerFiles VALUES (@Name, @ContentText);";
17+
18+
string name = markerInfo.Name.Substring(0, markerInfo.Name.Length - 5);
19+
cmd.Parameters.AddWithValue("@Name", name);
20+
cmd.Parameters.AddWithValue("@ContentText", File.ReadAllText(markerInfo.FullName, Encoding.UTF8));
21+
22+
cmd.Transaction = transaction;
23+
cmd.Connection = transaction.Connection;
24+
cmd.ExecuteNonQuery();
25+
26+
Console.WriteLine("Command executed for " + name + " marker");
27+
}
28+
}
29+
}
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.Data.Sqlite;
2+
using System;
3+
using System.IO;
4+
using System.Linq;
5+
6+
namespace DynmapFilesToSQLite.Converter.Reader.impl {
7+
public class SchemaVersionWriter : DynReader {
8+
public SchemaVersionWriter(DirectoryInfo myDir) : base(myDir) { }
9+
10+
public override void ExecuteSqliteCommands(SqliteTransaction transaction) {
11+
SqliteCommand cmd = new SqliteCommand();
12+
cmd.CommandText = "INSERT INTO SchemaVersion VALUES (@Version);";
13+
14+
cmd.Parameters.AddWithValue("@Version", 1); // yes this is the old one, so on newer versions, an automatic conversion should hopefully take place? that's not my problem at least...
15+
16+
cmd.Transaction = transaction;
17+
cmd.Connection = transaction.Connection;
18+
cmd.ExecuteNonQuery();
19+
20+
Console.WriteLine("Schema version written");
21+
}
22+
}
23+
}

DynmapFilesToSQLite/DynmapFilesToSQLite.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@
8181
<Compile Include="Converter\Converter.cs" />
8282
<Compile Include="Converter\Reader\DynReader.cs" />
8383
<Compile Include="Converter\Reader\impl\FacesReader.cs" />
84+
<Compile Include="Converter\Reader\impl\MapTypesReader.cs" />
85+
<Compile Include="Converter\Reader\impl\MarkerFilesReader.cs" />
8486
<Compile Include="Converter\Reader\impl\MarkerIconsReader.cs" />
87+
<Compile Include="Converter\Reader\impl\SchemaVersionWriter.cs" />
8588
<Compile Include="Converter\SQLiteWriter.cs" />
8689
<Compile Include="Program.cs" />
8790
<Compile Include="Properties\AssemblyInfo.cs" />

0 commit comments

Comments
 (0)