Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code so that OSX is now supported.
[xestiaab/.git] / source / common / mime.cpp
1 #include <wx/wx.h>
3 wxString GetMIME(wxString FilenameInc){
4     
5     wxString MIMEResult;
6     
7     // Check if file exists first before doing anything with it.
8     
9     if (!wxFileExists(FilenameInc)){
10         
11         // File doesn't exist so return.
12         
13         wxMessageBox(_("The file with the filename given doesn't exist."), _("Error opening picture/audio file"), wxICON_ERROR);
14         return wxEmptyString;
15         
16     }
17     
18 #if defined(__WIN32__)
19     
20     // TODO: Sort out Win32.
21     
22 #elif defined(__APPLE__)
23     
24 #include <stdio.h>
25     
26     FILE *MIMEIn;
27     
28     char MIMEData[512];
29     
30     // Build Command Line.
31     
32     wxString FilenameIncEscaped = FilenameInc;
33     FilenameIncEscaped.Replace(wxT(" "), wxT("\\ "));
34     wxString FileCommandLine;
35     
36     FileCommandLine.Append("file -b --mime-type ");
37     FileCommandLine.Append(FilenameIncEscaped);
38     
39     if (!(MIMEIn = popen(FileCommandLine.mb_str(), "r"))){
40         
41         wxMessageBox(_("The file with the filename given doesn't exist."), _("Error opening picture/audio file"), wxICON_ERROR);
42         return wxEmptyString;
43         
44     }
45     
46     while(fgets(MIMEData, sizeof(MIMEData), MIMEIn) != NULL){
47         MIMEResult.Append(wxString::FromUTF8(MIMEData));
48     }
49     pclose(MIMEIn);
50     
51     MIMEResult.Trim();
52     
53 #else
54     
55 #include <magic.h>
56     
57     const char *MIMEType;
58     magic_t MagicCookie = magic_open(MAGIC_MIME);
59     magic_setflags(MagicCookie, MAGIC_MIME_TYPE);
60     
61     if (!MagicCookie){
62         
63         wxMessageBox(_("An error occured with the support library for getting the picture/audio type."), _("Error opening picture/audio file"), wxICON_ERROR);
64         return wxEmptyString;
65         
66     }
67     
68     if (magic_load(MagicCookie, NULL) != 0) {
69         
70         wxMessageBox(_("An error occured whilst determining the picture/audio type."), _("Error opening picture/audio file"), wxICON_ERROR);
71         return wxEmptyString;
72         
73     }
74     
75     MIMEType = magic_file(MagicCookie, FilenameInc.mb_str());
76     MIMEResult = wxString::FromUTF8(MIMEType);
77     magic_close(MagicCookie);
78     
79 #endif
80     
81     return MIMEResult;
82     
83 }
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy