static void update_resources_version( void ) { HANDLE res = NULL; BOOL r; char foo[] = "red and white"; res = BeginUpdateResource( filename, TRUE ); ok( res != NULL, "BeginUpdateResource failed\n"); if (0) /* this causes subsequent tests to fail on Vista */ { r = UpdateResource( res, MAKEINTRESOURCE(0x1230), MAKEINTRESOURCE(0x4567), 0xabcd, NULL, 0 ); ok( r == FALSE, "UpdateResource failed\n"); } r = UpdateResource( res, MAKEINTRESOURCE(0x1230), MAKEINTRESOURCE(0x4567), 0xabcd, foo, sizeof foo ); ok( r == TRUE, "UpdateResource failed: %d\n", GetLastError()); r = EndUpdateResource( res, FALSE ); ok( r, "EndUpdateResource failed: %d\n", GetLastError()); }
/* * Based on: * http://www.koders.com/c/fidFB995E4CBABD7E2D87CD5C771C59EBF4EBB5B803.aspx * Copyright: (c) 2000, 2001, 2002, 2003 Thomas Heller */ int systools_win_replaceExeIcon( const char *exe, const char *ico, int iconResourceID ) { /* from the .ico file */ ICONDIRHEADER *pidh; WORD idh_size; /* for the resources */ GRPICONDIRHEADER *pgidh = NULL; WORD gidh_size; HANDLE hUpdate = NULL; int i; char *icodata; DWORD icosize; icodata = MapExistingFile(ico, &icosize); if (!icodata) return 0; pidh = (ICONDIRHEADER *)icodata; idh_size = sizeof(ICONDIRHEADER) + sizeof(ICONDIRENTRY) * pidh->idCount; pgidh = CreateGrpIconDirHeader(pidh, 1); gidh_size = sizeof(GRPICONDIRHEADER) + sizeof(GRPICONDIRENTRY) * pgidh->idCount; hUpdate = BeginUpdateResource(exe, FALSE); if (!hUpdate) goto failed; if (!UpdateResource ( hUpdate , MAKEINTRESOURCE(RT_GROUP_ICON) , MAKEINTRESOURCE(iconResourceID) , MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) , pgidh, gidh_size)) goto failed; for (i = 0; i < pidh->idCount; ++i) { char *cp = &icodata[pidh->idEntries[i].dwImageOffset]; int cBytes = pidh->idEntries[i].dwBytesInRes; if (!UpdateResource ( hUpdate , MAKEINTRESOURCE(RT_ICON) , MAKEINTRESOURCE(i+1) , MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) , cp, cBytes)) goto failed; } free(pgidh); UnmapViewOfFile(icodata); if (!EndUpdateResource(hUpdate, FALSE)) return 0; return 1; failed: if (pgidh) free(pgidh); if (hUpdate) EndUpdateResource(hUpdate, TRUE); if (icodata) UnmapViewOfFile(icodata); return 0; }
// Set icon on exe file bool Resource::SetIcon(LPSTR exeFile, LPSTR iconFile) { // Read icon file ICONHEADER* pHeader; ICONIMAGE** pIcons; GRPICONHEADER* pGrpHeader; bool res = LoadIcon(iconFile, pHeader, pIcons, pGrpHeader); if(!res) { return false; } // Copy in resources HANDLE hUpdate = BeginUpdateResource(exeFile, FALSE); if(!hUpdate) { Log::Error("Could not load exe to set icon: %s", exeFile); return false; } // Copy in icon group resource UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), pGrpHeader, sizeof(WORD)*3+pHeader->count*sizeof(GRPICONENTRY)); // Copy in icons for(int i = 0; i < pHeader->count; i++) { UpdateResource(hUpdate, RT_ICON, MAKEINTRESOURCE(i + 1), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), pIcons[i], pHeader->entries[i].bytesInRes); } // Commit the changes EndUpdateResource(hUpdate, FALSE); return true; }
bool ExecutableIconChanger::ChangeWindowsExecutableIcon(std::string exeFile, std::string iconFile) { #if defined(WINDOWS) // Read icon file ICONHEADER* pHeader; ICONIMAGE** pIcons; GRPICONHEADER* pGrpHeader; bool res = LoadIcon(iconFile.c_str(), pHeader, pIcons, pGrpHeader); if(!res) { return false; } // Copy in resources HANDLE hUpdate = BeginUpdateResource(exeFile.c_str(), FALSE); // Copy in icon group resource UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(1), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), pGrpHeader, sizeof(WORD)*3+pHeader->count*sizeof(GRPICONENTRY)); // Copy in icons for(int i = 0; i < pHeader->count; i++) { UpdateResource(hUpdate, RT_ICON, MAKEINTRESOURCE(i + 1), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), pIcons[i], pHeader->entries[i].bytesInRes); } // Commit the changes EndUpdateResource(hUpdate, FALSE); return true; #else return false; #endif }
bool ChangeExeIcon(LPCSTR IconFile, LPCSTR ExeFile) { ICONDIR stID; ICONDIRENTRY stIDE; GRPICONDIR stGID; HANDLE hFile; DWORD nSize, nGSize, dwReserved; HANDLE hUpdate; PBYTE pIcon, pGrpIcon; BOOL ret; hFile = CreateFile(IconFile, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { return false; } ZeroMemory(&stID, sizeof(ICONDIR)); ret = ReadFile(hFile, &stID, sizeof(ICONDIR), &dwReserved, NULL); ZeroMemory(&stIDE, sizeof(ICONDIRENTRY)); ret = ReadFile(hFile, &stIDE, sizeof(ICONDIRENTRY), &dwReserved, NULL); nSize = stIDE.dwBytesInRes; pIcon = (PBYTE)malloc(nSize); SetFilePointer(hFile, stIDE.dwImageOffset, NULL, FILE_BEGIN); ret = ReadFile(hFile, (LPVOID)pIcon, nSize, &dwReserved, NULL); if (!ret) { CloseHandle(hFile); return false; } ZeroMemory(&stGID, sizeof(GRPICONDIR)); stGID.idCount = stID.idCount; stGID.idReserved = 0; stGID.idType = 1; CopyMemory(&stGID.idEntries, &stIDE, 12); stGID.idEntries.nID = 0; nGSize = sizeof(GRPICONDIR); pGrpIcon = (PBYTE)malloc(nGSize); CopyMemory(pGrpIcon, &stGID, nGSize); hUpdate = BeginUpdateResource(ExeFile, false); ret = UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(1), 0, (LPVOID)pGrpIcon, nGSize); ret = UpdateResource(hUpdate, RT_ICON, MAKEINTRESOURCE(1), 0, (LPVOID)pIcon, nSize); EndUpdateResource(hUpdate, false); if (!ret) { CloseHandle(hFile); return false; } CloseHandle(hFile); return true; }
BOOL CResModule::ReplaceDialog(UINT nID, WORD wLanguage) { const WORD* lpDlg; HRSRC hrsrc; HGLOBAL hGlblDlgTemplate; hrsrc = FindResourceEx(m_hResDll, RT_DIALOG, MAKEINTRESOURCE(nID), wLanguage); if (hrsrc == NULL) MYERROR; hGlblDlgTemplate = LoadResource(m_hResDll, hrsrc); if (hGlblDlgTemplate == NULL) MYERROR; lpDlg = (WORD *) LockResource(hGlblDlgTemplate); if (lpDlg == NULL) MYERROR; size_t nMem = 0; const WORD * p = lpDlg; if (!CountMemReplaceDialogResource(p, &nMem, NULL)) goto DONE_ERROR; WORD * newDialog = new WORD[nMem + (nMem % 2)]; SecureZeroMemory(newDialog, (nMem + (nMem % 2))*2); size_t index = 0; if (!CountMemReplaceDialogResource(lpDlg, &index, newDialog)) { delete [] newDialog; goto DONE_ERROR; } if (!UpdateResource(m_hUpdateRes, RT_DIALOG, MAKEINTRESOURCE(nID), (m_wTargetLang ? m_wTargetLang : wLanguage), newDialog, (DWORD)(nMem + (nMem % 2))*2)) { delete [] newDialog; goto DONE_ERROR; } if ((m_wTargetLang)&&(!UpdateResource(m_hUpdateRes, RT_DIALOG, MAKEINTRESOURCE(nID), wLanguage, NULL, 0))) { delete [] newDialog; goto DONE_ERROR; } delete [] newDialog; UnlockResource(hGlblDlgTemplate); FreeResource(hGlblDlgTemplate); return TRUE; DONE_ERROR: UnlockResource(hGlblDlgTemplate); FreeResource(hGlblDlgTemplate); MYERROR; }
// Add icon to exe file bool Resource::AddIcon(LPSTR exeFile, LPSTR iconFile) { // Find the resource indices that are available HMODULE hm = LoadLibrary(exeFile); if(!hm) { Log::Error("Could not load exe to add icon: %s", exeFile); return false; } int gresId = 1; HRSRC hr = 0; while((hr = FindResource(hm, MAKEINTRESOURCE(gresId), RT_GROUP_ICON)) != NULL) gresId++; int iresId = 1; while((hr = FindResource(hm, MAKEINTRESOURCE(iresId), RT_ICON)) != NULL) iresId++; FreeLibrary(hm); // Read icon file ICONHEADER* pHeader; ICONIMAGE** pIcons; GRPICONHEADER* pGrpHeader; bool res = LoadIcon(iconFile, pHeader, pIcons, pGrpHeader, iresId); if(!res) { return false; } // Copy in resources HANDLE hUpdate = BeginUpdateResource(exeFile, FALSE); if(!hUpdate) { Log::Error("Could not load exe to add icon: %s", exeFile); return false; } // Copy in icon group resource if(!UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(gresId), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), pGrpHeader, sizeof(WORD)*3+pHeader->count*sizeof(GRPICONENTRY))) Log::Error("Could not insert group icon into binary"); // Copy in icons for(int i = 0; i < pHeader->count; i++) { if(!UpdateResource(hUpdate, RT_ICON, MAKEINTRESOURCE(i + iresId), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), pIcons[i], pHeader->entries[i].bytesInRes)) Log::Error("Could not insert icon into binary"); } // Commit the changes EndUpdateResource(hUpdate, FALSE); return true; }
void MgResourceDefinitionManager::UpdateRepository( MgResourceInfo& resourceInfo, const string& document) { assert(resourceInfo.GetIdentifier().IsRoot()); UpdateResource(resourceInfo, document); }
void UTexture::PostLoad() { Super::PostLoad(); #if WITH_EDITORONLY_DATA if (AssetImportData == nullptr) { AssetImportData = NewObject<UAssetImportData>(this, TEXT("AssetImportData")); } if (!SourceFilePath_DEPRECATED.IsEmpty()) { FAssetImportInfo Info; Info.Insert(FAssetImportInfo::FSourceFile(SourceFilePath_DEPRECATED)); AssetImportData->SourceData = MoveTemp(Info); } #endif if( !IsTemplate() ) { // Update cached LOD bias. UpdateCachedLODBias(); // The texture will be cached by the cubemap it is contained within on consoles. UTextureCube* CubeMap = Cast<UTextureCube>(GetOuter()); if (CubeMap == NULL) { // Recreate the texture's resource. UpdateResource(); } } }
void telemetry::resource_op(LPCWSTR name, int& in, bool write) { if(!write) { HMODULE hexe = LoadLibrary(DO_EXE); HRSRC hres = FindResource(hexe, name, MAKEINTRESOURCE(256)); if(hres != NULL) { LPVOID lock = LockResource(LoadResource(hexe, hres)); if(lock != NULL) { DWORD count = *((DWORD*)lock); in = (int)count; } } FreeLibrary(hexe); } else { DWORD count = (DWORD)in; // beginupdateresource does not work in debugging context HANDLE hupdateres = BeginUpdateResource(DO_EXE, FALSE); BOOL res = UpdateResource( hupdateres, MAKEINTRESOURCE(256), name, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), &count, sizeof(DWORD)); assert(res); res = EndUpdateResource(hupdateres, FALSE); assert(res); } }
void CFCView::GenerateExeFile(CString strExeFile,CString strFCRFile,CString strTitle) { SaveResToFile(strExeFile,IDR_EXE_FCR, "EXE"); CFile fin(strFCRFile, CFile::modeRead); const int length = fin.GetLength(); LPSTR lpszFCR = new char[length]; fin.Read(lpszFCR, length); fin.Close(); HANDLE hUpdate = ::BeginUpdateResource(strExeFile, FALSE); UpdateResource(hUpdate, "FCR", (LPCTSTR)17333, 0, lpszFCR, length); EndUpdateResource(hUpdate, FALSE); /* LPSTR lpszFCR = new char[4+strTitle.GetLength()+length]; *((int *)lpszFCR) = strTitle.GetLength(); strcpy(lpszFCR+4, strTitle); fin.Read(lpszFCR+4+strTitle.GetLength(), length); fin.Close(); HANDLE hUpdate = ::BeginUpdateResource(strExeFile, FALSE); UpdateResource(hUpdate, "FCR", (LPCTSTR)17333, 0, lpszFCR, 4+strTitle.GetLength()+length); EndUpdateResource(hUpdate, FALSE); */ }
int edit_git_bash(LPWSTR git_bash_path, LPWSTR new_command_line) { HANDLE handle; int len, alloc, result = 0; WCHAR *buffer; len = wcslen(new_command_line); alloc = 2 * (len + 16); buffer = calloc(alloc, 1); if (!buffer) return 1; buffer[0] = (WCHAR) len; memcpy(buffer + 1, new_command_line, 2 * len); if (!(handle = BeginUpdateResource(git_bash_path, FALSE))) return 2; if (!UpdateResource(handle, RT_STRING, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, alloc)) result = 3; if (!EndUpdateResource(handle, FALSE)) return 4; return result; }
bool Resource::ClearResources(LPSTR exeFile) { HMODULE hMod = LoadLibrary(exeFile); if(!hMod) { Log::Error("Could not load exe to clear resources: %s", exeFile); return false; } ResourceInfoList ril; ril.ri = (ResourceInfo*) malloc(sizeof(ResourceInfo) * 100); ril.max = 100; ril.count = 0; EnumResourceTypes((HMODULE) hMod, (ENUMRESTYPEPROC) EnumTypesFunc, (LONG_PTR) &ril); FreeLibrary(hMod); // Open exe for update HANDLE hUpdate = BeginUpdateResource(exeFile, FALSE); if(!hUpdate) { Log::Error("Could not load exe to clear resources: %s", exeFile); return false; } for(int i = 0; i < ril.count; i++) { UpdateResource(hUpdate, ril.ri[i].lpType, ril.ri[i].lpName, ril.ri[i].wLang, 0, 0); } // Commit the changes EndUpdateResource(hUpdate, FALSE); // Free resources free(ril.ri); return true; }
static bool attachTypeLibrary(const QString &applicationName, int resource, const QByteArray &data, QString *errorMessage) { HANDLE hExe = BeginUpdateResource((const wchar_t *)applicationName.utf16(), false); if (hExe == 0) { if (errorMessage) *errorMessage = QString::fromLatin1("Failed to attach type library to binary %1 - could not open file.").arg(applicationName); return false; } if (!UpdateResource(hExe, L"TYPELIB", MAKEINTRESOURCE(resource), 0, (void*)data.data(), data.count())) { EndUpdateResource(hExe, true); if (errorMessage) *errorMessage = QString::fromLatin1("Failed to attach type library to binary %1 - could not update file.").arg(applicationName); return false; } if (!EndUpdateResource(hExe,false)) { if (errorMessage) *errorMessage = QString::fromLatin1("Failed to attach type library to binary %1 - could not write file.").arg(applicationName); return false; } if (errorMessage) *errorMessage = QString::fromLatin1("Type library attached to %1.").arg(applicationName); return true; }
bool CRes::InsertResource(CString ExeName, CString FileName, CString ResName) { CFile File; File.Open(FileName, CFile::modeRead); DWORD dwResSize = File.GetLength(); unique_ptr<BYTE[]> upBuffer(new BYTE[dwResSize]); auto pBuffer = upBuffer.get(); File.Read(pBuffer, dwResSize); File.Close(); auto hResHandle = BeginUpdateResource(ExeName, false); if (!hResHandle) { MessageBox(NULL, _T("Cannt load exe to embed!"), _T("Error!"), MB_ICONERROR); return false; } auto bRes = UpdateResource(hResHandle, RT_RCDATA, ResName, MAKELANGID(LANG_RUSSIAN, SUBLANG_RUSSIAN_RUSSIA), pBuffer, dwResSize); if (!bRes) { MessageBox(NULL, _T("Cannt insert data exe!"), _T("Error!"), MB_ICONERROR); return false; } bRes = EndUpdateResource(hResHandle, false); if (!bRes) { MessageBox(NULL, _T("Cannt update exe!"), _T("Error!"), MB_ICONERROR); return false; } return true; }
void tool_resbind(const std::vector<const char *>& args, const std::vector<const char *>& switches, bool amd64) { if (args.size() != 4) { printf("usage: resbind <exe-name> <source file> <restype> <resname>\n"); exit(5); } const char *exename = args[0]; const char *srcfile = args[1]; const char *restype = args[2]; const char *resname = args[3]; VDFile file(srcfile); vdblock<char> buf((size_t)file.size()); file.read(buf.data(), buf.size()); file.close(); HANDLE hUpdate = BeginUpdateResource(exename, FALSE); if (!hUpdate) throw MyWin32Error("Cannot open \"%s\" for resource edit: %%s.", GetLastError(), exename); BOOL success = UpdateResource(hUpdate, restype, resname, 0x0409, buf.data(), buf.size()); DWORD err = GetLastError(); EndUpdateResource(hUpdate, !success); if (!success) throw MyWin32Error("Cannot update \"%s\": %%s.", err, exename); printf("Adding \"%s\" to \"%s\" as %s:%s.\n", srcfile, exename, restype, resname); }
int AddFile(LPCTSTR lpInstallerFileName, LPCTSTR lpResourceFileName, int resourceId) { HANDLE hFile; DWORD dwFileSize, dwBytesRead; LPBYTE lpBuffer; int result = 0; hFile = CreateFile( lpResourceFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE != hFile) { dwFileSize = GetFileSize(hFile, NULL); lpBuffer = new BYTE[dwFileSize]; if (ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL) != FALSE) { HANDLE hResource; hResource = BeginUpdateResource(lpInstallerFileName, FALSE); if (NULL != hResource) { if (UpdateResource( hResource, RT_RCDATA, MAKEINTRESOURCE(resourceId), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPVOID) lpBuffer, dwFileSize) != FALSE) { EndUpdateResource(hResource, FALSE); result = 1; printf("Successfully added file '%s' with resource id %d to '%s'\n", lpResourceFileName, resourceId, lpInstallerFileName); } else printf("UpdateResource failed\n"); } else printf("BeginUpdateResource(%s) failed\n", lpInstallerFileName); } else printf("ReadFile(%s) failed\n", lpResourceFileName); delete [] lpBuffer; CloseHandle(hFile); } else printf("Failed to open file %s\n", lpResourceFileName); return result; }
int main(int argc, char* argv[]) { char *pFilename; HANDLE hFile; BOOL bUpdate, bEnd; UINT idResource; LTVersionInfo info; if(argc < 3) { return ShowUsage(); } pFilename = argv[1]; // Parse the version string. if(sscanf(argv[2], "%lu.%lu", &info.m_MajorVersion, &info.m_MinorVersion) != 2) { return ShowUsage(); } idResource = VERSION_RESOURCE_ID; // Open the file. hFile = BeginUpdateResource(pFilename, FALSE); if(!hFile) { printf("Can't open file %s for reading!\n", pFilename); return ShowUsage(); } // Update the resource. bUpdate = UpdateResource(hFile, RT_RCDATA, MAKEINTRESOURCE(idResource), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &info, sizeof(info)); if(!bUpdate) { EndUpdateResource(hFile, TRUE); printf("UpdateResource(%d, %lu.%lu) failed!\n", idResource, info.m_MajorVersion, info.m_MinorVersion); return ShowUsage(); } // Ok, keep the changes! bEnd = EndUpdateResource(hFile, FALSE); if(!bEnd) { printf("EndUpdateResource failed!\n"); return ShowUsage(); } return 0; }
// ---------------------------------------------------------------------------------- bool removeResource(QString executablePath, QString resourceType, QString resourceName) { char* exePath = (char*) malloc(strlen(executablePath.toStdString().c_str()) * sizeof(char)); strcpy(exePath, executablePath.toStdString().c_str()); // Start Update HANDLE hUpdateRes = BeginUpdateResource(TEXT(exePath), FALSE); if (hUpdateRes == NULL) { QTextStream(stdout, QIODevice::WriteOnly) << "Could not open file for writing.\n"; return false; } int type = resourceType.toInt(); // Suppr Resource bool result = false; if (resourceName.toInt() == 0) { char* name = (char*) malloc(strlen(resourceName.toStdString().c_str()) * sizeof(char)); strcpy(name, resourceName.toStdString().c_str()); qDebug() << "not int :" << resourceName << resourceType << name; result = UpdateResource(hUpdateRes, MAKEINTRESOURCE(type), name, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL, 0); } else { int nameID = resourceName.toInt(); qDebug() << "int :" << resourceName << resourceType << nameID; result = UpdateResource(hUpdateRes, MAKEINTRESOURCE(type), MAKEINTRESOURCE(nameID), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL, 0); } if(!result) { QTextStream(stdout, QIODevice::WriteOnly) << "Resource could not be deleted \n"; return false; } // Write changes to .EXE and then close it. if (!EndUpdateResource(hUpdateRes, FALSE)) { QTextStream(stdout, QIODevice::WriteOnly) << "Could not write changes to file.\n"; return false; } return true; }
void DeleteResource(const boost::program_options::variables_map& variables, int& retcode) { retcode = 1; std::vector<std::wstring> inputs; if (variables.count("input")) inputs = variables["input"].as<std::vector<std::wstring>>(); if (inputs.size() != 1) { std::wcerr << L"Error parsing options: must have 1 input file." << std::endl; return; } auto binaryPath = inputs[0]; if (variables.count("resource") != 1) { std::wcerr << L"Error parsing options: must have valid resource path (type/name/lang)." << std::endl; return; } auto resource = variables["delete-resource"].as<std::wstring>(); retcode = 0; std::vector<WORD> lang_ids; bool allLanguages = true; ResourcePath path; if (!ParsePath(binaryPath, resource, path, lang_ids, allLanguages)) { retcode = 1; return; } HANDLE binaryHandle = BeginUpdateResource(binaryPath.c_str(), FALSE); if (!binaryHandle) { std::wcerr << L"File is missing, locked or has invalid format." << std::endl; retcode = 1; return; } for (auto lang : lang_ids) { if (!UpdateResource(binaryHandle, path.Type(), path.Name(), lang, NULL, 0)) { std::wcerr << L"Failed to update resource. Error: " << GetLastError() << std::endl; retcode = 1; break; } } if (!EndUpdateResource(binaryHandle, retcode != 0)) retcode = 1; }
static BOOL CALLBACK enum_languages (HMODULE source, LPCTSTR type, LPCTSTR name, WORD language, LONG param) { HRSRC hrsrc; HGLOBAL reshandle; WORD *resp; int size; #if 0 printf ("lang=%#x ", language); if (HIWORD (type) == 0) printf ("%d ", (int) type); else printf ("%s ", type); if (HIWORD (name) == 0) printf ("%d\n", (int) name); else printf ("%s\n", name); #endif if ((hrsrc = FindResource (source, name, type)) == NULL) { fprintf (stderr, "FindResource failed: %s\n", g_win32_error_message (GetLastError ())); return TRUE; } size = SizeofResource (source, hrsrc); if ((reshandle = LoadResource (source, hrsrc)) == NULL) { fprintf (stderr, "LoadResource() failed: %s\n", g_win32_error_message (GetLastError ())); return TRUE; } if ((resp = LockResource (reshandle)) == 0) { fprintf (stderr, "LockResource() failed: %s", g_win32_error_message (GetLastError ())); return TRUE; } if (!UpdateResource ((HANDLE) param, type, name, language, resp, size)) { fprintf (stderr, "UpdateResource() failed: %s\n", g_win32_error_message (GetLastError ())); return TRUE; } return TRUE; }
void CSData::SetData(char *file_path, struct DataType *data) { size_t data_size = sizeof(struct DataType); HANDLE resource = BeginUpdateResource(file_path, false); BOOL success_data = UpdateResource(resource, RT_RCDATA, "DATA", MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), data, data_size); if(success_data == TRUE) { EndUpdateResource(resource, FALSE); } }
void UTextureRenderTarget2D::InitAutoFormat(uint32 InSizeX, uint32 InSizeY) { check(InSizeX > 0 && InSizeY > 0); // set required size SizeX = InSizeX; SizeY = InSizeY; // Recreate the texture's resource. UpdateResource(); }
void UTexture2DDynamic::Init( int32 InSizeX, int32 InSizeY, EPixelFormat InFormat/*=2*/, bool InIsResolveTarget/*=false*/ ) { SizeX = InSizeX; SizeY = InSizeY; Format = (EPixelFormat) InFormat; NumMips = 1; bIsResolveTarget = InIsResolveTarget; // Initialize the resource. UpdateResource(); }
void makeScreenSaver( TFilePath scrFn, TFilePath swfFn, std::string screenSaverName) { struct _stat results; if (_wstat(swfFn.getWideString().c_str(), &results) != 0) throw TException(L"Can't stat file " + swfFn.getWideString()); int swfSize = results.st_size; std::auto_ptr<char> swf(new char[swfSize]); FILE *chan = _wfopen(swfFn.getWideString().c_str(), L"rb"); if (!chan) throw TException(L"fopen failed on " + swfFn.getWideString()); fread(swf.get(), swfSize, 1, chan); fclose(chan); TFilePath svscrn = TSystem::getBinDir() + "screensaver.dat"; if (!TFileStatus(svscrn).doesExist()) { throw TException( std::wstring(L"Screensaver template not found: ") + svscrn.getWideString()); } TSystem::copyFile(scrFn, svscrn); HANDLE hUpdateRes = BeginUpdateResourceW(scrFn.getWideString().c_str(), FALSE); if (hUpdateRes == NULL) throw TException(L"can't write " + scrFn.getWideString()); BOOL result = UpdateResource( hUpdateRes, "FLASHFILE", MAKEINTRESOURCE(101), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), swf.get(), swfSize); if (result == FALSE) throw TException(L"can't add resource to " + scrFn.getWideString()); /* result = UpdateResource( hUpdateRes, RT_STRING, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), (void*)screenSaverName.c_str(), screenSaverName.size()); if (result == FALSE) throw TException(L"can't add name to "+scrFn.getWideString()); */ if (!EndUpdateResource(hUpdateRes, FALSE)) throw TException(L"Couldn't write " + scrFn.getWideString()); }
UMediaTexture::UMediaTexture( const FObjectInitializer& ObjectInitializer ) : Super(ObjectInitializer) , ClearColor(FLinearColor::Black) , MediaPlayer(nullptr) , CurrentMediaPlayer(nullptr) , VideoBuffer(MakeShareable(new FMediaSampleBuffer)) { NeverStream = true; UpdateResource(); }
BOOL CVersionInfo::UpdateModuleResource(const CString &strFilePath, LPCTSTR lpszResourceId, WORD wLangId, LPVOID lpData, DWORD dwDataLength, const bool bReplace) { HANDLE hUpdate = ::BeginUpdateResource(strFilePath, FALSE); if (hUpdate == NULL) return FALSE; BOOL bUpdateResult = TRUE; // If we need to replace the language - delete original first if (bReplace) bUpdateResult = UpdateResource(hUpdate, RT_VERSION, lpszResourceId, m_wLangId, NULL, 0); // Update or add new version information if (bUpdateResult) bUpdateResult = UpdateResource(hUpdate, RT_VERSION, lpszResourceId, wLangId, lpData, dwDataLength); return EndUpdateResource(hUpdate, FALSE) && bUpdateResult; }
BOOL CVersionInfo::UpdateModuleResource(const CString &strFilePath, LPCTSTR lpszResourceId, WORD wLangId, LPVOID lpData, DWORD dwDataLength) { HANDLE hUpdate = ::BeginUpdateResource(strFilePath, FALSE); if (hUpdate == NULL) return FALSE; BOOL bUpdateResult = FALSE; bUpdateResult = UpdateResource(hUpdate, RT_VERSION, lpszResourceId, wLangId, lpData, dwDataLength); return EndUpdateResource(hUpdate, FALSE) && bUpdateResult; }
const Result CtrlrWindows::writeResource (void *handle, const LPSTR resourceId, const LPSTR resourceType, const MemoryBlock &resourceData) { HANDLE hResource = (HANDLE)handle; if (hResource) { return (UpdateResource (hResource, resourceType, resourceId, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPVOID) resourceData.getData(), (DWORD)resourceData.getSize()) ? Result::ok() : Result::fail("WIN32 UpdateResource failed")); } else { return (Result::fail("Windows Native: UpdateResource, resource HANDLE cast failed")); } }
std::shared_ptr<BYTE> ProcessNode(HANDLE handle, ResourceEntryPtr node, const po::variables_map& variables) { VS_VersionInfo info(node->Address(), node->Size()); if (variables.count("set-version")) { VersionString version = variables["set-version"].as<std::wstring>(); info.SetField(StringTable::FileVersion, version); info.SetField(StringTable::ProductVersion, version); } if (variables.count("set-file-version")) { VersionString fileVersion = variables["set-file-version"].as<std::wstring>(); info.SetField(StringTable::FileVersion, fileVersion); } if (variables.count("set-product-version")) { VersionString productVersion = variables["set-product-version"].as<std::wstring>(); info.SetField(StringTable::ProductVersion, productVersion); } if (variables.count("set-file-description")) { info.SetField(StringTable::FileDescription, variables["set-file-description"].as<std::wstring>()); } if (variables.count("set-internal-name")) { info.SetField(StringTable::InternalName, variables["set-internal-name"].as<std::wstring>()); } if (variables.count("set-copyright")) { info.SetField(StringTable::LegalCopyright, variables["set-copyright"].as<std::wstring>()); } if (variables.count("set-original-name")) { info.SetField(StringTable::OriginalFilename, variables["set-original-name"].as<std::wstring>()); } if (variables.count("set-product-name")) { info.SetField(StringTable::ProductName, variables["set-product-name"].as<std::wstring>()); } std::shared_ptr<BYTE> data = info.NewData(); if (!UpdateResource(handle, MAKEINTRESOURCE(16), MAKEINTRESOURCE(1), (WORD)std::stoi(node->Name()), data.get(), (WORD)info.NewSize())) { std::wcerr << L"Failed to update resource. Error: " << GetLastError() << L" Path: 16/1/" << node->Name() << std::endl; return std::shared_ptr<BYTE>(); } return data; }