| 306 | } |
| 307 | |
| 308 | void |
| 309 | SK_LoadImportModule (import_s& import) |
| 310 | { |
| 311 | // Do not load twice... |
| 312 | if (import.hLibrary != nullptr) |
| 313 | return; |
| 314 | |
| 315 | if (StrStrIW (import.filename->get_value_ref ().c_str (), L"ReShade") != nullptr) |
| 316 | { |
| 317 | SK_ReShade_LoadDLL ( import.filename->get_value_ref ().c_str (), |
| 318 | import.mode->get_value_str ().c_str () ); |
| 319 | } |
| 320 | |
| 321 | if (config.system.central_repository) |
| 322 | { |
| 323 | wchar_t wszProfilePlugIn [MAX_PATH + 2] = { }; |
| 324 | wcsncpy_s (wszProfilePlugIn, MAX_PATH, SK_GetConfigPath (), _TRUNCATE); |
| 325 | PathAppendW (wszProfilePlugIn, import.filename->get_value_str ().c_str ()); |
| 326 | |
| 327 | if (! SK_GetModuleHandleW (wszProfilePlugIn)) |
| 328 | { |
| 329 | import.hLibrary = SK_Modules->LoadLibrary ( |
| 330 | wszProfilePlugIn |
| 331 | ); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | if (import.hLibrary == nullptr && !SK_GetModuleHandleW (import.filename->get_value_str ().c_str ())) |
| 336 | { |
| 337 | import.hLibrary = SK_Modules->LoadLibrary ( |
| 338 | import.filename->get_value_str ().c_str () |
| 339 | ); |
| 340 | } |
| 341 | |
| 342 | // If we still can't find the library, try expanding environment variables |
| 343 | // in the user-supplied path. |
| 344 | if (import.hLibrary == nullptr) |
| 345 | { |
| 346 | wchar_t wszExpandedPath [MAX_PATH + 2] = { }; |
| 347 | const DWORD nExpandedPathSize = |
| 348 | ExpandEnvironmentStrings ( |
| 349 | import.filename->get_value_str ().c_str (), |
| 350 | wszExpandedPath, MAX_PATH ); |
| 351 | |
| 352 | if (nExpandedPathSize != 0 && !SK_GetModuleHandleW (wszExpandedPath)) |
| 353 | { |
| 354 | if (nExpandedPathSize <= MAX_PATH) |
| 355 | { |
| 356 | import.hLibrary = SK_Modules->LoadLibrary( |
| 357 | wszExpandedPath |
| 358 | ); |
| 359 | } |
| 360 | |
| 361 | else |
| 362 | { |
| 363 | // There's no guarantee that the length of the fully-expanded path will fit within |
| 364 | // the array defined above. If the path is long, we'll need to dynamically allocate |
| 365 | // memory on the heap for the long path and then call `ExpandEnvironmentStrings` again. |
no test coverage detected