| 237 | } |
| 238 | |
| 239 | Result MakePathDescriptor(ResourcePreloader* preloader, const char* name, PathDescriptor& out_path_descriptor) |
| 240 | { |
| 241 | if (name == 0x0) |
| 242 | { |
| 243 | return RESULT_INVALID_DATA; |
| 244 | } |
| 245 | // Ignore malformed paths that would fail anyway. |
| 246 | Result res = CheckSuppliedResourcePath(name); |
| 247 | if (res != dmResource::RESULT_OK) |
| 248 | { |
| 249 | return res; |
| 250 | } |
| 251 | uint32_t name_len = strlen(name); |
| 252 | if (name_len >= RESOURCE_PATH_MAX) |
| 253 | { |
| 254 | dmLogError("Resource path is to long: (%s)", name); |
| 255 | return RESULT_INVALID_DATA; |
| 256 | } |
| 257 | out_path_descriptor.m_NameHash = dmHashBuffer64(name, name_len); |
| 258 | out_path_descriptor.m_ResourceType = GetResourceType(preloader, name); |
| 259 | // We do not bail on out_path_descriptor.m_ResourceType being zero here, we want to |
| 260 | // create a request so we can get a proper error code for the resource in the request |
| 261 | |
| 262 | char canonical_path[RESOURCE_PATH_MAX]; |
| 263 | uint32_t canonical_path_len = dmResource::GetCanonicalPath(name, canonical_path, sizeof(canonical_path)); |
| 264 | out_path_descriptor.m_CanonicalPathHash = dmHashBuffer64(canonical_path, canonical_path_len); |
| 265 | |
| 266 | DM_SPINLOCK_SCOPED_LOCK(preloader->m_SyncedDataSpinlock) |
| 267 | { |
| 268 | out_path_descriptor.m_InternalizedName = InternalizePath(&preloader->m_SyncedData, out_path_descriptor.m_NameHash, name, name_len); |
| 269 | if (out_path_descriptor.m_InternalizedName == 0x0) |
| 270 | { |
| 271 | dmSpinlock::Unlock(&preloader->m_SyncedDataSpinlock); |
| 272 | return RESULT_OUT_OF_MEMORY; |
| 273 | } |
| 274 | out_path_descriptor.m_InternalizedCanonicalPath = InternalizePath(&preloader->m_SyncedData, out_path_descriptor.m_CanonicalPathHash, canonical_path, canonical_path_len); |
| 275 | if (out_path_descriptor.m_InternalizedCanonicalPath == 0x0) |
| 276 | { |
| 277 | dmSpinlock::Unlock(&preloader->m_SyncedDataSpinlock); |
| 278 | return RESULT_OUT_OF_MEMORY; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return RESULT_OK; |
| 283 | } |
| 284 | |
| 285 | static bool IsPathInProgress(ResourcePreloader* preloader, const PathDescriptor* path_descriptor) |
| 286 | { |
no test coverage detected