Ticket #8904: archive-prefix.patch
File archive-prefix.patch, 3.4 KB (added by , 17 years ago) |
---|
-
archive.cpp
71 71 */ 72 72 class FSDirectoryMember : public ArchiveMember { 73 73 FSNode _node; 74 74 75 75 public: 76 76 FSDirectoryMember(FSNode &node) : _node(node) { 77 77 } … … 96 96 97 97 FSDirectory::FSDirectory(const FSNode &node, int depth) 98 98 : _node(node), _cached(false), _depth(depth) { 99 100 setPrefix(String::emptyString); 99 101 } 100 102 103 FSDirectory::FSDirectory(const String &prefix, const FSNode &node, int depth) 104 : _node(node), _cached(false), _depth(depth) { 105 106 setPrefix(prefix); 107 } 108 101 109 FSDirectory::FSDirectory(const String &name, int depth) 102 110 : _node(name), _cached(false), _depth(depth) { 111 112 setPrefix(String::emptyString); 103 113 } 104 114 115 FSDirectory::FSDirectory(const String &prefix, const String &name, int depth) 116 : _node(name), _cached(false), _depth(depth) { 117 118 setPrefix(prefix); 119 } 120 105 121 FSDirectory::~FSDirectory() { 106 122 } 107 123 124 void FSDirectory::setPrefix(const String &prefix) { 125 _prefix = prefix; 126 127 if (!_prefix.empty() && !_prefix.hasSuffix("/")) { 128 _prefix += "/"; 129 } 130 } 131 108 132 FSNode FSDirectory::getFSNode() const { 109 133 return _node; 110 134 } … … 113 137 // make caching as lazy as possible 114 138 if (!name.empty()) { 115 139 if (!_cached) { 116 cacheDirectoryRecursive(_node, _depth, "");140 cacheDirectoryRecursive(_node, _depth, _prefix); 117 141 _cached = true; 118 142 } 119 143 … … 157 181 } 158 182 159 183 FSDirectory *FSDirectory::getSubDirectory(const String &name, int depth) { 184 return getSubDirectory(String::emptyString, name, depth); 185 } 186 187 FSDirectory *FSDirectory::getSubDirectory(const String &prefix, const String &name, int depth) { 160 188 if (name.empty() || !_node.isDirectory()) { 161 189 return 0; 162 190 } 163 191 164 192 FSNode node = lookupCache(_subDirCache, name); 165 return new FSDirectory( node, depth);193 return new FSDirectory(prefix, node, depth); 166 194 } 167 195 168 196 void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) { -
archive.h
131 131 // Key is stored in lowercase. 132 132 typedef HashMap<String, FSNode, IgnoreCase_Hash, IgnoreCase_EqualTo> NodeCache; 133 133 NodeCache _fileCache, _subDirCache; 134 Common::String _prefix; // string that is prepended to each cache item key 135 void setPrefix(const String &prefix); 134 136 135 137 // look for a match 136 138 FSNode lookupCache(NodeCache &cache, const String &name); … … 146 148 * unbound FSDirectory if name is not found on the filesystem or is not a directory. 147 149 */ 148 150 FSDirectory(const String &name, int depth = 1); 151 FSDirectory(const String &prefix, const String &name, int depth = 1); 149 152 150 153 /** 151 154 * Create a FSDirectory representing a tree with the specified depth. Will result in an 152 155 * unbound FSDirectory if node does not exist or is not a directory. 153 156 */ 154 157 FSDirectory(const FSNode &node, int depth = 1); 158 FSDirectory(const String &prefix, const FSNode &node, int depth = 1); 155 159 156 160 virtual ~FSDirectory(); 157 161 … … 165 169 * @return a new FSDirectory instance 166 170 */ 167 171 FSDirectory *getSubDirectory(const String &name, int depth = 1); 172 FSDirectory *getSubDirectory(const String &prefix, const String &name, int depth = 1); 168 173 169 174 virtual bool hasFile(const String &name); 170 175 virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern);