trunk/src/emu/fileio.c
| r243495 | r243496 | |
| 141 | 141 | emu_file::emu_file(UINT32 openflags) |
| 142 | 142 | : m_file(NULL), |
| 143 | 143 | m_iterator(""), |
| 144 | m_mediapaths(""), |
| 144 | 145 | m_crc(0), |
| 145 | 146 | m_openflags(openflags), |
| 146 | 147 | m_zipfile(NULL), |
| 147 | 148 | m_ziplength(0), |
| 148 | 149 | m__7zfile(NULL), |
| 149 | 150 | m__7zlength(0), |
| 150 | | m_remove_on_close(false) |
| 151 | m_remove_on_close(false), |
| 152 | m_restrict_to_mediapath(false) |
| 151 | 153 | { |
| 152 | 154 | // sanity check the open flags |
| 153 | 155 | if ((m_openflags & OPEN_FLAG_HAS_CRC) && (m_openflags & OPEN_FLAG_WRITE)) |
| r243495 | r243496 | |
| 157 | 159 | emu_file::emu_file(const char *searchpath, UINT32 openflags) |
| 158 | 160 | : m_file(NULL), |
| 159 | 161 | m_iterator(searchpath), |
| 162 | m_mediapaths(searchpath), |
| 160 | 163 | m_crc(0), |
| 161 | 164 | m_openflags(openflags), |
| 162 | 165 | m_zipfile(NULL), |
| 163 | 166 | m_ziplength(0), |
| 164 | 167 | m__7zfile(NULL), |
| 165 | 168 | m__7zlength(0), |
| 166 | | m_remove_on_close(false) |
| 169 | m_remove_on_close(false), |
| 170 | m_restrict_to_mediapath(false) |
| 167 | 171 | { |
| 168 | 172 | // sanity check the open flags |
| 169 | 173 | if ((m_openflags & OPEN_FLAG_HAS_CRC) && (m_openflags & OPEN_FLAG_WRITE)) |
| r243495 | r243496 | |
| 354 | 358 | { |
| 355 | 359 | astring tempfullpath = m_fullpath; |
| 356 | 360 | |
| 357 | | filerr = attempt__7zped(); |
| 361 | filerr = attempt_zipped(); |
| 358 | 362 | if (filerr == FILERR_NONE) |
| 359 | 363 | break; |
| 360 | 364 | |
| 361 | 365 | m_fullpath = tempfullpath; |
| 362 | 366 | |
| 363 | | filerr = attempt_zipped(); |
| 367 | filerr = attempt__7zped(); |
| 364 | 368 | if (filerr == FILERR_NONE) |
| 365 | 369 | break; |
| 366 | | |
| 367 | | |
| 368 | 370 | } |
| 369 | 371 | } |
| 370 | 372 | return filerr; |
| r243495 | r243496 | |
| 650 | 652 | } |
| 651 | 653 | |
| 652 | 654 | |
| 655 | //------------------------------------------------- |
| 656 | // part_of_mediapath - checks if 'path' is part of |
| 657 | // any media path |
| 658 | //------------------------------------------------- |
| 653 | 659 | |
| 660 | bool emu_file::part_of_mediapath(astring path) |
| 661 | { |
| 662 | bool result = false; |
| 663 | astring mediapath; |
| 664 | m_mediapaths.reset(); |
| 665 | while (m_mediapaths.next(mediapath, NULL) && !result) |
| 666 | if (path.cmpsubstr(mediapath, 0, mediapath.len())) |
| 667 | result = true; |
| 668 | return result; |
| 669 | } |
| 670 | |
| 654 | 671 | //------------------------------------------------- |
| 655 | 672 | // attempt_zipped - attempt to open a ZIPped file |
| 656 | 673 | //------------------------------------------------- |
| r243495 | r243496 | |
| 667 | 684 | if (dirsep == -1) |
| 668 | 685 | return FILERR_NOT_FOUND; |
| 669 | 686 | |
| 687 | if (restrict_to_mediapath()) |
| 688 | if ( !part_of_mediapath(m_fullpath) ) |
| 689 | return FILERR_NOT_FOUND; |
| 690 | |
| 670 | 691 | // insert the part from the right of the separator into the head of the filename |
| 671 | 692 | if (filename.len() > 0) |
| 672 | 693 | filename.ins(0, "/"); |
| r243495 | r243496 | |
| 798 | 819 | if (dirsep == -1) |
| 799 | 820 | return FILERR_NOT_FOUND; |
| 800 | 821 | |
| 822 | if (restrict_to_mediapath()) |
| 823 | if ( !part_of_mediapath(m_fullpath) ) |
| 824 | return FILERR_NOT_FOUND; |
| 825 | |
| 801 | 826 | // insert the part from the right of the separator into the head of the filename |
| 802 | 827 | if (filename.len() > 0) |
| 803 | 828 | filename.ins(0, "/"); |
trunk/src/emu/fileio.h
| r243495 | r243496 | |
| 97 | 97 | const char *fullpath() const { return m_fullpath; } |
| 98 | 98 | UINT32 openflags() const { return m_openflags; } |
| 99 | 99 | hash_collection &hashes(const char *types); |
| 100 | bool restrict_to_mediapath() { return m_restrict_to_mediapath; } |
| 101 | bool part_of_mediapath(astring path); |
| 100 | 102 | |
| 101 | 103 | // setters |
| 102 | 104 | void remove_on_close() { m_remove_on_close = true; } |
| 103 | 105 | void set_openflags(UINT32 openflags) { assert(m_file == NULL); m_openflags = openflags; } |
| 106 | void set_restrict_to_mediapath(bool rtmp = true) { m_restrict_to_mediapath = rtmp; } |
| 104 | 107 | |
| 105 | 108 | // open/close |
| 106 | 109 | file_error open(const char *name); |
| r243495 | r243496 | |
| 151 | 154 | astring m_fullpath; // full filename |
| 152 | 155 | core_file * m_file; // core file pointer |
| 153 | 156 | path_iterator m_iterator; // iterator for paths |
| 154 | | UINT32 m_crc; // iterator for paths |
| 157 | path_iterator m_mediapaths; // media-path iterator |
| 158 | UINT32 m_crc; // file's CRC |
| 155 | 159 | UINT32 m_openflags; // flags we used for the open |
| 156 | 160 | hash_collection m_hashes; // collection of hashes |
| 157 | 161 | |
| r243495 | r243496 | |
| 164 | 168 | UINT64 m__7zlength; // 7Z file length |
| 165 | 169 | |
| 166 | 170 | bool m_remove_on_close; // flag: remove the file when closing |
| 171 | bool m_restrict_to_mediapath; // flag: restrict to paths inside the media-path |
| 167 | 172 | }; |
| 168 | 173 | |
| 169 | 174 | |