src/mess/osd/winui/softwarepicker.c
| r2468 | r2469 | |
| 41 | 41 | const device_config *device; |
| 42 | 42 | |
| 43 | 43 | // hash information |
| 44 | | char szHash[HASH_BUF_SIZE]; |
| 45 | | BOOL bHashRealized; |
| 46 | | const hash_info *pHashInfo; |
| 44 | char hash_string[HASH_BUF_SIZE]; |
| 45 | BOOL hash_realized; |
| 46 | const hash_info *hashinfo; |
| 47 | 47 | |
| 48 | | LPCSTR pszZipEntryName; |
| 49 | | LPCSTR pszSubName; |
| 50 | | char szFilename[1]; |
| 48 | const char *zip_entry_name; |
| 49 | const char *base_name; |
| 50 | char file_name[1]; |
| 51 | 51 | }; |
| 52 | 52 | |
| 53 | 53 | typedef struct _directory_search_info directory_search_info; |
| 54 | 54 | struct _directory_search_info |
| 55 | 55 | { |
| 56 | | directory_search_info *pNext; |
| 57 | | HANDLE hFind; |
| 56 | directory_search_info *next; |
| 57 | HANDLE find_handle; |
| 58 | 58 | WIN32_FIND_DATA fd; |
| 59 | | char szDirectory[1]; |
| 59 | char directory_name[1]; |
| 60 | 60 | }; |
| 61 | 61 | |
| 62 | 62 | typedef struct _software_picker_info software_picker_info; |
| 63 | 63 | struct _software_picker_info |
| 64 | 64 | { |
| 65 | | WNDPROC pfnOldWndProc; |
| 66 | | file_info **ppIndex; |
| 67 | | int nIndexLength; |
| 68 | | int nHashesRealized; |
| 69 | | int nCurrentPosition; |
| 70 | | directory_search_info *pFirstSearchInfo; |
| 71 | | directory_search_info *pLastSearchInfo; |
| 72 | | const game_driver *pDriver; |
| 73 | | machine_config *pConfig; |
| 74 | | hash_file *pHashFile; |
| 75 | | void (*pfnErrorProc)(const char *message); |
| 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 game_driver *driver; |
| 73 | machine_config *config; |
| 74 | hash_file *hashfile; |
| 75 | void (*error_callback)(const char *message); |
| 76 | 76 | }; |
| 77 | 77 | |
| 78 | 78 | |
| r2468 | r2469 | |
| 81 | 81 | // CONSTANTS |
| 82 | 82 | //============================================================ |
| 83 | 83 | |
| 84 | | static const TCHAR s_szSoftwarePickerProp[] = TEXT("SWPICKER"); |
| 84 | static const TCHAR software_picker_property_name[] = TEXT("SWPICKER"); |
| 85 | 85 | |
| 86 | 86 | |
| 87 | 87 | |
| r2468 | r2469 | |
| 131 | 131 | static software_picker_info *GetSoftwarePickerInfo(HWND hwndPicker) |
| 132 | 132 | { |
| 133 | 133 | HANDLE h; |
| 134 | | h = GetProp(hwndPicker, s_szSoftwarePickerProp); |
| 134 | h = GetProp(hwndPicker, software_picker_property_name); |
| 135 | 135 | assert(h); |
| 136 | 136 | return (software_picker_info *) h; |
| 137 | 137 | } |
| r2468 | r2469 | |
| 142 | 142 | { |
| 143 | 143 | software_picker_info *pPickerInfo; |
| 144 | 144 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 145 | | if ((nIndex < 0) || (nIndex >= pPickerInfo->nIndexLength)) |
| 145 | if ((nIndex < 0) || (nIndex >= pPickerInfo->file_index_length)) |
| 146 | 146 | return NULL; |
| 147 | | return pPickerInfo->ppIndex[nIndex]->szFilename; |
| 147 | return pPickerInfo->file_index[nIndex]->file_name; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
| r2468 | r2469 | |
| 153 | 153 | { |
| 154 | 154 | software_picker_info *pPickerInfo; |
| 155 | 155 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 156 | | if ((nIndex < 0) || (nIndex >= pPickerInfo->nIndexLength)) |
| 156 | if ((nIndex < 0) || (nIndex >= pPickerInfo->file_index_length)) |
| 157 | 157 | { |
| 158 | 158 | return NULL; |
| 159 | 159 | } |
| 160 | | return pPickerInfo->ppIndex[nIndex]->device; |
| 160 | return pPickerInfo->file_index[nIndex]->device; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
| r2468 | r2469 | |
| 168 | 168 | int i; |
| 169 | 169 | |
| 170 | 170 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 171 | | for (i = 0; i < pPickerInfo->nIndexLength; i++) |
| 171 | for (i = 0; i < pPickerInfo->file_index_length; i++) |
| 172 | 172 | { |
| 173 | | if (!mame_stricmp(pPickerInfo->ppIndex[i]->szFilename, pszFilename)) |
| 173 | if (!mame_stricmp(pPickerInfo->file_index[i]->file_name, pszFilename)) |
| 174 | 174 | return i; |
| 175 | 175 | } |
| 176 | 176 | return -1; |
| r2468 | r2469 | |
| 185 | 185 | |
| 186 | 186 | if (device != NULL) |
| 187 | 187 | { |
| 188 | | type = image_device_getinfo(GetSoftwarePickerInfo(hwndPicker)->pConfig, device).type; |
| 188 | type = image_device_getinfo(GetSoftwarePickerInfo(hwndPicker)->config, device).type; |
| 189 | 189 | } |
| 190 | 190 | else |
| 191 | 191 | { |
| r2468 | r2469 | |
| 196 | 196 | |
| 197 | 197 | |
| 198 | 198 | |
| 199 | | void SoftwarePicker_SetDriver(HWND hwndPicker, const game_driver *pDriver) |
| 199 | void SoftwarePicker_SetDriver(HWND hwndPicker, const game_driver *driver) |
| 200 | 200 | { |
| 201 | 201 | software_picker_info *pPickerInfo; |
| 202 | 202 | int i; |
| r2468 | r2469 | |
| 204 | 204 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 205 | 205 | |
| 206 | 206 | // did the driver change? |
| 207 | | if (pPickerInfo->pDriver != pDriver) |
| 207 | if (pPickerInfo->driver != driver) |
| 208 | 208 | { |
| 209 | 209 | // is there a hash file loaded? |
| 210 | | if (pPickerInfo->pHashFile != NULL) |
| 210 | if (pPickerInfo->hashfile != NULL) |
| 211 | 211 | { |
| 212 | 212 | // close down the file |
| 213 | | hashfile_close(pPickerInfo->pHashFile); |
| 214 | | pPickerInfo->pHashFile = NULL; |
| 213 | hashfile_close(pPickerInfo->hashfile); |
| 214 | pPickerInfo->hashfile = NULL; |
| 215 | 215 | |
| 216 | 216 | // invalidate the hash "realization" |
| 217 | | for (i = 0; i < pPickerInfo->nIndexLength; i++) |
| 217 | for (i = 0; i < pPickerInfo->file_index_length; i++) |
| 218 | 218 | { |
| 219 | | pPickerInfo->ppIndex[i]->pHashInfo = NULL; |
| 220 | | pPickerInfo->ppIndex[i]->bHashRealized = FALSE; |
| 219 | pPickerInfo->file_index[i]->hashinfo = NULL; |
| 220 | pPickerInfo->file_index[i]->hash_realized = FALSE; |
| 221 | 221 | } |
| 222 | | pPickerInfo->nHashesRealized = 0; |
| 222 | pPickerInfo->hashes_realized = 0; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // is there a machine_config loaded? |
| 226 | | if (pPickerInfo->pConfig != NULL) |
| 226 | if (pPickerInfo->config != NULL) |
| 227 | 227 | { |
| 228 | 228 | // free the machine_config |
| 229 | | machine_config_free(pPickerInfo->pConfig); |
| 230 | | pPickerInfo->pConfig = NULL; |
| 229 | machine_config_free(pPickerInfo->config); |
| 230 | pPickerInfo->config = NULL; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // change the driver value |
| 234 | | pPickerInfo->pDriver = pDriver; |
| 234 | pPickerInfo->driver = driver; |
| 235 | 235 | |
| 236 | 236 | // if we have a driver, we have to load some stuff |
| 237 | | if (pDriver != NULL) |
| 237 | if (driver != NULL) |
| 238 | 238 | { |
| 239 | 239 | // get the configuration |
| 240 | | pPickerInfo->pConfig = machine_config_alloc_with_mess_devices(pDriver); |
| 240 | pPickerInfo->config = machine_config_alloc_with_mess_devices(driver); |
| 241 | 241 | |
| 242 | 242 | // find a hash file |
| 243 | | while((pDriver != NULL) && !pPickerInfo->pHashFile) |
| 243 | while((driver != NULL) && !pPickerInfo->hashfile) |
| 244 | 244 | { |
| 245 | | pPickerInfo->pHashFile = hashfile_open_options(MameUIGlobal(), pDriver->name, TRUE, pPickerInfo->pfnErrorProc); |
| 246 | | pDriver = mess_next_compatible_driver(pDriver); |
| 245 | pPickerInfo->hashfile = hashfile_open_options(MameUIGlobal(), driver->name, TRUE, pPickerInfo->error_callback); |
| 246 | driver = mess_next_compatible_driver(driver); |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | } |
| r2468 | r2469 | |
| 251 | 251 | |
| 252 | 252 | |
| 253 | 253 | |
| 254 | | void SoftwarePicker_SetErrorProc(HWND hwndPicker, void (*pfnErrorProc)(const char *message)) |
| 254 | void SoftwarePicker_SetErrorProc(HWND hwndPicker, void (*error_callback)(const char *message)) |
| 255 | 255 | { |
| 256 | 256 | software_picker_info *pPickerInfo; |
| 257 | 257 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 258 | | pPickerInfo->pfnErrorProc = pfnErrorProc; |
| 258 | pPickerInfo->error_callback = error_callback; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
| r2468 | r2469 | |
| 267 | 267 | unsigned int functions; |
| 268 | 268 | |
| 269 | 269 | // get the device info |
| 270 | | info = image_device_getinfo(pPickerInfo->pConfig, pFileInfo->device); |
| 270 | info = image_device_getinfo(pPickerInfo->config, pFileInfo->device); |
| 271 | 271 | |
| 272 | 272 | // determine which functions to use |
| 273 | | functions = hashfile_functions_used(pPickerInfo->pHashFile, info.type); |
| 273 | functions = hashfile_functions_used(pPickerInfo->hashfile, info.type); |
| 274 | 274 | |
| 275 | 275 | // compute the hash |
| 276 | | image_device_compute_hash(pFileInfo->szHash, pFileInfo->device, pBuffer, nLength, functions); |
| 276 | image_device_compute_hash(pFileInfo->hash_string, pFileInfo->device, pBuffer, nLength, functions); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | |
| r2468 | r2469 | |
| 290 | 290 | LVFINDINFO lvfi; |
| 291 | 291 | |
| 292 | 292 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 293 | | assert((nIndex >= 0) && (nIndex < pPickerInfo->nIndexLength)); |
| 294 | | pFileInfo = pPickerInfo->ppIndex[nIndex]; |
| 293 | assert((nIndex >= 0) && (nIndex < pPickerInfo->file_index_length)); |
| 294 | pFileInfo = pPickerInfo->file_index[nIndex]; |
| 295 | 295 | |
| 296 | | if (pFileInfo->pszZipEntryName) |
| 296 | if (pFileInfo->zip_entry_name) |
| 297 | 297 | { |
| 298 | 298 | // this is in a ZIP file |
| 299 | 299 | zip_file *zip; |
| r2468 | r2469 | |
| 301 | 301 | const zip_file_header *zipent; |
| 302 | 302 | |
| 303 | 303 | // open the ZIP file |
| 304 | | nLength = pFileInfo->pszZipEntryName - pFileInfo->szFilename; |
| 304 | nLength = pFileInfo->zip_entry_name - pFileInfo->file_name; |
| 305 | 305 | pszZipName = (LPSTR) alloca(nLength); |
| 306 | | memcpy(pszZipName, pFileInfo->szFilename, nLength); |
| 306 | memcpy(pszZipName, pFileInfo->file_name, nLength); |
| 307 | 307 | pszZipName[nLength - 1] = '\0'; |
| 308 | 308 | |
| 309 | 309 | // get the entry name |
| r2468 | r2469 | |
| 313 | 313 | zipent = zip_file_first_file(zip); |
| 314 | 314 | while(!rc && zipent) |
| 315 | 315 | { |
| 316 | | if (!mame_stricmp(zipent->filename, pFileInfo->pszZipEntryName)) |
| 316 | if (!mame_stricmp(zipent->filename, pFileInfo->zip_entry_name)) |
| 317 | 317 | { |
| 318 | 318 | pBuffer = malloc(zipent->uncompressed_length); |
| 319 | 319 | if (pBuffer) |
| r2468 | r2469 | |
| 335 | 335 | else |
| 336 | 336 | { |
| 337 | 337 | // plain open file; map it into memory and calculate the hash |
| 338 | | hFile = win_create_file_utf8(pFileInfo->szFilename, GENERIC_READ, FILE_SHARE_READ, NULL, |
| 338 | hFile = win_create_file_utf8(pFileInfo->file_name, GENERIC_READ, FILE_SHARE_READ, NULL, |
| 339 | 339 | OPEN_EXISTING, 0, NULL); |
| 340 | 340 | if (hFile != INVALID_HANDLE_VALUE) |
| 341 | 341 | { |
| r2468 | r2469 | |
| 380 | 380 | iodevice_t type; |
| 381 | 381 | |
| 382 | 382 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 383 | | assert((nIndex >= 0) && (nIndex < pPickerInfo->nIndexLength)); |
| 384 | | pFileInfo = pPickerInfo->ppIndex[nIndex]; |
| 383 | assert((nIndex >= 0) && (nIndex < pPickerInfo->file_index_length)); |
| 384 | pFileInfo = pPickerInfo->file_index[nIndex]; |
| 385 | 385 | |
| 386 | 386 | // Determine which hash functions we need to use for this file, and which hashes |
| 387 | 387 | // have already been calculated |
| 388 | | if ((pPickerInfo->pHashFile != NULL) && (pFileInfo->device != NULL)) |
| 388 | if ((pPickerInfo->hashfile != NULL) && (pFileInfo->device != NULL)) |
| 389 | 389 | { |
| 390 | | image_device_info info = image_device_getinfo(pPickerInfo->pConfig, pFileInfo->device); |
| 390 | image_device_info info = image_device_getinfo(pPickerInfo->config, pFileInfo->device); |
| 391 | 391 | type = info.type; |
| 392 | 392 | if (type < IO_COUNT) |
| 393 | | nHashFunctionsUsed = hashfile_functions_used(pPickerInfo->pHashFile, type); |
| 394 | | nCalculatedHashes = hash_data_used_functions(pFileInfo->szHash); |
| 393 | nHashFunctionsUsed = hashfile_functions_used(pPickerInfo->hashfile, type); |
| 394 | nCalculatedHashes = hash_data_used_functions(pFileInfo->hash_string); |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // Did we fully compute all hashes? |
| 398 | 398 | if ((nHashFunctionsUsed & ~nCalculatedHashes) == 0) |
| 399 | 399 | { |
| 400 | 400 | // We have calculated all hashs for this file; mark it as realized |
| 401 | | pPickerInfo->ppIndex[nIndex]->bHashRealized = TRUE; |
| 402 | | pPickerInfo->nHashesRealized++; |
| 401 | pPickerInfo->file_index[nIndex]->hash_realized = TRUE; |
| 402 | pPickerInfo->hashes_realized++; |
| 403 | 403 | |
| 404 | | if (pPickerInfo->pHashFile) |
| 404 | if (pPickerInfo->hashfile) |
| 405 | 405 | { |
| 406 | | pPickerInfo->ppIndex[nIndex]->pHashInfo = hashfile_lookup(pPickerInfo->pHashFile, |
| 407 | | pPickerInfo->ppIndex[nIndex]->szHash); |
| 406 | pPickerInfo->file_index[nIndex]->hashinfo = hashfile_lookup(pPickerInfo->hashfile, |
| 407 | pPickerInfo->file_index[nIndex]->hash_string); |
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | } |
| r2468 | r2469 | |
| 430 | 430 | // look up the device |
| 431 | 431 | if (strrchr(pszFilename, '.')) |
| 432 | 432 | pszExtension = strrchr(pszFilename, '.'); |
| 433 | | if ((pszExtension != NULL) && (pPickerInfo->pDriver != NULL)) |
| 433 | if ((pszExtension != NULL) && (pPickerInfo->driver != NULL)) |
| 434 | 434 | { |
| 435 | | for (device = image_device_first(pPickerInfo->pConfig); device != NULL; device = image_device_next(device)) |
| 435 | for (device = image_device_first(pPickerInfo->config); device != NULL; device = image_device_next(device)) |
| 436 | 436 | { |
| 437 | 437 | if (image_device_uses_file_extension(device, pszExtension)) |
| 438 | 438 | break; |
| r2468 | r2469 | |
| 451 | 451 | memset(pInfo, 0, nSize); |
| 452 | 452 | |
| 453 | 453 | // copy the filename |
| 454 | | strcpy(pInfo->szFilename, pszFilename); |
| 454 | strcpy(pInfo->file_name, pszFilename); |
| 455 | 455 | |
| 456 | 456 | // set up device and CRC, if specified |
| 457 | 457 | pInfo->device = device; |
| 458 | | if ((device != NULL) && (image_device_getinfo(pPickerInfo->pConfig, device).has_partial_hash != 0)) |
| 458 | if ((device != NULL) && (image_device_getinfo(pPickerInfo->config, device).has_partial_hash != 0)) |
| 459 | 459 | nCrc = 0; |
| 460 | 460 | if (nCrc != 0) |
| 461 | | snprintf(pInfo->szHash, sizeof(pInfo->szHash) / sizeof(pInfo->szHash[0]), "c:%08x#", nCrc); |
| 461 | snprintf(pInfo->hash_string, sizeof(pInfo->hash_string) / sizeof(pInfo->hash_string[0]), "c:%08x#", nCrc); |
| 462 | 462 | |
| 463 | 463 | // set up zip entry name length, if specified |
| 464 | 464 | if (nZipEntryNameLength > 0) |
| 465 | | pInfo->pszZipEntryName = pInfo->szFilename + strlen(pInfo->szFilename) - nZipEntryNameLength; |
| 465 | pInfo->zip_entry_name = pInfo->file_name + strlen(pInfo->file_name) - nZipEntryNameLength; |
| 466 | 466 | |
| 467 | 467 | // calculate the subname |
| 468 | | pInfo->pszSubName = strrchr(pInfo->szFilename, '\\'); |
| 469 | | if (pInfo->pszSubName) |
| 470 | | pInfo->pszSubName++; |
| 468 | pInfo->base_name = strrchr(pInfo->file_name, '\\'); |
| 469 | if (pInfo->base_name) |
| 470 | pInfo->base_name++; |
| 471 | 471 | else |
| 472 | | pInfo->pszSubName = pInfo->szFilename; |
| 472 | pInfo->base_name = pInfo->file_name; |
| 473 | 473 | |
| 474 | | ppNewIndex = realloc(pPickerInfo->ppIndex, (pPickerInfo->nIndexLength + 1) * sizeof(*pPickerInfo->ppIndex)); |
| 474 | ppNewIndex = realloc(pPickerInfo->file_index, (pPickerInfo->file_index_length + 1) * sizeof(*pPickerInfo->file_index)); |
| 475 | 475 | if (!ppNewIndex) |
| 476 | 476 | goto error; |
| 477 | 477 | |
| 478 | | nIndex = pPickerInfo->nIndexLength++; |
| 479 | | pPickerInfo->ppIndex = ppNewIndex; |
| 480 | | pPickerInfo->ppIndex[nIndex] = pInfo; |
| 478 | nIndex = pPickerInfo->file_index_length++; |
| 479 | pPickerInfo->file_index = ppNewIndex; |
| 480 | pPickerInfo->file_index[nIndex] = pInfo; |
| 481 | 481 | |
| 482 | 482 | // Realize the hash |
| 483 | 483 | SoftwarePicker_RealizeHash(hwndPicker, nIndex); |
| r2468 | r2469 | |
| 584 | 584 | if (!pSearchInfo) |
| 585 | 585 | return FALSE; |
| 586 | 586 | memset(pSearchInfo, 0, nSearchInfoSize); |
| 587 | | pSearchInfo->hFind = INVALID_HANDLE_VALUE; |
| 587 | pSearchInfo->find_handle = INVALID_HANDLE_VALUE; |
| 588 | 588 | |
| 589 | | strcpy(pSearchInfo->szDirectory, pszDirectory); |
| 589 | strcpy(pSearchInfo->directory_name, pszDirectory); |
| 590 | 590 | |
| 591 | 591 | // insert into linked list |
| 592 | | if (pPickerInfo->pLastSearchInfo) |
| 593 | | ppLast = &pPickerInfo->pLastSearchInfo->pNext; |
| 592 | if (pPickerInfo->last_search_info) |
| 593 | ppLast = &pPickerInfo->last_search_info->next; |
| 594 | 594 | else |
| 595 | | ppLast = &pPickerInfo->pFirstSearchInfo; |
| 595 | ppLast = &pPickerInfo->first_search_info; |
| 596 | 596 | *ppLast = pSearchInfo; |
| 597 | | pPickerInfo->pLastSearchInfo = pSearchInfo; |
| 597 | pPickerInfo->last_search_info = pSearchInfo; |
| 598 | 598 | return TRUE; |
| 599 | 599 | } |
| 600 | 600 | |
| r2468 | r2469 | |
| 602 | 602 | |
| 603 | 603 | static void SoftwarePicker_FreeSearchInfo(directory_search_info *pSearchInfo) |
| 604 | 604 | { |
| 605 | | if (pSearchInfo->hFind != INVALID_HANDLE_VALUE) |
| 606 | | FindClose(pSearchInfo->hFind); |
| 605 | if (pSearchInfo->find_handle != INVALID_HANDLE_VALUE) |
| 606 | FindClose(pSearchInfo->find_handle); |
| 607 | 607 | free(pSearchInfo); |
| 608 | 608 | } |
| 609 | 609 | |
| r2468 | r2469 | |
| 614 | 614 | directory_search_info *p; |
| 615 | 615 | int i; |
| 616 | 616 | |
| 617 | | for (i = 0; i < pPickerInfo->nIndexLength; i++) |
| 618 | | free(pPickerInfo->ppIndex[i]); |
| 617 | for (i = 0; i < pPickerInfo->file_index_length; i++) |
| 618 | free(pPickerInfo->file_index[i]); |
| 619 | 619 | |
| 620 | | while(pPickerInfo->pFirstSearchInfo) |
| 620 | while(pPickerInfo->first_search_info) |
| 621 | 621 | { |
| 622 | | p = pPickerInfo->pFirstSearchInfo->pNext; |
| 623 | | SoftwarePicker_FreeSearchInfo(pPickerInfo->pFirstSearchInfo); |
| 624 | | pPickerInfo->pFirstSearchInfo = p; |
| 622 | p = pPickerInfo->first_search_info->next; |
| 623 | SoftwarePicker_FreeSearchInfo(pPickerInfo->first_search_info); |
| 624 | pPickerInfo->first_search_info = p; |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | | pPickerInfo->ppIndex = NULL; |
| 628 | | pPickerInfo->nIndexLength = 0; |
| 629 | | pPickerInfo->nCurrentPosition = 0; |
| 630 | | pPickerInfo->pLastSearchInfo = NULL; |
| 627 | pPickerInfo->file_index = NULL; |
| 628 | pPickerInfo->file_index_length = 0; |
| 629 | pPickerInfo->current_position = 0; |
| 630 | pPickerInfo->last_search_info = NULL; |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | |
| r2468 | r2469 | |
| 661 | 661 | return TRUE; |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | | pszFilename = alloca(strlen(pSearchInfo->szDirectory) + 1 + strlen(utf8_FileName) + 1); |
| 665 | | strcpy(pszFilename, pSearchInfo->szDirectory); |
| 664 | pszFilename = alloca(strlen(pSearchInfo->directory_name) + 1 + strlen(utf8_FileName) + 1); |
| 665 | strcpy(pszFilename, pSearchInfo->directory_name); |
| 666 | 666 | strcat(pszFilename, "\\"); |
| 667 | 667 | strcat(pszFilename, utf8_FileName); |
| 668 | 668 | |
| r2468 | r2469 | |
| 691 | 691 | |
| 692 | 692 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 693 | 693 | |
| 694 | | pSearchInfo = pPickerInfo->pFirstSearchInfo; |
| 694 | pSearchInfo = pPickerInfo->first_search_info; |
| 695 | 695 | if (pSearchInfo) |
| 696 | 696 | { |
| 697 | 697 | // searching through directories |
| 698 | | if (pSearchInfo->hFind != INVALID_HANDLE_VALUE) |
| 698 | if (pSearchInfo->find_handle != INVALID_HANDLE_VALUE) |
| 699 | 699 | { |
| 700 | | bSuccess = FindNextFile(pSearchInfo->hFind, &pSearchInfo->fd); |
| 700 | bSuccess = FindNextFile(pSearchInfo->find_handle, &pSearchInfo->fd); |
| 701 | 701 | } |
| 702 | 702 | else |
| 703 | 703 | { |
| 704 | | pszFilter = alloca(strlen(pSearchInfo->szDirectory) + strlen(szWildcards) + 1); |
| 705 | | strcpy(pszFilter, pSearchInfo->szDirectory); |
| 704 | pszFilter = alloca(strlen(pSearchInfo->directory_name) + strlen(szWildcards) + 1); |
| 705 | strcpy(pszFilter, pSearchInfo->directory_name); |
| 706 | 706 | strcat(pszFilter, szWildcards); |
| 707 | | pSearchInfo->hFind = win_find_first_file_utf8(pszFilter, &pSearchInfo->fd); |
| 708 | | bSuccess = pSearchInfo->hFind != INVALID_HANDLE_VALUE; |
| 707 | pSearchInfo->find_handle = win_find_first_file_utf8(pszFilter, &pSearchInfo->fd); |
| 708 | bSuccess = pSearchInfo->find_handle != INVALID_HANDLE_VALUE; |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | if (bSuccess) |
| r2468 | r2469 | |
| 714 | 714 | } |
| 715 | 715 | else |
| 716 | 716 | { |
| 717 | | pPickerInfo->pFirstSearchInfo = pSearchInfo->pNext; |
| 718 | | if (!pPickerInfo->pFirstSearchInfo) |
| 719 | | pPickerInfo->pLastSearchInfo = NULL; |
| 717 | pPickerInfo->first_search_info = pSearchInfo->next; |
| 718 | if (!pPickerInfo->first_search_info) |
| 719 | pPickerInfo->last_search_info = NULL; |
| 720 | 720 | SoftwarePicker_FreeSearchInfo(pSearchInfo); |
| 721 | 721 | } |
| 722 | 722 | } |
| 723 | | else if (pPickerInfo->pHashFile && (pPickerInfo->nHashesRealized |
| 724 | | < pPickerInfo->nIndexLength)) |
| 723 | else if (pPickerInfo->hashfile && (pPickerInfo->hashes_realized |
| 724 | < pPickerInfo->file_index_length)) |
| 725 | 725 | { |
| 726 | 726 | // time to realize some hashes |
| 727 | 727 | nCount = 100; |
| 728 | 728 | |
| 729 | | while((nCount > 0) && pPickerInfo->ppIndex[pPickerInfo->nCurrentPosition]->bHashRealized) |
| 729 | while((nCount > 0) && pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized) |
| 730 | 730 | { |
| 731 | | pPickerInfo->nCurrentPosition++; |
| 732 | | pPickerInfo->nCurrentPosition %= pPickerInfo->nIndexLength; |
| 731 | pPickerInfo->current_position++; |
| 732 | pPickerInfo->current_position %= pPickerInfo->file_index_length; |
| 733 | 733 | nCount--; |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | | pFileInfo = pPickerInfo->ppIndex[pPickerInfo->nCurrentPosition]; |
| 737 | | if (!pFileInfo->bHashRealized) |
| 736 | pFileInfo = pPickerInfo->file_index[pPickerInfo->current_position]; |
| 737 | if (!pFileInfo->hash_realized) |
| 738 | 738 | { |
| 739 | 739 | type = mess_device_from_core_device(pFileInfo->device)->type; |
| 740 | | if (hashfile_functions_used(pPickerInfo->pHashFile, type)) |
| 740 | if (hashfile_functions_used(pPickerInfo->hashfile, type)) |
| 741 | 741 | { |
| 742 | 742 | // only calculate the hash if it is appropriate for this device |
| 743 | | if (!SoftwarePicker_CalculateHash(hwndPicker, pPickerInfo->nCurrentPosition)) |
| 743 | if (!SoftwarePicker_CalculateHash(hwndPicker, pPickerInfo->current_position)) |
| 744 | 744 | return FALSE; |
| 745 | 745 | } |
| 746 | | SoftwarePicker_RealizeHash(hwndPicker, pPickerInfo->nCurrentPosition); |
| 746 | SoftwarePicker_RealizeHash(hwndPicker, pPickerInfo->current_position); |
| 747 | 747 | |
| 748 | 748 | // under normal circumstances this will be redundant, but in the unlikely |
| 749 | 749 | // event of a failure, we do not want to keep running into a brick wall |
| 750 | 750 | // by calculating this hash over and over |
| 751 | | if (!pPickerInfo->ppIndex[pPickerInfo->nCurrentPosition]->bHashRealized) |
| 751 | if (!pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized) |
| 752 | 752 | { |
| 753 | | pPickerInfo->ppIndex[pPickerInfo->nCurrentPosition]->bHashRealized = TRUE; |
| 754 | | pPickerInfo->nHashesRealized++; |
| 753 | pPickerInfo->file_index[pPickerInfo->current_position]->hash_realized = TRUE; |
| 754 | pPickerInfo->hashes_realized++; |
| 755 | 755 | } |
| 756 | 756 | } |
| 757 | 757 | } |
| r2468 | r2469 | |
| 778 | 778 | TCHAR* t_buf; |
| 779 | 779 | |
| 780 | 780 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 781 | | if ((nRow < 0) || (nRow >= pPickerInfo->nIndexLength)) |
| 781 | if ((nRow < 0) || (nRow >= pPickerInfo->file_index_length)) |
| 782 | 782 | return NULL; |
| 783 | 783 | |
| 784 | | pFileInfo = pPickerInfo->ppIndex[nRow]; |
| 784 | pFileInfo = pPickerInfo->file_index[nRow]; |
| 785 | 785 | |
| 786 | 786 | switch(nColumn) |
| 787 | 787 | { |
| 788 | 788 | case MESS_COLUMN_IMAGES: |
| 789 | | t_buf = tstring_from_utf8(pFileInfo->pszSubName); |
| 789 | t_buf = tstring_from_utf8(pFileInfo->base_name); |
| 790 | 790 | if( !t_buf ) |
| 791 | 791 | return s; |
| 792 | 792 | _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf); |
| r2468 | r2469 | |
| 798 | 798 | case MESS_COLUMN_MANUFACTURER: |
| 799 | 799 | case MESS_COLUMN_YEAR: |
| 800 | 800 | case MESS_COLUMN_PLAYABLE: |
| 801 | | if (pFileInfo->pHashInfo) |
| 801 | if (pFileInfo->hashinfo) |
| 802 | 802 | { |
| 803 | 803 | switch(nColumn) |
| 804 | 804 | { |
| 805 | 805 | case MESS_COLUMN_GOODNAME: |
| 806 | | pszUtf8 = pFileInfo->pHashInfo->longname; |
| 806 | pszUtf8 = pFileInfo->hashinfo->longname; |
| 807 | 807 | break; |
| 808 | 808 | case MESS_COLUMN_MANUFACTURER: |
| 809 | | pszUtf8 = pFileInfo->pHashInfo->manufacturer; |
| 809 | pszUtf8 = pFileInfo->hashinfo->manufacturer; |
| 810 | 810 | break; |
| 811 | 811 | case MESS_COLUMN_YEAR: |
| 812 | | pszUtf8 = pFileInfo->pHashInfo->year; |
| 812 | pszUtf8 = pFileInfo->hashinfo->year; |
| 813 | 813 | break; |
| 814 | 814 | case MESS_COLUMN_PLAYABLE: |
| 815 | | pszUtf8 = pFileInfo->pHashInfo->playable; |
| 815 | pszUtf8 = pFileInfo->hashinfo->playable; |
| 816 | 816 | break; |
| 817 | 817 | } |
| 818 | 818 | if (pszUtf8) |
| r2468 | r2469 | |
| 836 | 836 | case MESS_COLUMN_MD5: nHashFunction = HASH_MD5; break; |
| 837 | 837 | case MESS_COLUMN_SHA1: nHashFunction = HASH_SHA1; break; |
| 838 | 838 | } |
| 839 | | if (hash_data_extract_printable_checksum(pFileInfo->szHash, nHashFunction, szBuffer)) |
| 839 | if (hash_data_extract_printable_checksum(pFileInfo->hash_string, nHashFunction, szBuffer)) |
| 840 | 840 | { |
| 841 | 841 | t_buf = tstring_from_utf8(szBuffer); |
| 842 | 842 | if( !t_buf ) |
| r2468 | r2469 | |
| 859 | 859 | LRESULT rc; |
| 860 | 860 | |
| 861 | 861 | pPickerInfo = GetSoftwarePickerInfo(hwndPicker); |
| 862 | | rc = CallWindowProc(pPickerInfo->pfnOldWndProc, hwndPicker, nMessage, wParam, lParam); |
| 862 | rc = CallWindowProc(pPickerInfo->old_window_proc, hwndPicker, nMessage, wParam, lParam); |
| 863 | 863 | |
| 864 | 864 | if (nMessage == WM_DESTROY) |
| 865 | 865 | { |
| r2468 | r2469 | |
| 886 | 886 | goto error; |
| 887 | 887 | memset(pPickerInfo, 0, sizeof(*pPickerInfo)); |
| 888 | 888 | |
| 889 | | if (!SetProp(hwndPicker, s_szSoftwarePickerProp, (HANDLE) pPickerInfo)) |
| 889 | if (!SetProp(hwndPicker, software_picker_property_name, (HANDLE) pPickerInfo)) |
| 890 | 890 | goto error; |
| 891 | 891 | |
| 892 | 892 | l = (LONG_PTR) SoftwarePicker_WndProc; |
| 893 | 893 | l = SetWindowLongPtr(hwndPicker, GWLP_WNDPROC, l); |
| 894 | | pPickerInfo->pfnOldWndProc = (WNDPROC) l; |
| 894 | pPickerInfo->old_window_proc = (WNDPROC) l; |
| 895 | 895 | return TRUE; |
| 896 | 896 | |
| 897 | 897 | error: |