UpdateGraphicsListbox Updates the listbox that contains the custom textures. Make sure all double-pointer arguments passes in are set to NULL is they don't have memory allocated for them yet, because if they're not null this function will try to free up their memory
| 2402 | // are set to NULL is they don't have memory allocated for them yet, because if they're not null this function |
| 2403 | // will try to free up their memory |
| 2404 | bool UpdateGraphicsListbox(tCustomListInfo *cust_bmps, newuiListBox *lb, char *selected_name) { |
| 2405 | ASSERT(lb); |
| 2406 | lb->RemoveAll(); |
| 2407 | |
| 2408 | cust_bmps->Reset(); |
| 2409 | cust_bmps->custom_bitmap_list = lb; |
| 2410 | |
| 2411 | // get a list of custom textures |
| 2412 | int count = 0; |
| 2413 | bool ok_to_get_files; |
| 2414 | int total_files = 0; |
| 2415 | |
| 2416 | // build list |
| 2417 | char oldpath[_MAX_PATH]; |
| 2418 | |
| 2419 | ddio_GetWorkingDir(oldpath, _MAX_PATH); |
| 2420 | |
| 2421 | if (ddio_SetWorkingDir(LocalCustomGraphicsDir)) |
| 2422 | ok_to_get_files = true; |
| 2423 | else |
| 2424 | ok_to_get_files = false; |
| 2425 | |
| 2426 | if (ok_to_get_files) { |
| 2427 | // Get all the filenames |
| 2428 | int totalsize, size; |
| 2429 | int count, totalcount; |
| 2430 | |
| 2431 | //.oaf |
| 2432 | //.ogf |
| 2433 | count = totalcount = totalsize = total_files = 0; |
| 2434 | |
| 2435 | totalsize += FindAllFilesSize("*.oaf", &count); |
| 2436 | totalcount += count; |
| 2437 | totalsize += FindAllFilesSize("*.ogf", &count); |
| 2438 | totalcount += count; |
| 2439 | |
| 2440 | if (totalsize) { |
| 2441 | cust_bmps->needed_size = totalsize; |
| 2442 | total_files = totalcount; |
| 2443 | cust_bmps->files = (char *)mem_malloc(totalsize); |
| 2444 | if (cust_bmps->files) { |
| 2445 | size = 0; |
| 2446 | count = 0; |
| 2447 | |
| 2448 | size += FindAllFiles("*.oaf", &cust_bmps->files[size], totalcount, &count); |
| 2449 | totalcount -= count; |
| 2450 | size += FindAllFiles("*.ogf", &cust_bmps->files[size], totalcount, &count); |
| 2451 | totalcount -= count; |
| 2452 | } else |
| 2453 | mprintf(0, "Unable to allocate memory for %d bytes\n", totalsize); |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | count = total_files + 1; // make room for "None" |
| 2458 | |
| 2459 | char chosen_name[256], ext[256]; |
| 2460 | if (selected_name) { |
| 2461 | ddio_SplitPath(selected_name, NULL, chosen_name, ext); |
no test coverage detected