src/mess/filemngr.c
| r3094 | r3095 | |
| 37 | 37 | #define ITEMREF_NEW_IMAGE_NAME ((void *) 0x0001) |
| 38 | 38 | #define ITEMREF_CREATE ((void *) 0x0002) |
| 39 | 39 | #define ITEMREF_FORMAT ((void *) 0x0003) |
| 40 | #define ITEMREF_NO ((void *) 0x0004) |
| 41 | #define ITEMREF_YES ((void *) 0x0005) |
| 40 | 42 | |
| 41 | 43 | |
| 42 | 44 | |
| r3094 | r3095 | |
| 97 | 99 | { |
| 98 | 100 | file_manager_menu_state *manager_menustate; |
| 99 | 101 | const image_device_format *current_format; |
| 102 | int confirm_save_as_yes; |
| 100 | 103 | char filename_buffer[1024]; |
| 101 | 104 | }; |
| 102 | 105 | |
| 103 | 106 | |
| 107 | /* state of the confirm save as menu */ |
| 108 | typedef struct _confirm_save_as_menu_state confirm_save_as_menu_state; |
| 109 | struct _confirm_save_as_menu_state |
| 110 | { |
| 111 | int *yes; |
| 112 | }; |
| 104 | 113 | |
| 114 | |
| 115 | |
| 105 | 116 | /*************************************************************************** |
| 106 | 117 | MENU HELPERS |
| 107 | 118 | ***************************************************************************/ |
| r3094 | r3095 | |
| 195 | 206 | |
| 196 | 207 | |
| 197 | 208 | /*************************************************************************** |
| 209 | CONFIRM SAVE AS MENU |
| 210 | ***************************************************************************/ |
| 211 | |
| 212 | /*------------------------------------------------- |
| 213 | menu_confirm_save_as_populate - populates the |
| 214 | confirm save as menu |
| 215 | -------------------------------------------------*/ |
| 216 | |
| 217 | static void menu_confirm_save_as_populate(running_machine *machine, ui_menu *menu, void *state) |
| 218 | { |
| 219 | ui_menu_item_append(menu, "File Already Exists - Overide?", NULL, MENU_FLAG_DISABLE, NULL); |
| 220 | ui_menu_item_append(menu, MENU_SEPARATOR_ITEM, NULL, MENU_FLAG_DISABLE, NULL); |
| 221 | ui_menu_item_append(menu, "No", NULL, 0, ITEMREF_NO); |
| 222 | ui_menu_item_append(menu, "Yes", NULL, 0, ITEMREF_YES); |
| 223 | } |
| 224 | |
| 225 | |
| 226 | |
| 227 | /*------------------------------------------------- |
| 228 | menu_confirm_save_as - confirm save as menu |
| 229 | -------------------------------------------------*/ |
| 230 | |
| 231 | static void menu_confirm_save_as(running_machine *machine, ui_menu *menu, void *parameter, void *state) |
| 232 | { |
| 233 | const ui_menu_event *event; |
| 234 | confirm_save_as_menu_state *menustate = (confirm_save_as_menu_state *) state; |
| 235 | |
| 236 | /* if the menu isn't built, populate now */ |
| 237 | if (!ui_menu_populated(menu)) |
| 238 | menu_confirm_save_as_populate(machine, menu, state); |
| 239 | |
| 240 | /* process the menu */ |
| 241 | event = ui_menu_process(menu, 0); |
| 242 | |
| 243 | /* process the event */ |
| 244 | if ((event != NULL) && (event->iptkey == IPT_UI_SELECT)) |
| 245 | { |
| 246 | if (event->itemref == ITEMREF_YES) |
| 247 | *menustate->yes = TRUE; |
| 248 | |
| 249 | /* no matter what, pop out */ |
| 250 | ui_menu_stack_pop(machine); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | |
| 255 | |
| 256 | /*************************************************************************** |
| 198 | 257 | FILE CREATE MENU |
| 199 | 258 | ***************************************************************************/ |
| 200 | 259 | |
| r3094 | r3095 | |
| 288 | 347 | create_new_image - creates a new disk image |
| 289 | 348 | -------------------------------------------------*/ |
| 290 | 349 | |
| 291 | | static int create_new_image(const device_config *device, const char *directory, const char *filename) |
| 350 | static int create_new_image(const device_config *device, const char *directory, const char *filename, int *yes) |
| 292 | 351 | { |
| 293 | 352 | astring *path; |
| 294 | 353 | osd_directory_entry *entry; |
| 295 | 354 | osd_dir_entry_type file_type; |
| 296 | 355 | int do_create, err; |
| 297 | 356 | int result = FALSE; |
| 357 | ui_menu *child_menu; |
| 358 | confirm_save_as_menu_state *child_menustate; |
| 298 | 359 | |
| 299 | 360 | /* assemble the full path */ |
| 300 | 361 | path = zippath_combine(astring_alloc(), directory, filename); |
| r3094 | r3095 | |
| 305 | 366 | if (entry != NULL) |
| 306 | 367 | free(entry); |
| 307 | 368 | |
| 369 | /* special case */ |
| 370 | if ((file_type == ENTTYPE_FILE) && *yes) |
| 371 | file_type = ENTTYPE_NONE; |
| 372 | |
| 308 | 373 | switch(file_type) |
| 309 | 374 | { |
| 310 | 375 | case ENTTYPE_NONE: |
| r3094 | r3095 | |
| 313 | 378 | break; |
| 314 | 379 | |
| 315 | 380 | case ENTTYPE_FILE: |
| 316 | | /* TODO - we should be raising a warning here, not an error */ |
| 317 | | ui_popup_time(ERROR_MESSAGE_TIME, "Cannot save over file"); |
| 381 | /* a file exists here - ask for permission from the user */ |
| 382 | child_menu = ui_menu_alloc(device->machine, menu_confirm_save_as, NULL); |
| 383 | child_menustate = ui_menu_alloc_state(child_menu, sizeof(*child_menustate), NULL); |
| 384 | child_menustate->yes = yes; |
| 385 | ui_menu_stack_push(child_menu); |
| 318 | 386 | do_create = FALSE; |
| 319 | 387 | break; |
| 320 | 388 | |
| 321 | 389 | case ENTTYPE_DIR: |
| 390 | /* a directory exists here - we can't save over it */ |
| 322 | 391 | ui_popup_time(ERROR_MESSAGE_TIME, "Cannot save over directory"); |
| 323 | 392 | do_create = FALSE; |
| 324 | 393 | break; |
| r3094 | r3095 | |
| 355 | 424 | { |
| 356 | 425 | void *selection; |
| 357 | 426 | const ui_menu_event *event; |
| 427 | ui_menu_event fake_event; |
| 358 | 428 | file_create_menu_state *menustate = (file_create_menu_state *) state; |
| 359 | 429 | |
| 360 | 430 | /* identify the selection */ |
| r3094 | r3095 | |
| 364 | 434 | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_POSITION); |
| 365 | 435 | menu_file_create_populate(machine, menu, state, selection); |
| 366 | 436 | |
| 367 | | /* process the menu */ |
| 368 | | event = ui_menu_process(menu, 0); |
| 437 | if (menustate->confirm_save_as_yes) |
| 438 | { |
| 439 | /* we just returned from a "confirm save as" dialog and the user said "yes" - fake an event */ |
| 440 | memset(&fake_event, 0, sizeof(fake_event)); |
| 441 | fake_event.iptkey = IPT_UI_SELECT; |
| 442 | fake_event.itemref = ITEMREF_CREATE; |
| 443 | event = &fake_event; |
| 444 | } |
| 445 | else |
| 446 | { |
| 447 | /* process the menu */ |
| 448 | event = ui_menu_process(menu, 0); |
| 449 | } |
| 369 | 450 | |
| 370 | 451 | /* process the event */ |
| 371 | 452 | if (event != NULL) |
| r3094 | r3095 | |
| 379 | 460 | if (create_new_image( |
| 380 | 461 | menustate->manager_menustate->selected_device, |
| 381 | 462 | astring_c(menustate->manager_menustate->current_directory), |
| 382 | | menustate->filename_buffer)) |
| 463 | menustate->filename_buffer, |
| 464 | &menustate->confirm_save_as_yes)) |
| 383 | 465 | { |
| 384 | 466 | /* success - pop out twice to device view */ |
| 385 | 467 | ui_menu_stack_pop(machine); |