From fd307dd24bc0fa6b20f6261ac09b975804352989 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 22 Jun 2017 18:24:17 +0200 Subject: [PATCH] Tweaked the hard disk image loading a bit in order to prevent double opening of the same file. --- src/hdd_image.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/hdd_image.c b/src/hdd_image.c index ecfcbeb3a..ff047fc80 100644 --- a/src/hdd_image.c +++ b/src/hdd_image.c @@ -124,18 +124,22 @@ int hdd_image_load(int id) int c; uint64_t i = 0, s = 0, t = 0; wchar_t *fn = hdc[id].fn; + int is_hdx[2] = { 0, 0 }; memset(empty_sector, 0, sizeof(empty_sector)); hdd_images[id].base = 0; - hdd_images[id].loaded = 0; - if (hdd_images[id].file != NULL) + if (hdd_images[id].loaded) { fclose(hdd_images[id].file); hdd_images[id].file = NULL; + hdd_images[id].loaded = 0; } + is_hdx[0] = image_is_hdx(fn, 0); + is_hdx[1] = image_is_hdx(fn, 1); + /* Try to open existing hard disk image */ if (fn[0] == '.') { @@ -185,7 +189,7 @@ int hdd_image_load(int id) } hdd_images[id].type = 1; } - else if (image_is_hdx(fn, 0)) + else if (is_hdx[0]) { full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; hdd_images[id].base = 0x28; @@ -257,7 +261,7 @@ int hdd_image_load(int id) hdc[id].tracks = tracks; hdd_images[id].type = 1; } - else if (image_is_hdx(fn, 1)) + else if (is_hdx[1]) { hdd_images[id].base = 0x28; fseeko64(hdd_images[id].file, 8, SEEK_SET);