Previous 15994 Revisions Next

r8203 Thursday 3rd June, 2010 at 08:30:37 UTC by Miodrag Milanović
[MESSUI] Added new tab for software list, copied some functionalities from software picker which need rewrite to make things work.
[src/mess/osd/winui]messui.c resourcems.h softwarelist.c* softwarelist.h* winui.mak
[src/osd/winui]mameui.rc winui.c

src/osd/winui/mameui.rc
r8202r8203
10031003                    LVS_SHOWSELALWAYS | LVS_OWNERDRAWFIXED | WS_BORDER |
10041004               LVS_SHAREIMAGELISTS | WS_TABSTOP,119,60,42,140
10051005   CONTROL         "",IDC_SWDEVVIEW,"MessSoftwareDevView",WS_VISIBLE,119,0,200,100
1006    CONTROL         "List3",IDC_SOFTLIST,"SysListView32",LVS_REPORT |
1007                    LVS_SHOWSELALWAYS | LVS_OWNERDRAWFIXED | WS_BORDER |
1008               LVS_SHAREIMAGELISTS | WS_TABSTOP,119,60,42,140   
10061009    GROUPBOX        "",IDC_SPLITTER3,163,28,8,172,BS_NOTIFY | NOT WS_VISIBLE
10071010    CONTROL         "",IDC_SSFRAME,"Static",SS_ETCHEDFRAME,175,11,181,194
10081011    CONTROL         "",IDC_SSPICTURE,"Static",SS_BITMAP | SS_NOTIFY |
src/osd/winui/winui.c
r8202r8203
763763   IDC_LIST
764764#ifdef MESS
765765   ,IDC_SWLIST
766   ,IDC_SOFTLIST
766767#endif
767768};
768769
r8202r8203
792793   { RA_ID,   { IDC_SSTAB },    FALSE,   RA_RIGHT | RA_TOP,                 NULL },
793794#ifdef MESS
794795   { RA_ID,   { IDC_SWLIST },    TRUE,   RA_RIGHT | RA_BOTTOM | RA_TOP,     NULL },
796   { RA_ID,   { IDC_SOFTLIST },  TRUE,   RA_RIGHT | RA_BOTTOM | RA_TOP,     NULL },
795797   { RA_ID,   { IDC_SPLITTER3 },FALSE,   RA_RIGHT | RA_BOTTOM | RA_TOP,     NULL },
796798#endif /* MESS */
797799   { RA_END,  { 0 },            FALSE, 0,                                 NULL }
src/mess/osd/winui/messui.c
r8202r8203
2929#include "mess.h"
3030#include "configms.h"
3131#include "softwarepicker.h"
32#include "softwarelist.h"
3233#include "devview.h"
3334#include "windows/window.h"
3435#include "utils.h"
r8202r8203
121122   TEXT("MD5")
122123};
123124
125static const LPCTSTR softlist_column_names[] =
126{
127   TEXT("Name"),
128   TEXT("List"),
129   TEXT("Description"),
130   TEXT("Year"),
131   TEXT("Publisher"),
132   TEXT("CRC"),
133   TEXT("SHA-1"),
134   TEXT("MD5")};
124135
125136
137
126138//============================================================
127139//  PROTOTYPES
128140//============================================================
129141
130142static void SoftwarePicker_OnHeaderContextMenu(POINT pt, int nColumn);
143static void SoftwareList_OnHeaderContextMenu(POINT pt, int nColumn);
131144
132145static LPCSTR SoftwareTabView_GetTabShortName(int tab);
133146static LPCSTR SoftwareTabView_GetTabLongName(int tab);
r8202r8203
142155static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem);
143156static void SoftwarePicker_EnteringItem(HWND hwndSoftwarePicker, int nItem);
144157
158static int SoftwareList_GetItemImage(HWND hwndPicker, int nItem);
159static void SoftwareList_LeavingItem(HWND hwndSoftwareList, int nItem);
160static void SoftwareList_EnteringItem(HWND hwndSoftwareList, int nItem);
161
145162static BOOL DevView_GetOpenFileName(HWND hwndDevView, const machine_config *config, const device_config *dev, LPTSTR pszFilename, UINT nFilenameLength);
146163static BOOL DevView_GetCreateFileName(HWND hwndDevView, const machine_config *config, const device_config *dev, LPTSTR pszFilename, UINT nFilenameLength);
147164static void DevView_SetSelectedSoftware(HWND hwndDevView, int nDriverIndex, const machine_config *config, const device_config *dev, LPCTSTR pszFilename);
r8202r8203
157174//  PICKER/TABVIEW CALLBACKS
158175//============================================================
159176
160static const struct PickerCallbacks s_softwareListCallbacks =
177static const struct PickerCallbacks s_softwarePickerCallbacks =
161178{
162179   SetMessSortColumn,               // pfnSetSortColumn
163180   GetMessSortColumn,               // pfnGetSortColumn
r8202r8203
186203   NULL                        // pfnOnBodyContextMenu
187204};
188205
206static const struct PickerCallbacks s_softwareListCallbacks =
207{
208   SetMessSortColumn,               // pfnSetSortColumn
209   GetMessSortColumn,               // pfnGetSortColumn
210   SetMessSortReverse,               // pfnSetSortReverse
211   GetMessSortReverse,               // pfnGetSortReverse
212   NULL,                        // pfnSetViewMode
213   GetViewMode,                  // pfnGetViewMode
214   SetMessColumnWidths,            // pfnSetColumnWidths
215   GetMessColumnWidths,            // pfnGetColumnWidths
216   SetMessColumnOrder,               // pfnSetColumnOrder
217   GetMessColumnOrder,               // pfnGetColumnOrder
218   SetMessColumnShown,               // pfnSetColumnShown
219   GetMessColumnShown,               // pfnGetColumnShown
220   NULL,                        // pfnGetOffsetChildren
189221
222   NULL,                        // pfnCompare
223   MamePlayGame,                  // pfnDoubleClick
224   SoftwareList_GetItemString,         // pfnGetItemString
225   SoftwareList_GetItemImage,         // pfnGetItemImage
226   SoftwareList_LeavingItem,         // pfnLeavingItem
227   SoftwareList_EnteringItem,         // pfnEnteringItem
228   NULL,                        // pfnBeginListViewDrag
229   NULL,                        // pfnFindItemParent
230   SoftwareList_Idle,               // pfnIdle
231   SoftwareList_OnHeaderContextMenu,   // pfnOnHeaderContextMenu
232   NULL                        // pfnOnBodyContextMenu
233};
190234
235
191236static const struct TabViewCallbacks s_softwareTabViewCallbacks =
192237{
193238   NULL,                        // pfnGetShowTabCtrl
r8202r8203
620665   hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST);
621666
622667   memset(&opts, 0, sizeof(opts));
623   opts.pCallbacks = &s_softwareListCallbacks;
668   opts.pCallbacks = &s_softwarePickerCallbacks;
624669   opts.nColumnCount = MESS_COLUMN_MAX;
625670   opts.ppszColumnNames = mess_column_names;
626671   SetupSoftwarePicker(hwndSoftware, &opts);
r8202r8203
640685      };
641686      DevView_SetCallbacks(GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW), &s_devViewCallbacks);
642687   }
688   
689   HWND hwndSoftwareList;
690
691   hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST);
692
693   memset(&opts, 0, sizeof(opts));
694   opts.pCallbacks = &s_softwareListCallbacks;
695   opts.nColumnCount = MESS_COLUMN_MAX;
696   opts.ppszColumnNames = softlist_column_names;
697   SetupSoftwareList(hwndSoftwareList, &opts);
698
699   SetWindowLong(hwndSoftwareList, GWL_STYLE, GetWindowLong(hwndSoftwareList, GWL_STYLE)
700      | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDRAWFIXED);
701
643702}
644703
645704
r8202r8203
10511110
10521111
10531112// ------------------------------------------------------------------------
1054// Software List Class
1113// Software Picker Class
10551114// ------------------------------------------------------------------------
10561115
10571116static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem)
r8202r8203
11431202}
11441203
11451204
1205// ------------------------------------------------------------------------
1206// Software List Class
1207// ------------------------------------------------------------------------
11461208
1209static int SoftwareList_GetItemImage(HWND hwndPicker, int nItem)
1210{
1211   iodevice_t nType;
1212   int nIcon;
1213   int drvindex;
1214   const char *icon_name;
1215   HWND hwndGamePicker;
1216   HWND hwndSoftwareList;
1217
1218   hwndGamePicker = GetDlgItem(GetMainWindow(), IDC_LIST);
1219   hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST);
1220   drvindex = Picker_GetSelectedItem(hwndGamePicker);
1221   nType = SoftwareList_GetImageType(hwndSoftwareList, nItem);
1222   nIcon = GetMessIcon(drvindex, nType);
1223   if (!nIcon)
1224   {
1225      switch(nType)
1226      {
1227         case IO_UNKNOWN:
1228            nIcon = FindIconIndex(IDI_WIN_REDX);
1229            break;
1230
1231         default:
1232            icon_name = lookupdevice(nType)->icon_name;
1233            if (!icon_name)
1234               icon_name = device_typename(nType);
1235            nIcon = FindIconIndexByName(icon_name);
1236            if (nIcon < 0)
1237               nIcon = FindIconIndex(IDI_WIN_UNKNOWN);
1238            break;
1239      }
1240    }
1241    return nIcon;
1242}
1243
1244
1245
1246static void SoftwareList_LeavingItem(HWND hwndSoftwareList, int nItem)
1247{
1248   int drvindex;
1249   const char *pszFullName;
1250   HWND hwndList;
1251
1252   if (!s_bIgnoreSoftwarePickerNotifies)
1253   {
1254      hwndList = GetDlgItem(GetMainWindow(), IDC_LIST);
1255      drvindex = Picker_GetSelectedItem(hwndList);
1256      pszFullName = SoftwareList_LookupFilename(hwndSoftwareList, nItem);
1257
1258      MessRemoveImage(drvindex, pszFullName);
1259   }
1260}
1261
1262
1263
1264static void SoftwareList_EnteringItem(HWND hwndSoftwareList, int nItem)
1265{
1266   LPCSTR pszFullName;
1267   LPCSTR pszName;
1268   const char* tmp;
1269   LPSTR s;
1270   int drvindex;
1271   HWND hwndList;
1272
1273   hwndList = GetDlgItem(GetMainWindow(), IDC_LIST);
1274
1275   if (!s_bIgnoreSoftwarePickerNotifies)
1276   {
1277      drvindex = Picker_GetSelectedItem(hwndList);
1278
1279      // Get the fullname and partialname for this file
1280      pszFullName = SoftwareList_LookupFilename(hwndSoftwareList, nItem);
1281      tmp = strchr(pszFullName, '\\');
1282      pszName = tmp ? tmp + 1 : pszFullName;
1283
1284      // Do the dirty work
1285      MessSpecifyImage(drvindex, NULL, pszFullName);
1286
1287      // Set up s_szSelecteItem, for the benefit of UpdateScreenShot()
1288      strncpyz(g_szSelectedItem, pszName, ARRAY_LENGTH(g_szSelectedItem));
1289      s = strrchr(g_szSelectedItem, '.');
1290      if (s)
1291         *s = '\0';
1292
1293      UpdateScreenShot();
1294   }
1295}
1296
1297
11471298// ------------------------------------------------------------------------
11481299// Header context menu stuff
11491300// ------------------------------------------------------------------------
r8202r8203
12541405   }
12551406}
12561407
1408static void SoftwareList_OnHeaderContextMenu(POINT pt, int nColumn)
1409{
1410   HMENU hMenu;
1411   HMENU hMenuLoad;
1412   HWND hwndPicker;
1413   int nMenuItem;
12571414
1415   hMenuLoad = LoadMenu(NULL, MAKEINTRESOURCE(IDR_CONTEXT_HEADER));
1416   hMenu = GetSubMenu(hMenuLoad, 0);
12581417
1418   nMenuItem = (int) TrackPopupMenu(hMenu,
1419      TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
1420      pt.x,
1421      pt.y,
1422      0,
1423      GetMainWindow(),
1424      NULL);
1425
1426   DestroyMenu(hMenuLoad);
1427
1428   hwndPicker = GetDlgItem(GetMainWindow(), IDC_SOFTLIST);
1429
1430   switch(nMenuItem) {
1431   case ID_SORT_ASCENDING:
1432      SetMessSortReverse(FALSE);
1433      SetMessSortColumn(Picker_GetRealColumnFromViewColumn(hwndPicker, nColumn));
1434      Picker_Sort(hwndPicker);
1435      break;
1436
1437   case ID_SORT_DESCENDING:
1438      SetMessSortReverse(TRUE);
1439      SetMessSortColumn(Picker_GetRealColumnFromViewColumn(hwndPicker, nColumn));
1440      Picker_Sort(hwndPicker);
1441      break;
1442
1443   case ID_CUSTOMIZE_FIELDS:
1444      if (RunColumnDialog(hwndPicker))
1445         Picker_ResetColumnDisplay(hwndPicker);
1446      break;
1447   }
1448}
1449
1450
12591451// ------------------------------------------------------------------------
12601452// MessCommand
12611453// ------------------------------------------------------------------------
r8202r8203
12861478static LPCSTR s_tabs[] =
12871479{
12881480   "picker\0Picker",
1289   "devview\0Device View"
1481   "devview\0Device View",
1482   "softlist\0Software",
12901483};
12911484
12921485
r8202r8203
13101503   int nTab;
13111504   HWND hwndSoftwarePicker;
13121505   HWND hwndSoftwareDevView;
1506   HWND hwndSoftwareList;
13131507
13141508   hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST);
13151509   hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW);
1510   hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST);
13161511
13171512   nTab = TabView_GetCurrentTab(GetDlgItem(GetMainWindow(), IDC_SWTAB));
13181513
r8202r8203
13211516      case 0:
13221517         ShowWindow(hwndSoftwarePicker, SW_SHOW);
13231518         ShowWindow(hwndSoftwareDevView, SW_HIDE);
1519         ShowWindow(hwndSoftwareList, SW_HIDE);
13241520         break;
13251521
13261522      case 1:
13271523         ShowWindow(hwndSoftwarePicker, SW_HIDE);
13281524         ShowWindow(hwndSoftwareDevView, SW_SHOW);
1525         ShowWindow(hwndSoftwareList, SW_HIDE);
13291526         break;
1527      case 2:
1528         ShowWindow(hwndSoftwarePicker, SW_HIDE);
1529         ShowWindow(hwndSoftwareDevView, SW_HIDE);
1530         ShowWindow(hwndSoftwareList, SW_SHOW);
1531         break;
13301532   }
13311533}
13321534
r8202r8203
13371539   HWND hwndSoftwareTabView;
13381540   HWND hwndSoftwarePicker;
13391541   HWND hwndSoftwareDevView;
1542   HWND hwndSoftwareList;
13401543   RECT rMain, rSoftwareTabView, rClient, rTab;
13411544   BOOL res;
13421545
13431546   hwndSoftwareTabView = GetDlgItem(GetMainWindow(), IDC_SWTAB);
13441547   hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST);
13451548   hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW);
1549   hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST);
13461550
13471551   GetWindowRect(hwndSoftwareTabView, &rSoftwareTabView);
13481552   GetClientRect(GetMainWindow(), &rMain);
r8202r8203
13701574   MoveWindow(hwndSoftwareDevView, rClient.left, rClient.top,
13711575      rClient.right - rClient.left, rClient.bottom - rClient.top,
13721576      TRUE);
1577   MoveWindow(hwndSoftwareList, rClient.left, rClient.top,
1578      rClient.right - rClient.left, rClient.bottom - rClient.top,
1579      TRUE);
13731580}
13741581
13751582
src/mess/osd/winui/winui.mak
r8202r8203
5757   $(MESS_WINUIOBJ)/propertiesms.o \
5858   $(MESS_WINUIOBJ)/swconfig.o \
5959   $(MESS_WINUIOBJ)/softwarepicker.o \
60   $(MESS_WINUIOBJ)/softwarelist.o \
6061   $(MESS_WINUIOBJ)/devview.o
6162
6263
src/mess/osd/winui/softwarelist.c
r0r8203
1//============================================================
2//
3//  softwarelist.c - MESS's software picker
4//
5//============================================================
6
7#define WIN32_LEAN_AND_MEAN
8#include <assert.h>
9#include <string.h>
10#include <windows.h>
11#include <shellapi.h>
12#include <commctrl.h>
13#include <commdlg.h>
14#include <wingdi.h>
15#include <winuser.h>
16#include <tchar.h>
17#include <ctype.h>
18
19#include "emu.h"
20#include "unzip.h"
21#include "strconv.h"
22#include "hashfile.h"
23#include "picker.h"
24#include "screenshot.h"
25#include "bitmask.h"
26#include "winui.h"
27#include "resourcems.h"
28#include "mui_opts.h"
29#include "softwarelist.h"
30#include "mui_util.h"
31
32
33
34//============================================================
35//  TYPE DEFINITIONS
36//============================================================
37
38typedef struct _file_info file_info;
39struct _file_info
40{
41   const device_config *device;
42
43   // hash information
44   char hash_string[HASH_BUF_SIZE];
45   BOOL hash_realized;
46   const hash_info *hashinfo;
47
48   const char *zip_entry_name;
49   const char *base_name;
50   char file_name[1];
51};
52
53typedef struct _directory_search_info directory_search_info;
54struct _directory_search_info
55{
56   directory_search_info *next;
57   HANDLE find_handle;
58   WIN32_FIND_DATA fd;
59   char directory_name[1];
60};
61
62typedef struct _software_list_info software_list_info;
63struct _software_list_info
64{
65   WNDPROC old_window_proc;
66   file_info **file_index;
67   int file_index_length;
68   int hashes_realized;
69   int current_position;
70   directory_search_info *first_search_info;
71   directory_search_info *last_search_info;
72   const software_config *config;
73};
74
75
76
77//============================================================
78//  CONSTANTS
79//============================================================
80
81static const TCHAR software_list_property_name[] = TEXT("SWLIST");
82
83
84
85//============================================================
86
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
128static software_list_info *GetSoftwareListInfo(HWND hwndPicker)
129{
130   HANDLE h;
131   h = GetProp(hwndPicker, software_list_property_name);
132   assert(h);
133   return (software_list_info *) h;
134}
135
136
137
138LPCSTR SoftwareList_LookupFilename(HWND hwndPicker, int nIndex)
139{
140   software_list_info *pPickerInfo;
141   pPickerInfo = GetSoftwareListInfo(hwndPicker);
142   if ((nIndex < 0) || (nIndex >= pPickerInfo->file_index_length))
143      return NULL;
144   return pPickerInfo->file_index[nIndex]->file_name;
145}
146
147
148
149const device_config *SoftwareList_LookupDevice(HWND hwndPicker, int nIndex)
150{
151   software_list_info *pPickerInfo;
152   pPickerInfo = GetSoftwareListInfo(hwndPicker);
153   if ((nIndex < 0) || (nIndex >= pPickerInfo->file_index_length))
154   {
155      return NULL;
156   }
157   return pPickerInfo->file_index[nIndex]->device;
158}
159
160
161
162int SoftwareList_LookupIndex(HWND hwndPicker, LPCSTR pszFilename)
163{
164   software_list_info *pPickerInfo;
165   int i;
166
167   pPickerInfo = GetSoftwareListInfo(hwndPicker);
168   for (i = 0; i < pPickerInfo->file_index_length; i++)
169   {
170      if (!mame_stricmp(pPickerInfo->file_index[i]->file_name, pszFilename))
171         return i;
172   }
173   return -1;
174}
175
176
177
178iodevice_t SoftwareList_GetImageType(HWND hwndPicker, int nIndex)
179{
180   iodevice_t type;
181   const device_config *device = SoftwareList_LookupDevice(hwndPicker, nIndex);
182
183   if (device != NULL)
184   {
185      type = image_device_getinfo(GetSoftwareListInfo(hwndPicker)->config->mconfig, device).type;
186   }
187   else
188   {
189      type = IO_UNKNOWN;
190   }
191   return type;
192}
193
194
195
196void SoftwareList_SetDriver(HWND hwndPicker, const software_config *config)
197{
198   int i;
199   software_list_info *pPickerInfo;
200
201   pPickerInfo = GetSoftwareListInfo(hwndPicker);
202   pPickerInfo->config = config;
203
204   // invalidate the hash "realization"
205   for (i = 0; i < pPickerInfo->file_index_length; i++)
206   {
207      pPickerInfo->file_index[i]->hashinfo = NULL;
208      pPickerInfo->file_index[i]->hash_realized = FALSE;
209   }
210   pPickerInfo->hashes_realized = 0;
211}
212
213
214
215static void ComputeFileHash(software_list_info *pPickerInfo,
216   file_info *pFileInfo, const unsigned char *pBuffer, unsigned int nLength)
217{
218   image_device_info info;
219   unsigned int functions;
220
221   // get the device info
222   info = image_device_getinfo(pPickerInfo->config->mconfig, pFileInfo->device);
223
224   // determine which functions to use
225   functions = hashfile_functions_used(pPickerInfo->config->hashfile, info.type);
226
227   // compute the hash
228   image_device_compute_hash(pFileInfo->hash_string, pFileInfo->device, pBuffer, nLength, functions);
229}
230
231
232
233static BOOL SoftwareList_CalculateHash(HWND hwndPicker, int nIndex)
234{
235   software_list_info *pPickerInfo;
236   file_info *pFileInfo;
237   LPSTR pszZipName;
238   BOOL rc = FALSE;
239   unsigned char *pBuffer;
240   unsigned int nLength;
241   HANDLE hFile, hFileMapping;
242   LVFINDINFO lvfi;
243   BOOL res;
244
245   pPickerInfo = GetSoftwareListInfo(hwndPicker);
246   assert((nIndex >= 0) && (nIndex < pPickerInfo->file_index_length));
247   pFileInfo = pPickerInfo->file_index[nIndex];
248
249   if (pFileInfo->zip_entry_name)
250   {
251      // this is in a ZIP file
252      zip_file *zip;
253      zip_error ziperr;
254      const zip_file_header *zipent;
255
256      // open the ZIP file
257      nLength = pFileInfo->zip_entry_name - pFileInfo->file_name;
258      pszZipName = (LPSTR) alloca(nLength);
259      memcpy(pszZipName, pFileInfo->file_name, nLength);
260      pszZipName[nLength - 1] = '\0';
261
262      // get the entry name
263      ziperr = zip_file_open(pszZipName, &zip);
264      if (ziperr == ZIPERR_NONE)
265      {
266         zipent = zip_file_first_file(zip);
267         while(!rc && zipent)
268         {
269            if (!mame_stricmp(zipent->filename, pFileInfo->zip_entry_name))
270            {
271               pBuffer = (unsigned char *)malloc(zipent->uncompressed_length);
272               if (pBuffer)
273               {
274                  ziperr = zip_file_decompress(zip, pBuffer, zipent->uncompressed_length);
275                  if (ziperr == ZIPERR_NONE)
276                  {
277                     ComputeFileHash(pPickerInfo, pFileInfo, pBuffer, zipent->uncompressed_length);
278                     rc = TRUE;
279                  }
280                  free(pBuffer);
281               }
282            }
283            zipent = zip_file_next_file(zip);
284         }
285         zip_file_close(zip);
286      }
287   }
288   else
289   {
290      // plain open file; map it into memory and calculate the hash
291      hFile = win_create_file_utf8(pFileInfo->file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
292         OPEN_EXISTING, 0, NULL);
293      if (hFile != INVALID_HANDLE_VALUE)
294      {
295         nLength = GetFileSize(hFile, NULL);
296         hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
297         if (hFileMapping)
298         {
299            pBuffer = (unsigned char *)MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
300            if (pBuffer)
301            {
302               ComputeFileHash(pPickerInfo, pFileInfo, pBuffer, nLength);
303               UnmapViewOfFile(pBuffer);
304               rc = TRUE;
305            }
306            CloseHandle(hFileMapping);
307         }
308         CloseHandle(hFile);
309      }
310   }
311
312   if (rc)
313   {
314      memset(&lvfi, 0, sizeof(lvfi));
315      lvfi.flags = LVFI_PARAM;
316      lvfi.lParam = nIndex;
317      nIndex = ListView_FindItem(hwndPicker, -1, &lvfi);
318      if (nIndex > 0)
319         res = ListView_RedrawItems(hwndPicker, nIndex, nIndex);
320   }
321
322   return rc;
323}
324
325
326
327static void SoftwareList_RealizeHash(HWND hwndPicker, int nIndex)
328{
329   software_list_info *pPickerInfo;
330   file_info *pFileInfo;
331   unsigned int nHashFunctionsUsed = 0;
332   unsigned int nCalculatedHashes = 0;
333   iodevice_t type;
334
335   pPickerInfo = GetSoftwareListInfo(hwndPicker);
336   assert((nIndex >= 0) && (nIndex < pPickerInfo->file_index_length));
337   pFileInfo = pPickerInfo->file_index[nIndex];
338
339   // Determine which hash functions we need to use for this file, and which hashes
340   // have already been calculated
341   if ((pPickerInfo->config->hashfile != NULL) && (pFileInfo->device != NULL))
342   {
343      image_device_info info = image_device_getinfo(pPickerInfo->config->mconfig, pFileInfo->device);
344      type = info.type;
345      if (type < IO_COUNT)
346           nHashFunctionsUsed = hashfile_functions_used(pPickerInfo->config->hashfile, type);
347      nCalculatedHashes = hash_data_used_functions(pFileInfo->hash_string);
348   }
349
350   // Did we fully compute all hashes?
351   if ((nHashFunctionsUsed & ~nCalculatedHashes) == 0)
352   {
353      // We have calculated all hashs for this file; mark it as realized
354      pPickerInfo->file_index[nIndex]->hash_realized = TRUE;
355      pPickerInfo->hashes_realized++;
356
357      if (pPickerInfo->config->hashfile)
358      {
359         pPickerInfo->file_index[nIndex]->hashinfo = hashfile_lookup(pPickerInfo->config->hashfile,
360            pPickerInfo->file_index[nIndex]->hash_string);
361      }
362   }
363}
364
365
366
367static BOOL SoftwareList_AddFileEntry(HWND hwndPicker, LPCSTR pszFilename,
368   UINT nZipEntryNameLength, UINT32 nCrc, BOOL bForce)
369{
370   software_list_info *pPickerInfo;
371   file_info **ppNewIndex;
372   file_info *pInfo;
373   int nIndex, nSize;
374   LPCSTR pszExtension = NULL;
375   const device_config *device = NULL;
376
377   // first check to see if it is already here
378   if (SoftwareList_LookupIndex(hwndPicker, pszFilename) >= 0)
379      return TRUE;
380
381   pPickerInfo = GetSoftwareListInfo(hwndPicker);
382
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
402   // create the FileInfo structure
403   nSize = sizeof(file_info) + strlen(pszFilename);
404   pInfo = (file_info *) malloc(nSize);
405   if (!pInfo)
406      goto error;
407   memset(pInfo, 0, nSize);
408
409   // copy the filename
410   strcpy(pInfo->file_name, pszFilename);
411
412   // set up device and CRC, if specified
413   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
430   ppNewIndex = (file_info**)malloc((pPickerInfo->file_index_length + 1) * sizeof(*pPickerInfo->file_index));
431   memcpy(ppNewIndex,pPickerInfo->file_index,pPickerInfo->file_index_length * sizeof(*pPickerInfo->file_index));
432   if (pPickerInfo->file_index) free(pPickerInfo->file_index);
433   if (!ppNewIndex)
434      goto error;
435
436   nIndex = pPickerInfo->file_index_length++;
437   pPickerInfo->file_index = ppNewIndex;
438   pPickerInfo->file_index[nIndex] = pInfo;
439
440   // Realize the hash
441   SoftwareList_RealizeHash(hwndPicker, nIndex);
442
443   // Actually insert the item into the picker
444   Picker_InsertItemSorted(hwndPicker, nIndex);
445   return TRUE;
446
447error:
448   if (pInfo)
449      free(pInfo);
450   return FALSE;
451}
452
453
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
561static void SoftwareList_FreeSearchInfo(directory_search_info *pSearchInfo)
562{
563   if (pSearchInfo->find_handle != INVALID_HANDLE_VALUE)
564      FindClose(pSearchInfo->find_handle);
565   free(pSearchInfo);
566}
567
568
569
570static void SoftwareList_InternalClear(software_list_info *pPickerInfo)
571{
572   directory_search_info *p;
573   int i;
574
575   for (i = 0; i < pPickerInfo->file_index_length; i++)
576      free(pPickerInfo->file_index[i]);
577
578   while(pPickerInfo->first_search_info)
579   {
580      p = pPickerInfo->first_search_info->next;
581      SoftwareList_FreeSearchInfo(pPickerInfo->first_search_info);
582      pPickerInfo->first_search_info = p;
583   }
584
585   pPickerInfo->file_index = NULL;
586   pPickerInfo->file_index_length = 0;
587   pPickerInfo->current_position = 0;
588   pPickerInfo->last_search_info = NULL;
589}
590
591
592
593void SoftwareList_Clear(HWND hwndPicker)
594{
595   software_list_info *pPickerInfo;
596   BOOL res;
597
598   pPickerInfo = GetSoftwareListInfo(hwndPicker);
599   SoftwareList_InternalClear(pPickerInfo);
600   res = ListView_DeleteAllItems(hwndPicker);
601}
602
603
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
640BOOL SoftwareList_Idle(HWND hwndPicker)
641{
642   software_list_info *pPickerInfo;
643   file_info *pFileInfo;
644   static const char szWildcards[] = "\\*.*";
645   directory_search_info *pSearchInfo;
646   LPSTR pszFilter;
647   BOOL bSuccess;
648   int nCount;
649   BOOL bDone = FALSE;
650   image_device_info info;
651
652   pPickerInfo = GetSoftwareListInfo(hwndPicker);
653
654   pSearchInfo = pPickerInfo->first_search_info;
655
656   if (pSearchInfo)
657   {
658      // searching through directories
659      if (pSearchInfo->find_handle != INVALID_HANDLE_VALUE)
660      {
661         bSuccess = FindNextFile(pSearchInfo->find_handle, &pSearchInfo->fd);
662      }
663      else
664      {
665         pszFilter = (LPSTR)alloca(strlen(pSearchInfo->directory_name) + strlen(szWildcards) + 1);
666         strcpy(pszFilter, pSearchInfo->directory_name);
667         strcat(pszFilter, szWildcards);
668         pSearchInfo->find_handle = win_find_first_file_utf8(pszFilter, &pSearchInfo->fd);
669         bSuccess = pSearchInfo->find_handle != INVALID_HANDLE_VALUE;
670      }
671
672      if (bSuccess)
673      {
674         SoftwareList_AddEntry(hwndPicker, pSearchInfo);
675      }
676      else
677      {
678         pPickerInfo->first_search_info = pSearchInfo->next;
679         if (!pPickerInfo->first_search_info)
680            pPickerInfo->last_search_info = NULL;
681         SoftwareList_FreeSearchInfo(pSearchInfo);
682      }
683   }
684   else if (pPickerInfo->config!=NULL  && pPickerInfo->config->hashfile && (pPickerInfo->hashes_realized
685      < pPickerInfo->file_index_length))
686   {
687      // time to realize some hashes
688      nCount = 100;
689
690      while((nCount > 0) && pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized)
691      {
692         pPickerInfo->current_position++;
693         pPickerInfo->current_position %= pPickerInfo->file_index_length;
694         nCount--;
695      }
696
697      pFileInfo = pPickerInfo->file_index[pPickerInfo->current_position];
698      if (!pFileInfo->hash_realized)
699      {
700         info = image_device_getinfo(pPickerInfo->config->mconfig, pFileInfo->device);
701         if (hashfile_functions_used(pPickerInfo->config->hashfile, info.type))
702         {
703            // only calculate the hash if it is appropriate for this device
704            if (!SoftwareList_CalculateHash(hwndPicker, pPickerInfo->current_position))
705               return FALSE;
706         }
707         SoftwareList_RealizeHash(hwndPicker, pPickerInfo->current_position);
708
709         // under normal circumstances this will be redundant, but in the unlikely
710         // event of a failure, we do not want to keep running into a brick wall
711         // by calculating this hash over and over
712         if (!pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized)
713         {
714            pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized = TRUE;
715            pPickerInfo->hashes_realized++;
716         }
717      }
718   }
719   else
720   {
721      // we are done!
722      bDone = TRUE;
723   }
724
725   return !bDone;
726}
727
728
729
730LPCTSTR SoftwareList_GetItemString(HWND hwndPicker, int nRow, int nColumn,
731   TCHAR *pszBuffer, UINT nBufferLength)
732{
733   software_list_info *pPickerInfo;
734   const file_info *pFileInfo;
735   LPCTSTR s = NULL;
736   const char *pszUtf8 = NULL;
737   unsigned int nHashFunction = 0;
738   char szBuffer[256];
739   TCHAR* t_buf;
740
741   pPickerInfo = GetSoftwareListInfo(hwndPicker);
742   if ((nRow < 0) || (nRow >= pPickerInfo->file_index_length))
743      return NULL;
744
745   pFileInfo = pPickerInfo->file_index[nRow];
746
747   switch(nColumn)
748   {
749      case MESS_COLUMN_IMAGES:
750         t_buf = tstring_from_utf8(pFileInfo->base_name);
751         if( !t_buf )
752            return s;
753         _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf);
754         s = pszBuffer;
755         osd_free(t_buf);
756         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         }
789         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         }
809         break;
810   }
811   return s;
812}
813
814
815
816static LRESULT CALLBACK SoftwareList_WndProc(HWND hwndPicker, UINT nMessage,
817   WPARAM wParam, LPARAM lParam)
818{
819   software_list_info *pPickerInfo;
820   LRESULT rc;
821
822   pPickerInfo = GetSoftwareListInfo(hwndPicker);
823   rc = CallWindowProc(pPickerInfo->old_window_proc, hwndPicker, nMessage, wParam, lParam);
824
825   if (nMessage == WM_DESTROY)
826   {
827      SoftwareList_InternalClear(pPickerInfo);
828      SoftwareList_SetDriver(hwndPicker, NULL);
829      free(pPickerInfo);
830   }
831
832   return rc;
833}
834
835
836
837BOOL SetupSoftwareList(HWND hwndPicker, const struct PickerOptions *pOptions)
838{
839   software_list_info *pPickerInfo = NULL;
840   LONG_PTR l;
841
842   if (!SetupPicker(hwndPicker, pOptions))
843      goto error;
844
845   pPickerInfo = (software_list_info *)malloc(sizeof(*pPickerInfo));
846   if (!pPickerInfo)
847      goto error;
848
849   memset(pPickerInfo, 0, sizeof(*pPickerInfo));
850   if (!SetProp(hwndPicker, software_list_property_name, (HANDLE) pPickerInfo))
851      goto error;
852
853   l = (LONG_PTR) SoftwareList_WndProc;
854   l = SetWindowLongPtr(hwndPicker, GWLP_WNDPROC, l);
855   pPickerInfo->old_window_proc = (WNDPROC) l;
856   return TRUE;
857
858error:
859   if (pPickerInfo)
860      free(pPickerInfo);
861   return FALSE;
862}
src/mess/osd/winui/softwarelist.h
r0r8203
1//============================================================
2//
3//  softwarelist.h - MESS's software
4//
5//============================================================
6
7#include "swconfig.h"
8
9LPCSTR SoftwareList_LookupFilename(HWND hwndPicker, int nIndex);
10const device_config *SoftwareList_LookupDevice(HWND hwndPicker, int nIndex);
11int SoftwareList_LookupIndex(HWND hwndPicker, LPCSTR pszFilename);
12iodevice_t SoftwareList_GetImageType(HWND hwndPicker, int nIndex);
13BOOL SoftwareList_AddFile(HWND hwndPicker, LPCSTR pszFilename);
14BOOL SoftwareList_AddDirectory(HWND hwndPicker, LPCSTR pszDirectory);
15void SoftwareList_Clear(HWND hwndPicker);
16void SoftwareList_SetDriver(HWND hwndPicker, const software_config *config);
17
18// PickerOptions callbacks
19LPCTSTR SoftwareList_GetItemString(HWND hwndPicker, int nRow, int nColumn,
20   TCHAR *pszBuffer, UINT nBufferLength);
21BOOL SoftwareList_Idle(HWND hwndPicker);
22
23BOOL SetupSoftwareList(HWND hwndPicker, const struct PickerOptions *pOptions);
src/mess/osd/winui/resourcems.h
r8202r8203
1515#define IDC_USE_NEW_UI                  2007
1616#define IDC_RAM_COMBOBOX            2008
1717#define IDC_RAM_CAPTION               2009
18#define IDC_SOFTLIST               2010
1819#define IDC_SKIP_WARNINGS               2013
1920#define IDI_WIN_NOROMSNEEDED         2100
2021#define IDI_WIN_MISSINGOPTROM         2101

Previous 15994 Revisions Next


© 1998-2018 The MESS Team