|
10 | 10 | using WDBXEditor.Archives.CASC.Handlers; |
11 | 11 | using WDBXEditor.Archives.MPQ; |
12 | 12 | using WDBXEditor.Common; |
| 13 | +using WDBXEditor.Reader; |
13 | 14 | using WDBXEditor.Storage; |
14 | 15 | using static WDBXEditor.Common.Constants; |
15 | 16 |
|
@@ -181,7 +182,41 @@ public static void ExtractCommand(string[] args) |
181 | 182 | Console.WriteLine(""); |
182 | 183 | } |
183 | 184 | #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 | + |
185 | 220 | #region Export |
186 | 221 | /// <summary> |
187 | 222 | /// 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 |
258 | 293 | { |
259 | 294 | try |
260 | 295 | { |
| 296 | + if (typeof(T).IsEnum) |
| 297 | + return (T)Enum.Parse(typeof(T), map[field], true); |
| 298 | + |
261 | 299 | return (T)Convert.ChangeType(map[field], typeof(T)); |
262 | 300 | } |
263 | 301 | catch |
|
0 commit comments