if ( !file.ReadAll(&text) )
return;
- int pos;
- const wxChar *pc;
+ // first find the description string: it is the value in either "Comment="
+ // line or "Comment[<locale_name>]=" one
+ int posComment = wxNOT_FOUND;
+
+ wxString comment;
+#if wxUSE_INTL
+ wxLocale *locale = wxGetLocale();
+ if ( locale )
+ {
+ // try "Comment[locale name]" first
+ comment << _T("Comment[") + locale->GetName() + _T("]=");
- // before trying to find an icon, grab mimetype information
- // (because BFU's machine would hardly have well-edited mime.types but (s)he might
- // have edited it in control panel...)
+ posComment = text.Find(comment);
+ }
+#endif // wxUSE_INTL
- wxString mime_extension, mime_desc;
+ if ( posComment == wxNOT_FOUND )
+ {
+ comment = _T("Comment=");
- pos = wxNOT_FOUND;
- if (wxGetLocale() != NULL)
- mime_desc = _T("Comment[") + wxGetLocale()->GetName() + _T("]=");
- if (pos == wxNOT_FOUND) mime_desc = _T("Comment=");
- pos = text.Find(mime_desc);
- if (pos == wxNOT_FOUND) mime_desc = wxEmptyString;
- else
+ posComment = text.Find(comment);
+ }
+
+ wxString mime_desc;
+ if ( posComment != wxNOT_FOUND )
{
- pc = text.c_str() + pos + mime_desc.Length();
- mime_desc = wxEmptyString;
- while ( *pc && *pc != _T('\n') ) mime_desc += *pc++;
+ // found desc: it follows the comment until the end of line
+ const wxChar *pc = text.c_str() + posComment + comment.length();
+ while ( *pc && *pc != _T('\n') )
+ {
+ mime_desc += *pc++;
+ }
}
+ //else: no description
- pos = text.Find(_T("Patterns="));
- if (pos != wxNOT_FOUND)
+ // next find the extensions
+ wxString mime_extension;
+
+ int posExts = text.Find(_T("Patterns="));
+ if ( posExts != wxNOT_FOUND )
{
wxString exts;
- pc = text.c_str() + pos + 9;
- while ( *pc && *pc != _T('\n') ) exts += *pc++;
- wxStringTokenizer tokenizer(exts, _T(";"));
- wxString e;
+ const wxChar *pc = text.c_str() + posExts + 9; // strlen("Patterns=")
+ while ( *pc && *pc != _T('\n') )
+ {
+ exts += *pc++;
+ }
- while (tokenizer.HasMoreTokens())
+ wxStringTokenizer tokenizer(exts, _T(";"));
+ while ( tokenizer.HasMoreTokens() )
{
- e = tokenizer.GetNextToken();
- if (e.Left(2) != _T("*.")) continue; // don't support too difficult patterns
+ wxString e = tokenizer.GetNextToken();
+ if ( e.Left(2) != _T("*.") )
+ continue; // don't support too difficult patterns
+
+ if ( !mime_extension.empty() )
+ {
+ // separate from the previous ext
+ mime_extension << _T(' ');
+ }
+
mime_extension << e.Mid(2);
- mime_extension << _T(' ');
}
- mime_extension.RemoveLast();
}
ms_infoTypes.Add(mimetype);
// ok, now we can take care of icon:
- pos = text.Find(_T("Icon="));
- if ( pos == wxNOT_FOUND )
+ int posIcon = text.Find(_T("Icon="));
+ if ( posIcon == wxNOT_FOUND )
{
// no icon info
return;
wxString icon;
- pc = text.c_str() + pos + 5; // 5 == strlen("Icon=")
+ const wxChar *pc = text.c_str() + posIcon + 5; // 5 == strlen("Icon=")
while ( *pc && *pc != _T('\n') )
{
icon += *pc++;