Only check if disk exists when reading disk part.

This commit is contained in:
Nathan Moinvaziri 2017-10-26 21:09:49 -07:00
parent 62e7e2b0b9
commit 507074781d

View File

@ -68,9 +68,21 @@ int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
uint32_t magic = 0;
int32_t i = 0;
int32_t err = MZ_OK;
int16_t disk_part = 0;
int16_t read_disk_part = 0;
if ((((split->disk_size > 0) && (split->mode & MZ_OPEN_MODE_WRITE)) ||
((split->mode & MZ_OPEN_MODE_WRITE) == 0)) && (number_disk >= 0))
// Check if we are reading or writing a disk part or the cd disk
if (number_disk >= 0)
{
if ((split->mode & MZ_OPEN_MODE_WRITE) == 0)
disk_part = MZ_OPEN_MODE_READ;
else if (split->disk_size > 0)
disk_part = MZ_OPEN_MODE_WRITE;
}
// Construct disk path
if (disk_part > 0)
{
for (i = strlen(split->path_disk) - 1; i >= 0; i -= 1)
{
@ -79,15 +91,16 @@ int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
snprintf(&split->path_disk[i], split->path_disk_size - i, ".z%02d", number_disk + 1);
break;
}
// If disk number doesn't exist then return MZ_EXIST_ERROR
err = mz_os_file_exists(split->path_disk);
}
else
{
strncpy(split->path_disk, split->path_cd, split->path_disk_size);
}
// If disk part doesn't exist during reading then return MZ_EXIST_ERROR
if (disk_part == MZ_OPEN_MODE_READ)
err = mz_os_file_exists(split->path_disk);
if (err == MZ_OK)
err = mz_stream_open(split->stream.base, split->path_disk, split->mode);