@@ -57,6 +57,39 @@ public override RomSignatureObject Parse(string XMLFile, Dictionary<string, obje
5757 XmlNode xmlHeader = tosecXmlDoc . DocumentElement . SelectSingleNode ( "/datafile/header" ) ;
5858 ParseHeader ( tosecObject , xmlHeader , "TOSEC" , md5Hash , sha1Hash ) ;
5959
60+ string [ ] fileNameTokens = tosecObject . Name ? . Split ( " - " ) ?? Array . Empty < string > ( ) ;
61+ List < string > fileTokens = new List < string > ( ) ;
62+ string fileType = "" ;
63+ if ( fileNameTokens != null && fileNameTokens . Length > 0 )
64+ {
65+ for ( int i = 0 ; i < fileNameTokens . Length ; i ++ )
66+ {
67+ if ( i == 0 )
68+ {
69+ // skip the first token, as this is the system name
70+ continue ;
71+ }
72+
73+ if ( fileNameTokens [ i ] . StartsWith ( '[' ) && fileNameTokens [ i ] . EndsWith ( ']' ) )
74+ {
75+ // this is a file type, save it and skip it
76+ fileType = fileNameTokens [ i ] . Replace ( "[" , "" ) . Replace ( "]" , "" ) . Trim ( ) ;
77+ continue ;
78+ }
79+
80+ if ( fileNameTokens [ i ] . StartsWith ( '(' ) && fileNameTokens [ i ] . EndsWith ( ')' ) )
81+ {
82+ // this is a file token, so we can skip it
83+ continue ;
84+ }
85+
86+ if ( ! fileTokens . Contains ( fileNameTokens [ i ] , StringComparer . CurrentCultureIgnoreCase ) )
87+ {
88+ fileTokens . Add ( fileNameTokens [ i ] ) ;
89+ }
90+ }
91+ }
92+
6093 // get games
6194 tosecObject . Games = new List < RomSignatureObject . Game > ( ) ;
6295 XmlNodeList xmlGames = tosecXmlDoc . DocumentElement . SelectNodes ( "/datafile/game" ) ;
@@ -315,7 +348,15 @@ public override RomSignatureObject Parse(string XMLFile, Dictionary<string, obje
315348
316349 case "rom" :
317350 RomSignatureObject . Game . Rom romObject = new RomSignatureObject . Game . Rom ( ) ;
318- romObject . Attributes = new Dictionary < string , object > ( ) ;
351+ romObject . Attributes = new Dictionary < string , object >
352+ {
353+ { "categories" , fileTokens }
354+ } ;
355+ if ( ! String . IsNullOrEmpty ( fileType ) )
356+ {
357+ romObject . Attributes . Add ( "filetype" , fileType ) ;
358+ }
359+
319360 if ( xmlGameDetail != null )
320361 {
321362 romObject . Name = xmlGameDetail . Attributes [ "name" ] ? . Value ;
@@ -399,7 +440,7 @@ public override RomSignatureObject Parse(string XMLFile, Dictionary<string, obje
399440 token != gameObject . LanguageString &&
400441 token != romObject . DevelopmentStatus
401442 )
402- )
443+ )
403444 {
404445 // likely the media label?
405446 romObject . MediaLabel = token ;
0 commit comments