Previous 15994 Revisions Next

r2489 Sunday 27th April, 2008 at 14:37:54 UTC by Nathan Woods
[Windows GUI] Refactoring
[src/mess]hashfile.h
[src/mess/osd/winui]devview.c devview.h messui.c softwarepicker.c softwarepicker.h swconfig.c* swconfig.h* winui.mak

src/mess/osd/winui/messui.c
r2488r2489
3535#include "strconv.h"
3636#include "messui.h"
3737#include "winutf8.h"
38#include "swconfig.h"
3839
3940
4041//============================================================
r2488r2489
7980//  LOCAL VARIABLES
8081//============================================================
8182
82static int s_nGame;
83static software_config *config;
8384static BOOL s_bIgnoreSoftwarePickerNotifies;
8485
8586static int *mess_icon_index;
r2488r2489
133134
134135static void MessOpenOtherSoftware(const device_config *dev);
135136static void MessCreateDevice(const device_config *dev);
136static void MessRefreshPicker(int drvindex);
137static void MessRefreshPicker(void);
137138
138139static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem);
139140static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem);
r2488r2489
346347
347348void MyFillSoftwareList(int drvindex, BOOL bForce)
348349{
350   BOOL is_same;
349351   const game_driver *drv;
350352   HWND hwndSoftwarePicker;
351353   HWND hwndSoftwareDevView;
352354
355   // do we have to do anything?
356   if (!bForce)
357   {
358      if (config != NULL)
359         is_same = (drvindex == config->driver_index);
360      else
361         is_same = (drvindex < 0);
362      if (is_same)
363         return;
364   }
365
366   // free the machine config, if necessary
367   if (config != NULL)
368   {
369      software_config_free(config);
370      config = NULL;
371   }
372
373   // allocate the machine config, if necessary
374   if (drvindex >= 0)
375   {
376      config = software_config_alloc(drvindex, MameUIGlobal(), NULL);
377   }
378
379   // locate key widgets
353380   hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST);
354381   hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW);
355382
356   // Set up the device view
357   DevView_SetDriver(hwndSoftwareDevView, drvindex);
383   // set up the device view
384   DevView_SetDriver(hwndSoftwareDevView, config);
358385
359   if (!bForce && (s_nGame == drvindex))
360      return;
361   s_nGame = drvindex;
386   // set up the software picker
387   SoftwarePicker_Clear(hwndSoftwarePicker);
388   SoftwarePicker_SetDriver(hwndSoftwarePicker, config);
362389
363   // Set up the software picker
364   SoftwarePicker_Clear(hwndSoftwarePicker);
390   // add the relevant paths
365391   drv = drivers[drvindex];
366   SoftwarePicker_SetDriver(hwndSoftwarePicker, drv);
367   while(drv)
392   while(drv != NULL)
368393   {
369394      AddSoftwarePickerDirs(hwndSoftwarePicker, GetSoftwareDirs(), drv->name);
370395      drv = mess_next_compatible_driver(drv);
r2488r2489
528553   DevView_Refresh(GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW));
529554
530555   // Now read stuff into picker
531   MessRefreshPicker(drvindex);
556   MessRefreshPicker();
532557}
533558
534559
535560
536static void MessRefreshPicker(int drvindex)
561static void MessRefreshPicker(void)
537562{
538563   HWND hwndSoftware;
539564   int i;
540565   LVFINDINFO lvfi;
541   machine_config *config;
542566   const device_config *dev;
543567   LPCSTR pszSoftware;
544568
545569   hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST);
546570
547   // allocate the machine config
548   config = machine_config_alloc_with_mess_devices(drivers[drvindex]);
549
550571   s_bIgnoreSoftwarePickerNotifies = TRUE;
551572
552573   // Now clear everything out; this may call back into us but it should not
553574   // be problematic
554575   ListView_SetItemState(hwndSoftware, -1, 0, LVIS_SELECTED);
555576
556   for (dev = image_device_first(config); dev != NULL; dev = image_device_next(dev))
577   for (dev = image_device_first(config->mconfig); dev != NULL; dev = image_device_next(dev))
557578   {
558      pszSoftware = GetSelectedSoftware(drvindex, config, dev);
579      pszSoftware = GetSelectedSoftware(config->driver_index, config->mconfig, dev);
559580      if (pszSoftware && *pszSoftware)
560581      {
561582         i = SoftwarePicker_LookupIndex(hwndSoftware, pszSoftware);
r2488r2489
575596      }
576597   }
577598
578   machine_config_free(config);
579599   s_bIgnoreSoftwarePickerNotifies = FALSE;
580600}
581601
r2488r2489
586606   struct PickerOptions opts;
587607   HWND hwndSoftware;
588608
589   s_nGame = -1;
609   config = NULL;
590610   hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST);
591611
592612   memset(&opts, 0, sizeof(opts));
r2488r2489
865885   if( !utf8_filename )
866886      return;
867887   MessSpecifyImage(drvindex, dev, utf8_filename);
868   MessRefreshPicker(drvindex);
888   MessRefreshPicker();
869889   free(utf8_filename);
870890}
871891
src/mess/osd/winui/devview.c
r2488r2489
2626struct DevViewInfo
2727{
2828   HFONT hFont;
29   int nGame;
3029   int nWidth;
3130   BOOL bSurpressFilenameChanged;
32   machine_config *config;
31   const software_config *config;
3332   const struct DevViewCallbacks *pCallbacks;
3433   struct DevViewEntry *pEntries;
3534};
r2488r2489
7574      pDevViewInfo->pEntries = NULL;
7675   }
7776
78   if (pDevViewInfo->config != NULL)
79   {
80      machine_config_free(pDevViewInfo->config);
81      pDevViewInfo->config = NULL;
82   }
77   pDevViewInfo->config = NULL;
8378}
8479
8580
r2488r2489
123118      {
124119         pszSelection = pDevViewInfo->pCallbacks->pfnGetSelectedSoftware(
125120            hwndDevView,
126            pDevViewInfo->nGame,
127            pDevViewInfo->config,
121            pDevViewInfo->config->driver_index,
122            pDevViewInfo->config->mconfig,
128123            pDevViewInfo->pEntries[i].dev,
129124            szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
130125
r2488r2489
148143   if (!pDevViewInfo->bSurpressFilenameChanged && pDevViewInfo->pCallbacks->pfnSetSelectedSoftware)
149144   {
150145      pDevViewInfo->pCallbacks->pfnSetSelectedSoftware(hwndDevView,
151         pDevViewInfo->nGame,
152         pDevViewInfo->config,
146         pDevViewInfo->config->driver_index,
147         pDevViewInfo->config->mconfig,
153148         pDevViewInfo->pEntries[nChangedEntry].dev,
154149         pszFilename);
155150   }
r2488r2489
183178
184179
185180
186BOOL DevView_SetDriver(HWND hwndDevView, int nGame)
181BOOL DevView_SetDriver(HWND hwndDevView, const software_config *config)
187182{
188183   struct DevViewInfo *pDevViewInfo;
189184   const device_config *dev;
r2488r2489
199194
200195   pDevViewInfo = GetDevViewInfo(hwndDevView);
201196
202   // already selected this driver?
203   if (nGame == pDevViewInfo->nGame)
204      return TRUE;
205
197   // clear out
206198   DevView_Clear(hwndDevView);
207199
208   // allocate the machine config
209   pDevViewInfo->config = machine_config_alloc_with_mess_devices(drivers[nGame]);
200   // copy the config
201   pDevViewInfo->config = config;
210202
211203   // count total amount of devices
212   nDevCount = image_device_count(pDevViewInfo->config);
204   nDevCount = image_device_count(pDevViewInfo->config->mconfig);
213205
214206   if (nDevCount > 0)
215207   {
r2488r2489
217209      ppszDevices = (LPTSTR *) alloca(nDevCount * sizeof(*ppszDevices));
218210      i = 0;
219211
220      for (dev = image_device_first(pDevViewInfo->config); dev != NULL; dev = image_device_next(dev))
212      for (dev = image_device_first(pDevViewInfo->config->mconfig); dev != NULL; dev = image_device_next(dev))
221213      {
222         image_device_info info = image_device_getinfo(pDevViewInfo->config, dev);
214         image_device_info info = image_device_getinfo(pDevViewInfo->config->mconfig, dev);
223215
224216         s = tstring_from_utf8(info.name);
225217         ppszDevices[i] = alloca((_tcslen(s) + 1) * sizeof(TCHAR));
r2488r2489
253245      DevView_GetColumns(hwndDevView, &nStaticPos, &nStaticWidth,
254246         &nEditPos, &nEditWidth, &nButtonPos, &nButtonWidth);
255247
256      for (dev = image_device_first(pDevViewInfo->config); dev != NULL; dev = image_device_next(dev))
248      for (dev = image_device_first(pDevViewInfo->config->mconfig); dev != NULL; dev = image_device_next(dev))
257249      {
258         image_device_info info = image_device_getinfo(pDevViewInfo->config, dev);
250         image_device_info info = image_device_getinfo(pDevViewInfo->config->mconfig, dev);
259251
260252         pEnt->dev = dev;
261253
r2488r2489
293285      }
294286   }
295287
296   pDevViewInfo->nGame = nGame;
297288   DevView_Refresh(hwndDevView);
298289   return TRUE;
299290}
r2488r2489
331322   switch(rc)
332323   {
333324      case 1:
334         b = pDevViewInfo->pCallbacks->pfnGetOpenFileName(hwndDevView, pDevViewInfo->config, pEnt->dev,
325         b = pDevViewInfo->pCallbacks->pfnGetOpenFileName(hwndDevView, pDevViewInfo->config->mconfig, pEnt->dev,
335326            szPath, sizeof(szPath) / sizeof(szPath[0]));
336327         break;
337328      case 2:
338         b = pDevViewInfo->pCallbacks->pfnGetCreateFileName(hwndDevView, pDevViewInfo->config, pEnt->dev,
329         b = pDevViewInfo->pCallbacks->pfnGetCreateFileName(hwndDevView, pDevViewInfo->config->mconfig, pEnt->dev,
339330            szPath, sizeof(szPath) / sizeof(szPath[0]));
340331         break;
341332      case 3:
r2488r2489
357348{
358349   struct DevViewInfo *pDevViewInfo;
359350
351   // allocate the device view info
360352   pDevViewInfo = malloc(sizeof(struct DevViewInfo));
361353   if (!pDevViewInfo)
362354      return FALSE;
363355   memset(pDevViewInfo, 0, sizeof(*pDevViewInfo));
364   pDevViewInfo->nGame = -1;
356
365357   SetWindowLongPtr(hwndDevView, GWLP_USERDATA, (LONG_PTR) pDevViewInfo);
366358
359   // create and specify the font
367360   pDevViewInfo->hFont = CreateFont(10, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0,
368361      0, 0, 0, TEXT("MS Sans Serif"));
369362   SendMessage(hwndDevView, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, FALSE);
src/mess/osd/winui/devview.h
r2488r2489
11#ifndef DEVVIEW_H
22#define DEVVIEW_H
33
4#include "swconfig.h"
5
6
47struct DevViewCallbacks
58{
69   BOOL (*pfnGetOpenFileName)(HWND hwndDevView, const machine_config *config, const device_config *dev, LPTSTR pszFilename, UINT nFilenameLength);
r2488r2489
1013};
1114
1215void DevView_SetCallbacks(HWND hwndDevView, const struct DevViewCallbacks *pCallbacks);
13BOOL DevView_SetDriver(HWND hwndDevView, int nGame);
16BOOL DevView_SetDriver(HWND hwndDevView, const software_config *config);
1417void DevView_RegisterClass(void);
1518void DevView_Refresh(HWND hwndDevView);
1619
src/mess/osd/winui/swconfig.c
r0r2489
1//============================================================
2//
3//  swconfig.c
4//
5//============================================================
6
7#include "swconfig.h"
8
9
10//============================================================
11//  IMPLEMENTATION
12//============================================================
13
14software_config *software_config_alloc(int driver_index, core_options *opts, hashfile_error_func error_proc)
15{
16   const game_driver *driver;
17   software_config *config;
18
19   // allocate the software_config
20   config = malloc_or_die(sizeof(*config));
21   memset(config, 0, sizeof(*config));
22
23   // allocate the machine config
24   config->mconfig = machine_config_alloc_with_mess_devices(drivers[driver_index]);
25
26   // allocate the hash file
27   driver = drivers[driver_index];
28   while((driver != NULL) && (config->hashfile != NULL))
29   {
30      config->hashfile = hashfile_open_options(opts, driver->name, TRUE, error_proc);
31      driver = mess_next_compatible_driver(driver);
32   }
33
34   // other stuff
35   config->driver_index = driver_index;
36   config->gamedrv = drivers[driver_index];
37
38   return config;
39}
40
41
42
43void software_config_free(software_config *config)
44{
45   if (config->mconfig != NULL)
46   {
47      machine_config_free(config->mconfig);
48      config->mconfig = NULL;
49   }
50   if (config->hashfile != NULL)
51   {
52      hashfile_close(config->hashfile);
53      config->hashfile = NULL;
54   }
55   free(config);
56}
src/mess/osd/winui/winui.mak
r2488r2489
5252    $(MESS_WINUIOBJ)/layoutms.o \
5353   $(MESS_WINUIOBJ)/msuiutil.o \
5454   $(MESS_WINUIOBJ)/propertiesms.o \
55   $(MESS_WINUIOBJ)/swconfig.o \
5556   $(MESS_WINUIOBJ)/softwarepicker.o \
5657   $(MESS_WINUIOBJ)/devview.o
5758
src/mess/osd/winui/swconfig.h
r0r2489
1//============================================================
2//
3//  swconfig.h
4//
5//============================================================
6
7#ifndef __SWCONFIG_H__
8#define __SWCONFIG_H__
9
10#include "driver.h"
11#include "mconfig.h"
12#include "hashfile.h"
13
14
15//============================================================
16//  TYPE DEFINITIONS
17//============================================================
18
19typedef struct _software_config software_config;
20struct _software_config
21{
22   int driver_index;
23   const game_driver *gamedrv;
24   machine_config *mconfig;
25   hash_file *hashfile;
26};
27
28
29
30//============================================================
31//  PROTOTYPES
32//============================================================
33
34software_config *software_config_alloc(int driver_index, core_options *opts, hashfile_error_func error_proc);
35void software_config_free(software_config *config);
36
37#endif // __SWCONFIG_H__
src/mess/osd/winui/softwarepicker.c
r2488r2489
6969   int current_position;
7070   directory_search_info *first_search_info;
7171   directory_search_info *last_search_info;
72   const game_driver *driver;
73   machine_config *config;
74   hash_file *hashfile;
75   void (*error_callback)(const char *message);
72   const software_config *config;
7673};
7774
7875
r2488r2489
185182
186183   if (device != NULL)
187184   {
188      type = image_device_getinfo(GetSoftwarePickerInfo(hwndPicker)->config, device).type;
185      type = image_device_getinfo(GetSoftwarePickerInfo(hwndPicker)->config->mconfig, device).type;
189186   }
190187   else
191188   {
r2488r2489
196193
197194
198195
199void SoftwarePicker_SetDriver(HWND hwndPicker, const game_driver *driver)
196void SoftwarePicker_SetDriver(HWND hwndPicker, const software_config *config)
200197{
201   software_picker_info *pPickerInfo;
202198   int i;
199   software_picker_info *pPickerInfo;
203200
204201   pPickerInfo = GetSoftwarePickerInfo(hwndPicker);
202   pPickerInfo->config = config;
205203
206   // did the driver change?
207   if (pPickerInfo->driver != driver)
204   // invalidate the hash "realization"
205   for (i = 0; i < pPickerInfo->file_index_length; i++)
208206   {
209      // is there a hash file loaded?
210      if (pPickerInfo->hashfile != NULL)
211      {
212         // close down the file
213         hashfile_close(pPickerInfo->hashfile);
214         pPickerInfo->hashfile = NULL;
215
216         // invalidate the hash "realization"
217         for (i = 0; i < pPickerInfo->file_index_length; i++)
218         {
219            pPickerInfo->file_index[i]->hashinfo = NULL;
220            pPickerInfo->file_index[i]->hash_realized = FALSE;
221         }
222         pPickerInfo->hashes_realized = 0;
223      }
224
225      // is there a machine_config loaded?
226      if (pPickerInfo->config != NULL)
227      {
228         // free the machine_config
229         machine_config_free(pPickerInfo->config);
230         pPickerInfo->config = NULL;
231      }
232
233      // change the driver value
234      pPickerInfo->driver = driver;
235
236      // if we have a driver, we have to load some stuff
237      if (driver != NULL)
238      {
239         // get the configuration
240         pPickerInfo->config = machine_config_alloc_with_mess_devices(driver);
241
242         // find a hash file
243         while((driver != NULL) && !pPickerInfo->hashfile)
244         {
245            pPickerInfo->hashfile = hashfile_open_options(MameUIGlobal(), driver->name, TRUE, pPickerInfo->error_callback);
246            driver = mess_next_compatible_driver(driver);
247         }
248      }
207      pPickerInfo->file_index[i]->hashinfo = NULL;
208      pPickerInfo->file_index[i]->hash_realized = FALSE;
249209   }
210   pPickerInfo->hashes_realized = 0;
250211}
251212
252213
253214
254void SoftwarePicker_SetErrorProc(HWND hwndPicker, void (*error_callback)(const char *message))
255{
256   software_picker_info *pPickerInfo;
257   pPickerInfo = GetSoftwarePickerInfo(hwndPicker);
258   pPickerInfo->error_callback = error_callback;
259}
260
261
262
263215static void ComputeFileHash(software_picker_info *pPickerInfo,
264216   file_info *pFileInfo, const unsigned char *pBuffer, unsigned int nLength)
265217{
r2488r2489
267219   unsigned int functions;
268220
269221   // get the device info
270   info = image_device_getinfo(pPickerInfo->config, pFileInfo->device);
222   info = image_device_getinfo(pPickerInfo->config->mconfig, pFileInfo->device);
271223
272224   // determine which functions to use
273   functions = hashfile_functions_used(pPickerInfo->hashfile, info.type);
225   functions = hashfile_functions_used(pPickerInfo->config->hashfile, info.type);
274226
275227   // compute the hash
276228   image_device_compute_hash(pFileInfo->hash_string, pFileInfo->device, pBuffer, nLength, functions);
r2488r2489
385337
386338   // Determine which hash functions we need to use for this file, and which hashes
387339   // have already been calculated
388   if ((pPickerInfo->hashfile != NULL) && (pFileInfo->device != NULL))
340   if ((pPickerInfo->config->hashfile != NULL) && (pFileInfo->device != NULL))
389341   {
390      image_device_info info = image_device_getinfo(pPickerInfo->config, pFileInfo->device);
342      image_device_info info = image_device_getinfo(pPickerInfo->config->mconfig, pFileInfo->device);
391343      type = info.type;
392344      if (type < IO_COUNT)
393           nHashFunctionsUsed = hashfile_functions_used(pPickerInfo->hashfile, type);
345           nHashFunctionsUsed = hashfile_functions_used(pPickerInfo->config->hashfile, type);
394346      nCalculatedHashes = hash_data_used_functions(pFileInfo->hash_string);
395347   }
396348
r2488r2489
401353      pPickerInfo->file_index[nIndex]->hash_realized = TRUE;
402354      pPickerInfo->hashes_realized++;
403355
404      if (pPickerInfo->hashfile)
356      if (pPickerInfo->config->hashfile)
405357      {
406         pPickerInfo->file_index[nIndex]->hashinfo = hashfile_lookup(pPickerInfo->hashfile,
358         pPickerInfo->file_index[nIndex]->hashinfo = hashfile_lookup(pPickerInfo->config->hashfile,
407359            pPickerInfo->file_index[nIndex]->hash_string);
408360      }
409361   }
r2488r2489
430382   // look up the device
431383   if (strrchr(pszFilename, '.'))
432384      pszExtension = strrchr(pszFilename, '.');
433   if ((pszExtension != NULL) && (pPickerInfo->driver != NULL))
385   if ((pszExtension != NULL) && (pPickerInfo->config != NULL))
434386   {
435      for (device = image_device_first(pPickerInfo->config); device != NULL; device = image_device_next(device))
387      for (device = image_device_first(pPickerInfo->config->mconfig); device != NULL; device = image_device_next(device))
436388      {
437389         if (image_device_uses_file_extension(device, pszExtension))
438390            break;
r2488r2489
455407
456408   // set up device and CRC, if specified
457409   pInfo->device = device;
458   if ((device != NULL) && (image_device_getinfo(pPickerInfo->config, device).has_partial_hash != 0))
410   if ((device != NULL) && (image_device_getinfo(pPickerInfo->config->mconfig, device).has_partial_hash != 0))
459411      nCrc = 0;
460412   if (nCrc != 0)
461413      snprintf(pInfo->hash_string, sizeof(pInfo->hash_string) / sizeof(pInfo->hash_string[0]), "c:%08x#", nCrc);
r2488r2489
720672         SoftwarePicker_FreeSearchInfo(pSearchInfo);
721673      }
722674   }
723   else if (pPickerInfo->hashfile && (pPickerInfo->hashes_realized
675   else if (pPickerInfo->config->hashfile && (pPickerInfo->hashes_realized
724676      < pPickerInfo->file_index_length))
725677   {
726678      // time to realize some hashes
r2488r2489
737689      if (!pFileInfo->hash_realized)
738690      {
739691         type = mess_device_from_core_device(pFileInfo->device)->type;
740         if (hashfile_functions_used(pPickerInfo->hashfile, type))
692         if (hashfile_functions_used(pPickerInfo->config->hashfile, type))
741693         {
742694            // only calculate the hash if it is appropriate for this device
743695            if (!SoftwarePicker_CalculateHash(hwndPicker, pPickerInfo->current_position))
src/mess/osd/winui/softwarepicker.h
r2488r2489
44//
55//============================================================
66
7#include "swconfig.h"
8
79LPCSTR SoftwarePicker_LookupFilename(HWND hwndPicker, int nIndex);
810const device_config *SoftwarePicker_LookupDevice(HWND hwndPicker, int nIndex);
911int SoftwarePicker_LookupIndex(HWND hwndPicker, LPCSTR pszFilename);
r2488r2489
1113BOOL SoftwarePicker_AddFile(HWND hwndPicker, LPCSTR pszFilename);
1214BOOL SoftwarePicker_AddDirectory(HWND hwndPicker, LPCSTR pszDirectory);
1315void SoftwarePicker_Clear(HWND hwndPicker);
14void SoftwarePicker_SetDriver(HWND hwndPicker, const game_driver *pDriver);
15void SoftwarePicker_SetErrorProc(HWND hwndPicker, void (*pfnErrorProc)(const char *message));
16void SoftwarePicker_SetDriver(HWND hwndPicker, const software_config *config);
1617
1718// PickerOptions callbacks
1819LPCTSTR SoftwarePicker_GetItemString(HWND hwndPicker, int nRow, int nColumn,
src/mess/hashfile.h
r2488r2489
3030
3131typedef struct _hash_file hash_file;
3232
33typedef void (*hashfile_error_func)(const char *message);
3334
3435
36
3537/***************************************************************************
3638    FUNCTION PROTOTYPES
3739***************************************************************************/
3840
3941/* opens a hash file; if is_preload is non-zero, the entire file is preloaded */
40hash_file *hashfile_open(const char *sysname, int is_preload,
41   void (*error_proc)(const char *message));
42hash_file *hashfile_open(const char *sysname, int is_preload, hashfile_error_func error_proc);
4243
4344/* opens a hash file; if is_preload is non-zero, the entire file is preloaded */
4445hash_file *hashfile_open_options(core_options *opts, const char *sysname, int is_preload,
45   void (*error_proc)(const char *message));
46   hashfile_error_func error_proc);
4647
4748/* closes a hash file and associated resources */
4849void hashfile_close(hash_file *hashfile);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team