From d45bb357ef7b5722ef0f1a4cfc6c4069354fec96 Mon Sep 17 00:00:00 2001 From: Alastair Poole Date: Fri, 20 Dec 2019 18:00:57 +0000 Subject: [PATCH] Edi_Mime: Use our own variation to detect mime. Replace efreet_mime_type_get with our own internal edi_mime_type_get. Due to inacurracies do our own test for binary file. --- src/bin/edi_debugpanel.c | 2 +- src/bin/edi_filepanel.c | 2 +- src/bin/edi_main.c | 2 +- src/bin/edi_scm_ui.c | 2 +- src/bin/edi_searchpanel.c | 2 +- src/bin/mainview/edi_mainview.c | 2 +- src/bin/mainview/edi_mainview_panel.c | 2 +- src/lib/.edi_mime.c.swp | Bin 0 -> 12288 bytes src/lib/Edi.h | 1 + src/lib/edi_mime.c | 63 ++++++++++++++++++++++++++ src/lib/edi_mime.h | 31 +++++++++++++ src/lib/meson.build | 2 + 12 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 src/lib/.edi_mime.c.swp create mode 100644 src/lib/edi_mime.c create mode 100644 src/lib/edi_mime.h diff --git a/src/bin/edi_debugpanel.c b/src/bin/edi_debugpanel.c index 1361c64..54914f8 100644 --- a/src/bin/edi_debugpanel.c +++ b/src/bin/edi_debugpanel.c @@ -295,7 +295,7 @@ void edi_debugpanel_start(const char *name) return; } - mime = efreet_mime_type_get(_edi_project_config->launch.path); + mime = edi_mime_type_get(_edi_project_config->launch.path); if (mime && !strcmp(mime, "application/x-shellscript")) snprintf(debug->cmd, sizeof(debug->cmd), LIBTOOL_COMMAND " --mode execute %s %s", debug->tool->exec, _edi_project_config->launch.path); else if (debug->tool->arguments) diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c index 7d188b5..e822873 100644 --- a/src/bin/edi_filepanel.c +++ b/src/bin/edi_filepanel.c @@ -68,7 +68,7 @@ _get_provider_from_hashset(const char *filename) const char *mime = eina_hash_find(mime_entries, filename); if ( !mime ) { - mime = efreet_mime_type_get(filename); + mime = edi_mime_type_get(filename); if (mime) eina_hash_add(mime_entries, filename, strdup(mime)); diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c index 8ffb285..6788203 100644 --- a/src/bin/edi_main.c +++ b/src/bin/edi_main.c @@ -1801,7 +1801,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) { const char *mime; - mime = efreet_mime_type_get(project_path); + mime = edi_mime_type_get(project_path); if (!edi_content_provider_for_mime_get(mime)) { fprintf(stderr, _("Could not open file of unsupported mime type (%s)\n"), mime); diff --git a/src/bin/edi_scm_ui.c b/src/bin/edi_scm_ui.c index 9f74a34..258e8db 100644 --- a/src/bin/edi_scm_ui.c +++ b/src/bin/edi_scm_ui.c @@ -235,7 +235,7 @@ _content_get(void *data, Evas_Object *obj, const char *source) status = (Edi_Scm_Status *) data; - mime = efreet_mime_type_get(status->fullpath); + mime = edi_mime_type_get(status->fullpath); if (mime) icon_file = efreet_mime_type_icon_get(mime, elm_config_icon_theme_get(), 32); diff --git a/src/bin/edi_searchpanel.c b/src/bin/edi_searchpanel.c index cbcd5c0..19feb8d 100644 --- a/src/bin/edi_searchpanel.c +++ b/src/bin/edi_searchpanel.c @@ -407,7 +407,7 @@ _edi_searchpanel_search_project_file(const char *path, const char *search_term, // If the file looks big, check if it is a text file first. if (eina_file_size_get(f) > 1 * 1024 * 1024 && - strncmp(efreet_mime_type_get(path), "text/", 5)) + strncmp(edi_mime_type_get(path), "text/", 5)) { eina_file_close(f); return ; diff --git a/src/bin/mainview/edi_mainview.c b/src/bin/mainview/edi_mainview.c index 67a65f7..39cd61a 100644 --- a/src/bin/mainview/edi_mainview.c +++ b/src/bin/mainview/edi_mainview.c @@ -257,7 +257,7 @@ _edi_mainview_win_stat_done(void *data, Eio_File *handler EINA_UNUSED, const Ein if (!S_ISREG(stat->mode)) return; - mime = efreet_mime_type_get(options->path); + mime = edi_mime_type_get(options->path); provider = edi_content_provider_for_mime_get(mime); if (!provider) { diff --git a/src/bin/mainview/edi_mainview_panel.c b/src/bin/mainview/edi_mainview_panel.c index c4ae9f6..629f7ee 100644 --- a/src/bin/mainview/edi_mainview_panel.c +++ b/src/bin/mainview/edi_mainview_panel.c @@ -912,7 +912,7 @@ _edi_mainview_panel_tab_stat_done(void *data, Eio_File *handler EINA_UNUSED, con if (!S_ISREG(stat->mode)) return; - mime = efreet_mime_type_get(options->path); + mime = edi_mime_type_get(options->path); provider = edi_content_provider_for_mime_get(mime); if (!provider) { diff --git a/src/lib/.edi_mime.c.swp b/src/lib/.edi_mime.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..da3048f4bea21af131e8578497c5f07a1a317f50 GIT binary patch literal 12288 zcmeI2O=#3W7>1|fsapRP6oly(+TB{aTYsS1A6aXvt5vJEMbHw`WU@P$O_n5;YEh|p zR8M+Sdh;UaP4Omp@Fsc@Pl9(niQWX?nay^0D^&DW_yW&PGV^_3-g#$oD4m(yRN*x5 z@9kr_HZgXn_1E;zk58DrjWNr!qS%t58d~WZ2|Oo?Lt&Lyiel_$tzdQ}a70!(G8=_< z){`^p-YmK>M%?*O4TX1LOcXKn{=twbNg45nf+7iTM;CH>R@(=*?cg<75I`yfx!%6=4=doUT}LDN_|8q;Hw7^n_`9 zK_t>H`jK7lE?X5-)kwQN9QR3DqxR-|B+uZS@RdY99`)5A52}p9nY=lgAG=^QhUuy5 zXfc=M!pGyDJsEAVs)8Oq%=hIE z^y^V1sQZ6e00^qP(PWaAS|9tJqNkxWVP%$_kL300x+wFRPWoeKthA0g z13&eO%VgFis1;OiK-(liX}3I2Epl~j3S)*jes+9vEI(l+s`MP(Ol>3oMUmT7Kd1;_ zZ@XH3wf0F}Lm6>22)xEUjBG7r;{0TFkIed!Ec(LXUf>s#AFQ^Tj9s!q-i;|#p8`LM zYkm4-Lx_IID7HE8b_duzs~twKe-m~?n*KhRksmMc#%>&`mA>uGI)bNEfl4T^TCwOY zrIwHAbMEM_#~Y4pjvG{xdP~Fgm_fr1LSZVE%lfO|@M%m&4X_U3JJMwxd`S&dy0WNV W&>>w%xco$Z$}mUHo*6A1XTJdj{*YY& literal 0 HcmV?d00001 diff --git a/src/lib/Edi.h b/src/lib/Edi.h index eaf9d82..9d42fd3 100644 --- a/src/lib/Edi.h +++ b/src/lib/Edi.h @@ -39,6 +39,7 @@ extern "C" { #include #include #include +#include /** * @file diff --git a/src/lib/edi_mime.c b/src/lib/edi_mime.c new file mode 100644 index 0000000..9808bf5 --- /dev/null +++ b/src/lib/edi_mime.c @@ -0,0 +1,63 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include +#include +#include + +#include "Edi.h" +#include "edi_mime.h" + +#include "edi_private.h" + +EAPI const char * +edi_mime_type_get(const char *path) +{ + Eina_File *f; + const char *mime; + char *map; + unsigned long long len; + Eina_Bool likely_text = EINA_TRUE; + + f = eina_file_open(path, EINA_FALSE); + if (!f) return efreet_mime_type_get(path); + + map = eina_file_map_all(f, EINA_FILE_POPULATE); + if (!map) + { + eina_file_close(f); + return efreet_mime_type_get(path); + } + + len = eina_file_size_get(f); + if (!len) + { + eina_file_map_free(f, map); + eina_file_close(f); + return "text/plain"; + } + + if (len > 2048) len = 2048; + + for (int i = 0; i < (int) len; i++) + { + if (map[i] == '\0') + { + likely_text = EINA_FALSE; + break; + } + } + + eina_file_map_free(f, map); + eina_file_close(f); + + mime = efreet_mime_type_get(path); + if ((strncmp(mime, "text/", 5)) && likely_text) + { + return "text/plain"; + } + + return mime; +} + diff --git a/src/lib/edi_mime.h b/src/lib/edi_mime.h new file mode 100644 index 0000000..805705e --- /dev/null +++ b/src/lib/edi_mime.h @@ -0,0 +1,31 @@ +#ifndef EDI_MIME_H_ +# define EDI_MIME_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for Edi mime handling + */ + +/** + * Return the mime type of a file + * + * @param path The path of the file to return the mime type of. + * + * @return A pointer to the mime type as a const character string. + * + */ +EAPI const char *edi_mime_type_get(const char *path); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* EDI_MIME_H_ */ diff --git a/src/lib/meson.build b/src/lib/meson.build index 9d948cd..dcd2600 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -15,6 +15,8 @@ src = files([ 'edi_create.h', 'edi_exe.c', 'edi_exe.h', + 'edi_mime.c', + 'edi_mime.h', 'edi_path.c', 'edi_path.h', 'edi_process.c',