Previous 15994 Revisions Next

r2882 Monday 23rd June, 2008 at 01:23:54 UTC by Nathan Woods
More file manager cleanups
[src/mess]filemngr.c

src/mess/filemngr.c
r2881r2882
2525
2626
2727/***************************************************************************
28    CONSTANTS
29***************************************************************************/
30
31#define SLOT_EMPTY      "[empty slot]"
32#define SLOT_CREATE      "[create]"
33
34
35
36/***************************************************************************
2837    TYPE DEFINITIONS
2938***************************************************************************/
3039
r2881r2882
5261
5362
5463/***************************************************************************
55    IMPLEMENTATION
64    MENU HELPERS
5665***************************************************************************/
5766
5867/*-------------------------------------------------
59    alloc_directory_entry - allocates a struct
60   of type osd_directory_entry
61-------------------------------------------------*/
62
63static osd_directory_entry *alloc_directory_entry(const char *name, osd_dir_entry_type type, UINT64 size)
64{
65   char *name_dupe = NULL;
66   osd_directory_entry *new_entry;
67   size_t name_length;
68   
69   /* allocate the new entry */
70   name_length = (name != NULL) ? strlen(name) + 1 : 0;
71   new_entry = malloc_or_die(sizeof(*new_entry) + name_length);
72
73   /* copy the name, if specified */
74   if (name != NULL)
75   {
76      name_dupe = ((char *) new_entry) + sizeof(*new_entry);
77      strcpy(name_dupe, name);
78   }
79
80   new_entry->name = name_dupe;
81   new_entry->type = type;
82   new_entry->size = size;
83   return new_entry;
84}
85
86
87
88/*-------------------------------------------------
89    dupe_directory_entry - duplicates a struct
90   of type osd_directory_entry
91-------------------------------------------------*/
92
93static osd_directory_entry *dupe_directory_entry(const osd_directory_entry *entry)
94{
95   return alloc_directory_entry(entry->name, entry->type, entry->size);
96}
97
98
99
100/*-------------------------------------------------
10168    extra_text_draw_box - generically adds header
10269   or footer text
10370-------------------------------------------------*/
r2881r2882
161128
162129
163130
131/***************************************************************************
132    FILE CREATE MENU
133***************************************************************************/
134
164135/*-------------------------------------------------
136    menu_file_create - file creator menu
137-------------------------------------------------*/
138
139static UINT32 menu_file_create(running_machine *machine, UINT32 state)
140{
141   fatalerror("NYI");
142   return 0;
143}
144
145
146
147/***************************************************************************
148    FILE SELECTOR MENU
149***************************************************************************/
150
151/*-------------------------------------------------
152    alloc_directory_entry - allocates a struct
153   of type osd_directory_entry
154-------------------------------------------------*/
155
156static osd_directory_entry *alloc_directory_entry(const char *name, osd_dir_entry_type type, UINT64 size)
157{
158   char *name_dupe = NULL;
159   osd_directory_entry *new_entry;
160   size_t name_length;
161   
162   /* allocate the new entry */
163   name_length = (name != NULL) ? strlen(name) + 1 : 0;
164   new_entry = malloc_or_die(sizeof(*new_entry) + name_length);
165
166   /* copy the name, if specified */
167   if (name != NULL)
168   {
169      name_dupe = ((char *) new_entry) + sizeof(*new_entry);
170      strcpy(name_dupe, name);
171   }
172
173   new_entry->name = name_dupe;
174   new_entry->type = type;
175   new_entry->size = size;
176   return new_entry;
177}
178
179
180
181/*-------------------------------------------------
182    dupe_directory_entry - duplicates a struct
183   of type osd_directory_entry
184-------------------------------------------------*/
185
186static osd_directory_entry *dupe_directory_entry(const osd_directory_entry *entry)
187{
188   return alloc_directory_entry(entry->name, entry->type, entry->size);
189}
190
191
192
193/*-------------------------------------------------
165194    file_selector_render_extra - perform our
166195    special rendering
167196-------------------------------------------------*/
r2881r2882
178207   allocates all menu items for a directory
179208-------------------------------------------------*/
180209
181static file_error build_file_selector_menu_items(const char *path, ui_menu_item *item_list,
182   size_t item_list_length, int *menu_items, int *selected)
210static file_error build_file_selector_menu_items(const device_config *device, const char *path,
211   ui_menu_item *item_list, size_t item_list_length, int *menu_items, int *selected)
183212{
184213   zippath_directory *directory = NULL;
185214   file_error err = FILERR_NONE;
r2881r2882
187216   osd_directory_entry *dirent_dupe;
188217   const char *subtext;
189218   int count, i;
219   image_device_info info;
190220
191221   /* reset count */
192222   *menu_items = 0;
r2881r2882
194224
195225   /* add the "[empty slot]" entry */
196226   memset(&item_list[*menu_items], 0, sizeof(item_list[*menu_items]));
197   item_list[*menu_items].text = "[empty slot]";
227   item_list[*menu_items].text = SLOT_EMPTY;
198228   item_list[*menu_items].ref = alloc_directory_entry(NULL, ENTTYPE_FILE, 0);
199229   (*menu_items)++;
200230
231   info = image_device_getinfo(device->machine->config, device);
232   if (0 && info.creatable)   /* NYI */
233   {
234      /* add the "[create]" entry */
235      memset(&item_list[*menu_items], 0, sizeof(item_list[*menu_items]));
236      item_list[*menu_items].text = SLOT_CREATE;
237      item_list[*menu_items].ref = alloc_directory_entry(NULL, ENTTYPE_FILE, 0);
238      (*menu_items)++;
239   }
240
201241   /* add the drives */
202242   count = osd_num_devices();
203243   for (i = 0; i < count; i++)
r2881r2882
280320
281321
282322/*-------------------------------------------------
283    menu_file_selector - MESS-specific menu
323    menu_file_selector - file selector menu
284324-------------------------------------------------*/
285325
286326static UINT32 menu_file_selector(running_machine *machine, UINT32 state)
r2881r2882
304344   /* do we have to build the menu? */
305345   if (!menu_is_built)
306346   {
307      err = build_file_selector_menu_items(astring_c(current_directory), item_list, ARRAY_LENGTH(item_list),
308         &menu_items, &selected);
347      err = build_file_selector_menu_items(selected_device, astring_c(current_directory),
348         item_list, ARRAY_LENGTH(item_list), &menu_items, &selected);
309349      if (err != FILERR_NONE)
310350      {
311351         /* if we error here, we must pop out */
r2881r2882
358398         case ENTTYPE_FILE:
359399            if (dirent->name != NULL)
360400            {
401               /* specified a file */
361402               new_path = zippath_combine(astring_alloc(), astring_c(current_directory), dirent->name);
362403               image_load(selected_device, astring_c(new_path));
363404               astring_free(new_path);
364405            }
365            else
406            else if (!strcmp(item_list[selected].text, SLOT_EMPTY))
366407            {
408               /* empty slot - unload */
367409               image_unload(selected_device);
368410            }
411            else if (!strcmp(item_list[selected].text, SLOT_CREATE))
412            {
413               /* create */
414               fs_state.i = ui_menu_stack_push(menu_file_create, 0);
415            }
416            else
417            {
418               fatalerror("Should not reach here");
419            }
369420            fs_state.i = ui_menu_stack_pop();
370421            goto done;
371422
r2881r2882
398449
399450
400451
452/***************************************************************************
453    FILE MANAGER
454***************************************************************************/
455
401456/*-------------------------------------------------
402457    file_manager_render_extra - perform our
403458    special rendering
r2881r2882
412467
413468
414469/*-------------------------------------------------
415    menu_file_manager - MESS-specific menu
470    menu_file_manager - main file manager menu
416471-------------------------------------------------*/
417472
418473UINT32 menu_file_manager(running_machine *machine, UINT32 state)
r2881r2882
494549   {
495550      if (selected_absolute_index >= 0)
496551      {
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) : "");
552         /* set up current_directory and current_file - depends on whether we have an image */
553         if (image_exists(selected_device))
554         {
555            /* note that we _should_ be able to use image_working_directory(); please fix */
556            current_directory = zippath_parent(astring_alloc(), image_filename(selected_device));
557            current_file = astring_cpyc(astring_alloc(), image_basename(selected_device));
558         }
559         else
560         {
561            current_directory = astring_cpyc(astring_alloc(), image_working_directory(selected_device));
562            current_file = astring_cpyc(astring_alloc(), "");
563         }
500564
501565         memset(&fs_state, 0, sizeof(fs_state));
502566         return ui_menu_stack_push(menu_file_selector, fs_state.i);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team