comparison dmres.c @ 602:c1a5652e473d

Sanitize resource preloading function a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 12 Apr 2013 09:34:21 +0300
parents b60220fd1669
children 36b544eb6f4b
comparison
equal deleted inserted replaced
601:588998ccc07a 602:c1a5652e473d
570 if (handle->fops == NULL) 570 if (handle->fops == NULL)
571 { 571 {
572 #ifdef DM_USE_PACKFS 572 #ifdef DM_USE_PACKFS
573 if (handle->lib->flags & DRF_USE_PACK) 573 if (handle->lib->flags & DRF_USE_PACK)
574 handle->fops = &dfPackFileOps; 574 handle->fops = &dfPackFileOps;
575 #ifdef DM_USE_STDIO 575 # ifdef DM_USE_STDIO
576 else 576 else
577 handle->fops = &dfStdioFileOps; 577 handle->fops = &dfStdioFileOps;
578 #else 578 # else
579 handle->fops = &dfPackFileOps; 579 handle->fops = &dfPackFileOps;
580 #endif 580 # endif
581 581
582 #else 582 #else
583 handle->fops = NULL; 583 handle->fops = NULL;
584 #endif 584 #endif
585 } 585 }
589 int dmf_preload(DMResource *handle) 589 int dmf_preload(DMResource *handle)
590 { 590 {
591 int ret = DMERR_INIT_FAIL; 591 int ret = DMERR_INIT_FAIL;
592 592
593 // Check if we want to preload raw data? 593 // Check if we want to preload raw data?
594 if (((handle->flags & DMF_PRELOAD_RAW) || 594 if ((handle->flags & DMF_PRELOAD_RAW) ||
595 (handle->lib->flags & DRF_PRELOAD_ALL)) && 595 (handle->lib->flags & DRF_PRELOAD_ALL))
596 (handle->flags & DMF_LOADED_RAW) == 0 && 596 {
597 handle->fops->preload != NULL) 597 if (handle->flags & DMF_LOADED_RAW)
598 { 598 ret = DMERR_OK;
599 ret = handle->fops->preload(handle);
600 if (ret == DMERR_OK)
601 {
602 handle->flags |= DMF_LOADED_RAW;
603 }
604 }
605 else
606 {
607 if (handle->fops->fopen != NULL)
608 ret = handle->fops->fopen(handle);
609 else 599 else
610 if (handle->fops->preload != NULL) 600 if (handle->fops->preload != NULL)
611 { 601 {
612 ret = handle->fops->preload(handle); 602 ret = handle->fops->preload(handle);
613 if (ret == DMERR_OK) 603 if (ret == DMERR_OK)
604 handle->flags |= DMF_LOADED_RAW;
605 }
606 }
607 else
608 {
609 if (handle->fops->fopen != NULL)
610 ret = handle->fops->fopen(handle);
611 }
612
613 // Check if resource data is to be preloaded
614 if ((handle->flags & DMF_PRELOAD_RES) || (handle->lib->flags & DRF_PRELOAD_RES))
615 {
616 if (handle->flags & DMF_LOADED_RES)
617 ret = DMERR_OK;
618 else
619 if (handle->rops != NULL &&
620 handle->rops->load != NULL)
621 {
622 ret = handle->rops->load(handle);
623 if (ret == DMERR_OK)
614 { 624 {
615 handle->flags |= DMF_LOADED_RAW; 625 // Okay, mark as loaded
626 handle->flags |= DMF_LOADED_RES;
627
628 // Check if we can purge the raw data now
629 if ((handle->flags & DMF_PERSIST) == 0)
630 dmres_purge_raw_data(handle);
616 } 631 }
617 }
618 }
619
620 // Check if resource data is to be preloaded
621 if (((handle->flags & DMF_PRELOAD_RES) || (handle->lib->flags & DRF_PRELOAD_RES)) &&
622 (handle->flags & DMF_LOADED_RES) == 0 &&
623 handle->rops != NULL &&
624 handle->rops->load != NULL)
625 {
626 ret = handle->rops->load(handle);
627 if (ret == DMERR_OK)
628 {
629 // Okay, mark as loaded
630 handle->flags |= DMF_LOADED_RES;
631
632 // Check if we can purge the raw data now
633 if ((handle->flags & DMF_PERSIST) == 0)
634 dmres_purge_raw_data(handle);
635 } 632 }
636 } 633 }
637 634
638 return ret; 635 return ret;
639 } 636 }