Previous 15994 Revisions Next

r8205 Thursday 3rd June, 2010 at 14:37:56 UTC by Miodrag Milanović
[MESSUI] Added list of all software items from all lists into software list picker, with additional data
[src/mess/osd/winui]messui.c softwarelist.c softwarelist.h

src/mess/osd/winui/messui.c
r8204r8205
3939#include "swconfig.h"
4040#include "device.h"
4141#include "zippath.h"
42#include "emuopts.h"
4243
4344
4445//============================================================
r8204r8205
393394   BOOL is_same;
394395   const game_driver *drv;
395396   HWND hwndSoftwarePicker;
396   HWND hwndSoftwareDevView;
397   HWND hwndSoftwareList;
398   HWND hwndSoftwareDevView;   
397399
398400   // do we have to do anything?
399401   if (!bForce)
r8204r8205
417419
418420   // locate key widgets
419421   hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST);
422   hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST);
420423   hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW);
421424
422425   // set up the device view
r8204r8205
434437      drv = driver_get_compatible(drv);
435438   }
436439   AddSoftwarePickerDirs(hwndSoftwarePicker, GetExtraSoftwarePaths(drvindex), NULL);
440   
441   // set up the software picker
442   SoftwareList_Clear(hwndSoftwareList);
443   SoftwareList_SetDriver(hwndSoftwareList, s_config);
444
445   /* allocate the machine config */
446   machine_config *config = machine_config_alloc( drivers[drvindex]->machine_config );
447
448   core_options *options = mame_options_init(NULL);
449   for (const device_config *dev = config->devicelist.first(); dev != NULL; dev = dev->next)
450   {
451      if ( ! strcmp( dev->tag(), __SOFTWARE_LIST_TAG ) )
452      {
453         software_list_config *swlist = (software_list_config *)dev->inline_config;
454
455         for ( int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++ )
456         {
457            if (swlist->list_name[i])
458            {
459               software_list *list = software_list_open(options, swlist->list_name[i], FALSE, NULL);
460
461               if (list)
462               {
463                  for (software_info *swinfo = software_list_first(list); swinfo != NULL; swinfo = software_list_next(list))
464                  {                     
465                     SoftwareList_AddFile(hwndSoftwareList, core_strdup(swinfo->shortname), core_strdup(swlist->list_name[i]), core_strdup(swinfo->longname), core_strdup(swinfo->publisher), core_strdup(swinfo->year));
466                  }
467
468                  software_list_close(list);
469               }                 
470            }
471         }
472      }
473   }
474
475   /* free the machine config */
476   machine_config_free( config );     
437477}
438478
439479
src/mess/osd/winui/softwarelist.c
r8204r8205
4646   const hash_info *hashinfo;
4747
4848   const char *zip_entry_name;
49   const char *base_name;
50   char file_name[1];
49   char list_name[256];
50   char description[256];
51   char file_name[256];
52   char publisher[256];
53   char year[10];
5154};
5255
5356typedef struct _directory_search_info directory_search_info;
r8204r8205
8285
8386
8487
85//============================================================
8688
87static LPCSTR NormalizePath(LPCSTR pszPath, LPSTR pszBuffer, size_t nBufferSize)
88{
89   BOOL bChanged = FALSE;
90   LPSTR s;
91   int i, j;
92
93   if (pszPath[0] == '\\')
94   {
95      win_get_current_directory_utf8(nBufferSize, pszBuffer);
96      pszBuffer[2] = '\0';
97      bChanged = TRUE;
98   }
99   else if (!isalpha(pszPath[0]) || (pszPath[1] != ':'))
100   {
101      win_get_current_directory_utf8(nBufferSize, pszBuffer);
102      bChanged = TRUE;
103   }
104
105   if (bChanged)
106   {
107      s = (LPSTR) alloca(strlen(pszBuffer) + 1);
108      strcpy(s, pszBuffer);
109      snprintf(pszBuffer, nBufferSize, "%s\\%s", s, pszPath);
110      pszPath = pszBuffer;
111
112      // Remove double path separators
113      i = 0;
114      j = 0;
115      while(pszBuffer[i])
116      {
117         while ((pszBuffer[i] == '\\') && (pszBuffer[i+1] == '\\'))
118            i++;
119         pszBuffer[j++] = pszBuffer[i++];
120      }
121      pszBuffer[j] = '\0';
122   }
123   return pszPath;
124}
125
126
127
12889static software_list_info *GetSoftwareListInfo(HWND hwndPicker)
12990{
13091   HANDLE h;
r8204r8205
363324}
364325
365326
366
367static BOOL SoftwareList_AddFileEntry(HWND hwndPicker, LPCSTR pszFilename,
368   UINT nZipEntryNameLength, UINT32 nCrc, BOOL bForce)
327BOOL SoftwareList_AddFile(HWND hwndPicker,LPCSTR pszName, LPCSTR pszListname, LPCSTR pszDescription, LPCSTR pszPublisher, LPCSTR pszYear)
369328{
329   Picker_ResetIdle(hwndPicker);
330   
370331   software_list_info *pPickerInfo;
371332   file_info **ppNewIndex;
372333   file_info *pInfo;
373334   int nIndex, nSize;
374   LPCSTR pszExtension = NULL;
335//   LPCSTR pszExtension = NULL;
375336   const device_config *device = NULL;
376337
377338   // first check to see if it is already here
378   if (SoftwareList_LookupIndex(hwndPicker, pszFilename) >= 0)
339   if (SoftwareList_LookupIndex(hwndPicker, pszName) >= 0)
379340      return TRUE;
380341
381342   pPickerInfo = GetSoftwareListInfo(hwndPicker);
382343
383   // look up the device
384   if (strrchr(pszFilename, '.'))
385      pszExtension = strrchr(pszFilename, '.');
386   if ((pszExtension != NULL) && (pPickerInfo->config != NULL))
387   {
388      for (device = pPickerInfo->config->mconfig->devicelist.first(); device != NULL;device = device->next)
389      {
390         if (is_image_device(device))
391         {
392            if (image_device_uses_file_extension(device, pszExtension))
393               break;
394         }
395      }
396   }
397
398   // no device?  cop out unless bForce is on
399   if ((device == NULL) && !bForce)
400      return TRUE;
401
402344   // create the FileInfo structure
403   nSize = sizeof(file_info) + strlen(pszFilename);
345   nSize = sizeof(file_info);
404346   pInfo = (file_info *) malloc(nSize);
405347   if (!pInfo)
406348      goto error;
407349   memset(pInfo, 0, nSize);
408350
409351   // copy the filename
410   strcpy(pInfo->file_name, pszFilename);
352   strcpy(pInfo->file_name, pszName);
353   strcpy(pInfo->list_name, pszListname);
354   strcpy(pInfo->description, pszDescription);
355   strcpy(pInfo->publisher, pszPublisher);
356   strcpy(pInfo->year, pszYear);
411357
412358   // set up device and CRC, if specified
413359   pInfo->device = device;
414   if ((device != NULL) && (image_device_getinfo(pPickerInfo->config->mconfig, device).has_partial_hash != 0))
415      nCrc = 0;
416   if (nCrc != 0)
417      snprintf(pInfo->hash_string, ARRAY_LENGTH(pInfo->hash_string), "c:%08x#", nCrc);
418
419   // set up zip entry name length, if specified
420   if (nZipEntryNameLength > 0)
421      pInfo->zip_entry_name = pInfo->file_name + strlen(pInfo->file_name) - nZipEntryNameLength;
422
423   // calculate the subname
424   pInfo->base_name = strrchr(pInfo->file_name, '\\');
425   if (pInfo->base_name)
426      pInfo->base_name++;
427   else
428      pInfo->base_name = pInfo->file_name;
429
360   
430361   ppNewIndex = (file_info**)malloc((pPickerInfo->file_index_length + 1) * sizeof(*pPickerInfo->file_index));
431362   memcpy(ppNewIndex,pPickerInfo->file_index,pPickerInfo->file_index_length * sizeof(*pPickerInfo->file_index));
432363   if (pPickerInfo->file_index) free(pPickerInfo->file_index);
r8204r8205
447378error:
448379   if (pInfo)
449380      free(pInfo);
450   return FALSE;
381   return FALSE;   
451382}
452383
453384
454
455static BOOL SoftwareList_AddZipEntFile(HWND hwndPicker, LPCSTR pszZipPath,
456   BOOL bForce, zip_file *pZip, const zip_file_header *pZipEnt)
457{
458   LPSTR s;
459   LPCSTR temp = pZipEnt->filename;
460   int nLength;
461   int nZipEntryNameLength;
462
463   // special case; skip first two characters if they are './'
464   if ((pZipEnt->filename[0] == '.') && (pZipEnt->filename[1] == '/'))
465   {
466      while(*(++temp) == '/')
467         ;
468   }
469
470   nZipEntryNameLength = strlen(pZipEnt->filename);
471   nLength = strlen(pszZipPath) + 1 + nZipEntryNameLength + 1;
472   s = (LPSTR) alloca(nLength);
473   snprintf(s, nLength, "%s\\%s", pszZipPath, pZipEnt->filename);
474
475   return SoftwareList_AddFileEntry(hwndPicker, s,
476      nZipEntryNameLength, pZipEnt->crc, bForce);
477}
478
479static BOOL SoftwareList_InternalAddFile(HWND hwndPicker, LPCSTR pszFilename,
480   BOOL bForce)
481{
482   LPCSTR s;
483   BOOL rc = TRUE;
484   zip_error ziperr;
485   zip_file *pZip;
486   const zip_file_header *pZipEnt;
487
488   s = strrchr(pszFilename, '.');
489   if (s && !mame_stricmp(s, ".zip"))
490   {
491      ziperr = zip_file_open(pszFilename, &pZip);
492      if (ziperr  == ZIPERR_NONE)
493      {
494         pZipEnt = zip_file_first_file(pZip);
495         while(rc && pZipEnt)
496         {
497            rc = SoftwareList_AddZipEntFile(hwndPicker, pszFilename,
498               bForce, pZip, pZipEnt);
499            pZipEnt = zip_file_next_file(pZip);
500         }
501         zip_file_close(pZip);
502      }
503   }
504   else
505   {
506      rc = SoftwareList_AddFileEntry(hwndPicker, pszFilename, 0, 0, bForce);
507   }
508   return rc;
509}
510
511
512
513BOOL SoftwareList_AddFile(HWND hwndPicker, LPCSTR pszFilename)
514{
515   char szBuffer[MAX_PATH];
516
517   Picker_ResetIdle(hwndPicker);
518   pszFilename = NormalizePath(pszFilename, szBuffer, sizeof(szBuffer)
519      / sizeof(szBuffer[0]));
520
521   return SoftwareList_InternalAddFile(hwndPicker, pszFilename, TRUE);
522}
523
524
525
526BOOL SoftwareList_AddDirectory(HWND hwndPicker, LPCSTR pszDirectory)
527{
528   software_list_info *pPickerInfo;
529   directory_search_info *pSearchInfo;
530   directory_search_info **ppLast;
531   size_t nSearchInfoSize;
532   char szBuffer[MAX_PATH];
533
534   pszDirectory = NormalizePath(pszDirectory, szBuffer, sizeof(szBuffer)
535      / sizeof(szBuffer[0]));
536
537   Picker_ResetIdle(hwndPicker);
538   pPickerInfo = GetSoftwareListInfo(hwndPicker);
539
540   nSearchInfoSize = sizeof(directory_search_info) + strlen(pszDirectory);
541   pSearchInfo = (directory_search_info *)malloc(nSearchInfoSize);
542   if (!pSearchInfo)
543      return FALSE;
544   memset(pSearchInfo, 0, nSearchInfoSize);
545   pSearchInfo->find_handle = INVALID_HANDLE_VALUE;
546
547   strcpy(pSearchInfo->directory_name, pszDirectory);
548
549   // insert into linked list
550   if (pPickerInfo->last_search_info)
551      ppLast = &pPickerInfo->last_search_info->next;
552   else
553      ppLast = &pPickerInfo->first_search_info;
554   *ppLast = pSearchInfo;
555   pPickerInfo->last_search_info = pSearchInfo;
556   return TRUE;
557}
558
559
560
561385static void SoftwareList_FreeSearchInfo(directory_search_info *pSearchInfo)
562386{
563387   if (pSearchInfo->find_handle != INVALID_HANDLE_VALUE)
r8204r8205
601425}
602426
603427
604
605static BOOL SoftwareList_AddEntry(HWND hwndPicker,
606   directory_search_info *pSearchInfo)
607{
608   //software_list_info *pPickerInfo;
609   LPSTR pszFilename;
610   BOOL rc;
611   char* utf8_FileName;
612
613   //pPickerInfo = GetSoftwareListInfo(hwndPicker);
614
615   utf8_FileName = utf8_from_tstring(pSearchInfo->fd.cFileName);
616   if( !utf8_FileName )
617      return FALSE;
618
619   if (!strcmp(utf8_FileName, ".") || !strcmp(utf8_FileName, "..")) {
620      osd_free(utf8_FileName);
621      return TRUE;
622   }
623
624   pszFilename = (LPSTR)alloca(strlen(pSearchInfo->directory_name) + 1 + strlen(utf8_FileName) + 1);
625   strcpy(pszFilename, pSearchInfo->directory_name);
626   strcat(pszFilename, "\\");
627   strcat(pszFilename, utf8_FileName);
628
629   if (pSearchInfo->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
630      rc = SoftwareList_AddDirectory(hwndPicker, pszFilename);
631   else
632      rc = SoftwareList_InternalAddFile(hwndPicker, pszFilename, FALSE);
633
634   osd_free(utf8_FileName);
635   return rc;
636}
637
638
639
640428BOOL SoftwareList_Idle(HWND hwndPicker)
641429{
642430   software_list_info *pPickerInfo;
r8204r8205
671459
672460      if (bSuccess)
673461      {
674         SoftwareList_AddEntry(hwndPicker, pSearchInfo);
462         //SoftwareList_AddEntry(hwndPicker, pSearchInfo);
675463      }
676464      else
677465      {
r8204r8205
733521   software_list_info *pPickerInfo;
734522   const file_info *pFileInfo;
735523   LPCTSTR s = NULL;
736   const char *pszUtf8 = NULL;
737   unsigned int nHashFunction = 0;
738   char szBuffer[256];
739524   TCHAR* t_buf;
740525
741526   pPickerInfo = GetSoftwareListInfo(hwndPicker);
r8204r8205
747532   switch(nColumn)
748533   {
749534      case MESS_COLUMN_IMAGES:
750         t_buf = tstring_from_utf8(pFileInfo->base_name);
535         t_buf = tstring_from_utf8(pFileInfo->file_name);
751536         if( !t_buf )
752537            return s;
753538         _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf);
754539         s = pszBuffer;
755540         osd_free(t_buf);
756541         break;
757
758      case MESS_COLUMN_GOODNAME:
759      case MESS_COLUMN_MANUFACTURER:
760      case MESS_COLUMN_YEAR:
761      case MESS_COLUMN_PLAYABLE:
762         if (pFileInfo->hashinfo)
763         {
764            switch(nColumn)
765            {
766               case MESS_COLUMN_GOODNAME:
767                  pszUtf8 = pFileInfo->hashinfo->longname;
768                  break;
769               case MESS_COLUMN_MANUFACTURER:
770                  pszUtf8 = pFileInfo->hashinfo->manufacturer;
771                  break;
772               case MESS_COLUMN_YEAR:
773                  pszUtf8 = pFileInfo->hashinfo->year;
774                  break;
775               case MESS_COLUMN_PLAYABLE:
776                  pszUtf8 = pFileInfo->hashinfo->playable;
777                  break;
778            }
779            if (pszUtf8)
780            {
781               t_buf = tstring_from_utf8(pszUtf8);
782               if( !t_buf )
783                  return s;
784               _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf);
785               s = pszBuffer;
786               osd_free(t_buf);
787            }
788         }
542      case 1:
543         t_buf = tstring_from_utf8(pFileInfo->list_name);
544         if( !t_buf )
545            return s;
546         _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf);
547         s = pszBuffer;
548         osd_free(t_buf);
789549         break;
790
791      case MESS_COLUMN_CRC:
792      case MESS_COLUMN_MD5:
793      case MESS_COLUMN_SHA1:
794      switch (nColumn)
795         {
796            case MESS_COLUMN_CRC:   nHashFunction = HASH_CRC;   break;
797            case MESS_COLUMN_MD5:   nHashFunction = HASH_MD5;   break;
798            case MESS_COLUMN_SHA1:   nHashFunction = HASH_SHA1;   break;
799         }
800         if (hash_data_extract_printable_checksum(pFileInfo->hash_string, nHashFunction, szBuffer))
801         {
802            t_buf = tstring_from_utf8(szBuffer);
803            if( !t_buf )
804               return s;
805            _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf);
806            s = pszBuffer;
807            osd_free(t_buf);
808         }
550      case 2:
551         t_buf = tstring_from_utf8(pFileInfo->description);
552         if( !t_buf )
553            return s;
554         _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf);
555         s = pszBuffer;
556         osd_free(t_buf);
809557         break;
558      case 3:
559         t_buf = tstring_from_utf8(pFileInfo->year);
560         if( !t_buf )
561            return s;
562         _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf);
563         s = pszBuffer;
564         osd_free(t_buf);
565         break;
566      case 4:
567         t_buf = tstring_from_utf8(pFileInfo->publisher);
568         if( !t_buf )
569            return s;
570         _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf);
571         s = pszBuffer;
572         osd_free(t_buf);
573         break;
574     
810575   }
811576   return s;
812577}
src/mess/osd/winui/softwarelist.h
r8204r8205
1010const device_config *SoftwareList_LookupDevice(HWND hwndPicker, int nIndex);
1111int SoftwareList_LookupIndex(HWND hwndPicker, LPCSTR pszFilename);
1212iodevice_t SoftwareList_GetImageType(HWND hwndPicker, int nIndex);
13BOOL SoftwareList_AddFile(HWND hwndPicker, LPCSTR pszFilename);
14BOOL SoftwareList_AddDirectory(HWND hwndPicker, LPCSTR pszDirectory);
13BOOL SoftwareList_AddFile(HWND hwndPicker, LPCSTR pszName, LPCSTR pszListname, LPCSTR pszDescription, LPCSTR pszPublisher, LPCSTR pszYear);
1514void SoftwareList_Clear(HWND hwndPicker);
1615void SoftwareList_SetDriver(HWND hwndPicker, const software_config *config);
1716

Previous 15994 Revisions Next


© 1998-2018 The MESS Team