comparison src/xs_sidplay2.cpp @ 869:3a9bf45178ff

Use xs_fload_buffer() again, to support potential VFS backends.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 09 Nov 2012 04:00:27 +0200
parents 011ba70e271e
children a5b118c853f5
comparison
equal deleted inserted replaced
868:3c3569894b23 869:3a9bf45178ff
393 /* Load a given SID-tune file 393 /* Load a given SID-tune file
394 */ 394 */
395 gboolean xs_sidplay2_load(XSEngineState * state, gchar * filename) 395 gboolean xs_sidplay2_load(XSEngineState * state, gchar * filename)
396 { 396 {
397 XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; 397 XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal;
398 398 gboolean res = FALSE;
399 if (!engine || !filename) 399 guint8 *buf = NULL;
400 return FALSE; 400 size_t bufSize;
401 401
402 engine->tune.load(filename); 402 if (!engine)
403 return FALSE;
404
405 if (!xs_fload_buffer(filename, &buf, &bufSize, XS_SIDBUF_SIZE, TRUE))
406 goto error;
407
408 engine->tune.read(buf, bufSize);
403 if (!engine->tune) 409 if (!engine->tune)
404 { 410 {
405 xs_error("Could not load file '%s': %s\n", 411 xs_error("Could not load file '%s': %s\n",
406 filename, (engine->tune.getInfo()).statusString); 412 filename, (engine->tune.getInfo()).statusString);
407 return FALSE; 413 goto error;
408 } 414 }
409 415
410 return TRUE; 416 res = TRUE;
417
418 error:
419 g_free(buf);
420 return res;
411 } 421 }
412 422
413 423
414 /* Delete INTERNAL information 424 /* Delete INTERNAL information
415 */ 425 */
439 * (those variables that are only set by libSIDPlay when tune is initialized). 449 * (those variables that are only set by libSIDPlay when tune is initialized).
440 * Rest of the information is acquired in xs_sidplay2_updateinfo() 450 * Rest of the information is acquired in xs_sidplay2_updateinfo()
441 */ 451 */
442 XSTuneInfo *xs_sidplay2_getinfo(const gchar *filename) 452 XSTuneInfo *xs_sidplay2_getinfo(const gchar *filename)
443 { 453 {
444 XSTuneInfo *res; 454 XSTuneInfo *res = NULL;
445 SidTune *tune; 455 SidTune *tune = NULL;
446 SidTuneInfo info; 456 SidTuneInfo info;
457 guint8 *buf = NULL;
458 size_t bufSize;
447 459
448 /* Check if the tune exists and is readable */ 460 /* Check if the tune exists and is readable */
449 if ((tune = new SidTune(filename)) == NULL) 461 if (!xs_fload_buffer(filename, &buf, &bufSize, XS_SIDBUF_SIZE, TRUE))
462 {
463 XSDEBUG("could not load file '%s'.\n", filename);
464 goto error;
465 }
466
467 if ((tune = new SidTune(buf, bufSize)) == NULL)
450 { 468 {
451 XSDEBUG("could not initialize tune from '%s'.\n", filename); 469 XSDEBUG("could not initialize tune from '%s'.\n", filename);
452 return NULL; 470 goto error;
453 } 471 }
454 472
455 if (!tune->getStatus()) 473 if (!tune->getStatus())
456 { 474 {
457 XSDEBUG("tune->getStatus() returned false for '%s'.\n", filename); 475 XSDEBUG("tune->getStatus() returned false for '%s'.\n", filename);
458 delete tune; 476 goto error;
459 return NULL;
460 } 477 }
461 478
462 /* Get general tune information */ 479 /* Get general tune information */
463 tune->getInfo(info); 480 tune->getInfo(info);
464 481
468 info.infoString[0], info.infoString[1], info.infoString[2], 485 info.infoString[0], info.infoString[1], info.infoString[2],
469 info.loadAddr, info.initAddr, info.playAddr, 486 info.loadAddr, info.initAddr, info.playAddr,
470 info.dataFileLen, info.formatString, 487 info.dataFileLen, info.formatString,
471 info.sidModel 488 info.sidModel
472 ); 489 );
473 490
474 delete tune; 491 error:
492 if (tune)
493 delete tune;
494
495 g_free(buf);
475 return res; 496 return res;
476 } 497 }
477 498
478 499
479 /* Updates the information of currently playing tune 500 /* Updates the information of currently playing tune