metadata_editor_format_e format;
} metadata_editor_s;
-static bool __metadata_editor_get_file_ext(const char *file_path, char *file_ext, int max_len)
+static String __get_file_ext(const char *file_path)
{
- unsigned int i = 0;
- unsigned int path_len = strlen(file_path);
-
- for (i = path_len; i > 0; i--) {
- if ((file_path[i] == '.') && (i < path_len)) {
- strncpy(file_ext, &file_path[i + 1], max_len);
- return true;
- }
-
- /* meet the dir. no ext */
- if (file_path[i] == '/')
- return false;
- }
-
- return false;
+ String s = String(file_path, String::UTF8);
+ const int pos = s.rfind(".");
+ if (pos != -1)
+ return s.substr(pos + 1).upper();
+ return "";
}
static metadata_editor_format_e __metadata_editor_get_file_type(const char *path)
{
char mimetype[EXT_LEN] = {0, };
- char ext[EXT_LEN] = { 0 };
/* get content type and mime type from file. */
if (aul_get_mime_from_file(path, mimetype, sizeof(mimetype)) < 0) {
metadata_editor_debug("aul_get_mime_from_file fail.. Now trying to get type by extension");
- metadata_editor_retvm_if(!__metadata_editor_get_file_ext(path, ext, EXT_LEN), METADATA_EDITOR_FORMAT_NOTYPE, "__metadata_editor_get_file_ext failed");
-
- if (strcasecmp(ext, "MP3") == 0)
+ String ext = __get_file_ext(path);
+ if (ext == "MP3")
return METADATA_EDITOR_FORMAT_MP3;
- else if (strcasecmp(ext, "MP4") == 0)
+ else if (ext == "MP4")
return METADATA_EDITOR_FORMAT_MP4;
- else if (strcasecmp(ext, "FLAC") == 0)
+ else if (ext == "FLAC")
return METADATA_EDITOR_FORMAT_FLAC;
- else if (strcasecmp(ext, "WAV") == 0)
+ else if (ext == "WAV")
return METADATA_EDITOR_FORMAT_WAV;
- else if (strcasecmp(ext, "OGG") == 0)
+ else if (ext == "OGG")
return METADATA_EDITOR_FORMAT_OGG_VORBIS;
else
return METADATA_EDITOR_FORMAT_NOTYPE;
static int __metadata_editor_get_picture_type(const char *path, char **type)
{
- int ret = 0;
char mimetype[EXT_LEN] = {0, };
- char ext[EXT_LEN] = {0, };
/* get content type and mime type from file. */
if (aul_get_mime_from_file(path, mimetype, sizeof(mimetype)) < 0) {
metadata_editor_debug("aul_get_mime_from_file fail.. Now trying to get type by extension");
- ret = __metadata_editor_get_file_ext(path, ext, EXT_LEN);
- metadata_editor_retvm_if(ret < 0, METADATA_EDITOR_ERROR_OPERATION_FAILED, "__metadata_editor_get_file_ext failed");
-
- if (strcasecmp(ext, "JPG") == 0 || strcasecmp(ext, "JPEG") == 0) {
+ String ext = __get_file_ext(path);
+ if (ext == "JPG" || ext == "JPEG") {
*type = g_strdup(MIME_TYPE_JPEG);
return METADATA_EDITOR_ERROR_NONE;
- } else if (strcasecmp(ext, "PNG") == 0) {
- *type = g_strdup(MIME_TYPE_JPEG);
+ } else if (ext == "PNG") {
+ *type = g_strdup(MIME_TYPE_PNG);
return METADATA_EDITOR_ERROR_NONE;
} else {
return METADATA_EDITOR_ERROR_NOT_SUPPORTED;
char *mime_type = NULL;
ret = __metadata_editor_get_picture_type(path, &mime_type);
- if (ret != METADATA_EDITOR_ERROR_NONE)
- return ret;
+ metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "__metadata_editor_get_picture_type failed");
if (!g_file_get_contents(path, picture, size, &error)) {
metadata_editor_error("Unable to read [%s], error [%s]", path, error->message);
else
ret = METADATA_EDITOR_ERROR_PERMISSION_DENIED;
- g_error_free (error);
+ g_error_free(error);
g_free(mime_type);
return ret;
if (errno == EACCES || errno == EPERM) {
metadata_editor_error("Permission denied");
return METADATA_EDITOR_ERROR_PERMISSION_DENIED;
- } else {
- metadata_editor_error("Fail to open path");
- return METADATA_EDITOR_ERROR_FILE_EXISTS;
}
+
+ metadata_editor_error("Fail to open path");
+ return METADATA_EDITOR_ERROR_FILE_EXISTS;
}
return METADATA_EDITOR_ERROR_NONE;
static int __is_valid_picture_index(bool is_empty, unsigned int list_size, int index)
{
metadata_editor_debug("list size [%d] picture index[%d]", list_size, index);
-
metadata_editor_retvm_if(is_empty, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "No picture");
metadata_editor_retvm_if((index < 0) || (list_size <= (uint)index), METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Out of range");
class OggFileTypeResolver : public TagLib::FileRef::FileTypeResolver {
TagLib::File *createFile(TagLib::FileName fileName, bool, AudioProperties::ReadStyle) const {
- char ext[EXT_LEN] = {0, };
- if (__metadata_editor_get_file_ext(fileName, ext, EXT_LEN)) {
- if (strcasecmp(ext, "OGG") == 0) {
- File *file = new Ogg::FLAC::File(fileName);
- if(file->isValid())
- return file;
- delete file;
- return new Ogg::Vorbis::File(fileName);
- }
+ String ext = __get_file_ext(fileName);
+ if (ext == "OGG") {
+ File *file = new Ogg::FLAC::File(fileName);
+ if (file->isValid())
+ return file;
+ delete file;
+ return new Ogg::Vorbis::File(fileName);
}
return 0;
}