src/emu/clifront.c
| r14496 | r14497 | |
| 44 | 44 | #include "audit.h" |
| 45 | 45 | #include "info.h" |
| 46 | 46 | #include "unzip.h" |
| 47 | #include "un7z.h" |
| 47 | 48 | #include "validity.h" |
| 48 | 49 | #include "sound/samples.h" |
| 49 | 50 | #include "clifront.h" |
| r14496 | r14497 | |
| 1438 | 1439 | } |
| 1439 | 1440 | |
| 1440 | 1441 | // if that failed, and the filename ends with .zip, identify as a ZIP file |
| 1442 | if (core_filename_ends_with(filename, ".7z")) |
| 1443 | { |
| 1444 | // first attempt to examine it as a valid _7Z file |
| 1445 | _7z_file *_7z = NULL; |
| 1446 | _7z_error _7zerr = _7z_file_open(filename, &_7z); |
| 1447 | if (_7zerr == _7ZERR_NONE && _7z != NULL) |
| 1448 | { |
| 1449 | // loop over entries in the .7z, skipping empty files and directories |
| 1450 | for (int i = 0; i < _7z->db.db.NumFiles; i++) |
| 1451 | { |
| 1452 | const CSzFileItem *f = _7z->db.db.Files + i; |
| 1453 | _7z->curr_file_idx = i; |
| 1454 | int namelen = SzArEx_GetFileNameUtf16(&_7z->db, i, NULL); |
| 1455 | UINT16* temp = (UINT16 *)malloc(namelen * sizeof(UINT16)); |
| 1456 | void* temp2 = malloc((namelen+1) * sizeof(UINT8)); |
| 1457 | UINT8* temp3 = (UINT8*)temp2; |
| 1458 | memset(temp3, 0x00, namelen); |
| 1459 | SzArEx_GetFileNameUtf16(&_7z->db, i, temp); |
| 1460 | // crude, need real UTF16->UTF8 conversion ideally |
| 1461 | for (int j=0;j<namelen;j++) |
| 1462 | { |
| 1463 | temp3[j] = (UINT8)temp[j]; |
| 1464 | } |
| 1465 | |
| 1466 | if (!(f->IsDir) && (f->Size != 0)) |
| 1467 | { |
| 1468 | UINT8 *data = global_alloc_array(UINT8, f->Size); |
| 1469 | if (data != NULL) |
| 1470 | { |
| 1471 | // decompress data into RAM and identify it |
| 1472 | _7zerr = _7z_file_decompress(_7z, data, f->Size); |
| 1473 | if (_7zerr == _7ZERR_NONE) |
| 1474 | identify_data((const char*)temp2, data, f->Size); |
| 1475 | global_free(data); |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | free(temp); |
| 1480 | free(temp2); |
| 1481 | } |
| 1482 | |
| 1483 | // close up |
| 1484 | _7z_file_close(_7z); |
| 1485 | } |
| 1486 | |
| 1487 | // clear out any cached files |
| 1488 | _7z_file_cache_clear(); |
| 1489 | } |
| 1441 | 1490 | else if (core_filename_ends_with(filename, ".zip")) |
| 1442 | 1491 | { |
| 1443 | 1492 | // first attempt to examine it as a valid ZIP file |