diff --git a/WDBXEditor/ConsoleHandler/ConsoleCommands.cs b/WDBXEditor/ConsoleHandler/ConsoleCommands.cs
index b33661d..1569d33 100644
--- a/WDBXEditor/ConsoleHandler/ConsoleCommands.cs
+++ b/WDBXEditor/ConsoleHandler/ConsoleCommands.cs
@@ -10,6 +10,7 @@
using WDBXEditor.Archives.CASC.Handlers;
using WDBXEditor.Archives.MPQ;
using WDBXEditor.Common;
+using WDBXEditor.Reader;
using WDBXEditor.Storage;
using static WDBXEditor.Common.Constants;
@@ -181,7 +182,41 @@ public static void ExtractCommand(string[] args)
Console.WriteLine("");
}
#endregion
-
+
+ #region Import
+ ///
+ /// Imports a csv into a DBC
+ /// -import -f "foo.dbc" -b 11802 -c "foo.csv" -h true -u replace -i FixIds
+ /// -f name of dbc file
+ /// -b build number to use when loading dbc
+ /// -c name of csv file
+ /// -h sets whether csv has header row
+ /// -u updateMode (0:Insert|1:Update|2:Replace)
+ /// -i idImportMode (1:FixIds|2:TakeNewest)
+ ///
+ ///
+ public static void ImportArgCommand(string[] args)
+ {
+ LoadCommand(args);
+
+ var pmap = ConsoleManager.ParseCommand(args);
+ var csvFileName = ParamCheck(pmap, "-c");
+ var hasHeader = ParamCheck(pmap, "-h", false);
+ var updateMode = ParamCheck(pmap, "-u");
+ var importMode = ParamCheck(pmap, "-i");
+
+ var entry = Database.Entries[0];
+
+ if ( !entry.ImportCSV(csvFileName, hasHeader, updateMode, out var importError, importMode) )
+ {
+ var dbcFileName = ParamCheck(pmap, "-f");
+ throw new Exception($" Error importing {csvFileName} into {dbcFileName}: {importError}");
+ }
+
+ new DBReader().Write(entry, entry.SavePath);
+ }
+ #endregion
+
#region Export
///
/// Exports a file to either SQL, JSON or CSV
@@ -258,6 +293,9 @@ private static T ParamCheck(Dictionary map, string field, boo
{
try
{
+ if (typeof(T).IsEnum)
+ return (T)Enum.Parse(typeof(T), map[field], true);
+
return (T)Convert.ChangeType(map[field], typeof(T));
}
catch
diff --git a/WDBXEditor/ConsoleHandler/ConsoleManager.cs b/WDBXEditor/ConsoleHandler/ConsoleManager.cs
index 035ddc1..54ad2cf 100644
--- a/WDBXEditor/ConsoleHandler/ConsoleManager.cs
+++ b/WDBXEditor/ConsoleHandler/ConsoleManager.cs
@@ -51,6 +51,7 @@ public static void LoadCommandDefinitions()
DefineCommand("-export", ConsoleCommands.ExportArgCommand);
DefineCommand("-sqldump", ConsoleCommands.SqlDumpArgCommand);
DefineCommand("-extract", ConsoleCommands.ExtractCommand);
+ DefineCommand("-import", ConsoleCommands.ImportArgCommand);
}
///