src/mess/osd/winui/softwarepicker.c
| r2259 | r2260 | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | | struct FileInfo |
| 34 | //============================================================ |
| 35 | // TYPE DEFINITIONS |
| 36 | //============================================================ |
| 37 | |
| 38 | typedef struct _file_info file_info; |
| 39 | struct _file_info |
| 35 | 40 | { |
| 36 | 41 | mess_device_class devclass; |
| 37 | 42 | |
| r2259 | r2260 | |
| 45 | 50 | char szFilename[1]; |
| 46 | 51 | }; |
| 47 | 52 | |
| 48 | | struct DirectorySearchInfo |
| 53 | typedef struct _directory_search_info directory_search_info; |
| 54 | struct _directory_search_info |
| 49 | 55 | { |
| 50 | | struct DirectorySearchInfo *pNext; |
| 56 | directory_search_info *pNext; |
| 51 | 57 | HANDLE hFind; |
| 52 | 58 | WIN32_FIND_DATA fd; |
| 53 | 59 | char szDirectory[1]; |
| 54 | 60 | }; |
| 55 | 61 | |
| 56 | | struct SoftwarePickerInfo |
| 62 | typedef struct _software_picker_info software_picker_info; |
| 63 | struct _software_picker_info |
| 57 | 64 | { |
| 58 | 65 | WNDPROC pfnOldWndProc; |
| 59 | | struct FileInfo **ppIndex; |
| 66 | file_info **ppIndex; |
| 60 | 67 | int nIndexLength; |
| 61 | 68 | int nHashesRealized; |
| 62 | 69 | int nCurrentPosition; |
| 63 | | struct DirectorySearchInfo *pFirstSearchInfo; |
| 64 | | struct DirectorySearchInfo *pLastSearchInfo; |
| 70 | directory_search_info *pFirstSearchInfo; |
| 71 | directory_search_info *pLastSearchInfo; |
| 65 | 72 | const game_driver *pDriver; |
| 66 | 73 | machine_config *pConfig; |
| 67 | 74 | hash_file *pHashFile; |
| r2259 | r2260 | |
| 70 | 77 | |
| 71 | 78 | |
| 72 | 79 | |
| 80 | //============================================================ |
| 81 | // CONSTANTS |
| 82 | //============================================================ |
| 83 | |
| 73 | 84 | static const TCHAR s_szSoftwarePickerProp[] = TEXT("SWPICKER"); |
| 74 | 85 | |
| 75 | 86 | |
| 76 | 87 | |
| 88 | //============================================================ |
| 89 | |
| 77 | 90 | static LPCSTR NormalizePath(LPCSTR pszPath, LPSTR pszBuffer, size_t nBufferSize) |
| 78 | 91 | { |
| 79 | 92 | BOOL bChanged = FALSE; |
| r2259 | r2260 | |
| 115 | 128 | |
| 116 | 129 | |
| 117 | 130 | |
| 118 | | static struct SoftwarePickerInfo *GetSoftwarePickerInfo(HWND hwndPicker) |
| 131 | static software_picker_info *GetSoftwarePickerInfo(HWND hwndPicker) |
| 119 | 132 | { |
| 120 | 133 | HANDLE h; |
| 121 | 134 | h = GetProp(hwndPicker, s_szSoftwarePickerProp); |
| 122 | 135 | assert(h); |
| 123 | | return (struct SoftwarePickerInfo *) h; |
| 136 | return (software_picker_info *) h; |
| 124 | 137 | } |
| 125 | 138 | |
| 126 | 139 | |
| 127 | 140 | |
| 128 | 141 | LPCSTR SoftwarePicker_LookupFilename(HWND hwndPicker, int nIndex) |
| 129 | 142 | { |
| 130 | | struct SoftwarePickerInfo *pPickerInfo; |
| 143 | software_picker_info *pPickerInfo; |
| 131 | 144 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 132 | 145 | if ((nIndex < 0) || (nIndex >= pPickerInfo->nIndexLength)) |
| 133 | 146 | return NULL; |
| r2259 | r2260 | |
| 138 | 151 | |
| 139 | 152 | mess_device_class SoftwarePicker_LookupDevice(HWND hwndPicker, int nIndex) |
| 140 | 153 | { |
| 141 | | struct SoftwarePickerInfo *pPickerInfo; |
| 154 | software_picker_info *pPickerInfo; |
| 142 | 155 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 143 | 156 | if ((nIndex < 0) || (nIndex >= pPickerInfo->nIndexLength)) |
| 144 | 157 | { |
| r2259 | r2260 | |
| 153 | 166 | |
| 154 | 167 | int SoftwarePicker_LookupIndex(HWND hwndPicker, LPCSTR pszFilename) |
| 155 | 168 | { |
| 156 | | struct SoftwarePickerInfo *pPickerInfo; |
| 169 | software_picker_info *pPickerInfo; |
| 157 | 170 | int i; |
| 158 | 171 | |
| 159 | 172 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| r2259 | r2260 | |
| 169 | 182 | |
| 170 | 183 | iodevice_t SoftwarePicker_GetImageType(HWND hwndPicker, int nIndex) |
| 171 | 184 | { |
| 172 | | struct SoftwarePickerInfo *pPickerInfo; |
| 185 | software_picker_info *pPickerInfo; |
| 173 | 186 | const mess_device_class *devclass; |
| 174 | 187 | |
| 175 | 188 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| r2259 | r2260 | |
| 186 | 199 | |
| 187 | 200 | void SoftwarePicker_SetDriver(HWND hwndPicker, const game_driver *pDriver) |
| 188 | 201 | { |
| 189 | | struct SoftwarePickerInfo *pPickerInfo; |
| 202 | software_picker_info *pPickerInfo; |
| 190 | 203 | int i; |
| 191 | 204 | |
| 192 | 205 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| r2259 | r2260 | |
| 241 | 254 | |
| 242 | 255 | void SoftwarePicker_SetErrorProc(HWND hwndPicker, void (*pfnErrorProc)(const char *message)) |
| 243 | 256 | { |
| 244 | | struct SoftwarePickerInfo *pPickerInfo; |
| 257 | software_picker_info *pPickerInfo; |
| 245 | 258 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 246 | 259 | pPickerInfo->pfnErrorProc = pfnErrorProc; |
| 247 | 260 | } |
| 248 | 261 | |
| 249 | 262 | |
| 250 | 263 | |
| 251 | | static void ComputeFileHash(struct SoftwarePickerInfo *pPickerInfo, |
| 252 | | struct FileInfo *pFileInfo, const unsigned char *pBuffer, unsigned int nLength) |
| 264 | static void ComputeFileHash(software_picker_info *pPickerInfo, |
| 265 | file_info *pFileInfo, const unsigned char *pBuffer, unsigned int nLength) |
| 253 | 266 | { |
| 254 | 267 | unsigned int nFunctions; |
| 255 | 268 | iodevice_t type; |
| r2259 | r2260 | |
| 274 | 287 | |
| 275 | 288 | static BOOL SoftwarePicker_CalculateHash(HWND hwndPicker, int nIndex) |
| 276 | 289 | { |
| 277 | | struct SoftwarePickerInfo *pPickerInfo; |
| 278 | | struct FileInfo *pFileInfo; |
| 290 | software_picker_info *pPickerInfo; |
| 291 | file_info *pFileInfo; |
| 279 | 292 | LPSTR pszZipName; |
| 280 | 293 | BOOL rc = FALSE; |
| 281 | 294 | unsigned char *pBuffer; |
| r2259 | r2260 | |
| 367 | 380 | |
| 368 | 381 | static void SoftwarePicker_RealizeHash(HWND hwndPicker, int nIndex) |
| 369 | 382 | { |
| 370 | | struct SoftwarePickerInfo *pPickerInfo; |
| 371 | | struct FileInfo *pFileInfo; |
| 383 | software_picker_info *pPickerInfo; |
| 384 | file_info *pFileInfo; |
| 372 | 385 | unsigned int nHashFunctionsUsed = 0; |
| 373 | 386 | unsigned int nCalculatedHashes = 0; |
| 374 | 387 | iodevice_t type; |
| r2259 | r2260 | |
| 407 | 420 | static BOOL SoftwarePicker_AddFileEntry(HWND hwndPicker, LPCSTR pszFilename, |
| 408 | 421 | UINT nZipEntryNameLength, UINT32 nCrc, BOOL bForce) |
| 409 | 422 | { |
| 410 | | struct SoftwarePickerInfo *pPickerInfo; |
| 411 | | struct FileInfo **ppNewIndex; |
| 412 | | struct FileInfo *pInfo; |
| 423 | software_picker_info *pPickerInfo; |
| 424 | file_info **ppNewIndex; |
| 425 | file_info *pInfo; |
| 413 | 426 | int nIndex, nSize; |
| 414 | 427 | LPCSTR pszExtension = NULL, s; |
| 415 | 428 | mess_device_class devclass = {0,}; |
| r2259 | r2260 | |
| 452 | 465 | return TRUE; |
| 453 | 466 | |
| 454 | 467 | // create the FileInfo structure |
| 455 | | nSize = sizeof(struct FileInfo) + strlen(pszFilename); |
| 456 | | pInfo = (struct FileInfo *) malloc(nSize); |
| 468 | nSize = sizeof(file_info) + strlen(pszFilename); |
| 469 | pInfo = (file_info *) malloc(nSize); |
| 457 | 470 | if (!pInfo) |
| 458 | 471 | goto error; |
| 459 | 472 | memset(pInfo, 0, nSize); |
| r2259 | r2260 | |
| 575 | 588 | |
| 576 | 589 | BOOL SoftwarePicker_AddDirectory(HWND hwndPicker, LPCSTR pszDirectory) |
| 577 | 590 | { |
| 578 | | struct SoftwarePickerInfo *pPickerInfo; |
| 579 | | struct DirectorySearchInfo *pSearchInfo; |
| 580 | | struct DirectorySearchInfo **ppLast; |
| 591 | software_picker_info *pPickerInfo; |
| 592 | directory_search_info *pSearchInfo; |
| 593 | directory_search_info **ppLast; |
| 581 | 594 | size_t nSearchInfoSize; |
| 582 | 595 | char szBuffer[MAX_PATH]; |
| 583 | 596 | |
| r2259 | r2260 | |
| 587 | 600 | Picker_ResetIdle(hwndPicker); |
| 588 | 601 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 589 | 602 | |
| 590 | | nSearchInfoSize = sizeof(struct DirectorySearchInfo) + strlen(pszDirectory); |
| 603 | nSearchInfoSize = sizeof(directory_search_info) + strlen(pszDirectory); |
| 591 | 604 | pSearchInfo = malloc(nSearchInfoSize); |
| 592 | 605 | if (!pSearchInfo) |
| 593 | 606 | return FALSE; |
| r2259 | r2260 | |
| 608 | 621 | |
| 609 | 622 | |
| 610 | 623 | |
| 611 | | static void SoftwarePicker_FreeSearchInfo(struct DirectorySearchInfo *pSearchInfo) |
| 624 | static void SoftwarePicker_FreeSearchInfo(directory_search_info *pSearchInfo) |
| 612 | 625 | { |
| 613 | 626 | if (pSearchInfo->hFind != INVALID_HANDLE_VALUE) |
| 614 | 627 | FindClose(pSearchInfo->hFind); |
| r2259 | r2260 | |
| 617 | 630 | |
| 618 | 631 | |
| 619 | 632 | |
| 620 | | static void SoftwarePicker_InternalClear(struct SoftwarePickerInfo *pPickerInfo) |
| 633 | static void SoftwarePicker_InternalClear(software_picker_info *pPickerInfo) |
| 621 | 634 | { |
| 622 | | struct DirectorySearchInfo *p; |
| 635 | directory_search_info *p; |
| 623 | 636 | int i; |
| 624 | 637 | |
| 625 | 638 | for (i = 0; i < pPickerInfo->nIndexLength; i++) |
| r2259 | r2260 | |
| 642 | 655 | |
| 643 | 656 | void SoftwarePicker_Clear(HWND hwndPicker) |
| 644 | 657 | { |
| 645 | | struct SoftwarePickerInfo *pPickerInfo; |
| 658 | software_picker_info *pPickerInfo; |
| 646 | 659 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 647 | 660 | SoftwarePicker_InternalClear(pPickerInfo); |
| 648 | 661 | ListView_DeleteAllItems(hwndPicker); |
| r2259 | r2260 | |
| 651 | 664 | |
| 652 | 665 | |
| 653 | 666 | static BOOL SoftwarePicker_AddEntry(HWND hwndPicker, |
| 654 | | struct DirectorySearchInfo *pSearchInfo) |
| 667 | directory_search_info *pSearchInfo) |
| 655 | 668 | { |
| 656 | | struct SoftwarePickerInfo *pPickerInfo; |
| 669 | software_picker_info *pPickerInfo; |
| 657 | 670 | LPSTR pszFilename; |
| 658 | 671 | BOOL rc; |
| 659 | 672 | char* utf8_FileName; |
| r2259 | r2260 | |
| 687 | 700 | |
| 688 | 701 | BOOL SoftwarePicker_Idle(HWND hwndPicker) |
| 689 | 702 | { |
| 690 | | struct SoftwarePickerInfo *pPickerInfo; |
| 691 | | struct FileInfo *pFileInfo; |
| 703 | software_picker_info *pPickerInfo; |
| 704 | file_info *pFileInfo; |
| 692 | 705 | static const char szWildcards[] = "\\*.*"; |
| 693 | | struct DirectorySearchInfo *pSearchInfo; |
| 706 | directory_search_info *pSearchInfo; |
| 694 | 707 | LPSTR pszFilter; |
| 695 | 708 | BOOL bSuccess; |
| 696 | 709 | int nCount; |
| r2259 | r2260 | |
| 777 | 790 | LPCTSTR SoftwarePicker_GetItemString(HWND hwndPicker, int nRow, int nColumn, |
| 778 | 791 | TCHAR *pszBuffer, UINT nBufferLength) |
| 779 | 792 | { |
| 780 | | struct SoftwarePickerInfo *pPickerInfo; |
| 781 | | const struct FileInfo *pFileInfo; |
| 793 | software_picker_info *pPickerInfo; |
| 794 | const file_info *pFileInfo; |
| 782 | 795 | LPCTSTR s = NULL; |
| 783 | 796 | const char *pszUtf8 = NULL; |
| 784 | 797 | unsigned int nHashFunction = 0; |
| r2259 | r2260 | |
| 863 | 876 | static LRESULT CALLBACK SoftwarePicker_WndProc(HWND hwndPicker, UINT nMessage, |
| 864 | 877 | WPARAM wParam, LPARAM lParam) |
| 865 | 878 | { |
| 866 | | struct SoftwarePickerInfo *pPickerInfo; |
| 879 | software_picker_info *pPickerInfo; |
| 867 | 880 | LRESULT rc; |
| 868 | 881 | |
| 869 | 882 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| r2259 | r2260 | |
| 883 | 896 | |
| 884 | 897 | BOOL SetupSoftwarePicker(HWND hwndPicker, const struct PickerOptions *pOptions) |
| 885 | 898 | { |
| 886 | | struct SoftwarePickerInfo *pPickerInfo = NULL; |
| 899 | software_picker_info *pPickerInfo = NULL; |
| 887 | 900 | LONG_PTR l; |
| 888 | 901 | |
| 889 | 902 | if (!SetupPicker(hwndPicker, pOptions)) |