MCPcopy Create free account
hub / github.com/ConEmu/ConEmu / ExportFile

Function ExportFile

src/Setup/Setupper/Setupper.cpp:401–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

399}
400
401int ExportFile(int ResID, wchar_t* FilePath)
402{
403 HRSRC hResInfo = FindResource(hInst, MAKEINTRESOURCE(ResID), L"DATA");
404 if (!hResInfo)
405 return ReportError(exit_FindResource, msgFindResourceFailed, (void*)ResID);
406
407 HGLOBAL hGbl = LoadResource(hInst, hResInfo);
408 if (!hGbl)
409 return ReportError(exit_LoadResource, msgLoadResourceFailed, (void*)ResID);
410
411 DWORD nResSize = hResInfo ? SizeofResource(hInst, hResInfo) : 0;
412 LPVOID pRes = hGbl ? LockResource(hGbl) : NULL;
413
414 int iRc = 0;
415
416 if (!nResSize || !pRes)
417 {
418 iRc = ReportError(exit_LockResource, msgLoadResourceFailed, (void*)ResID);
419 }
420 else
421 {
422 HANDLE hFile = CreateFile(FilePath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
423 if (!hFile || hFile == INVALID_HANDLE_VALUE)
424 {
425 iRc = ReportError(exit_CreateFile, msgCreateFileFailed, FilePath);
426 }
427 else
428 {
429 DWORD nWritten = 0;
430 if (!WriteFile(hFile, pRes, nResSize, &nWritten, NULL) || nWritten != nResSize)
431 {
432 iRc = ReportError(exit_WriteFile, msgWriteFileFailed, FilePath);
433 }
434
435 CloseHandle(hFile);
436
437 if (iRc != 0)
438 DeleteFile(FilePath);
439 }
440 }
441
442 return iRc;
443}
444
445class CTempDir
446{

Callers 1

_tWinMainFunction · 0.85

Calls 1

ReportErrorFunction · 0.70

Tested by

no test coverage detected