src/mess/osd/windows/menu.c
| r2390 | r2391 | |
| 825 | 825 | // change_device |
| 826 | 826 | //============================================================ |
| 827 | 827 | |
| 828 | | static void change_device(HWND wnd, const device_config *img, int is_save) |
| 828 | static void change_device(HWND wnd, const device_config *device, int is_save) |
| 829 | 829 | { |
| 830 | 830 | dialog_box *dialog = NULL; |
| 831 | 831 | char filter[2048]; |
| 832 | 832 | char filename[MAX_PATH]; |
| 833 | 833 | char buffer[512]; |
| 834 | | const struct IODevice *dev = mess_device_from_core_device(img); |
| 835 | 834 | const char *initial_dir; |
| 836 | 835 | BOOL result; |
| 837 | 836 | int create_format = 0; |
| 838 | 837 | option_resolution *create_args = NULL; |
| 839 | 838 | image_error_t err; |
| 839 | image_device_info info; |
| 840 | const struct IODevice *iodev; |
| 840 | 841 | |
| 841 | | assert(dev); |
| 842 | // sanity check |
| 843 | assert(device != NULL); |
| 842 | 844 | |
| 845 | // get device info |
| 846 | info = image_device_getinfo(device->machine->config, device); |
| 847 | |
| 843 | 848 | // get the file |
| 844 | | if (image_exists(img)) |
| 849 | if (image_exists(device)) |
| 845 | 850 | { |
| 846 | 851 | const char *imgname; |
| 847 | | imgname = image_basename(img); |
| 848 | | strncpyz(filename, imgname, sizeof(filename) / sizeof(filename[0])); |
| 852 | imgname = image_basename(device); |
| 853 | snprintf(filename, ARRAY_LENGTH(filename), "%s", imgname); |
| 849 | 854 | } |
| 850 | 855 | else |
| 851 | 856 | { |
| r2390 | r2391 | |
| 853 | 858 | } |
| 854 | 859 | |
| 855 | 860 | // use image directory, if it is there |
| 856 | | get_devicedirectory(dev->type); |
| 857 | | initial_dir = image_working_directory(img); |
| 861 | get_devicedirectory(info.type); |
| 862 | initial_dir = image_working_directory(device); |
| 858 | 863 | |
| 859 | 864 | // add custom dialog elements, if appropriate |
| 860 | | if (is_save && dev->createimage_optguide && dev->createimage_options[0].optspec) |
| 865 | iodev = mess_device_from_core_device(device); |
| 866 | if (is_save && (iodev != NULL) |
| 867 | && (iodev->createimage_optguide != NULL) |
| 868 | && (iodev->createimage_options[0].optspec != NULL)) |
| 861 | 869 | { |
| 862 | | dialog = build_option_dialog(img, filter, sizeof(filter) / sizeof(filter[0]), &create_format, &create_args); |
| 870 | dialog = build_option_dialog(device, filter, sizeof(filter) / sizeof(filter[0]), &create_format, &create_args); |
| 863 | 871 | if (!dialog) |
| 864 | 872 | goto done; |
| 865 | 873 | } |
| 866 | 874 | else |
| 867 | 875 | { |
| 868 | 876 | // build a normal filter |
| 869 | | build_generic_filter(img, is_save, filter, sizeof(filter) / sizeof(filter[0])); |
| 877 | build_generic_filter(device, is_save, filter, sizeof(filter) / sizeof(filter[0])); |
| 870 | 878 | } |
| 871 | 879 | |
| 872 | 880 | // display the dialog |
| 873 | | result = win_file_dialog(img->machine, wnd, is_save ? WIN_FILE_DIALOG_SAVE : WIN_FILE_DIALOG_OPEN, |
| 881 | result = win_file_dialog(device->machine, wnd, is_save ? WIN_FILE_DIALOG_SAVE : WIN_FILE_DIALOG_OPEN, |
| 874 | 882 | dialog, filter, initial_dir, filename, sizeof(filename) / sizeof(filename[0])); |
| 875 | 883 | if (result) |
| 876 | 884 | { |
| 877 | 885 | // mount the image |
| 878 | 886 | if (is_save) |
| 879 | | err = image_create(img, filename, create_format, create_args); |
| 887 | err = image_create(device, filename, create_format, create_args); |
| 880 | 888 | else |
| 881 | | err = image_load(img, filename); |
| 889 | err = image_load(device, filename); |
| 882 | 890 | |
| 883 | 891 | // error? |
| 884 | 892 | if (err) |
| 885 | 893 | { |
| 886 | | snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), |
| 894 | snprintf(buffer, ARRAY_LENGTH(buffer), |
| 887 | 895 | "Error when %s the image: %s", |
| 888 | 896 | is_save ? "creating" : "loading", |
| 889 | | image_error(img)); |
| 897 | image_error(device)); |
| 890 | 898 | |
| 891 | 899 | win_message_box_utf8(wnd, buffer, APPNAME, MB_OK); |
| 892 | 900 | } |
| 893 | 901 | } |
| 894 | 902 | |
| 895 | 903 | done: |
| 896 | | if (dialog) |
| 904 | if (dialog != NULL) |
| 897 | 905 | win_dialog_exit(dialog); |
| 898 | | if (create_args) |
| 906 | if (create_args != NULL) |
| 899 | 907 | option_resolution_close(create_args); |
| 900 | 908 | } |
| 901 | 909 | |