Skip to content

Commit 4cb9c4f

Browse files
author
Wes Long
committed
Merge remote-tracking branch 'origin/add-import-support-to-command-line'
2 parents d34cee1 + 3596a0c commit 4cb9c4f

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

WDBXEditor/ConsoleHandler/ConsoleCommands.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using WDBXEditor.Archives.CASC.Handlers;
1111
using WDBXEditor.Archives.MPQ;
1212
using WDBXEditor.Common;
13+
using WDBXEditor.Reader;
1314
using WDBXEditor.Storage;
1415
using static WDBXEditor.Common.Constants;
1516

@@ -181,7 +182,41 @@ public static void ExtractCommand(string[] args)
181182
Console.WriteLine("");
182183
}
183184
#endregion
184-
185+
186+
#region Import
187+
/// <summary>
188+
/// Imports a csv into a DBC
189+
/// <para>-import -f "foo.dbc" -b 11802 -c "foo.csv" -h true -u replace -i FixIds</para>
190+
/// -f name of dbc file
191+
/// -b build number to use when loading dbc
192+
/// -c name of csv file
193+
/// -h sets whether csv has header row
194+
/// -u updateMode (0:Insert|1:Update|2:Replace)
195+
/// -i idImportMode (1:FixIds|2:TakeNewest)
196+
/// </summary>
197+
/// <param name="args"></param>
198+
public static void ImportArgCommand(string[] args)
199+
{
200+
LoadCommand(args);
201+
202+
var pmap = ConsoleManager.ParseCommand(args);
203+
var csvFileName = ParamCheck<string>(pmap, "-c");
204+
var hasHeader = ParamCheck<bool>(pmap, "-h", false);
205+
var updateMode = ParamCheck<UpdateMode>(pmap, "-u");
206+
var importMode = ParamCheck<ImportFlags>(pmap, "-i");
207+
208+
var entry = Database.Entries[0];
209+
210+
if ( !entry.ImportCSV(csvFileName, hasHeader, updateMode, out var importError, importMode) )
211+
{
212+
var dbcFileName = ParamCheck<string>(pmap, "-f");
213+
throw new Exception($" Error importing {csvFileName} into {dbcFileName}: {importError}");
214+
}
215+
216+
new DBReader().Write(entry, entry.SavePath);
217+
}
218+
#endregion
219+
185220
#region Export
186221
/// <summary>
187222
/// Exports a file to either SQL, JSON or CSV
@@ -258,6 +293,9 @@ private static T ParamCheck<T>(Dictionary<string, string> map, string field, boo
258293
{
259294
try
260295
{
296+
if (typeof(T).IsEnum)
297+
return (T)Enum.Parse(typeof(T), map[field], true);
298+
261299
return (T)Convert.ChangeType(map[field], typeof(T));
262300
}
263301
catch

WDBXEditor/ConsoleHandler/ConsoleManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static void LoadCommandDefinitions()
5151
DefineCommand("-export", ConsoleCommands.ExportArgCommand);
5252
DefineCommand("-sqldump", ConsoleCommands.SqlDumpArgCommand);
5353
DefineCommand("-extract", ConsoleCommands.ExtractCommand);
54+
DefineCommand("-import", ConsoleCommands.ImportArgCommand);
5455
}
5556

5657
/// <summary>

0 commit comments

Comments
 (0)