src/mess/filemngr.c
| r2881 | r2882 | |
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | /*************************************************************************** |
| 28 | CONSTANTS |
| 29 | ***************************************************************************/ |
| 30 | |
| 31 | #define SLOT_EMPTY "[empty slot]" |
| 32 | #define SLOT_CREATE "[create]" |
| 33 | |
| 34 | |
| 35 | |
| 36 | /*************************************************************************** |
| 28 | 37 | TYPE DEFINITIONS |
| 29 | 38 | ***************************************************************************/ |
| 30 | 39 | |
| r2881 | r2882 | |
| 52 | 61 | |
| 53 | 62 | |
| 54 | 63 | /*************************************************************************** |
| 55 | | IMPLEMENTATION |
| 64 | MENU HELPERS |
| 56 | 65 | ***************************************************************************/ |
| 57 | 66 | |
| 58 | 67 | /*------------------------------------------------- |
| 59 | | alloc_directory_entry - allocates a struct |
| 60 | | of type osd_directory_entry |
| 61 | | -------------------------------------------------*/ |
| 62 | | |
| 63 | | static 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 | | |
| 93 | | static 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 | | /*------------------------------------------------- |
| 101 | 68 | extra_text_draw_box - generically adds header |
| 102 | 69 | or footer text |
| 103 | 70 | -------------------------------------------------*/ |
| r2881 | r2882 | |
| 161 | 128 | |
| 162 | 129 | |
| 163 | 130 | |
| 131 | /*************************************************************************** |
| 132 | FILE CREATE MENU |
| 133 | ***************************************************************************/ |
| 134 | |
| 164 | 135 | /*------------------------------------------------- |
| 136 | menu_file_create - file creator menu |
| 137 | -------------------------------------------------*/ |
| 138 | |
| 139 | static 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 | |
| 156 | static 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 | |
| 186 | static 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 | /*------------------------------------------------- |
| 165 | 194 | file_selector_render_extra - perform our |
| 166 | 195 | special rendering |
| 167 | 196 | -------------------------------------------------*/ |
| r2881 | r2882 | |
| 178 | 207 | allocates all menu items for a directory |
| 179 | 208 | -------------------------------------------------*/ |
| 180 | 209 | |
| 181 | | static 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) |
| 210 | static 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) |
| 183 | 212 | { |
| 184 | 213 | zippath_directory *directory = NULL; |
| 185 | 214 | file_error err = FILERR_NONE; |
| r2881 | r2882 | |
| 187 | 216 | osd_directory_entry *dirent_dupe; |
| 188 | 217 | const char *subtext; |
| 189 | 218 | int count, i; |
| 219 | image_device_info info; |
| 190 | 220 | |
| 191 | 221 | /* reset count */ |
| 192 | 222 | *menu_items = 0; |
| r2881 | r2882 | |
| 194 | 224 | |
| 195 | 225 | /* add the "[empty slot]" entry */ |
| 196 | 226 | 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; |
| 198 | 228 | item_list[*menu_items].ref = alloc_directory_entry(NULL, ENTTYPE_FILE, 0); |
| 199 | 229 | (*menu_items)++; |
| 200 | 230 | |
| 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 | |
| 201 | 241 | /* add the drives */ |
| 202 | 242 | count = osd_num_devices(); |
| 203 | 243 | for (i = 0; i < count; i++) |
| r2881 | r2882 | |
| 280 | 320 | |
| 281 | 321 | |
| 282 | 322 | /*------------------------------------------------- |
| 283 | | menu_file_selector - MESS-specific menu |
| 323 | menu_file_selector - file selector menu |
| 284 | 324 | -------------------------------------------------*/ |
| 285 | 325 | |
| 286 | 326 | static UINT32 menu_file_selector(running_machine *machine, UINT32 state) |
| r2881 | r2882 | |
| 304 | 344 | /* do we have to build the menu? */ |
| 305 | 345 | if (!menu_is_built) |
| 306 | 346 | { |
| 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); |
| 309 | 349 | if (err != FILERR_NONE) |
| 310 | 350 | { |
| 311 | 351 | /* if we error here, we must pop out */ |
| r2881 | r2882 | |
| 358 | 398 | case ENTTYPE_FILE: |
| 359 | 399 | if (dirent->name != NULL) |
| 360 | 400 | { |
| 401 | /* specified a file */ |
| 361 | 402 | new_path = zippath_combine(astring_alloc(), astring_c(current_directory), dirent->name); |
| 362 | 403 | image_load(selected_device, astring_c(new_path)); |
| 363 | 404 | astring_free(new_path); |
| 364 | 405 | } |
| 365 | | else |
| 406 | else if (!strcmp(item_list[selected].text, SLOT_EMPTY)) |
| 366 | 407 | { |
| 408 | /* empty slot - unload */ |
| 367 | 409 | image_unload(selected_device); |
| 368 | 410 | } |
| 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 | } |
| 369 | 420 | fs_state.i = ui_menu_stack_pop(); |
| 370 | 421 | goto done; |
| 371 | 422 | |
| r2881 | r2882 | |
| 398 | 449 | |
| 399 | 450 | |
| 400 | 451 | |
| 452 | /*************************************************************************** |
| 453 | FILE MANAGER |
| 454 | ***************************************************************************/ |
| 455 | |
| 401 | 456 | /*------------------------------------------------- |
| 402 | 457 | file_manager_render_extra - perform our |
| 403 | 458 | special rendering |
| r2881 | r2882 | |
| 412 | 467 | |
| 413 | 468 | |
| 414 | 469 | /*------------------------------------------------- |
| 415 | | menu_file_manager - MESS-specific menu |
| 470 | menu_file_manager - main file manager menu |
| 416 | 471 | -------------------------------------------------*/ |
| 417 | 472 | |
| 418 | 473 | UINT32 menu_file_manager(running_machine *machine, UINT32 state) |
| r2881 | r2882 | |
| 494 | 549 | { |
| 495 | 550 | if (selected_absolute_index >= 0) |
| 496 | 551 | { |
| 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 | } |
| 500 | 564 | |
| 501 | 565 | memset(&fs_state, 0, sizeof(fs_state)); |
| 502 | 566 | return ui_menu_stack_push(menu_file_selector, fs_state.i); |