src/mess/image.c
| r2879 | r2880 | |
| 578 | 578 | { |
| 579 | 579 | image_error_t err = IMAGE_ERROR_SUCCESS; |
| 580 | 580 | astring *alloc_filename = NULL; |
| 581 | char *full_filename = NULL; |
| 581 | 582 | char *new_name; |
| 582 | 583 | char *new_dir; |
| 583 | 584 | char *new_working_directory; |
| 584 | 585 | int pos; |
| 585 | 586 | |
| 587 | /* get the full path */ |
| 588 | if (osd_get_full_path(&full_filename, filename) == FILERR_NONE) |
| 589 | filename = full_filename; |
| 590 | |
| 586 | 591 | /* create the directory string */ |
| 587 | 592 | new_dir = filename ? image_strdup(image->dev, filename) : NULL; |
| 588 | 593 | for (pos = strlen(new_dir); (pos > 0); pos--) |
| r2879 | r2880 | |
| 631 | 636 | done: |
| 632 | 637 | if (alloc_filename != NULL) |
| 633 | 638 | astring_free(alloc_filename); |
| 639 | if (full_filename != NULL) |
| 640 | free(full_filename); |
| 634 | 641 | return err; |
| 635 | 642 | } |
| 636 | 643 | |
| r2879 | r2880 | |
| 769 | 776 | specific path |
| 770 | 777 | -------------------------------------------------*/ |
| 771 | 778 | |
| 772 | | static image_error_t load_image_by_path(image_slot_data *image, const char *software_path, |
| 773 | | const game_driver *gamedrv, UINT32 open_flags, const char *path) |
| 779 | static image_error_t load_image_by_path(image_slot_data *image, UINT32 open_flags, const char *path) |
| 774 | 780 | { |
| 775 | 781 | file_error filerr = FILERR_NOT_FOUND; |
| 776 | 782 | image_error_t err = IMAGE_ERROR_FILENOTFOUND; |
| 777 | 783 | astring *full_path = NULL; |
| 778 | 784 | const char *file_extension; |
| 779 | 785 | |
| 780 | | /* assemble the path */ |
| 781 | | if (software_path) |
| 782 | | { |
| 783 | | full_path = astring_assemble_5(astring_alloc(), software_path, PATH_SEPARATOR, gamedrv->name, PATH_SEPARATOR, path); |
| 784 | | path = astring_c(full_path); |
| 785 | | } |
| 786 | | |
| 787 | 786 | /* quick check to see if the file is a ZIP file */ |
| 788 | 787 | file_extension = strrchr(path, '.'); |
| 789 | 788 | if (!file_extension || mame_stricmp(file_extension, ".zip")) |
| r2879 | r2880 | |
| 898 | 897 | { |
| 899 | 898 | running_machine *machine = image->machine; |
| 900 | 899 | image_error_t err; |
| 901 | | const char *software_path; |
| 902 | | char *software_path_list = NULL; |
| 903 | 900 | const void *buffer; |
| 904 | | const game_driver *gamedrv; |
| 905 | 901 | UINT32 open_plan[4]; |
| 906 | 902 | int i; |
| 907 | 903 | image_slot_data *slot = find_image_slot(image); |
| r2879 | r2880 | |
| 931 | 927 | /* attempt to open the file in various ways */ |
| 932 | 928 | for (i = 0; !slot->file && open_plan[i]; i++) |
| 933 | 929 | { |
| 934 | | software_path = software_path_list; |
| 935 | | do |
| 936 | | { |
| 937 | | gamedrv = machine->gamedrv; |
| 938 | | while(!is_loaded(slot) && (gamedrv != NULL)) |
| 939 | | { |
| 940 | | /* open the file */ |
| 941 | | slot->err = load_image_by_path(slot, software_path, gamedrv, open_plan[i], path); |
| 942 | | if (slot->err && (slot->err != IMAGE_ERROR_FILENOTFOUND)) |
| 943 | | goto done; |
| 944 | | |
| 945 | | /* move on to the next driver */ |
| 946 | | gamedrv = mess_next_compatible_driver(gamedrv); |
| 947 | | } |
| 948 | | |
| 949 | | /* move on to the next entry in the software path; if we can */ |
| 950 | | if (software_path) |
| 951 | | software_path += strlen(software_path) + 1; |
| 952 | | } |
| 953 | | while(!is_loaded(slot) && software_path && *software_path); |
| 930 | /* open the file */ |
| 931 | slot->err = load_image_by_path(slot, open_plan[i], path); |
| 932 | if (slot->err && (slot->err != IMAGE_ERROR_FILENOTFOUND)) |
| 933 | goto done; |
| 954 | 934 | } |
| 955 | 935 | |
| 956 | 936 | /* did we fail to find the file? */ |
| r2879 | r2880 | |
| 1006 | 986 | /* success! */ |
| 1007 | 987 | |
| 1008 | 988 | done: |
| 1009 | | if (software_path_list) |
| 1010 | | free(software_path_list); |
| 1011 | 989 | if (slot->err) |
| 1012 | 990 | image_clear(slot); |
| 1013 | 991 | slot->is_loading = 1; |
src/mess/filemngr.c
| r2879 | r2880 | |
| 494 | 494 | { |
| 495 | 495 | if (selected_absolute_index >= 0) |
| 496 | 496 | { |
| 497 | | file_error err; |
| 498 | | char *full_path; |
| 497 | current_directory = astring_cpyc(astring_alloc(), image_working_directory(selected_device)); |
| 498 | current_file = astring_cpyc(astring_alloc(), |
| 499 | image_exists(selected_device) ? image_basename(selected_device) : ""); |
| 499 | 500 | |
| 500 | | err = osd_get_full_path(&full_path, image_filename(selected_device)); |
| 501 | | if (err != FILERR_NONE) |
| 502 | | return state; |
| 503 | | |
| 504 | | current_directory = zippath_parent(astring_alloc(), full_path); |
| 505 | | current_file = astring_cpyc(astring_alloc(), image_basename(selected_device)); |
| 506 | | free(full_path); |
| 507 | | |
| 508 | 501 | memset(&fs_state, 0, sizeof(fs_state)); |
| 509 | 502 | return ui_menu_stack_push(menu_file_selector, fs_state.i); |
| 510 | 503 | } |