| 280 | } |
| 281 | |
| 282 | void AndroidAssetStream::Open(FileAccess mode) |
| 283 | { |
| 284 | FileAccess maskedMode = mode & FileAccess::ReadWrite; |
| 285 | if (maskedMode != FileAccess::Read) { |
| 286 | #if defined(DEATH_TRACE_VERBOSE_IO) |
| 287 | LOGE("Failed to open file \"{}/{}\" because of invalid mode ({})", Prefix, _path, std::uint32_t(mode)); |
| 288 | #endif |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | #if defined(DEATH_USE_FILE_DESCRIPTORS) |
| 293 | // An asset file can only be read |
| 294 | AAsset* asset = AAssetManager_open(_nativeActivity->assetManager, _path.data(), AASSET_MODE_RANDOM); |
| 295 | if (asset == nullptr) { |
| 296 | # if defined(DEATH_TRACE_VERBOSE_IO) |
| 297 | LOGE("Failed to open file \"{}/{}\"", Prefix, _path); |
| 298 | # endif |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | off64_t outStart = 0; |
| 303 | off64_t outLength = 0; |
| 304 | _fileDescriptor = AAsset_openFileDescriptor64(asset, &outStart, &outLength); |
| 305 | _startOffset = outStart; |
| 306 | _size = outLength; |
| 307 | |
| 308 | ::lseek(_fileDescriptor, _startOffset, SEEK_SET); |
| 309 | AAsset_close(asset); |
| 310 | asset = nullptr; |
| 311 | |
| 312 | if (_fileDescriptor < 0) { |
| 313 | # if defined(DEATH_TRACE_VERBOSE_IO) |
| 314 | LOGE("Failed to open file \"{}/{}\"", Prefix, _path); |
| 315 | # endif |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | # if defined(DEATH_TRACE_VERBOSE_IO) |
| 320 | LOGB("File \"{}/{}\" opened", Prefix, _path); |
| 321 | # endif |
| 322 | #else |
| 323 | // An asset file can only be read |
| 324 | _asset = AAssetManager_open(_nativeActivity->assetManager, _path.data(), AASSET_MODE_RANDOM); |
| 325 | if (_asset == nullptr) { |
| 326 | # if defined(DEATH_TRACE_VERBOSE_IO) |
| 327 | LOGE("Failed to open file \"{}/{}\"", Prefix, _path); |
| 328 | # endif |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | # if defined(DEATH_TRACE_VERBOSE_IO) |
| 333 | LOGB("File \"{}/{}\" opened", Prefix, _path); |
| 334 | # endif |
| 335 | |
| 336 | // Calculating file size |
| 337 | _size = AAsset_getLength64(_asset); |
| 338 | #endif |
| 339 | } |