src/mess/osd/winui/messui.c
| r2262 | r2263 | |
| 438 | 438 | |
| 439 | 439 | |
| 440 | 440 | |
| 441 | static int device_uses_file_extension(const device_config *device, const char *file_extension) |
| 442 | { |
| 443 | int result = FALSE; |
| 444 | const struct IODevice *iodev = mess_device_from_core_device(device); |
| 445 | if (iodev != NULL) |
| 446 | { |
| 447 | const char *s = iodev->file_extensions; |
| 448 | if (s != NULL) |
| 449 | { |
| 450 | while(!result && (*s != '\0')) |
| 451 | { |
| 452 | if (!mame_stricmp(s, file_extension)) |
| 453 | { |
| 454 | result = TRUE; |
| 455 | break; |
| 456 | } |
| 457 | s += strlen(s) + 1; |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | return result; |
| 462 | } |
| 463 | |
| 464 | |
| 465 | |
| 441 | 466 | // Places the specified image in the specified slot; nID = -1 means don't matter |
| 442 | 467 | static void MessSpecifyImage(int drvindex, const device_config *device, LPCSTR pszFilename) |
| 443 | 468 | { |
| r2262 | r2263 | |
| 474 | 499 | { |
| 475 | 500 | for (device = image_device_first(config); device != NULL; device = image_device_next(device)) |
| 476 | 501 | { |
| 477 | | const struct IODevice *iodev = mess_device_from_core_device(device); |
| 478 | | const char *s = iodev->file_extensions; |
| 479 | | if (s != NULL) |
| 480 | | { |
| 481 | | while(*s != '\0') |
| 482 | | { |
| 483 | | if (!mame_stricmp(s, file_extension)) |
| 484 | | break; |
| 485 | | } |
| 486 | | |
| 487 | | if (*s != '\0') |
| 488 | | break; |
| 489 | | } |
| 502 | if (device_uses_file_extension(device, file_extension)) |
| 503 | break; |
| 490 | 504 | } |
| 491 | 505 | } |
| 492 | 506 | } |
| r2262 | r2263 | |
| 508 | 522 | |
| 509 | 523 | |
| 510 | 524 | |
| 511 | | static void MessRemoveImage(int drvindex, mess_device_class devclass, LPCSTR pszFilename) |
| 525 | static void MessRemoveImage(int drvindex, const device_config *device, LPCSTR pszFilename) |
| 512 | 526 | { |
| 513 | | int nPos; |
| 514 | | machine_config *config; |
| 515 | | const device_config *dev; |
| 516 | | const struct IODevice *iodev = NULL; |
| 517 | | |
| 518 | | if (devclass.gamedrv != NULL) |
| 519 | | { |
| 520 | | // allocate the machine config |
| 521 | | config = machine_config_alloc_with_mess_devices(drivers[drvindex]); |
| 522 | | |
| 523 | | nPos = 0; |
| 524 | | for (dev = image_device_first(config); dev != NULL; dev = image_device_next(dev)) |
| 525 | | { |
| 526 | | iodev = mess_device_from_core_device(dev); |
| 527 | | |
| 528 | | if (iodev->devclass.get_info == devclass.get_info) |
| 529 | | break; |
| 530 | | nPos++; |
| 531 | | } |
| 532 | | |
| 533 | | if (iodev != NULL) |
| 534 | | { |
| 535 | | if (!mame_stricmp(pszFilename, GetSelectedSoftware(drvindex, dev))) |
| 536 | | { |
| 537 | | MessSpecifyImage(drvindex, dev, NULL); |
| 538 | | } |
| 539 | | } |
| 540 | | |
| 541 | | machine_config_free(config); |
| 542 | | } |
| 527 | if (device != NULL) |
| 528 | MessSpecifyImage(drvindex, device, NULL); |
| 543 | 529 | } |
| 544 | 530 | |
| 545 | 531 | |
| r2262 | r2263 | |
| 985 | 971 | static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem) |
| 986 | 972 | { |
| 987 | 973 | int drvindex; |
| 988 | | mess_device_class devclass; |
| 974 | const device_config *device; |
| 989 | 975 | LPCSTR pszFullName; |
| 990 | 976 | HWND hwndList; |
| 991 | 977 | |
| r2262 | r2263 | |
| 993 | 979 | { |
| 994 | 980 | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 995 | 981 | drvindex = Picker_GetSelectedItem(hwndList); |
| 996 | | devclass = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem); |
| 982 | device = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem); |
| 997 | 983 | pszFullName = SoftwarePicker_LookupFilename(hwndSoftwarePicker, nItem); |
| 998 | 984 | |
| 999 | | MessRemoveImage(drvindex, devclass, pszFullName); |
| 985 | MessRemoveImage(drvindex, device, pszFullName); |
| 1000 | 986 | } |
| 1001 | 987 | } |
| 1002 | 988 | |
| r2262 | r2263 | |
| 1008 | 994 | LPCSTR pszName; |
| 1009 | 995 | LPSTR s; |
| 1010 | 996 | int drvindex; |
| 1011 | | mess_device_class devclass; |
| 997 | const device_config *device; |
| 1012 | 998 | HWND hwndList; |
| 1013 | 999 | |
| 1014 | 1000 | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| r2262 | r2263 | |
| 1023 | 1009 | pszName = s ? s + 1 : pszFullName; |
| 1024 | 1010 | |
| 1025 | 1011 | // Do the dirty work |
| 1026 | | devclass = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem); |
| 1027 | | if (!devclass.gamedrv) |
| 1012 | device = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem); |
| 1013 | if (device == NULL) |
| 1028 | 1014 | return; |
| 1029 | 1015 | MessSpecifyImage(drvindex, NULL, pszFullName); |
| 1030 | 1016 | |
src/mess/osd/winui/softwarepicker.c
| r2262 | r2263 | |
| 38 | 38 | typedef struct _file_info file_info; |
| 39 | 39 | struct _file_info |
| 40 | 40 | { |
| 41 | | mess_device_class devclass; |
| 41 | const device_config *device; |
| 42 | 42 | |
| 43 | 43 | // hash information |
| 44 | 44 | char szHash[HASH_BUF_SIZE]; |
| r2262 | r2263 | |
| 149 | 149 | |
| 150 | 150 | |
| 151 | 151 | |
| 152 | | mess_device_class SoftwarePicker_LookupDevice(HWND hwndPicker, int nIndex) |
| 152 | const device_config *SoftwarePicker_LookupDevice(HWND hwndPicker, int nIndex) |
| 153 | 153 | { |
| 154 | 154 | software_picker_info *pPickerInfo; |
| 155 | 155 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 156 | 156 | if ((nIndex < 0) || (nIndex >= pPickerInfo->nIndexLength)) |
| 157 | 157 | { |
| 158 | | mess_device_class dummy; |
| 159 | | memset(&dummy, 0, sizeof(dummy)); |
| 160 | | return dummy; |
| 158 | return NULL; |
| 161 | 159 | } |
| 162 | | return pPickerInfo->ppIndex[nIndex]->devclass; |
| 160 | return pPickerInfo->ppIndex[nIndex]->device; |
| 163 | 161 | } |
| 164 | 162 | |
| 165 | 163 | |
| r2262 | r2263 | |
| 182 | 180 | |
| 183 | 181 | iodevice_t SoftwarePicker_GetImageType(HWND hwndPicker, int nIndex) |
| 184 | 182 | { |
| 185 | | software_picker_info *pPickerInfo; |
| 186 | | const mess_device_class *devclass; |
| 183 | iodevice_t type; |
| 184 | const device_config *device = SoftwarePicker_LookupDevice(hwndPicker, nIndex); |
| 187 | 185 | |
| 188 | | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 189 | | if ((nIndex < 0) || (nIndex >= pPickerInfo->nIndexLength)) |
| 190 | | return -1; |
| 191 | | |
| 192 | | devclass = &pPickerInfo->ppIndex[nIndex]->devclass; |
| 193 | | if (!devclass->gamedrv) |
| 194 | | return -1; |
| 195 | | return (iodevice_t) (int) mess_device_get_info_int(devclass, MESS_DEVINFO_INT_TYPE); |
| 186 | if (device != NULL) |
| 187 | { |
| 188 | const struct IODevice *iodev = mess_device_from_core_device(device); |
| 189 | type = iodev->type; |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | type = (iodevice_t) -1; |
| 194 | } |
| 195 | return type; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | |
| r2262 | r2263 | |
| 265 | 265 | file_info *pFileInfo, const unsigned char *pBuffer, unsigned int nLength) |
| 266 | 266 | { |
| 267 | 267 | unsigned int nFunctions; |
| 268 | const struct IODevice *iodev; |
| 268 | 269 | iodevice_t type; |
| 269 | 270 | device_image_partialhash_func partialhash; |
| 270 | 271 | |
| 271 | | type = (iodevice_t) (int) mess_device_get_info_int(&pFileInfo->devclass, MESS_DEVINFO_INT_TYPE); |
| 272 | | partialhash = (device_image_partialhash_func) mess_device_get_info_fct(&pFileInfo->devclass, MESS_DEVINFO_PTR_PARTIAL_HASH); |
| 272 | iodev = mess_device_from_core_device(pFileInfo->device); |
| 273 | type = iodev->type; |
| 274 | partialhash = iodev->partialhash; |
| 273 | 275 | |
| 274 | 276 | nFunctions = hashfile_functions_used(pPickerInfo->pHashFile, type); |
| 275 | 277 | |
| r2262 | r2263 | |
| 392 | 394 | |
| 393 | 395 | // Determine which hash functions we need to use for this file, and which hashes |
| 394 | 396 | // have already been calculated |
| 395 | | if ((pPickerInfo->pHashFile != NULL) && (pFileInfo->devclass.get_info != NULL)) |
| 397 | if ((pPickerInfo->pHashFile != NULL) && (pFileInfo->device != NULL)) |
| 396 | 398 | { |
| 397 | | type = (iodevice_t) (int) mess_device_get_info_int(&pFileInfo->devclass, MESS_DEVINFO_INT_TYPE); |
| 399 | const struct IODevice *iodev = mess_device_from_core_device(pFileInfo->device); |
| 400 | type = iodev->type; |
| 398 | 401 | if (type < IO_COUNT) |
| 399 | 402 | nHashFunctionsUsed = hashfile_functions_used(pPickerInfo->pHashFile, type); |
| 400 | 403 | nCalculatedHashes = hash_data_used_functions(pFileInfo->szHash); |
| r2262 | r2263 | |
| 425 | 428 | file_info *pInfo; |
| 426 | 429 | int nIndex, nSize; |
| 427 | 430 | LPCSTR pszExtension = NULL, s; |
| 428 | | mess_device_class devclass = {0,}; |
| 429 | | const device_config *device; |
| 431 | const device_config *device = NULL; |
| 430 | 432 | |
| 431 | 433 | // first check to see if it is already here |
| 432 | 434 | if (SoftwarePicker_LookupIndex(hwndPicker, pszFilename) >= 0) |
| r2262 | r2263 | |
| 452 | 454 | while(*s && mame_stricmp(pszExtension, s)) |
| 453 | 455 | s += strlen(s) + 1; |
| 454 | 456 | if (*s) |
| 455 | | { |
| 456 | | devclass = iodev->devclass; |
| 457 | 457 | break; |
| 458 | | } |
| 459 | 458 | } |
| 460 | 459 | } |
| 461 | 460 | } |
| 462 | 461 | |
| 463 | 462 | // no device? cop out unless bForce is on |
| 464 | | if (!devclass.gamedrv && !bForce) |
| 463 | if ((device == NULL) && !bForce) |
| 465 | 464 | return TRUE; |
| 466 | 465 | |
| 467 | 466 | // create the FileInfo structure |
| r2262 | r2263 | |
| 475 | 474 | strcpy(pInfo->szFilename, pszFilename); |
| 476 | 475 | |
| 477 | 476 | // set up device and CRC, if specified |
| 478 | | pInfo->devclass = devclass; |
| 479 | | if (devclass.gamedrv && mess_device_get_info_fct(&devclass, MESS_DEVINFO_PTR_PARTIAL_HASH)) |
| 477 | pInfo->device = device; |
| 478 | if ((device != NULL) && (mess_device_from_core_device(device)->partialhash != NULL)) |
| 480 | 479 | nCrc = 0; |
| 481 | 480 | if (nCrc != 0) |
| 482 | 481 | snprintf(pInfo->szHash, sizeof(pInfo->szHash) / sizeof(pInfo->szHash[0]), "c:%08x#", nCrc); |
| r2262 | r2263 | |
| 757 | 756 | pFileInfo = pPickerInfo->ppIndex[pPickerInfo->nCurrentPosition]; |
| 758 | 757 | if (!pFileInfo->bHashRealized) |
| 759 | 758 | { |
| 760 | | type = (iodevice_t) (int) mess_device_get_info_int(&pFileInfo->devclass, MESS_DEVINFO_INT_TYPE); |
| 759 | type = mess_device_from_core_device(pFileInfo->device)->type; |
| 761 | 760 | if (hashfile_functions_used(pPickerInfo->pHashFile, type)) |
| 762 | 761 | { |
| 763 | 762 | // only calculate the hash if it is appropriate for this device |