src/mess/osd/winui/messui.c
| r8202 | r8203 | |
| 29 | 29 | #include "mess.h" |
| 30 | 30 | #include "configms.h" |
| 31 | 31 | #include "softwarepicker.h" |
| 32 | #include "softwarelist.h" |
| 32 | 33 | #include "devview.h" |
| 33 | 34 | #include "windows/window.h" |
| 34 | 35 | #include "utils.h" |
| r8202 | r8203 | |
| 121 | 122 | TEXT("MD5") |
| 122 | 123 | }; |
| 123 | 124 | |
| 125 | static 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")}; |
| 124 | 135 | |
| 125 | 136 | |
| 137 | |
| 126 | 138 | //============================================================ |
| 127 | 139 | // PROTOTYPES |
| 128 | 140 | //============================================================ |
| 129 | 141 | |
| 130 | 142 | static void SoftwarePicker_OnHeaderContextMenu(POINT pt, int nColumn); |
| 143 | static void SoftwareList_OnHeaderContextMenu(POINT pt, int nColumn); |
| 131 | 144 | |
| 132 | 145 | static LPCSTR SoftwareTabView_GetTabShortName(int tab); |
| 133 | 146 | static LPCSTR SoftwareTabView_GetTabLongName(int tab); |
| r8202 | r8203 | |
| 142 | 155 | static void SoftwarePicker_LeavingItem(HWND hwndSoftwarePicker, int nItem); |
| 143 | 156 | static void SoftwarePicker_EnteringItem(HWND hwndSoftwarePicker, int nItem); |
| 144 | 157 | |
| 158 | static int SoftwareList_GetItemImage(HWND hwndPicker, int nItem); |
| 159 | static void SoftwareList_LeavingItem(HWND hwndSoftwareList, int nItem); |
| 160 | static void SoftwareList_EnteringItem(HWND hwndSoftwareList, int nItem); |
| 161 | |
| 145 | 162 | static BOOL DevView_GetOpenFileName(HWND hwndDevView, const machine_config *config, const device_config *dev, LPTSTR pszFilename, UINT nFilenameLength); |
| 146 | 163 | static BOOL DevView_GetCreateFileName(HWND hwndDevView, const machine_config *config, const device_config *dev, LPTSTR pszFilename, UINT nFilenameLength); |
| 147 | 164 | static void DevView_SetSelectedSoftware(HWND hwndDevView, int nDriverIndex, const machine_config *config, const device_config *dev, LPCTSTR pszFilename); |
| r8202 | r8203 | |
| 157 | 174 | // PICKER/TABVIEW CALLBACKS |
| 158 | 175 | //============================================================ |
| 159 | 176 | |
| 160 | | static const struct PickerCallbacks s_softwareListCallbacks = |
| 177 | static const struct PickerCallbacks s_softwarePickerCallbacks = |
| 161 | 178 | { |
| 162 | 179 | SetMessSortColumn, // pfnSetSortColumn |
| 163 | 180 | GetMessSortColumn, // pfnGetSortColumn |
| r8202 | r8203 | |
| 186 | 203 | NULL // pfnOnBodyContextMenu |
| 187 | 204 | }; |
| 188 | 205 | |
| 206 | static 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 |
| 189 | 221 | |
| 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 | }; |
| 190 | 234 | |
| 235 | |
| 191 | 236 | static const struct TabViewCallbacks s_softwareTabViewCallbacks = |
| 192 | 237 | { |
| 193 | 238 | NULL, // pfnGetShowTabCtrl |
| r8202 | r8203 | |
| 620 | 665 | hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 621 | 666 | |
| 622 | 667 | memset(&opts, 0, sizeof(opts)); |
| 623 | | opts.pCallbacks = &s_softwareListCallbacks; |
| 668 | opts.pCallbacks = &s_softwarePickerCallbacks; |
| 624 | 669 | opts.nColumnCount = MESS_COLUMN_MAX; |
| 625 | 670 | opts.ppszColumnNames = mess_column_names; |
| 626 | 671 | SetupSoftwarePicker(hwndSoftware, &opts); |
| r8202 | r8203 | |
| 640 | 685 | }; |
| 641 | 686 | DevView_SetCallbacks(GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW), &s_devViewCallbacks); |
| 642 | 687 | } |
| 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 | |
| 643 | 702 | } |
| 644 | 703 | |
| 645 | 704 | |
| r8202 | r8203 | |
| 1051 | 1110 | |
| 1052 | 1111 | |
| 1053 | 1112 | // ------------------------------------------------------------------------ |
| 1054 | | // Software List Class |
| 1113 | // Software Picker Class |
| 1055 | 1114 | // ------------------------------------------------------------------------ |
| 1056 | 1115 | |
| 1057 | 1116 | static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem) |
| r8202 | r8203 | |
| 1143 | 1202 | } |
| 1144 | 1203 | |
| 1145 | 1204 | |
| 1205 | // ------------------------------------------------------------------------ |
| 1206 | // Software List Class |
| 1207 | // ------------------------------------------------------------------------ |
| 1146 | 1208 | |
| 1209 | static 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 | |
| 1246 | static 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 | |
| 1264 | static 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 | |
| 1147 | 1298 | // ------------------------------------------------------------------------ |
| 1148 | 1299 | // Header context menu stuff |
| 1149 | 1300 | // ------------------------------------------------------------------------ |
| r8202 | r8203 | |
| 1254 | 1405 | } |
| 1255 | 1406 | } |
| 1256 | 1407 | |
| 1408 | static void SoftwareList_OnHeaderContextMenu(POINT pt, int nColumn) |
| 1409 | { |
| 1410 | HMENU hMenu; |
| 1411 | HMENU hMenuLoad; |
| 1412 | HWND hwndPicker; |
| 1413 | int nMenuItem; |
| 1257 | 1414 | |
| 1415 | hMenuLoad = LoadMenu(NULL, MAKEINTRESOURCE(IDR_CONTEXT_HEADER)); |
| 1416 | hMenu = GetSubMenu(hMenuLoad, 0); |
| 1258 | 1417 | |
| 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 | |
| 1259 | 1451 | // ------------------------------------------------------------------------ |
| 1260 | 1452 | // MessCommand |
| 1261 | 1453 | // ------------------------------------------------------------------------ |
| r8202 | r8203 | |
| 1286 | 1478 | static LPCSTR s_tabs[] = |
| 1287 | 1479 | { |
| 1288 | 1480 | "picker\0Picker", |
| 1289 | | "devview\0Device View" |
| 1481 | "devview\0Device View", |
| 1482 | "softlist\0Software", |
| 1290 | 1483 | }; |
| 1291 | 1484 | |
| 1292 | 1485 | |
| r8202 | r8203 | |
| 1310 | 1503 | int nTab; |
| 1311 | 1504 | HWND hwndSoftwarePicker; |
| 1312 | 1505 | HWND hwndSoftwareDevView; |
| 1506 | HWND hwndSoftwareList; |
| 1313 | 1507 | |
| 1314 | 1508 | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 1315 | 1509 | hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW); |
| 1510 | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 1316 | 1511 | |
| 1317 | 1512 | nTab = TabView_GetCurrentTab(GetDlgItem(GetMainWindow(), IDC_SWTAB)); |
| 1318 | 1513 | |
| r8202 | r8203 | |
| 1321 | 1516 | case 0: |
| 1322 | 1517 | ShowWindow(hwndSoftwarePicker, SW_SHOW); |
| 1323 | 1518 | ShowWindow(hwndSoftwareDevView, SW_HIDE); |
| 1519 | ShowWindow(hwndSoftwareList, SW_HIDE); |
| 1324 | 1520 | break; |
| 1325 | 1521 | |
| 1326 | 1522 | case 1: |
| 1327 | 1523 | ShowWindow(hwndSoftwarePicker, SW_HIDE); |
| 1328 | 1524 | ShowWindow(hwndSoftwareDevView, SW_SHOW); |
| 1525 | ShowWindow(hwndSoftwareList, SW_HIDE); |
| 1329 | 1526 | break; |
| 1527 | case 2: |
| 1528 | ShowWindow(hwndSoftwarePicker, SW_HIDE); |
| 1529 | ShowWindow(hwndSoftwareDevView, SW_HIDE); |
| 1530 | ShowWindow(hwndSoftwareList, SW_SHOW); |
| 1531 | break; |
| 1330 | 1532 | } |
| 1331 | 1533 | } |
| 1332 | 1534 | |
| r8202 | r8203 | |
| 1337 | 1539 | HWND hwndSoftwareTabView; |
| 1338 | 1540 | HWND hwndSoftwarePicker; |
| 1339 | 1541 | HWND hwndSoftwareDevView; |
| 1542 | HWND hwndSoftwareList; |
| 1340 | 1543 | RECT rMain, rSoftwareTabView, rClient, rTab; |
| 1341 | 1544 | BOOL res; |
| 1342 | 1545 | |
| 1343 | 1546 | hwndSoftwareTabView = GetDlgItem(GetMainWindow(), IDC_SWTAB); |
| 1344 | 1547 | hwndSoftwarePicker = GetDlgItem(GetMainWindow(), IDC_SWLIST); |
| 1345 | 1548 | hwndSoftwareDevView = GetDlgItem(GetMainWindow(), IDC_SWDEVVIEW); |
| 1549 | hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SOFTLIST); |
| 1346 | 1550 | |
| 1347 | 1551 | GetWindowRect(hwndSoftwareTabView, &rSoftwareTabView); |
| 1348 | 1552 | GetClientRect(GetMainWindow(), &rMain); |
| r8202 | r8203 | |
| 1370 | 1574 | MoveWindow(hwndSoftwareDevView, rClient.left, rClient.top, |
| 1371 | 1575 | rClient.right - rClient.left, rClient.bottom - rClient.top, |
| 1372 | 1576 | TRUE); |
| 1577 | MoveWindow(hwndSoftwareList, rClient.left, rClient.top, |
| 1578 | rClient.right - rClient.left, rClient.bottom - rClient.top, |
| 1579 | TRUE); |
| 1373 | 1580 | } |
| 1374 | 1581 | |
| 1375 | 1582 | |
src/mess/osd/winui/softwarelist.c
| r0 | r8203 | |
| 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 | |
| 38 | typedef struct _file_info file_info; |
| 39 | struct _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 | |
| 53 | typedef struct _directory_search_info directory_search_info; |
| 54 | struct _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 | |
| 62 | typedef struct _software_list_info software_list_info; |
| 63 | struct _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 | |
| 81 | static const TCHAR software_list_property_name[] = TEXT("SWLIST"); |
| 82 | |
| 83 | |
| 84 | |
| 85 | //============================================================ |
| 86 | |
| 87 | static 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 | |
| 128 | static 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 | |
| 138 | LPCSTR 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 | |
| 149 | const 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 | |
| 162 | int 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 | |
| 178 | iodevice_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 | |
| 196 | void 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 | |
| 215 | static 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 | |
| 233 | static 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 | |
| 327 | static 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 | |
| 367 | static 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 | |
| 447 | error: |
| 448 | if (pInfo) |
| 449 | free(pInfo); |
| 450 | return FALSE; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | |
| 455 | static 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 | |
| 479 | static 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 | |
| 513 | BOOL 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 | |
| 526 | BOOL 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 | |
| 561 | static 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 | |
| 570 | static 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 | |
| 593 | void 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 | |
| 605 | static 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 | |
| 640 | BOOL 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 | |
| 730 | LPCTSTR 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 | |
| 816 | static 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 | |
| 837 | BOOL 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 | |
| 858 | error: |
| 859 | if (pPickerInfo) |
| 860 | free(pPickerInfo); |
| 861 | return FALSE; |
| 862 | } |