Previous 199869 Revisions Next

r20006 Wednesday 2nd January, 2013 at 11:24:18 UTC by O. Galibert
floppy: Correctly reach files inside zips or softlists [O. Galibert]
[src/emu]softlist.c softlist.h
[src/emu/imagedev]floppy.c floppy.h
[src/lib/formats]ioprocs.c ioprocs.h

trunk/src/emu/softlist.c
r20005r20006
183183
184184#define global_strdup(s)            strcpy(global_alloc_array(char, strlen(s) + 1), s)
185185
186static void software_name_split(const char *swlist_swname, char **swlist_name, char **swname, char **swpart )
186void software_name_split(const char *swlist_swname, char **swlist_name, char **swname, char **swpart )
187187{
188188   const char *split_1st_loc = strchr( swlist_swname, ':' );
189189   const char *split_2nd_loc = ( split_1st_loc ) ? strchr( split_1st_loc + 1, ':' ) : NULL;
trunk/src/emu/softlist.h
r20005r20006
191191const char *software_get_clone(emu_options &options, char *swlist, const char *swname);
192192UINT32 software_get_support(emu_options &options, char *swlist, const char *swname);
193193const char *software_part_get_feature(const software_part *part, const char *feature_name);
194void software_name_split(const char *swlist_swname, char **swlist_name, char **swname, char **swpart);
194195
195196bool load_software_part(emu_options &options, device_image_interface *image, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name, char**list_name);
196197
trunk/src/emu/imagedev/floppy.c
r20005r20006
55*********************************************************************/
66
77#include "emu.h"
8#include "emuopts.h"
89#include "zippath.h"
910#include "floppy.h"
1011#include "formats/imageutl.h"
r20005r20006
233234   index_resync();
234235}
235236
236floppy_image_format_t *floppy_image_device::identify(astring filename) const
237floppy_image_format_t *floppy_image_device::identify(astring filename)
237238{
238   FILE *fd;
239   fd = fopen(filename.cstr(), "r");
240   if(!fd)
239   core_file *fd;
240   astring revised_path;
241
242   file_error err = zippath_fopen(filename, OPEN_FLAG_READ, fd, revised_path);
243   if(err) {
244      seterror(IMAGE_ERROR_INVALIDIMAGE, "Unable to open the image file");
241245      return 0;
246   }
242247
243248   io_generic io;
244249   io.file = fd;
245   io.procs = &stdio_ioprocs_noclose;
250   io.procs = &corefile_ioprocs_noclose;
246251   io.filler = 0xff;
247252   int best = 0;
248253   floppy_image_format_t *best_format = 0;
r20005r20006
253258         best_format = format;
254259      }
255260   }
256   fclose(fd);
261   core_fclose(fd);
257262   return best_format;
258263}
259264
r20005r20006
283288   image = global_alloc(floppy_image(tracks, sides, form_factor));
284289   best_format->load(&io, form_factor, image);
285290
291   if(!is_readonly())
292      output_format = best_format;
293
286294   revolution_start_time = motor_always_on ? machine().time() : attotime::never;
287295   revolution_count = 0;
288296
r20005r20006
725733   }
726734}
727735
736astring ui_menu_control_floppy_image::try_file(astring location, astring name, bool has_crc, UINT32 crc)
737{
738   emu_file fd(machine().options().media_path(), OPEN_FLAG_READ);
739   file_error filerr;
740   if(has_crc)
741      filerr = fd.open(location.cstr(), PATH_SEPARATOR, name.cstr(), crc);
742   else
743      filerr = fd.open(location.cstr(), PATH_SEPARATOR, name.cstr());
744   if(filerr != FILERR_NONE)
745      return "";
746   return fd.fullpath();
747}
748
728749void ui_menu_control_floppy_image::hook_load(astring filename, bool softlist)
729750{
730751   input_filename = filename;
752   if(softlist) {
753      char *swlist_name, *swname, *swpart;
754      software_name_split(filename.cstr(), &swlist_name, &swname, &swpart);
755      software_list *sw_list = software_list_open(machine().options(), swlist_name, FALSE, NULL);
756      software_info *sw_info = software_list_find(sw_list, swname, NULL);
757      software_part *sw_part = software_find_part(sw_info, swpart, NULL);
758      const char *parentname = software_get_clone(machine().options(), swlist_name, sw_info->shortname);
759      for(const rom_entry *region = sw_part->romdata; region; region = rom_next_region(region)) {
760         const rom_entry *romp = region + 1;
761         UINT32 crc = 0;
762         bool has_crc = hash_collection(ROM_GETHASHDATA(romp)).crc(crc);
763         
764         filename = try_file(astring(swlist_name) + PATH_SEPARATOR + astring(swname), ROM_GETNAME(romp), has_crc, crc);
765         if(filename == "")
766            filename = try_file(astring(swlist_name) + PATH_SEPARATOR + astring(parentname), ROM_GETNAME(romp), has_crc, crc);
767         if(filename == "")
768            filename = try_file(swname, ROM_GETNAME(romp), has_crc, crc);
769         if(filename == "")
770            filename = try_file(parentname, ROM_GETNAME(romp), has_crc, crc);
771         if(filename != "")
772            goto found;
773      }
774
775   found:
776      software_list_close(sw_list);
777      global_free(swlist_name);
778   }
779
731780   input_format = static_cast<floppy_image_device *>(image)->identify(filename);
732781   if(!input_format) {
733782      popmessage("Error: %s\n", image->error());
trunk/src/emu/imagedev/floppy.h
r20005r20006
6060   void set_formats(const floppy_format_type *formats);
6161   floppy_image_format_t *get_formats() const;
6262   floppy_image_format_t *get_load_format() const;
63   floppy_image_format_t *identify(astring filename) const;
63   floppy_image_format_t *identify(astring filename);
6464   void set_rpm(float rpm);
6565
6666   // image-level overrides
r20005r20006
190190
191191   void do_load_create();
192192   virtual void hook_load(astring filename, bool softlist);
193   astring try_file(astring location, astring name, bool has_crc, UINT32 crc);
193194};
194195
195196class floppy_3_ssdd : public floppy_image_device {
trunk/src/lib/formats/ioprocs.c
r20005r20006
22#include <string.h>
33#include "osdcore.h"
44#include "ioprocs.h"
5#include "corefile.h"
56
67
78/*********************************************************************
r20005r20006
5859   stdio_filesizeproc
5960};
6061
62/*********************************************************************
63    ioprocs implementation on corefile
64*********************************************************************/
6165
66static void corefile_closeproc(void *file)
67{
68   core_fclose((core_file*)file);
69}
6270
71static int corefile_seekproc(void *file, INT64 offset, int whence)
72{
73   return core_fseek((core_file*)file, (long) offset, whence);
74}
75
76static size_t corefile_readproc(void *file, void *buffer, size_t length)
77{
78   return core_fread((core_file*)file, buffer, length);
79}
80
81static size_t corefile_writeproc(void *file, const void *buffer, size_t length)
82{
83   return core_fwrite((core_file*)file, buffer, length);
84}
85
86static UINT64 corefile_filesizeproc(void *file)
87{
88   long l, sz;
89   l = core_ftell((core_file*)file);
90   if (core_fseek((core_file*)file, 0, SEEK_END))
91      return (size_t) -1;
92   sz = core_ftell((core_file*)file);
93   if (core_fseek((core_file*)file, l, SEEK_SET))
94      return (size_t) -1;
95   return (size_t) sz;
96}
97
98const struct io_procs corefile_ioprocs =
99{
100   corefile_closeproc,
101   corefile_seekproc,
102   corefile_readproc,
103   corefile_writeproc,
104   corefile_filesizeproc
105};
106
107const struct io_procs corefile_ioprocs_noclose =
108{
109   NULL,
110   corefile_seekproc,
111   corefile_readproc,
112   corefile_writeproc,
113   corefile_filesizeproc
114};
115
116
117
63118/*********************************************************************
64119    calls for accessing generic IO
65120*********************************************************************/
trunk/src/lib/formats/ioprocs.h
r20005r20006
4646
4747extern const struct io_procs stdio_ioprocs;
4848extern const struct io_procs stdio_ioprocs_noclose;
49extern const struct io_procs corefile_ioprocs;
50extern const struct io_procs corefile_ioprocs_noclose;
4951
5052
5153

Previous 199869 Revisions Next


© 1997-2024 The MAME Team