| 539 | |
| 540 | static cc_bool needReload; |
| 541 | static cc_result ExtractFrom(struct Stream* stream, const cc_string* path) { |
| 542 | #if CC_BUILD_MAXSTACK <= (32 * 1024) |
| 543 | struct ZipEntry* entries = (struct ZipEntry*)Mem_TryAllocCleared(512, sizeof(struct ZipEntry)); |
| 544 | #else |
| 545 | struct ZipEntry entries[512]; |
| 546 | #endif |
| 547 | cc_result res; |
| 548 | #if CC_BUILD_MAXSTACK <= (32 * 1024) |
| 549 | if (!entries) return ERR_OUT_OF_MEMORY; |
| 550 | #endif |
| 551 | |
| 552 | Event_RaiseVoid(&TextureEvents.PackChanged); |
| 553 | /* If context is lost, then trying to load textures will just fail */ |
| 554 | /* So defer loading the texture pack until context is restored */ |
| 555 | if (Gfx.LostContext) { |
| 556 | needReload = true; |
| 557 | res = 0; |
| 558 | goto ret; |
| 559 | } |
| 560 | needReload = false; |
| 561 | |
| 562 | res = ExtractPng(stream); |
| 563 | if (res == PNG_ERR_INVALID_SIG) { |
| 564 | /* file isn't a .png image, probably a .zip archive then */ |
| 565 | |
| 566 | #if CC_BUILD_MAXSTACK <= (32 * 1024) |
| 567 | res = Zip_Extract(stream, SelectZipEntry, ProcessZipEntry, |
| 568 | entries, 512); |
| 569 | #else |
| 570 | res = Zip_Extract(stream, SelectZipEntry, ProcessZipEntry, |
| 571 | entries, Array_Elems(entries)); |
| 572 | #endif |
| 573 | |
| 574 | if (res) Logger_SysWarn2(res, "extracting", path); |
| 575 | } else if (res) { |
| 576 | Logger_SysWarn2(res, "decoding", path); |
| 577 | } |
| 578 | ret: |
| 579 | #if CC_BUILD_MAXSTACK <= (32 * 1024) |
| 580 | Mem_Free(entries); |
| 581 | #endif |
| 582 | return res; |
| 583 | } |
| 584 | |
| 585 | #if defined CC_BUILD_PS1 || defined CC_BUILD_SATURN |
| 586 | /* Load hardcoded texture pack */ |
no test coverage detected