Previous 15994 Revisions Next

r3068 Thursday 21st August, 2008 at 11:24:46 UTC by Nathan Woods
File manager improvements; made the creation menu work a bit better, more error
reporting
[src/emu]uimenu.c
[src/mess]filemngr.c

src/emu/uimenu.c
r3067r3068
556556   /* update the selection if we need to */
557557   if (menu->resetpos == index || (menu->resetref != NULL && menu->resetref == ref))
558558      menu->selected = index;
559   if (menu->resetpos == menu->numitems - 1)
560      menu->selected = menu->numitems - 1;
559561}
560562
561563
src/mess/filemngr.c
r3067r3068
237237   creator menu
238238-------------------------------------------------*/
239239
240static void menu_file_create_populate(running_machine *machine, ui_menu *menu, void *state)
240static void menu_file_create_populate(running_machine *machine, ui_menu *menu, void *state, void *selection)
241241{
242242   astring *buffer = astring_alloc();
243243   file_create_menu_state *menustate = (file_create_menu_state *) state;
244244   const device_config *device = menustate->manager_menustate->selected_device;
245245   const image_device_format *format;
246246   const char *new_image_name;
247   void *selection;
248247
249   /* identify the selection */
250   selection = ui_menu_get_selection(menu);
251
252248   /* append the "New Image Name" item */
253249   if (selection == ITEMREF_NEW_IMAGE_NAME)
254250   {
r3067r3068
283279
284280
285281/*-------------------------------------------------
282    create_new_image - creates a new disk image
283-------------------------------------------------*/
284
285static 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/*-------------------------------------------------
286345    menu_file_create - file creator menu
287346-------------------------------------------------*/
288347
289348static void menu_file_create(running_machine *machine, ui_menu *menu, void *parameter, void *state)
290349{
291   astring *new_path;
350   void *selection;
292351   const ui_menu_event *event;
293352   file_create_menu_state *menustate = (file_create_menu_state *) state;
294353
354   /* identify the selection */
355   selection = ui_menu_get_selection(menu);
356
295357   /* rebuild the menu */
296358   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);
298360
299361   /* process the menu */
300362   event = ui_menu_process(menu, 0);
r3067r3068
306368      switch(event->iptkey)
307369      {
308370         case IPT_UI_SELECT:
309            if (event->itemref == ITEMREF_CREATE)
371            if ((event->itemref == ITEMREF_CREATE) || (event->itemref == ITEMREF_NEW_IMAGE_NAME))
310372            {
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(
317374                  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               }
322382            }
323383            break;
324384

Previous 15994 Revisions Next


© 1998-2018 The MESS Team