| 115 | } |
| 116 | |
| 117 | IReader* CLocatorAPI::archive::read_db(const char* fname, const struct file& desc, u32 gran) const |
| 118 | { |
| 119 | size_t start = (desc.ptr / gran) * gran; |
| 120 | size_t end = (desc.ptr + desc.size_compressed) / gran; |
| 121 | if ((desc.ptr + desc.size_compressed) % gran) |
| 122 | end += 1; |
| 123 | end *= gran; |
| 124 | if (end > size) |
| 125 | end = size; |
| 126 | size_t sz = end - start; |
| 127 | |
| 128 | u8* ptr = (u8*)MapViewOfFile(hSrcMap, FILE_MAP_READ, 0, start, sz); |
| 129 | if (!ptr) |
| 130 | { |
| 131 | VERIFY(ptr, "cannot create file mapping on file", fname); |
| 132 | return nullptr; |
| 133 | } |
| 134 | |
| 135 | #ifdef DEBUG |
| 136 | string512 temp; |
| 137 | sprintf_s(temp, "%s:%s", *path, fname); |
| 138 | |
| 139 | register_file_mapping(ptr, sz, temp); |
| 140 | #endif // DEBUG |
| 141 | |
| 142 | size_t ptr_offs = desc.ptr - start; |
| 143 | if (desc.size_real == desc.size_compressed) |
| 144 | return xr_new<CPackReader>(ptr, ptr + ptr_offs, desc.size_real); |
| 145 | |
| 146 | // Compressed |
| 147 | u8* dest = xr_alloc<u8>(desc.size_real); |
| 148 | rtc_decompress(dest, desc.size_real, ptr + ptr_offs, desc.size_compressed); |
| 149 | |
| 150 | auto* R = xr_new<CTempReader>(dest, desc.size_real, 0); |
| 151 | UnmapViewOfFile(ptr); |
| 152 | |
| 153 | #ifdef DEBUG |
| 154 | unregister_file_mapping(ptr, sz); |
| 155 | #endif // DEBUG |
| 156 | |
| 157 | return R; |
| 158 | } |
| 159 | |
| 160 | CStreamReader* CLocatorAPI::archive::stream_db(const char* fname, const struct file& desc) const |
| 161 | { |
nothing calls this directly
no test coverage detected