src/mess/filemngr.c
| r3067 | r3068 | |
| 237 | 237 | creator menu |
| 238 | 238 | -------------------------------------------------*/ |
| 239 | 239 | |
| 240 | | static void menu_file_create_populate(running_machine *machine, ui_menu *menu, void *state) |
| 240 | static void menu_file_create_populate(running_machine *machine, ui_menu *menu, void *state, void *selection) |
| 241 | 241 | { |
| 242 | 242 | astring *buffer = astring_alloc(); |
| 243 | 243 | file_create_menu_state *menustate = (file_create_menu_state *) state; |
| 244 | 244 | const device_config *device = menustate->manager_menustate->selected_device; |
| 245 | 245 | const image_device_format *format; |
| 246 | 246 | const char *new_image_name; |
| 247 | | void *selection; |
| 248 | 247 | |
| 249 | | /* identify the selection */ |
| 250 | | selection = ui_menu_get_selection(menu); |
| 251 | | |
| 252 | 248 | /* append the "New Image Name" item */ |
| 253 | 249 | if (selection == ITEMREF_NEW_IMAGE_NAME) |
| 254 | 250 | { |
| r3067 | r3068 | |
| 283 | 279 | |
| 284 | 280 | |
| 285 | 281 | /*------------------------------------------------- |
| 282 | create_new_image - creates a new disk image |
| 283 | -------------------------------------------------*/ |
| 284 | |
| 285 | static int create_new_image(const device_config *device, const char *directory, const char *filename) |
| 286 | { |
| 287 | astring *path; |
| 288 | osd_directory_entry *entry; |
| 289 | osd_dir_entry_type file_type; |
| 290 | int do_create, err; |
| 291 | int result = FALSE; |
| 292 | |
| 293 | /* assemble the full path */ |
| 294 | path = zippath_combine(astring_alloc(), directory, filename); |
| 295 | |
| 296 | /* does a file or a directory exist at the path */ |
| 297 | entry = osd_stat(astring_c(path)); |
| 298 | file_type = (entry != NULL) ? entry->type : ENTTYPE_NONE; |
| 299 | if (entry != NULL) |
| 300 | free(entry); |
| 301 | |
| 302 | switch(file_type) |
| 303 | { |
| 304 | case ENTTYPE_NONE: |
| 305 | /* no file/dir here - always create */ |
| 306 | do_create = TRUE; |
| 307 | break; |
| 308 | |
| 309 | case ENTTYPE_FILE: |
| 310 | /* TODO - we should be raising a warning here, not an error */ |
| 311 | popmessage("Cannot save over file"); |
| 312 | do_create = FALSE; |
| 313 | break; |
| 314 | |
| 315 | case ENTTYPE_DIR: |
| 316 | popmessage("Cannot save over directory"); |
| 317 | do_create = FALSE; |
| 318 | break; |
| 319 | |
| 320 | default: |
| 321 | fatalerror("Unexpected"); |
| 322 | do_create = FALSE; |
| 323 | break; |
| 324 | } |
| 325 | |
| 326 | /* create the image, if appropriate */ |
| 327 | if (do_create) |
| 328 | { |
| 329 | err = image_create(device, astring_c(path), 0, NULL); |
| 330 | if (err != 0) |
| 331 | popmessage("Error: %s", image_error(device)); |
| 332 | else |
| 333 | result = TRUE; |
| 334 | } |
| 335 | |
| 336 | /* free the path */ |
| 337 | astring_free(path); |
| 338 | |
| 339 | return result; |
| 340 | } |
| 341 | |
| 342 | |
| 343 | |
| 344 | /*------------------------------------------------- |
| 286 | 345 | menu_file_create - file creator menu |
| 287 | 346 | -------------------------------------------------*/ |
| 288 | 347 | |
| 289 | 348 | static void menu_file_create(running_machine *machine, ui_menu *menu, void *parameter, void *state) |
| 290 | 349 | { |
| 291 | | astring *new_path; |
| 350 | void *selection; |
| 292 | 351 | const ui_menu_event *event; |
| 293 | 352 | file_create_menu_state *menustate = (file_create_menu_state *) state; |
| 294 | 353 | |
| 354 | /* identify the selection */ |
| 355 | selection = ui_menu_get_selection(menu); |
| 356 | |
| 295 | 357 | /* rebuild the menu */ |
| 296 | 358 | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_POSITION); |
| 297 | | menu_file_create_populate(machine, menu, state); |
| 359 | menu_file_create_populate(machine, menu, state, selection); |
| 298 | 360 | |
| 299 | 361 | /* process the menu */ |
| 300 | 362 | event = ui_menu_process(menu, 0); |
| r3067 | r3068 | |
| 306 | 368 | switch(event->iptkey) |
| 307 | 369 | { |
| 308 | 370 | case IPT_UI_SELECT: |
| 309 | | if (event->itemref == ITEMREF_CREATE) |
| 371 | if ((event->itemref == ITEMREF_CREATE) || (event->itemref == ITEMREF_NEW_IMAGE_NAME)) |
| 310 | 372 | { |
| 311 | | /* create the image */ |
| 312 | | new_path = zippath_combine( |
| 313 | | astring_alloc(), |
| 314 | | astring_c(menustate->manager_menustate->current_directory), |
| 315 | | menustate->filename_buffer); |
| 316 | | image_create( |
| 373 | if (create_new_image( |
| 317 | 374 | menustate->manager_menustate->selected_device, |
| 318 | | astring_c(new_path), |
| 319 | | 0, |
| 320 | | NULL); |
| 321 | | astring_free(new_path); |
| 375 | astring_c(menustate->manager_menustate->current_directory), |
| 376 | menustate->filename_buffer)) |
| 377 | { |
| 378 | /* success - pop out twice to device view */ |
| 379 | ui_menu_stack_pop(machine); |
| 380 | ui_menu_stack_pop(machine); |
| 381 | } |
| 322 | 382 | } |
| 323 | 383 | break; |
| 324 | 384 | |