3 wxString GetMIME(wxString FilenameInc){
7 // Check if file exists first before doing anything with it.
9 if (!wxFileExists(FilenameInc)){
11 // File doesn't exist so return.
13 wxMessageBox(_("The file with the filename given doesn't exist."), _("Error opening picture/audio file"), wxICON_ERROR);
18 #if defined(__WIN32__)
20 // TODO: Sort out Win32.
22 #elif defined(__APPLE__)
30 // Build Command Line.
32 wxString FilenameIncEscaped = FilenameInc;
33 FilenameIncEscaped.Replace(wxT(" "), wxT("\\ "));
34 wxString FileCommandLine;
36 FileCommandLine.Append("file -b --mime-type ");
37 FileCommandLine.Append(FilenameIncEscaped);
39 if (!(MIMEIn = popen(FileCommandLine.mb_str(), "r"))){
41 wxMessageBox(_("The file with the filename given doesn't exist."), _("Error opening picture/audio file"), wxICON_ERROR);
46 while(fgets(MIMEData, sizeof(MIMEData), MIMEIn) != NULL){
47 MIMEResult.Append(wxString::FromUTF8(MIMEData));
58 magic_t MagicCookie = magic_open(MAGIC_MIME);
59 magic_setflags(MagicCookie, MAGIC_MIME_TYPE);
63 wxMessageBox(_("An error occured with the support library for getting the picture/audio type."), _("Error opening picture/audio file"), wxICON_ERROR);
68 if (magic_load(MagicCookie, NULL) != 0) {
70 wxMessageBox(_("An error occured whilst determining the picture/audio type."), _("Error opening picture/audio file"), wxICON_ERROR);
75 MIMEType = magic_file(MagicCookie, FilenameInc.mb_str());
76 MIMEResult = wxString::FromUTF8(MIMEType);
77 magic_close(MagicCookie);