return METADATA_EDITOR_ERROR_NOT_SUPPORTED;
}
-static int __metadata_editor_get_picture_info(const char *path, void **picture, size_t *size, char **type)
+static int __metadata_editor_get_picture_info(const char *path, char **picture, size_t *size, char **type)
{
- int ret;
+ int ret = METADATA_EDITOR_ERROR_NONE;
+ GError *error = NULL;
ret = __metadata_editor_get_picture_type(path, type);
if (ret != METADATA_EDITOR_ERROR_NONE)
- return METADATA_EDITOR_ERROR_OPERATION_FAILED;
+ return ret;
- //IF ok.. read file
- FILE *fin = fopen(path, "rb");
- size_t file_size = 0;
-
- if (fin) {
- while (fgetc(fin) != EOF)
- file_size++;
-
- fclose(fin);
- char picture_buffer[file_size] = {0, };
- memset(picture_buffer, 0, file_size * sizeof(char));
- fin = fopen(path, "rb");
- if (fin) {
- if(file_size != fread(picture_buffer, 1, file_size, fin)) {
- metadata_editor_error("fread error");
- fclose(fin);
- return METADATA_EDITOR_ERROR_OPERATION_FAILED;
- }
- fclose(fin);
- }
- if (*picture == NULL) {
- *picture = malloc(file_size * sizeof(char));
- memset(*picture, 0, file_size * sizeof(char));
- memcpy(*picture, picture_buffer, file_size);
- *size = file_size;
- }
+ if (!g_file_get_contents(path, picture, size, &error)) {
+ metadata_editor_error("Unable to read [%s], error [%s]", path, error->message);
+ if (error->code == G_FILE_ERROR_NOENT || error->code == G_FILE_ERROR_ISDIR)
+ ret = METADATA_EDITOR_ERROR_FILE_EXISTS;
+ else
+ ret = METADATA_EDITOR_ERROR_PERMISSION_DENIED;
+
+ g_error_free (error);
}
- return METADATA_EDITOR_ERROR_NONE;
+ return ret;
}
extern "C" int metadata_editor_create(metadata_editor_h *metadata)
}
}
-static int __append_APIC(ID3v2::Tag *tag, void *picture, size_t size, const char *mime_type)
+static int __append_APIC(ID3v2::Tag *tag, const char *picture, size_t size, const char *mime_type)
{
metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. No ID3v2 tag in file.");
metadata_editor_info("New APIC frame will be added to the ID3v2 tag");
- pictureFrame->setPicture(ByteVector((char*)picture, size));
+ pictureFrame->setPicture(ByteVector(picture, size));
pictureFrame->setType(ID3v2::AttachedPictureFrame::FrontCover);
pictureFrame->setMimeType(mime_type);
return METADATA_EDITOR_ERROR_NONE;
}
-static int __append_mp3_picture(metadata_editor_s *metadata, void *picture ,size_t size, const char *mime_type)
+static int __append_mp3_picture(metadata_editor_s *metadata, const char *picture ,size_t size, const char *mime_type)
{
return __append_APIC(dynamic_cast<MPEG::File*>(metadata->file)->ID3v2Tag(true), picture, size, mime_type);
}
-static int __append_mp4_picture(metadata_editor_s *metadata, void *picture, size_t size, const char *mime_type)
+static int __append_mp4_picture(metadata_editor_s *metadata, const char *picture, size_t size, const char *mime_type)
{
auto tag = dynamic_cast<MP4::Tag*>(metadata->file->tag());
metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist");
lst = tag->item("covr").toCoverArtList();
}
- lst.append(MP4::CoverArt(format, ByteVector((char*)picture, size)));
+ lst.append(MP4::CoverArt(format, ByteVector(picture, size)));
tag->setItem("covr", lst);
return METADATA_EDITOR_ERROR_NONE;
}
#if 0
-static int __append_flac_picture(metadata_editor_s *metadata, void *picture, size_t size, const char *mime_type)
+static int __append_flac_picture(metadata_editor_s *metadata, const char *picture, size_t size, const char *mime_type)
{
FLAC::File *_file = (FLAC::File*) metadata->file;
auto frontCover = new FLAC::Picture;
metadata_editor_debug_fenter();
- frontCover->setData(ByteVector((char*)picture, size));
+ frontCover->setData(ByteVector(picture, size));
frontCover->setType(FLAC::Picture::FrontCover);
frontCover->setMimeType(mime_type);
return METADATA_EDITOR_ERROR_NONE;
}
-static int __append_wav_picture(metadata_editor_s *metadata, void *picture, size_t size, const char *mime_type)
+static int __append_wav_picture(metadata_editor_s *metadata, const char *picture, size_t size, const char *mime_type)
{
return __append_APIC(dynamic_cast<ID3v2::Tag*>(metadata->file->tag()), picture, size, mime_type);
}
extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const char *path)
{
int ret = METADATA_EDITOR_ERROR_NONE;
- void *picture = NULL;
+ char *picture = NULL;
size_t size = 0;
char *mime_type = NULL;
metadata_editor_s *_metadata = (metadata_editor_s*) metadata;
metadata_editor_retvm_if(!path, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid path");
ret = __metadata_editor_get_picture_info(path, &picture, &size, &mime_type);
- metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it");
+ metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it"); //FixMe!. It should return proper error!
switch (_metadata->filetype) {
case METADATA_EDITOR_FORMAT_MP3:
}
}
- META_SAFE_FREE(picture);
+ g_free(picture);
g_free(mime_type);
return ret;