int ExtractComponent::GetCabCount() const { int currentIndex = 1; std::wstring resname = GetResName(currentIndex); HRSRC l_res = FindResource(m_h, resname.c_str(), TEXT("RES_CAB")); if (l_res == NULL) return 0; do { currentIndex++; resname = GetResName(currentIndex); l_res = FindResource(m_h, resname.c_str(), TEXT("RES_CAB")); } while(l_res); return currentIndex - 1; }
void ExtractComponent::ExtractFromResource() { std::wstring resname = GetResName(1); LOG(L"Extracting '" << resname << L"' for component '" << (component_id.empty() ? L"*" : component_id) << L"'"); Cabinet::CExtractResource extract; Cabinet::CExtract::kCallbacks callbacks; callbacks.f_OnBeforeCopyFile = & ExtractComponent::OnBeforeCopyFile; callbacks.f_OnAfterCopyFile = & ExtractComponent::OnAfterCopyFile; callbacks.f_OnProgressInfo = & ExtractComponent::OnProgressInfo; callbacks.s32_ProgressInterval = status_interval; extract.SetCallbacks(& callbacks); CHECK_BOOL(extract.CreateFDIContext(), L"Error initializing cabinet.dll: " << extract.LastErrorW()); std::wstring module = DVLib::GetModuleFileNameW(m_h); CHECK_BOOL(extract.ExtractResourceW(Cabinet::CStrW(module.c_str()), Cabinet::CStrW(resname.c_str()), L"RES_CAB", Cabinet::CStrW(resolved_cab_path.c_str()), this), L"Error extracting '" << resname << L"': " << extract.LastErrorW()); }
// mode is either // rnStartsWith // rnContains // rnIs // rnEndsWith // Please note this code is as yet untested Handle BetterGetResourceByName(short resFile,ResType type,StringPtr name,unsigned char mode,Boolean caseSens) { UResFileSaver safe(resFile); UResLoadSaver safe2(false); short numRes=Count1Resources(type); Str255 resName; Handle handle; Boolean ok=false; gGetResErr=noErr; for (short counter=1; counter<numRes; counter++) { handle=BetterGetIndResource(-1,type,counter); if (!handle) return 0L; // got the handle, get the name. GetResName(handle,resName); // got the name, do the check switch (mode) { case rnStartsWith: if (name[0]<=resName[0]) resName[0]=name[0]; // fall through and do a comparison else { ok=false; break; } case rnIs: // exact match if (caseSens) ok=CmpPStr(name,resName); else ok=CmpPStrNoCase(name,resName); break; case rnContains: ok=(SearchForChars((Ptr)&resName[1],(Ptr)&name[1],resName[0],name[0],caseSens)!=-1); break; case rnEndsWith: if (name[0]<=resName[0]) ok=CmpBuffer((Ptr)&name[1],(Ptr)&resName[name[0]],name[0],caseSens); else ok=false; break; default: ok=false; break; } if (ok) return handle; else ReleaseResource(handle); } gGetResErr=resNotFound; return 0L; }