Previous 15994 Revisions Next

r2263 Saturday 5th April, 2008 at 02:48:11 UTC by Nathan Woods
[Windows GUI] More device changeover
[src/mess/osd/winui]messui.c softwarepicker.c softwarepicker.h

src/mess/osd/winui/messui.c
r2262r2263
438438
439439
440440
441static 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
441466// Places the specified image in the specified slot; nID = -1 means don't matter
442467static void MessSpecifyImage(int drvindex, const device_config *device, LPCSTR pszFilename)
443468{
r2262r2263
474499      {
475500         for (device = image_device_first(config); device != NULL; device = image_device_next(device))
476501         {
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;
490504         }
491505      }
492506   }
r2262r2263
508522
509523
510524
511static void MessRemoveImage(int drvindex, mess_device_class devclass, LPCSTR pszFilename)
525static void MessRemoveImage(int drvindex, const device_config *device, LPCSTR pszFilename)
512526{
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);
543529}
544530
545531
r2262r2263
985971static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem)
986972{
987973   int drvindex;
988   mess_device_class devclass;
974   const device_config *device;
989975   LPCSTR pszFullName;
990976   HWND hwndList;
991977
r2262r2263
993979   {
994980      hwndList = GetDlgItem(GetMainWindow(), IDC_LIST);
995981      drvindex = Picker_GetSelectedItem(hwndList);
996      devclass = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem);
982      device = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem);
997983      pszFullName = SoftwarePicker_LookupFilename(hwndSoftwarePicker, nItem);
998984
999      MessRemoveImage(drvindex, devclass, pszFullName);
985      MessRemoveImage(drvindex, device, pszFullName);
1000986   }
1001987}
1002988
r2262r2263
1008994   LPCSTR pszName;
1009995   LPSTR s;
1010996   int drvindex;
1011   mess_device_class devclass;
997   const device_config *device;
1012998   HWND hwndList;
1013999
10141000   hwndList = GetDlgItem(GetMainWindow(), IDC_LIST);
r2262r2263
10231009      pszName = s ? s + 1 : pszFullName;
10241010
10251011      // Do the dirty work
1026      devclass = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem);
1027      if (!devclass.gamedrv)
1012      device = SoftwarePicker_LookupDevice(hwndSoftwarePicker, nItem);
1013      if (device == NULL)
10281014         return;
10291015      MessSpecifyImage(drvindex, NULL, pszFullName);
10301016
src/mess/osd/winui/softwarepicker.c
r2262r2263
3838typedef struct _file_info file_info;
3939struct _file_info
4040{
41   mess_device_class devclass;
41   const device_config *device;
4242
4343   // hash information
4444   char szHash[HASH_BUF_SIZE];
r2262r2263
149149
150150
151151
152mess_device_class SoftwarePicker_LookupDevice(HWND hwndPicker, int nIndex)
152const device_config *SoftwarePicker_LookupDevice(HWND hwndPicker, int nIndex)
153153{
154154   software_picker_info *pPickerInfo;
155155   pPickerInfo = GetSoftwarePickerInfo(hwndPicker);
156156   if ((nIndex < 0) || (nIndex >= pPickerInfo->nIndexLength))
157157   {
158      mess_device_class dummy;
159      memset(&dummy, 0, sizeof(dummy));
160      return dummy;
158      return NULL;
161159   }
162   return pPickerInfo->ppIndex[nIndex]->devclass;
160   return pPickerInfo->ppIndex[nIndex]->device;
163161}
164162
165163
r2262r2263
182180
183181iodevice_t SoftwarePicker_GetImageType(HWND hwndPicker, int nIndex)
184182{
185   software_picker_info *pPickerInfo;
186   const mess_device_class *devclass;
183   iodevice_t type;
184   const device_config *device = SoftwarePicker_LookupDevice(hwndPicker, nIndex);
187185
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;
196196}
197197
198198
r2262r2263
265265   file_info *pFileInfo, const unsigned char *pBuffer, unsigned int nLength)
266266{
267267   unsigned int nFunctions;
268   const struct IODevice *iodev;
268269   iodevice_t type;
269270   device_image_partialhash_func partialhash;
270271
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;
273275
274276   nFunctions = hashfile_functions_used(pPickerInfo->pHashFile, type);
275277
r2262r2263
392394
393395   // Determine which hash functions we need to use for this file, and which hashes
394396   // have already been calculated
395   if ((pPickerInfo->pHashFile != NULL) && (pFileInfo->devclass.get_info != NULL))
397   if ((pPickerInfo->pHashFile != NULL) && (pFileInfo->device != NULL))
396398   {
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;
398401      if (type < IO_COUNT)
399402           nHashFunctionsUsed = hashfile_functions_used(pPickerInfo->pHashFile, type);
400403      nCalculatedHashes = hash_data_used_functions(pFileInfo->szHash);
r2262r2263
425428   file_info *pInfo;
426429   int nIndex, nSize;
427430   LPCSTR pszExtension = NULL, s;
428   mess_device_class devclass = {0,};
429   const device_config *device;
431   const device_config *device = NULL;
430432
431433   // first check to see if it is already here
432434   if (SoftwarePicker_LookupIndex(hwndPicker, pszFilename) >= 0)
r2262r2263
452454            while(*s && mame_stricmp(pszExtension, s))
453455               s += strlen(s) + 1;
454456            if (*s)
455            {
456               devclass = iodev->devclass;
457457               break;
458            }
459458         }
460459      }
461460   }
462461
463462   // no device?  cop out unless bForce is on
464   if (!devclass.gamedrv && !bForce)
463   if ((device == NULL) && !bForce)
465464      return TRUE;
466465
467466   // create the FileInfo structure
r2262r2263
475474   strcpy(pInfo->szFilename, pszFilename);
476475
477476   // 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))
480479      nCrc = 0;
481480   if (nCrc != 0)
482481      snprintf(pInfo->szHash, sizeof(pInfo->szHash) / sizeof(pInfo->szHash[0]), "c:%08x#", nCrc);
r2262r2263
757756      pFileInfo = pPickerInfo->ppIndex[pPickerInfo->nCurrentPosition];
758757      if (!pFileInfo->bHashRealized)
759758      {
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;
761760         if (hashfile_functions_used(pPickerInfo->pHashFile, type))
762761         {
763762            // only calculate the hash if it is appropriate for this device
src/mess/osd/winui/softwarepicker.h
r2262r2263
55//============================================================
66
77LPCSTR SoftwarePicker_LookupFilename(HWND hwndPicker, int nIndex);
8mess_device_class SoftwarePicker_LookupDevice(HWND hwndPicker, int nIndex);
8const device_config *SoftwarePicker_LookupDevice(HWND hwndPicker, int nIndex);
99int SoftwarePicker_LookupIndex(HWND hwndPicker, LPCSTR pszFilename);
1010iodevice_t SoftwarePicker_GetImageType(HWND hwndPicker, int nIndex);
1111BOOL SoftwarePicker_AddFile(HWND hwndPicker, LPCSTR pszFilename);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team