@@ -19,9 +19,9 @@ public FormMain()
1919 Thread . CurrentThread . CurrentUICulture = CultureInfo . InvariantCulture ;
2020
2121#if DEBUG
22- textSourcePath . Text = @"d:\Work\Crackshell\ARPGProj\trunk\ARPG\bin \assets\" ;
23- textLevelsXmlPath . Text = @"d:\Work\Crackshell\ARPGProj\trunk\ARPG\bin \campaign\levels.xml" ;
24- textOutputPath . Text = @"d:\Work\Crackshell\SSBD\trunk\bin\scenarios\hwport \" ;
22+ textSourcePath . Text = @"g:\Steam\steamapps\common\Hammerwatch \assets\" ;
23+ textLevelsXmlPath . Text = @"g:\Steam\steamapps\common\Hammerwatch\assets_campaign \campaign\levels.xml" ;
24+ textOutputPath . Text = @"g:\Steam\steamapps\common\Hammerwatch\assets_hwr \" ;
2525#endif
2626 }
2727
@@ -192,214 +192,223 @@ private void buttonConvert_Click(object sender, EventArgs e)
192192 var waiting = new FormWaiting ( ) ;
193193
194194 var thread = new Thread ( ( ) => {
195- var tmStart = DateTime . Now ;
196195 int fileCount = 0 ;
196+ var tmStart = DateTime . Now ;
197197
198- var files = Directory . GetFiles ( Settings . SourcePath , "*.xml" , SearchOption . AllDirectories ) ;
199-
200- foreach ( var fnm in files ) {
201- string filename = fnm . Substring ( Settings . SourcePath . Length ) . Replace ( '\\ ' , '/' ) ;
202- string dir = Path . GetDirectoryName ( filename ) ;
198+ try {
199+ var files = Directory . GetFiles ( Settings . SourcePath , "*.xml" , SearchOption . AllDirectories ) ;
203200
204- var xml = XmlFile . FromFile ( fnm ) ;
205- var root = xml . Root . Children [ 0 ] ;
201+ foreach ( var fnm in files ) {
202+ string filename = fnm . Substring ( Settings . SourcePath . Length ) . Replace ( '\\ ' , '/' ) ;
203+ string dir = Path . GetDirectoryName ( filename ) ;
206204
207- if ( Settings . ConvertActors && root . Name == "actor" ) {
208- // Actor units
209- string filenameUnit = Path . ChangeExtension ( filename , "unit" ) ;
210- waiting . SetStatus ( "Actor: " + filenameUnit ) ;
211- fileCount ++ ;
205+ var xml = XmlFile . FromFile ( fnm ) ;
206+ var root = xml . Root . Children [ 0 ] ;
212207
213- Program . Prepare ( dir , filenameUnit ) ;
208+ if ( Settings . ConvertActors && root . Name == "actor" ) {
209+ // Actor units
210+ string filenameUnit = Path . ChangeExtension ( filename , "unit" ) ;
211+ waiting . SetStatus ( "Actor: " + filenameUnit ) ;
212+ fileCount ++ ;
214213
215- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameUnit ) ) ) {
216- UnitConverter . Convert ( xml , writer , "actor" , Path . GetFileNameWithoutExtension ( filenameUnit ) , filenameUnit ) ;
217- }
214+ Program . Prepare ( dir , filenameUnit ) ;
218215
219- } else if ( Settings . ConvertProjectiles && root . Name == "projectile" ) {
220- // Projectile units
221- string filenameUnit = Path . ChangeExtension ( filename , "unit" ) ;
222- waiting . SetStatus ( "Projectile: " + filenameUnit ) ;
223- fileCount ++ ;
216+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameUnit ) ) ) {
217+ UnitConverter . Convert ( xml , writer , "actor" , Path . GetFileNameWithoutExtension ( filenameUnit ) , filenameUnit ) ;
218+ }
224219
225- Program . Prepare ( dir , filenameUnit ) ;
220+ } else if ( Settings . ConvertProjectiles && root . Name == "projectile" ) {
221+ // Projectile units
222+ string filenameUnit = Path . ChangeExtension ( filename , "unit" ) ;
223+ waiting . SetStatus ( "Projectile: " + filenameUnit ) ;
224+ fileCount ++ ;
226225
227- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameUnit ) ) ) {
228- UnitConverter . Convert ( xml , writer , "projectile" , Path . GetFileNameWithoutExtension ( filenameUnit ) , filenameUnit ) ;
229- }
226+ Program . Prepare ( dir , filenameUnit ) ;
230227
231- } else if ( Settings . ConvertDoodads && root . Name == "doodad" ) {
232- // Doodad units
233- string filenameUnit = Path . ChangeExtension ( filename , "unit" ) ;
234- waiting . SetStatus ( "Doodad: " + filenameUnit ) ;
235- fileCount ++ ;
228+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameUnit ) ) ) {
229+ UnitConverter . Convert ( xml , writer , "projectile" , Path . GetFileNameWithoutExtension ( filenameUnit ) , filenameUnit ) ;
230+ }
236231
237- Program . Prepare ( dir , filenameUnit ) ;
232+ } else if ( Settings . ConvertDoodads && root . Name == "doodad" ) {
233+ // Doodad units
234+ string filenameUnit = Path . ChangeExtension ( filename , "unit" ) ;
235+ waiting . SetStatus ( "Doodad: " + filenameUnit ) ;
236+ fileCount ++ ;
238237
239- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameUnit ) ) ) {
240- UnitConverter . Convert ( xml , writer , "doodad" , Path . GetFileNameWithoutExtension ( filenameUnit ) , filenameUnit ) ;
241- }
238+ Program . Prepare ( dir , filenameUnit ) ;
242239
243- } else if ( Settings . ConvertTilesets && root . Name == "tileset" ) {
244- // Tilesets
245- string filenameTileset = Path . ChangeExtension ( filename , "tileset" ) ;
246- waiting . SetStatus ( "Tilemap: " + filenameTileset ) ;
247- fileCount ++ ;
240+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameUnit ) ) ) {
241+ UnitConverter . Convert ( xml , writer , "doodad" , Path . GetFileNameWithoutExtension ( filenameUnit ) , filenameUnit ) ;
242+ }
248243
249- Program . Prepare ( dir , filenameTileset ) ;
244+ } else if ( Settings . ConvertTilesets && root . Name == "tileset" ) {
245+ // Tilesets
246+ string filenameTileset = Path . ChangeExtension ( filename , "tileset" ) ;
247+ waiting . SetStatus ( "Tilemap: " + filenameTileset ) ;
248+ fileCount ++ ;
250249
251- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameTileset ) ) ) {
252- TilesetConverter . Convert ( xml , writer ) ;
253- }
250+ Program . Prepare ( dir , filenameTileset ) ;
254251
255- } else if ( Settings . ConvertItems && root . Name == "item" ) {
256- // Items (actually just units with behaviors)
257- string filenameUnit = Path . ChangeExtension ( filename , "unit" ) ;
258- waiting . SetStatus ( "Item: " + filenameUnit ) ;
259- fileCount ++ ;
260-
261- Program . Prepare ( dir , filenameUnit ) ;
262-
263- var slot = "" ;
264-
265- var behavior = root . Attributes [ "behavior" ] ;
266- switch ( behavior ) {
267- case "food" :
268- case "money" :
269- case "key" :
270- case "collectable" :
271- case "mana" :
272- case "life" :
273- case "potion" :
274- case "present" : // uhh
275- case "upgrade" :
276- slot = "item" ;
277- break ;
278-
279- case "breakable" :
280- case "door" :
281- case "bomb" :
282- case "checkpoint" : //TODO: This needs a behavior
283- slot = "doodad" ;
284- break ;
285-
286- default :
287- Console . WriteLine ( "WARNING: Unknown behavior '{0}'" , behavior ) ;
288- continue ;
289- }
252+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameTileset ) ) ) {
253+ TilesetConverter . Convert ( xml , writer ) ;
254+ }
290255
291- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameUnit ) ) ) {
292- UnitConverter . Convert ( xml , writer , slot , "" , filenameUnit ) ;
293- }
256+ } else if ( Settings . ConvertItems && root . Name == "item" ) {
257+ // Items (actually just units with behaviors)
258+ string filenameUnit = Path . ChangeExtension ( filename , "unit" ) ;
259+ waiting . SetStatus ( "Item: " + filenameUnit ) ;
260+ fileCount ++ ;
294261
295- } else if ( Settings . ConvertStrings && filename . StartsWith ( "language\\ " ) && root . Name == "dictionary" ) {
296- // String files (almost the same format, but we want to append our language prefix)
297- string filenameLang = Path . ChangeExtension ( filename , "lang" ) ;
298- waiting . SetStatus ( "Strings: " + filenameLang ) ;
299- fileCount ++ ;
262+ Program . Prepare ( dir , filenameUnit ) ;
263+
264+ var slot = "" ;
265+
266+ var behavior = root . Attributes [ "behavior" ] ;
267+ switch ( behavior ) {
268+ case "food" :
269+ case "money" :
270+ case "key" :
271+ case "collectable" :
272+ case "mana" :
273+ case "life" :
274+ case "potion" :
275+ case "present" : // uhh
276+ case "upgrade" :
277+ slot = "item" ;
278+ break ;
279+
280+ case "breakable" :
281+ case "door" :
282+ case "bomb" :
283+ case "checkpoint" : //TODO: This needs a behavior
284+ slot = "doodad" ;
285+ break ;
286+
287+ default :
288+ Console . WriteLine ( "WARNING: Unknown behavior '{0}'" , behavior ) ;
289+ continue ;
290+ }
300291
301- Program . Prepare ( dir , filenameLang ) ;
292+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameUnit ) ) ) {
293+ UnitConverter . Convert ( xml , writer , slot , "" , filenameUnit ) ;
294+ }
302295
303- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameLang ) ) ) {
304- StringConverter . Convert ( xml , writer ) ;
305- }
296+ } else if ( Settings . ConvertStrings && filename . StartsWith ( "language\\ " ) && root . Name == "dictionary" ) {
297+ // String files (almost the same format, but we want to append our language prefix)
298+ string filenameLang = Path . ChangeExtension ( filename , "lang" ) ;
299+ waiting . SetStatus ( "Strings: " + filenameLang ) ;
300+ fileCount ++ ;
306301
307- } else if ( Settings . ConvertSpeechStyles && root . Name == "speech" ) {
308- // Speech styles
309- string filenameUnit = Path . ChangeExtension ( filename , "sval" ) ;
310- waiting . SetStatus ( "Speech style: " + filenameUnit ) ;
311- fileCount ++ ;
302+ Program . Prepare ( dir , filenameLang ) ;
312303
313- Program . Prepare ( dir , filenameUnit ) ;
304+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameLang ) ) ) {
305+ StringConverter . Convert ( xml , writer ) ;
306+ }
314307
315- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameUnit ) ) ) {
316- SpeechStyleConverter . Convert ( xml , writer ) ;
317- }
308+ } else if ( Settings . ConvertSpeechStyles && root . Name == "speech" ) {
309+ // Speech styles
310+ string filenameUnit = Path . ChangeExtension ( filename , "sval" ) ;
311+ waiting . SetStatus ( "Speech style: " + filenameUnit ) ;
312+ fileCount ++ ;
318313
319- } else if ( Settings . ConvertFonts && root . Name == "font" ) {
320- // Fonts
321- string filenameLocal = Path . ChangeExtension ( filename , "fnt" ) ;
322- waiting . SetStatus ( "Font: " + filenameLocal ) ;
323- fileCount ++ ;
314+ Program . Prepare ( dir , filenameUnit ) ;
324315
325- Program . Prepare ( dir , filenameLocal ) ;
316+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameUnit ) ) ) {
317+ SpeechStyleConverter . Convert ( xml , writer ) ;
318+ }
326319
327- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameLocal ) ) ) {
328- BitmapFontConverter . Convert ( xml , writer ) ;
329- }
320+ } else if ( Settings . ConvertFonts && root . Name == "font" ) {
321+ // Fonts
322+ string filenameLocal = Path . ChangeExtension ( filename , "fnt" ) ;
323+ waiting . SetStatus ( "Font: " + filenameLocal ) ;
324+ fileCount ++ ;
330325
331- }
332- }
326+ Program . Prepare ( dir , filenameLocal ) ;
333327
334- if ( Settings . ConvertLoot ) {
335- if ( fileCount == 0 ) {
336- waiting . SetStatus ( "WARNING: Can't convert loot if no units are being converted." ) ;
337- } else {
338- string [ ] slots = LootConverter . GetSlots ( ) ;
339- foreach ( var slot in slots ) {
340- string filenameLocal = slot + ".sval" ;
341- waiting . SetStatus ( "Loot: " + filenameLocal ) ;
342- fileCount ++ ;
328+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameLocal ) ) ) {
329+ BitmapFontConverter . Convert ( xml , writer ) ;
330+ }
343331
344- Program . Prepare ( "loot" , filenameLocal ) ;
332+ }
333+ }
345334
346- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + "loot/" + filenameLocal ) ) ) {
347- LootConverter . Convert ( slot , writer ) ;
335+ if ( Settings . ConvertLoot ) {
336+ if ( fileCount == 0 ) {
337+ waiting . SetStatus ( "WARNING: Can't convert loot if no units are being converted." ) ;
338+ } else {
339+ string [ ] slots = LootConverter . GetSlots ( ) ;
340+ foreach ( var slot in slots ) {
341+ string filenameLocal = slot + ".sval" ;
342+ waiting . SetStatus ( "Loot: " + filenameLocal ) ;
343+ fileCount ++ ;
344+
345+ Program . Prepare ( "loot" , filenameLocal ) ;
346+
347+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + "loot/" + filenameLocal ) ) ) {
348+ LootConverter . Convert ( slot , writer ) ;
349+ }
348350 }
349351 }
350352 }
351- }
352353
353- var levelsPath = Settings . LevelsPath ;
354+ var levelsPath = Settings . LevelsPath ;
354355
355- if ( Settings . ConvertLevels && levelsPath != "" && File . Exists ( levelsPath ) ) {
356- levelsPath = Path . GetDirectoryName ( levelsPath ) + "\\ " ;
356+ if ( Settings . ConvertLevels && levelsPath != "" && File . Exists ( levelsPath ) ) {
357+ levelsPath = Path . GetDirectoryName ( levelsPath ) + "\\ " ;
357358
358- //TODO: Properly convert this into a scenario xml
359- var levelsXml = XmlFile . FromFile ( levelsPath + "levels.xml" ) ;
360- var levelsTags = levelsXml . Root . FindTagsByName ( "level" ) ;
361- foreach ( var level in levelsTags ) {
362- Program . LevelKeys . Add ( level . Attributes [ "id" ] , Path . ChangeExtension ( level . Attributes [ "res" ] , "lvl" ) ) ;
363- }
359+ //TODO: Properly convert this into a scenario xml
360+ var levelsXml = XmlFile . FromFile ( levelsPath + "levels.xml" ) ;
361+ var levelsTags = levelsXml . Root . FindTagsByName ( "level" ) ;
362+ foreach ( var level in levelsTags ) {
363+ Program . LevelKeys . Add ( level . Attributes [ "id" ] , Path . ChangeExtension ( level . Attributes [ "res" ] , "lvl" ) ) ;
364+ }
364365
365- var levels = Directory . GetFiles ( levelsPath + "levels\\ " , "*.xml" , SearchOption . AllDirectories ) ;
366- foreach ( var level in levels ) {
367- string filenameLocal = Path . ChangeExtension ( level . Substring ( levelsPath . Length + "levels\\ " . Length ) , "lvl" ) ;
368- waiting . SetStatus ( "Level: " + filenameLocal ) ;
369- fileCount ++ ;
366+ var levels = Directory . GetFiles ( levelsPath + "levels\\ " , "*.xml" , SearchOption . AllDirectories ) ;
367+ foreach ( var level in levels ) {
368+ string filenameLocal = Path . ChangeExtension ( level . Substring ( levelsPath . Length + "levels\\ " . Length ) , "lvl" ) ;
369+ waiting . SetStatus ( "Level: " + filenameLocal ) ;
370+ fileCount ++ ;
370371
371- Program . Prepare ( "levels/" + Path . GetDirectoryName ( filenameLocal ) , filenameLocal ) ;
372+ Program . Prepare ( "levels/" + Path . GetDirectoryName ( filenameLocal ) , filenameLocal ) ;
372373
373- XmlFile xmlLevel = XmlFile . FromFile ( level ) ;
374- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + "levels/" + filenameLocal ) ) ) {
375- LevelConverter . Convert ( xmlLevel , writer , filenameLocal ) ;
374+ XmlFile xmlLevel = XmlFile . FromFile ( level ) ;
375+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + "levels/" + filenameLocal ) ) ) {
376+ LevelConverter . Convert ( xmlLevel , writer , filenameLocal ) ;
377+ }
376378 }
377379 }
378- }
379380
380- if ( Settings . ConvertSounds ) {
381- var filesSbnks = Directory . GetFiles ( Settings . SourcePath + "/sound" , "*.xml" , SearchOption . AllDirectories ) ;
381+ if ( Settings . ConvertSounds ) {
382+ var filesSbnks = Directory . GetFiles ( Settings . SourcePath + "/sound" , "*.xml" , SearchOption . AllDirectories ) ;
382383
383- foreach ( var fnm in filesSbnks ) {
384- string filename = fnm . Substring ( Settings . SourcePath . Length ) ;
385- string dir = Path . GetDirectoryName ( filename ) ;
384+ foreach ( var fnm in filesSbnks ) {
385+ string filename = fnm . Substring ( Settings . SourcePath . Length ) ;
386+ string dir = Path . GetDirectoryName ( filename ) ;
386387
387- var xml = XmlFile . FromFile ( fnm ) ;
388- var root = xml . Root . Children [ 0 ] ;
388+ var xml = XmlFile . FromFile ( fnm ) ;
389+ var root = xml . Root . Children [ 0 ] ;
389390
390- if ( root . Name == "soundbank" ) {
391- // Soundbanks (are the *exact* same format, but we're parsing it anyway, we want to copy the sound files!)
392- string filenameSbnk = Path . ChangeExtension ( filename , "sbnk" ) ;
393- waiting . SetStatus ( "Soundbank: " + filenameSbnk ) ;
394- fileCount ++ ;
391+ if ( root . Name == "soundbank" ) {
392+ // Soundbanks (are the *exact* same format, but we're parsing it anyway, we want to copy the sound files!)
393+ string filenameSbnk = Path . ChangeExtension ( filename , "sbnk" ) ;
394+ waiting . SetStatus ( "Soundbank: " + filenameSbnk ) ;
395+ fileCount ++ ;
395396
396- Program . Prepare ( dir , filenameSbnk ) ;
397+ Program . Prepare ( dir , filenameSbnk ) ;
397398
398- using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameSbnk ) ) ) {
399- SoundbankConverter . Convert ( xml , writer , Path . GetFileNameWithoutExtension ( filenameSbnk ) ) ;
399+ using ( StreamWriter writer = new StreamWriter ( File . Create ( Settings . OutputPath + filenameSbnk ) ) ) {
400+ SoundbankConverter . Convert ( xml , writer , Path . GetFileNameWithoutExtension ( filenameSbnk ) ) ;
401+ }
400402 }
401403 }
402404 }
405+ } catch ( Exception ex ) {
406+ BeginInvoke ( new Action ( ( ) => {
407+ MessageBox . Show ( "Conversion has thrown an exception! Conversion will be stopped.\n \n " + ex . ToString ( ) , "Converter" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
408+ Enabled = true ;
409+ waiting . Close ( ) ;
410+ } ) ) ;
411+ return ;
403412 }
404413
405414 Invoke ( new Action ( ( ) => {
0 commit comments