on xenial help sign in
Use Qt file operations and be more pedantic on returned value.
ee4c29fJussi Pakkanen
plugins/Utils/albumartprovider.cpp+12−12
@@ -168,22 +168,22 @@ std::string AlbumArtProvider::get_image(const std::string &artist, const std::st
168 return DEFAULT_ALBUM_ART;
168 return DEFAULT_ALBUM_ART;
169 }
169 }
170 fix_format(tmpname.c_str());
170 fix_format(tmpname.c_str());
171− FILE *f = fopen(tmpname.c_str(), "r");
171+ QFile f(fname);
172− fseek(f, 0, SEEK_END);
172+ if(!f.open(QIODevice::ReadWrite)) {
173− long s = ftell(f);
173+ return DEFAULT_ALBUM_ART;
174− fseek(f, 0, SEEK_SET);
174+ }
175− char *buf = new char[s];
175+ QByteArray arr = f.readAll();
176− fread(buf, 1, s, f);
176+ f.close();
177− fclose(f);
178
177
178+ cache.add_art(info.artist, info.album, arr.data(), arr.size());
179 try {
179 try {
180− cache.add_art(info.artist, info.album, buf, s);
180+ std::string res = cache.get_art_file(info.artist, info.album);
181+ if(res.empty())
182+ return DEFAULT_ALBUM_ART;
183+ return res;
181 } catch(...) {
184 } catch(...) {
182− delete []buf;
183− throw;
184 }
185 }
185− delete []buf;
186+ return DEFAULT_ALBUM_ART;
186− return cache.get_art_file(info.artist, info.album);
187}
187}
188
188
189QImage AlbumArtProvider::requestImage(const QString &id, QSize *realSize, const QSize &requestedSize) {
189QImage AlbumArtProvider::requestImage(const QString &id, QSize *realSize, const QSize &requestedSize) {