From 6416aaa52b6138602e61fc3b68fb7b2bd6f28474 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 11 Feb 2021 15:36:56 +0100 Subject: [PATCH] add simple detection of file based on extension ftc --- client/src/fileutils.c | 38 ++++++++++++++++++++++++++++++++++++++ client/src/fileutils.h | 7 +++++++ 2 files changed, 45 insertions(+) diff --git a/client/src/fileutils.c b/client/src/fileutils.c index d68c95563..137d2640b 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -77,6 +77,44 @@ struct wave_info_t { } PACKED audio_data; } PACKED; +/** + * @brief detects if file is of a supported filetype based on extension + * @param filename + * @return o + */ +DumpFileType_t getfiletype(const char *filename) { + // assume unknown file is BINARY + DumpFileType_t o = BIN; + if (filename == NULL) { + return o; + } + + size_t len = strlen(filename); + if (len > 4) { + // check if valid file extension and attempt to load data + char s[FILE_PATH_SIZE]; + memset(s, 0, sizeof(s)); + memcpy(s, filename, len); + str_lower(s); + + if (str_endswith(s, "bin")) { + o = BIN; + } else if (str_endswith(s, "eml")) { + o = EML; + } else if (str_endswith(s, "json")) { + o = JSON; + } else if (str_endswith(s, "dic")) { + o = DICTIONARY; + } else { + // mfd, trc, trace is binary + o = BIN; + // log is text + // .pm3 is text values of signal data + } + } + return o; +} + /** * @brief checks if a file exists * @param filename diff --git a/client/src/fileutils.h b/client/src/fileutils.h index 480cb013b..5e5cee664 100644 --- a/client/src/fileutils.h +++ b/client/src/fileutils.h @@ -272,4 +272,11 @@ mfu_df_e detect_mfu_dump_format(uint8_t **dump, size_t *dumplen, bool verbose); int searchAndList(const char *pm3dir, const char *ext); int searchFile(char **foundpath, const char *pm3dir, const char *searchname, const char *suffix, bool silent); + +/** + * @brief detects if file is of a supported filetype based on extension + * @param filename + * @return + */ +DumpFileType_t getfiletype(const char *filename); #endif // FILEUTILS_H