Clean up attachments

Avoid use of raw pointers.
This commit is contained in:
Urs Fleisch
2025-08-22 13:27:07 +02:00
parent 98bc68d16e
commit 3566b00596
8 changed files with 210 additions and 57 deletions

View File

@ -56,17 +56,17 @@ int main(int argc, char *argv[])
if(attachments) {
const TagLib::Matroska::Attachments::AttachedFileList &list = attachments->attachedFileList();
printf("Found %u attachment(s)\n", list.size());
for(auto attachedFile : list) {
PRINT_PRETTY("Filename", attachedFile->fileName().toCString(true));
const TagLib::String &description = attachedFile->description();
for(const auto &attachedFile : list) {
PRINT_PRETTY("Filename", attachedFile.fileName().toCString(true));
const TagLib::String &description = attachedFile.description();
PRINT_PRETTY("Description", !description.isEmpty() ? description.toCString(true) : "None");
const TagLib::String &mediaType = attachedFile->mediaType();
const TagLib::String &mediaType = attachedFile.mediaType();
PRINT_PRETTY("Media Type", !mediaType.isEmpty() ? mediaType.toCString(false) : "None");
PRINT_PRETTY("Data Size",
TagLib::Utils::formatString("%u byte(s)",attachedFile->data().size()).toCString(false)
TagLib::Utils::formatString("%u byte(s)",attachedFile.data().size()).toCString(false)
);
PRINT_PRETTY("UID",
TagLib::Utils::formatString("%llu",attachedFile->uid()).toCString(false)
TagLib::Utils::formatString("%llu",attachedFile.uid()).toCString(false)
);
}
}

View File

@ -41,11 +41,11 @@ int main(int argc, char *argv[])
TagLib::FileStream image(argv[2]);
auto data = image.readBlock(image.length());
auto attachments = file.attachments(true);
auto attachedFile = new TagLib::Matroska::AttachedFile();
attachedFile->setFileName("cover.jpg");
attachedFile->setMediaType("image/jpeg");
attachedFile->setData(data);
//attachedFile->setUID(5081000385627515072ull);
TagLib::Matroska::AttachedFile attachedFile;
attachedFile.setFileName("cover.jpg");
attachedFile.setMediaType("image/jpeg");
attachedFile.setData(data);
//attachedFile.setUID(5081000385627515072ull);
attachments->addAttachedFile(attachedFile);
file.save();