struct imagedata
{
Gdiplus::Image *image;
+ IStream *stream;
TCHAR *metafile;
};
SetWindowPos(boxarthwnd, HWND_TOPMOST, r.left, r.top, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSIZE);
}
-void close_box_art_window(void)
+static void freeimages(void)
{
for (int i = 0; i < MAX_BOX_ART_IMAGES; i++) {
- if (images[i]) {
- struct imagedata *im = images[i];
- delete im->image;
+ struct imagedata *im = images[i];
+ if (im) {
+ if (im->image) {
+ delete im->image;
+ }
+ if (im->stream) {
+ im->stream->Release();
+ }
xfree(im->metafile);
xfree(im);
images[i] = NULL;
}
}
+}
+
+void close_box_art_window(void)
+{
+ freeimages();
if (!boxarthwnd)
return;
ShowWindow(boxarthwnd, SW_HIDE);
{
TCHAR tmp1[MAX_DPATH];
- for (int i = 0; i < MAX_BOX_ART_IMAGES; i++) {
- if (images[i]) {
- delete images[i];
- images[i] = NULL;
- }
- }
+ freeimages();
if (!path) {
close_box_art_window();
}
Gdiplus::Image *image = NULL;
+ IStream *stream = NULL;
for (int imgtype = 0; imgtype < 2 && !image; imgtype++) {
- if (imgtype == 1) {
+ if (imgtype == 1 && _tcslen(tmp1) > 3) {
_tcscpy(tmp1 + _tcslen(tmp1) - 3, _T("jpg"));
}
int outlen = 0;
uae_u8 *filedata = zfile_load_file(tmp1, &outlen);
if (filedata) {
- IStream *stream = SHCreateMemStream(filedata, outlen);
+ stream = SHCreateMemStream(filedata, outlen);
+ xfree(filedata);
if (stream) {
image = Gdiplus::Image::FromStream(stream);
- if (image && image->GetLastStatus() != Gdiplus::Ok) {
+ if (image && image->GetLastStatus() == Gdiplus::Ok) {
+ break;
+ }
+ if (image) {
delete image;
image = NULL;
}
stream->Release();
+ stream = NULL;
}
- xfree(filedata);
}
}
- if (image) {
+ if (image && stream) {
int w = image->GetWidth();
int h = image->GetHeight();
write_log(_T("Image '%s' loaded %d*%d\n"), tmp1, w, h);
struct imagedata *img = xcalloc(struct imagedata, 1);
if (img) {
img->image = image;
+ img->stream = stream;
if (metafile[0]) {
img->metafile = my_strdup(metafile);
}
total_images++;
}
image = NULL;
+ stream = NULL;
}
- if (image) {
- delete image;
+ if (image || stream) {
+ if (image) {
+ delete image;
+ }
+ if (stream) {
+ stream->Release();
+ }
break;
}
}