public static bool CheckIfMimetypeExists( MimeType mt ) { foreach ( MimeType m in mimeTypes ) { if ( m.TypeName == mt.TypeName ) return true; } return false; }
public SubClassReader( XmlTextReader xtr, MimeType mt ) { this.xtr = xtr; this.mt = mt; }
private void AddMatches( ArrayList matches, MimeType mimeType, int cookie, string lastmatchname ) { foreach ( Match match in matches ) { string matchname = ""; string tabs = new String( '\t', 3 + cookie ); if ( cookie == 0 ) { outputLines.Add( tabs + "match0 = new Match();" ); outputLines.Add( tabs + "match0.MimeType = \"" + mimeType.TypeName + "\";" ); matchname = "match0"; } else { matchname = "match" + cookie; if ( lastmatchname != null && lastmatchname != matchname ) outputLines.Add( tabs + "Match " + matchname + " = null;" ); lastmatchname = matchname; outputLines.Add( tabs + matchname + " = new Match();" ); } if ( cookie == 0 ) outputLines.Add( tabs + matchname + ".Priority = " + mimeType.MagicPriority + ";" ); outputLines.Add( tabs + matchname + ".Offset = " + match.Offset + ";" ); outputLines.Add( tabs + matchname + ".OffsetLength = " + ( match.OffsetEnd == -1 ? "1" : ( match.OffsetEnd - match.Offset ).ToString( ) ) + ";" ); outputLines.Add( tabs + matchname + ".MatchType = MatchTypes." + match.MatchType + ";" ); int word_size = -1; switch ( match.MatchType ) { case MatchTypes.TypeHost16: word_size = 2; break; case MatchTypes.TypeHost32: word_size = 4; break; default: break; } if ( word_size != -1 ) { outputLines.Add( tabs + matchname + ".WordSize = " + word_size + ";" ); } if ( match.MatchType == MatchTypes.TypeString ) { byte[] bmatchvalue = MatchValueStringToByteArray( match.MatchValue ); BuildByteArrays( tabs, matchname, bmatchvalue, match ); } else { byte[] bmatchvalue = MatchValueOtherToByteArray( match.MatchValue, match.MatchType ); BuildByteArrays( tabs, matchname, bmatchvalue, match ); } if ( match.Matches.Count != 0 ) { cookie++; outputLines.Add( "" ); outputLines.Add( tabs + "if ( " + matchname + ".Matches.Count > 0 )" ); outputLines.Add( tabs + "{" ); AddMatches( match.Matches, null, cookie, matchname ); outputLines.Add( tabs + "}" ); cookie--; } if ( cookie == 0 ) { if ( mimeType.MagicPriority < 80 ) outputLines.Add( "\t\t\tMatchesBelow80.Add( match0 );" ); else outputLines.Add( "\t\t\tMatches80Plus.Add( match0 );" ); } else outputLines.Add( tabs + "match" + ( cookie - 1 ).ToString( ) + ".Matches.Add( match" + cookie + " );" ); outputLines.Add( "" ); } }
private bool ReadXMLFile( FileInfo fi ) { xtr = new XmlTextReader( fi.FullName ); if ( !CheckIfMimeFileIsCorrect( ) ) { xtr.Close( ); Console.WriteLine( fi.Name + " doesn't seem to be a correct freedesktop shared mime info file..." ); return false; } Console.WriteLine( fi.Name + " seems to be a correct freedesktop shared mime info file..." ); Console.WriteLine( "Start parsing..." ); while ( xtr.Read( ) ) { switch ( xtr.NodeType ) { case XmlNodeType.Element: if ( xtr.Name == "mime-type" ) { MimeType mt = new MimeType( ); MimeTypeReader mtr = new MimeTypeReader( xtr, mt ); mtr.Start( ); if ( !MimeUtils.CheckIfMimetypeExists( mt ) ) MimeUtils.mimeTypes.Add( mt ); } break; case XmlNodeType.EndElement: if ( xtr.Name == "mime-info" ) break; break; } } xtr.Close( ); return true; }
public GlobReader( XmlTextReader xtr, MimeType mt ) { this.xtr = xtr; this.mt = mt; }
public CommentReader( XmlTextReader xtr, MimeType mt ) { this.xtr = xtr; this.mt = mt; }
public MimeTypeReader(XmlTextReader xtr, MimeType mt) { this.xtr = xtr; this.mt = mt; }