| 8388 | } |
| 8389 | |
| 8390 | bool Line::FileInstallExtract(LPTSTR aSource, LPTSTR aDest, bool aOverwrite) |
| 8391 | { |
| 8392 | // Open the file first since it's the most likely to fail: |
| 8393 | HANDLE hfile = CreateFile(aDest, GENERIC_WRITE, 0, NULL, aOverwrite ? CREATE_ALWAYS : CREATE_NEW, 0, NULL); |
| 8394 | if (hfile == INVALID_HANDLE_VALUE) |
| 8395 | return false; |
| 8396 | |
| 8397 | // Create a temporary copy of aSource to ensure it is the correct case (upper-case). |
| 8398 | // Ahk2Exe converts it to upper-case before adding the resource. My testing showed that |
| 8399 | // using lower or mixed case in some instances prevented the resource from being found. |
| 8400 | // Since file paths are case-insensitive, it certainly doesn't seem harmful to do this: |
| 8401 | TCHAR source[T_MAX_PATH]; |
| 8402 | size_t source_length = _tcslen(aSource); |
| 8403 | if (source_length >= _countof(source)) |
| 8404 | // Probably can't happen; for simplicity, truncate it. |
| 8405 | source_length = _countof(source) - 1; |
| 8406 | tmemcpy(source, aSource, source_length + 1); |
| 8407 | _tcsupr(source); |
| 8408 | |
| 8409 | // Find and load the resource. |
| 8410 | HRSRC res; |
| 8411 | HGLOBAL res_load; |
| 8412 | LPVOID res_lock; |
| 8413 | bool success = false; |
| 8414 | if ( (res = FindResource(NULL, source, RT_RCDATA)) |
| 8415 | && (res_load = LoadResource(NULL, res)) |
| 8416 | && (res_lock = LockResource(res_load)) ) |
| 8417 | { |
| 8418 | DWORD num_bytes_written; |
| 8419 | // Write the resource data to file. |
| 8420 | success = WriteFile(hfile, res_lock, SizeofResource(NULL, res), &num_bytes_written, NULL); |
| 8421 | } |
| 8422 | CloseHandle(hfile); |
| 8423 | return success; |
| 8424 | } |
| 8425 | |
| 8426 | #ifndef AUTOHOTKEYSC |
| 8427 | bool Line::FileInstallCopy(LPTSTR aSource, LPTSTR aDest, bool aOverwrite) |
nothing calls this directly
no outgoing calls
no test coverage detected