src/mess/osd/winui/messui.c
| r2069 | r2070 | |
| 50 | 50 | |
| 51 | 51 | static const LPCTSTR mess_column_names[] = |
| 52 | 52 | { |
| 53 | | TEXT("Software"), |
| 53 | TEXT("Software"), |
| 54 | 54 | TEXT("Goodname"), |
| 55 | | TEXT("Manufacturer"), |
| 56 | | TEXT("Year"), |
| 57 | | TEXT("Playable"), |
| 55 | TEXT("Manufacturer"), |
| 56 | TEXT("Year"), |
| 57 | TEXT("Playable"), |
| 58 | 58 | TEXT("CRC"), |
| 59 | 59 | TEXT("SHA-1"), |
| 60 | 60 | TEXT("MD5") |
| r2069 | r2070 | |
| 64 | 64 | |
| 65 | 65 | static void MessOpenOtherSoftware(int iDevice); |
| 66 | 66 | static void MessCreateDevice(int iDevice); |
| 67 | | static void MessRefreshPicker(int nGame); |
| 67 | static void MessRefreshPicker(int drvindex); |
| 68 | 68 | |
| 69 | 69 | static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem); |
| 70 | 70 | static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem); |
| r2069 | r2070 | |
| 249 | 249 | |
| 250 | 250 | |
| 251 | 251 | |
| 252 | | static int GetMessIcon(int nGame, int nSoftwareType) |
| 252 | static int GetMessIcon(int drvindex, int nSoftwareType) |
| 253 | 253 | { |
| 254 | 254 | int the_index; |
| 255 | 255 | int nIconPos = 0; |
| r2069 | r2070 | |
| 258 | 258 | char buffer[32]; |
| 259 | 259 | const char *iconname; |
| 260 | 260 | |
| 261 | | assert(nGame >= 0); |
| 262 | | assert(nGame < driver_list_get_count(drivers)); |
| 261 | assert(drvindex >= 0); |
| 262 | assert(drvindex < driver_list_get_count(drivers)); |
| 263 | 263 | |
| 264 | 264 | if ((nSoftwareType >= 0) && (nSoftwareType < IO_COUNT)) |
| 265 | 265 | { |
| 266 | 266 | iconname = device_brieftypename(nSoftwareType); |
| 267 | | the_index = (nGame * IO_COUNT) + nSoftwareType; |
| 267 | the_index = (drvindex * IO_COUNT) + nSoftwareType; |
| 268 | 268 | |
| 269 | 269 | nIconPos = mess_icon_index[the_index]; |
| 270 | 270 | if (nIconPos >= 0) |
| 271 | 271 | { |
| 272 | | for (drv = drivers[nGame]; drv; drv = driver_get_clone(drv)) |
| 272 | for (drv = drivers[drvindex]; drv; drv = driver_get_clone(drv)) |
| 273 | 273 | { |
| 274 | 274 | _snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%s/%s", drv->name, iconname); |
| 275 | 275 | hIcon = LoadIconFromFile(buffer); |
| r2069 | r2070 | |
| 335 | 335 | |
| 336 | 336 | |
| 337 | 337 | |
| 338 | | void MyFillSoftwareList(int nGame, BOOL bForce) |
| 338 | void MyFillSoftwareList(int drvindex, BOOL bForce) |
| 339 | 339 | { |
| 340 | 340 | const game_driver *drv; |
| 341 | 341 | HWND hwndSoftwarePicker; |
| r2069 | r2070 | |
| 345 | 345 | hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW); |
| 346 | 346 | |
| 347 | 347 | // Set up the device view |
| 348 | | DevView_SetDriver(hwndSoftwareDevView, nGame); |
| 348 | DevView_SetDriver(hwndSoftwareDevView, drvindex); |
| 349 | 349 | |
| 350 | | if (!bForce && (s_nGame == nGame)) |
| 350 | if (!bForce && (s_nGame == drvindex)) |
| 351 | 351 | return; |
| 352 | | s_nGame = nGame; |
| 352 | s_nGame = drvindex; |
| 353 | 353 | |
| 354 | 354 | // Set up the software picker |
| 355 | 355 | SoftwarePicker_Clear(hwndSoftwarePicker); |
| 356 | | drv = drivers[nGame]; |
| 356 | drv = drivers[drvindex]; |
| 357 | 357 | SoftwarePicker_SetDriver(hwndSoftwarePicker, drv); |
| 358 | 358 | while(drv) |
| 359 | 359 | { |
| 360 | 360 | AddSoftwarePickerDirs(hwndSoftwarePicker, GetSoftwareDirs(), drv->name); |
| 361 | 361 | drv = mess_next_compatible_driver(drv); |
| 362 | 362 | } |
| 363 | | AddSoftwarePickerDirs(hwndSoftwarePicker, GetExtraSoftwarePaths(nGame), NULL); |
| 363 | AddSoftwarePickerDirs(hwndSoftwarePicker, GetExtraSoftwarePaths(drvindex), NULL); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
| r2069 | r2070 | |
| 373 | 373 | |
| 374 | 374 | |
| 375 | 375 | |
| 376 | | BOOL MessApproveImageList(HWND hParent, int nGame) |
| 376 | BOOL MessApproveImageList(HWND hParent, int drvindex) |
| 377 | 377 | { |
| 378 | 378 | int i, nPos, devindex; |
| 379 | 379 | const struct IODevice *devices; |
| r2069 | r2070 | |
| 384 | 384 | |
| 385 | 385 | begin_resource_tracking(); |
| 386 | 386 | |
| 387 | | pDriver = drivers[nGame]; |
| 387 | pDriver = drivers[drvindex]; |
| 388 | 388 | devices = devices_allocate(pDriver); |
| 389 | 389 | |
| 390 | 390 | nPos = 0; |
| r2069 | r2070 | |
| 395 | 395 | { |
| 396 | 396 | for (i = 0; i < devices[devindex].count; i++) |
| 397 | 397 | { |
| 398 | | pszSoftware = GetSelectedSoftware(nGame, &devices[devindex].devclass, i); |
| 398 | pszSoftware = GetSelectedSoftware(drvindex, &devices[devindex].devclass, i); |
| 399 | 399 | if (!pszSoftware || !*pszSoftware) |
| 400 | 400 | { |
| 401 | 401 | snprintf(szMessage, sizeof(szMessage) / sizeof(szMessage[0]), |
| r2069 | r2070 | |
| 424 | 424 | |
| 425 | 425 | |
| 426 | 426 | // this is a wrapper call to wrap the idiosycracies of SetSelectedSoftware() |
| 427 | | static void InternalSetSelectedSoftware(int nGame, const mess_device_class *devclass, int device_inst, const char *pszSoftware) |
| 427 | static void InternalSetSelectedSoftware(int drvindex, const mess_device_class *devclass, int device_inst, const char *pszSoftware) |
| 428 | 428 | { |
| 429 | 429 | if (!pszSoftware) |
| 430 | 430 | pszSoftware = ""; |
| 431 | 431 | |
| 432 | 432 | // only call SetSelectedSoftware() if this value is different |
| 433 | | if (strcmp(GetSelectedSoftware(nGame, devclass, device_inst), pszSoftware)) |
| 433 | if (strcmp(GetSelectedSoftware(drvindex, devclass, device_inst), pszSoftware)) |
| 434 | 434 | { |
| 435 | | SetSelectedSoftware(nGame, devclass, device_inst, pszSoftware); |
| 435 | SetSelectedSoftware(drvindex, devclass, device_inst, pszSoftware); |
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
| 440 | 440 | |
| 441 | 441 | // Places the specified image in the specified slot; nID = -1 means don't matter |
| 442 | | static void MessSpecifyImage(int nGame, const mess_device_class *devclass, int nID, LPCSTR pszFilename) |
| 442 | static void MessSpecifyImage(int drvindex, const mess_device_class *devclass, int nID, LPCSTR pszFilename) |
| 443 | 443 | { |
| 444 | 444 | const struct IODevice *devices; |
| 445 | 445 | const struct IODevice *dev; |
| r2069 | r2070 | |
| 464 | 464 | // special case; first try to find existing image |
| 465 | 465 | for (i = 0; i < dev->count; i++) |
| 466 | 466 | { |
| 467 | | s = GetSelectedSoftware(nGame, &dev->devclass, i); |
| 467 | s = GetSelectedSoftware(drvindex, &dev->devclass, i); |
| 468 | 468 | if (s && !mame_stricmp(s, pszFilename)) |
| 469 | 469 | { |
| 470 | 470 | nID = i; |
| r2069 | r2070 | |
| 478 | 478 | // still not found? locate an empty slot |
| 479 | 479 | for (i = 0; i < dev->count; i++) |
| 480 | 480 | { |
| 481 | | s = GetSelectedSoftware(nGame, &dev->devclass, i); |
| 481 | s = GetSelectedSoftware(drvindex, &dev->devclass, i); |
| 482 | 482 | if (!s || !*s || !mame_stricmp(s, pszFilename)) |
| 483 | 483 | { |
| 484 | 484 | nID = i; |
| r2069 | r2070 | |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | if (nID >= 0) |
| 491 | | InternalSetSelectedSoftware(nGame, &dev->devclass, nID, pszFilename); |
| 491 | InternalSetSelectedSoftware(drvindex, &dev->devclass, nID, pszFilename); |
| 492 | 492 | else if (LOG_SOFTWARE) |
| 493 | 493 | dprintf("MessSpecifyImage(): Failed to place image '%s'\n", pszFilename); |
| 494 | 494 | |
| r2069 | r2070 | |
| 497 | 497 | |
| 498 | 498 | |
| 499 | 499 | |
| 500 | | static void MessRemoveImage(int nGame, mess_device_class devclass, LPCSTR pszFilename) |
| 500 | static void MessRemoveImage(int drvindex, mess_device_class devclass, LPCSTR pszFilename) |
| 501 | 501 | { |
| 502 | 502 | int i, nPos; |
| 503 | 503 | const struct IODevice *devices; |
| r2069 | r2070 | |
| 519 | 519 | { |
| 520 | 520 | for (i = 0; i < dev->count; i++) |
| 521 | 521 | { |
| 522 | | if (!mame_stricmp(pszFilename, GetSelectedSoftware(nGame, &dev->devclass, i))) |
| 522 | if (!mame_stricmp(pszFilename, GetSelectedSoftware(drvindex, &dev->devclass, i))) |
| 523 | 523 | { |
| 524 | | MessSpecifyImage(nGame, &devclass, i, NULL); |
| 524 | MessSpecifyImage(drvindex, &devclass, i, NULL); |
| 525 | 525 | break; |
| 526 | 526 | } |
| 527 | 527 | } |
| r2069 | r2070 | |
| 533 | 533 | |
| 534 | 534 | |
| 535 | 535 | |
| 536 | | void MessReadMountedSoftware(int nGame) |
| 536 | void MessReadMountedSoftware(int drvindex) |
| 537 | 537 | { |
| 538 | 538 | // First read stuff into device view |
| 539 | 539 | DevView_Refresh(GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW)); |
| 540 | 540 | |
| 541 | 541 | // Now read stuff into picker |
| 542 | | MessRefreshPicker(nGame); |
| 542 | MessRefreshPicker(drvindex); |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | |
| 546 | 546 | |
| 547 | | static void MessRefreshPicker(int nGame) |
| 547 | static void MessRefreshPicker(int drvindex) |
| 548 | 548 | { |
| 549 | 549 | HWND hwndSoftware; |
| 550 | 550 | int i, id; |
| r2069 | r2070 | |
| 555 | 555 | LPCSTR pszSoftware; |
| 556 | 556 | |
| 557 | 557 | hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 558 | | pDriver = drivers[nGame]; |
| 558 | pDriver = drivers[drvindex]; |
| 559 | 559 | pDeviceList = devices_allocate(pDriver); |
| 560 | 560 | if (!pDeviceList) |
| 561 | 561 | goto done; |
| r2069 | r2070 | |
| 570 | 570 | { |
| 571 | 571 | for (id = 0; id < pDevice->count; id++) |
| 572 | 572 | { |
| 573 | | pszSoftware = GetSelectedSoftware(nGame, &pDevice->devclass, id); |
| 573 | pszSoftware = GetSelectedSoftware(drvindex, &pDevice->devclass, id); |
| 574 | 574 | if (pszSoftware && *pszSoftware) |
| 575 | 575 | { |
| 576 | 576 | i = SoftwarePicker_LookupIndex(hwndSoftware, pszSoftware); |
| r2069 | r2070 | |
| 796 | 796 | { |
| 797 | 797 | TCHAR filename[MAX_PATH]; |
| 798 | 798 | mess_image_type imagetypes[64]; |
| 799 | | int nGame; |
| 799 | int drvindex; |
| 800 | 800 | HWND hwndList; |
| 801 | 801 | char* utf8_filename; |
| 802 | 802 | const struct IODevice *devices; |
| r2069 | r2070 | |
| 804 | 804 | begin_resource_tracking(); |
| 805 | 805 | |
| 806 | 806 | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 807 | | nGame = Picker_GetSelectedItem(hwndList); |
| 808 | | devices = devices_allocate(drivers[nGame]); |
| 807 | drvindex = Picker_GetSelectedItem(hwndList); |
| 808 | devices = devices_allocate(drivers[drvindex]); |
| 809 | 809 | SetupImageTypes(devices, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, iDevice); |
| 810 | 810 | |
| 811 | 811 | if (CommonFileImageDialog(last_directory, cfd, filename, imagetypes)) |
| r2069 | r2070 | |
| 880 | 880 | |
| 881 | 881 | |
| 882 | 882 | |
| 883 | | static void DevView_SetSelectedSoftware(HWND hwndDevView, int nGame, |
| 883 | static void DevView_SetSelectedSoftware(HWND hwndDevView, int drvindex, |
| 884 | 884 | const struct IODevice *dev, int nID, LPCTSTR pszFilename) |
| 885 | 885 | { |
| 886 | 886 | char* utf8_filename = utf8_from_tstring(pszFilename); |
| 887 | 887 | if( !utf8_filename ) |
| 888 | 888 | return; |
| 889 | | MessSpecifyImage(nGame, &dev->devclass, nID, utf8_filename); |
| 890 | | MessRefreshPicker(nGame); |
| 889 | MessSpecifyImage(drvindex, &dev->devclass, nID, utf8_filename); |
| 890 | MessRefreshPicker(drvindex); |
| 891 | 891 | free(utf8_filename); |
| 892 | 892 | } |
| 893 | 893 | |
| r2069 | r2070 | |
| 919 | 919 | |
| 920 | 920 | static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem) |
| 921 | 921 | { |
| 922 | | int nType; |
| 923 | | int nIcon; |
| 924 | | int nGame; |
| 922 | int nType; |
| 923 | int nIcon; |
| 924 | int drvindex; |
| 925 | 925 | const char *icon_name; |
| 926 | 926 | HWND hwndGamePicker; |
| 927 | 927 | HWND hwndSoftwarePicker; |
| 928 | 928 | |
| 929 | 929 | hwndGamePicker = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 930 | 930 | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 931 | | nGame = Picker_GetSelectedItem(hwndGamePicker); |
| 932 | | nType = SoftwarePicker_GetImageType(hwndSoftwarePicker, nItem); |
| 933 | | nIcon = GetMessIcon(nGame, nType); |
| 934 | | if (!nIcon) |
| 931 | drvindex = Picker_GetSelectedItem(hwndGamePicker); |
| 932 | nType = SoftwarePicker_GetImageType(hwndSoftwarePicker, nItem); |
| 933 | nIcon = GetMessIcon(drvindex, nType); |
| 934 | if (!nIcon) |
| 935 | 935 | { |
| 936 | 936 | if (nType < 0) |
| 937 | 937 | nType = IO_BAD; |
| r2069 | r2070 | |
| 965 | 965 | |
| 966 | 966 | static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem) |
| 967 | 967 | { |
| 968 | | int nGame; |
| 968 | int drvindex; |
| 969 | 969 | mess_device_class devclass; |
| 970 | 970 | LPCSTR pszFullName; |
| 971 | 971 | HWND hwndList; |
| r2069 | r2070 | |
| 973 | 973 | if (!s_bIgnoreSoftwarePickerNotifies) |
| 974 | 974 | { |
| 975 | 975 | hwndList = GetDlgItem(GetMainWindow(), IDC_LIST); |
| 976 | | nGame = Picker_GetSelectedItem(hwndList); |
| 976 | drvindex = Picker_GetSelectedItem(hwndList); |
| 977 | 977 | devclass = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem); |
| 978 | 978 | pszFullName = SoftwarePicker_LookupFilename(hwndSoftwarePicker, nItem); |
| 979 | 979 | |
| 980 | | MessRemoveImage(nGame, devclass, pszFullName); |
| 980 | MessRemoveImage(drvindex, devclass, pszFullName); |
| 981 | 981 | } |
| 982 | 982 | } |
| 983 | 983 | |
| r2069 | r2070 | |
| 988 | 988 | LPCSTR pszFullName; |
| 989 | 989 | LPCSTR pszName; |
| 990 | 990 | LPSTR s; |
| 991 | | int nGame; |
| 991 | int drvindex; |
| 992 | 992 | mess_device_class devclass; |
| 993 | 993 | HWND hwndList; |
| 994 | 994 | |
| r2069 | r2070 | |
| 996 | 996 | |
| 997 | 997 | if (!s_bIgnoreSoftwarePickerNotifies) |
| 998 | 998 | { |
| 999 | | nGame = Picker_GetSelectedItem(hwndList); |
| 999 | drvindex = Picker_GetSelectedItem(hwndList); |
| 1000 | 1000 | |
| 1001 | 1001 | // Get the fullname and partialname for this file |
| 1002 | 1002 | pszFullName = SoftwarePicker_LookupFilename(hwndSoftwarePicker, nItem); |
| r2069 | r2070 | |
| 1007 | 1007 | devclass = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem); |
| 1008 | 1008 | if (!devclass.gamedrv) |
| 1009 | 1009 | return; |
| 1010 | | MessSpecifyImage(nGame, &devclass, -1, pszFullName); |
| 1010 | MessSpecifyImage(drvindex, &devclass, -1, pszFullName); |
| 1011 | 1011 | |
| 1012 | 1012 | // Set up s_szSelecteItem, for the benefit of UpdateScreenShot() |
| 1013 | 1013 | strncpyz(g_szSelectedItem, pszName, sizeof(g_szSelectedItem) / sizeof(g_szSelectedItem[0])); |