| 80 | |
| 81 | |
| 82 | std::istream* FileManager::createDataInStream(const std::string& filename, |
| 83 | bool binary) const { |
| 84 | // choose open mode |
| 85 | std::ios::openmode mode = std::ios::in; |
| 86 | if (binary) { |
| 87 | mode |= std::ios::binary; |
| 88 | } |
| 89 | |
| 90 | std::ifstream* stream = NULL; |
| 91 | |
| 92 | const bool relative = !isAbsolute(filename); |
| 93 | |
| 94 | if (relative) { |
| 95 | // try directory stored in DB |
| 96 | if (BZDB.isSet("directory")) { |
| 97 | stream = getInStream(catPath(BZDB.get("directory"), filename), mode); |
| 98 | if (stream) { |
| 99 | return stream; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // try data directory |
| 104 | stream = getInStream(catPath("data", filename), mode); |
| 105 | if (stream) { |
| 106 | return stream; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // try current directory (or absolute path) |
| 111 | stream = getInStream(filename, mode); |
| 112 | if (stream) { |
| 113 | return stream; |
| 114 | } |
| 115 | |
| 116 | // try install directory |
| 117 | #if defined(BZFLAG_DATA) |
| 118 | if (relative) { |
| 119 | stream = getInStream(catPath(BZFLAG_DATA, filename), mode); |
| 120 | if (stream) { |
| 121 | return stream; |
| 122 | } |
| 123 | } |
| 124 | #endif |
| 125 | |
| 126 | return NULL; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | std::ostream* FileManager::createDataOutStream(const std::string& filename, |
no test coverage detected