void CLDS2_UrlHandler_Base::FillInfo(SLDS2_File& info) { info.format = GetFileFormat(info); info.crc = GetFileCRC(info); info.size = GetFileSize(info); info.time = GetFileTime(info); }
bool C4Network2Res::SetByFile(const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iResID, const char *szResName, bool fSilent) { CStdLock FileLock(&FileCSec); // default resource name: relative path if (!szResName) szResName = Config.AtRelativePath(strFilePath); SCopy(strFilePath, szFile, sizeof(szFile)-1); // group? C4Group Grp; if (Reloc.Open(Grp, strFilePath)) return SetByGroup(&Grp, fTemp, eType, iResID, szResName, fSilent); // so it needs to be a file StdStrBuf szFullFile; if (!Reloc.LocateItem(szFile, szFullFile)) { if (!fSilent) LogF("SetByFile: file %s not found!", strFilePath); return false; } // calc checksum uint32_t iCRC32; if (!GetFileCRC(szFullFile.getData(), &iCRC32)) return false; #ifdef C4NET2RES_DEBUG_LOG // log LogSilentF("Network: Resource: complete %d:%s is file %s (%s)", iResID, szResName, szFile, fTemp ? "temp" : "static"); #endif // set core Core.Set(eType, iResID, Config.AtRelativePath(szFullFile.getData()), iCRC32); // set own data fDirty = true; fTempFile = fTemp; fStandaloneFailed = false; fRemoved = false; iLastReqTime = time(NULL); fLoading = false; // ok return true; }
ISoundInstance * CSoundManager2D::GetInstance(const char * c_pszFileName) { DWORD dwFileCRC = GetFileCRC(c_pszFileName); TSoundDataMap::iterator itor = ms_dataMap.find(dwFileCRC); CSoundData * pkSoundData; if (itor == ms_dataMap.end()) pkSoundData = AddFile(dwFileCRC, c_pszFileName); // CSoundBase::AddFile else pkSoundData = itor->second; assert(pkSoundData != NULL); static DWORD k = 0; DWORD start = k++; DWORD end = start + INSTANCE_MAX_COUNT; while (start < end) { CSoundInstance2D * pkInst = &ms_Instances[start % INSTANCE_MAX_COUNT]; if (pkInst->IsDone()) { if (!pkInst->SetSound(pkSoundData)) TraceError("CSoundManager2D::GetInstance (filename: %s)", c_pszFileName); return (pkInst); } ++start; } return NULL; }
int C4UpdatePackage::Check(C4Group *pGroup) { // Version requirement is set if (RequireVersion[0]) { // Engine and game version must match (rest ignored) if ((C4XVER1 != RequireVersion[0]) || (C4XVER2 != RequireVersion[1])) return C4UPD_CHK_BAD_VERSION; } // only group updates have any special needs if (!GrpUpdate) return C4UPD_CHK_OK; // check source file C4Group TargetGrp; if (!TargetGrp.Open(DestPath)) return C4UPD_CHK_NO_SOURCE; if (!TargetGrp.IsPacked()) return C4UPD_CHK_BAD_SOURCE; TargetGrp.Close(); // check source crc uint32_t iCRC32; if (!GetFileCRC(DestPath, &iCRC32)) return C4UPD_CHK_BAD_SOURCE; // equal to destination group? if (iCRC32 == GrpChks2) // so there's nothing to do return C4UPD_CHK_ALREADY_UPDATED; // check if it's one of our registered sources int i = 0; for (; i < UpGrpCnt; i++) if (iCRC32 == GrpChks1[i]) break; if (i >= UpGrpCnt) return C4UPD_CHK_BAD_SOURCE; // ok return C4UPD_CHK_OK; }
bool C4Network2Res::GetStandalone(char *pTo, int32_t iMaxL, bool fSetOfficial, bool fAllowUnloadable, bool fSilent) { // already set? if (szStandalone[0]) { if (pTo) SCopy(szStandalone, pTo, iMaxL); return true; } // already tried and failed? No point in retrying if (fStandaloneFailed) return false; // not loadable? Wo won't be able to check the standalone as the core will lack the needed information. // the standalone won't be interesting in this case, anyway. if (!fSetOfficial && !Core.isLoadable()) return false; // set flag, so failure below will let future calls fail fStandaloneFailed = true; // lock file CStdLock FileLock(&FileCSec); // directory? SCopy(szFile, szStandalone, sizeof(szStandalone)-1); if (DirectoryExists(szFile)) { // size check for the directory, if allowed if (fAllowUnloadable) { uint32_t iDirSize; if (!DirSizeHelper::GetDirSize(szFile, &iDirSize, Config.Network.MaxLoadFileSize)) { if (!fSilent) LogF("Network: could not get directory size of %s!", szFile); szStandalone[0] = '\0'; return false; } if (iDirSize > uint32_t(Config.Network.MaxLoadFileSize)) { if (!fSilent) LogSilentF("Network: %s over size limit, will be marked unloadable!", szFile); szStandalone[0] = '\0'; return false; } } // log - this may take a few seconds if (!fSilent) LogF(LoadResStr("IDS_PRC_NETPACKING"), GetFilename(szFile)); // pack inplace? if (!fTempFile) { if (!pParent->FindTempResFileName(szFile, szStandalone)) { if (!fSilent) Log("GetStandalone: could not find free name for temporary file!"); szStandalone[0] = '\0'; return false; } if (!C4Group_PackDirectoryTo(szFile, szStandalone)) { if (!fSilent) Log("GetStandalone: could not pack directory!"); szStandalone[0] = '\0'; return false; } } else if (!C4Group_PackDirectory(szStandalone)) { if (!fSilent) Log("GetStandalone: could not pack directory!"); if (!SEqual(szFile, szStandalone)) EraseDirectory(szStandalone); szStandalone[0] = '\0'; return false; } // make sure directory is packed if (DirectoryExists(szStandalone)) { if (!fSilent) Log("GetStandalone: directory hasn't been packed!"); if (!SEqual(szFile, szStandalone)) EraseDirectory(szStandalone); szStandalone[0] = '\0'; return false; } // fallthru } // doesn't exist physically? if (!FileExists(szStandalone)) { // try C4Group (might be packed) if (!pParent->FindTempResFileName(szFile, szStandalone)) { if (!fSilent) Log("GetStandalone: could not find free name for temporary file!"); szStandalone[0] = '\0'; return false; } if (!C4Group_CopyItem(szFile, szStandalone)) { if (!fSilent) Log("GetStandalone: could not copy to temporary file!"); szStandalone[0] = '\0'; return false; } } // remains missing? give up. if (!FileExists(szStandalone)) { if (!fSilent) Log("GetStandalone: file not found!"); szStandalone[0] = '\0'; return false; } // do optimizations (delete unneeded entries) if (!OptimizeStandalone(fSilent)) { if (!SEqual(szFile, szStandalone)) EraseItem(szStandalone); szStandalone[0] = '\0'; return false; } // get file size size_t iSize = FileSize(szStandalone); // size limit if (fAllowUnloadable) if (iSize > uint32_t(Config.Network.MaxLoadFileSize)) { if (!fSilent) LogSilentF("Network: %s over size limit, will be marked unloadable!", szFile); szStandalone[0] = '\0'; return false; } // check if (!fSetOfficial && iSize != Core.getFileSize()) { // remove file if (!SEqual(szFile, szStandalone)) EraseItem(szStandalone); szStandalone[0] = '\0'; // sorry, this version isn't good enough :( return false; } // calc checksum uint32_t iCRC32; if (!GetFileCRC(szStandalone, &iCRC32)) { if (!fSilent) Log("GetStandalone: could not calculate checksum!"); return false; } // set / check if (!fSetOfficial && iCRC32 != Core.getFileCRC()) { // remove file, return if (!SEqual(szFile, szStandalone)) EraseItem(szStandalone); szStandalone[0] = '\0'; return false; } // we didn't fail fStandaloneFailed = false; // mark resource as loadable and safe file information Core.SetLoadable(iSize, iCRC32); // set up chunk data Chunks.SetComplete(Core.getChunkCnt()); // ok return true; }
bool C4UpdatePackage::MakeUpdate(const char *strFile1, const char *strFile2, const char *strUpdateFile, const char *strName) { #ifdef UPDATE_DEBUG char *pData; int iSize; CStdFile MyFile; MyFile.Load(strFile2, (BYTE **)&pData, &iSize, 0, true); MyFile.Create("SoIstRichtig.txt", false); MyFile.Write(pData, iSize); MyFile.Close(); MemScramble((BYTE *)pData, iSize); MyFile.Create("UndSoAuch.txt", false); MyFile.Write(pData, iSize); MyFile.Close(); #endif // open Log if (!Log.Create("Update.log")) return false; // begin message WriteLog("Source: %s\nTarget: %s\nOutput: %s\n\n", strFile1, strFile2, strUpdateFile); // open both groups C4Group Group1, Group2; if (!Group1.Open(strFile1)) { WriteLog("Error: could not open %s!\n", strFile1); return false; } if (!Group2.Open(strFile2)) { WriteLog("Error: could not open %s!\n", strFile2); return false; } // All groups to be compared need to be packed if (!Group1.IsPacked()) { WriteLog("Error: source group %s not packed!\n", strFile1); return false; } if (!Group2.IsPacked()) { WriteLog("Error: target group %s not packed!\n", strFile2); return false; } if (Group1.HasPackedMother()) { WriteLog("Error: source group %s must not have a packed mother group!\n", strFile1); return false; } if (Group2.HasPackedMother()) { WriteLog("Error: target group %s must not have a packed mother group!\n", strFile2); return false; } // create/open update-group C4GroupEx UpGroup; if (!UpGroup.Open(strUpdateFile, true)) { WriteLog("Error: could not open %s!\n", strUpdateFile); return false; } // may be continued update-file -> try to load core UpGrpCnt = 0; bool fContinued = C4UpdatePackageCore::Load(UpGroup); // save crc2 for later check unsigned int iOldChks2 = GrpChks2; // create core info if (strName) SCopy(strName, Name, C4MaxName); else sprintf(Name, "%s Update", GetFilename(strFile1)); SCopy(strFile1, DestPath, _MAX_PATH); GrpUpdate = true; if (!GetFileCRC(strFile1, &GrpChks1[UpGrpCnt])) { WriteLog("Error: could not calc checksum for %s!\n", strFile1); return false; } if (!GetFileCRC(strFile2, &GrpChks2)) { WriteLog("Error: could not calc checksum for %s!\n", strFile2); return false; } if (fContinued) { // continuation check: GrpChks2 matches? if (GrpChks2 != iOldChks2) // that would mess up the update result... { WriteLog("Error: could not add to update package - target groups don't match (checksum error)\n"); return false; } // already supported by this update? int i = 0; for (; i < UpGrpCnt; i++) if (GrpChks1[UpGrpCnt] == GrpChks1[i]) break; if (i < UpGrpCnt) { WriteLog("This update already supports the version of the source file.\n"); return false; } } UpGrpCnt++; // save core if (!C4UpdatePackageCore::Save(UpGroup)) { WriteLog("Could not save update package core!\n"); return false; } // compare groups, create update bool fModified = false; bool fSuccess = MkUp(&Group1, &Group2, &UpGroup, &fModified); // close (save) it UpGroup.Close(false); // error? if (!fSuccess) { WriteLog("Update package not created.\n"); EraseItem(strUpdateFile); return false; } WriteLog("Update package created.\n"); return true; }
bool C4UpdatePackage::Execute(C4Group *pGroup) { // search target C4GroupEx TargetGrp; char strTarget[_MAX_PATH]; SCopy(DestPath, strTarget, _MAX_PATH); char *p = strTarget, *lp = strTarget; while ((p = strchr(p + 1, '\\'))) { *p = 0; if (!*(p + 1)) break; if (!SEqual(lp, "..")) { if (TargetGrp.Open(strTarget)) { // packed? bool fPacked = TargetGrp.IsPacked(); // Close Group TargetGrp.Close(true); if (fPacked) // Unpack C4Group_UnpackDirectory(strTarget); } else { // GrpUpdate -> file must exist if (GrpUpdate) return false; // create dir CreatePath(strTarget); } } *p = '\\'; lp = p + 1; } // try to open it if (!TargetGrp.Open(strTarget, !GrpUpdate)) return false; // check if the update is allowed if (GrpUpdate) { // check checksum uint32_t iCRC32; if (!GetFileCRC(TargetGrp.GetFullName().getData(), &iCRC32)) return false; int i = 0; for (; i < UpGrpCnt; i++) if (iCRC32 == GrpChks1[i]) break; if (i >= UpGrpCnt) return false; } else { // only allow Extra.ocg-Updates if (!SEqual2(DestPath, "Extra.ocg")) return false; } // update children char ItemFileName[_MAX_PATH]; pGroup->ResetSearch(); while (pGroup->FindNextEntry("*", ItemFileName)) if (!SEqual(ItemFileName, C4CFN_UpdateCore) && !SEqual(ItemFileName, C4CFN_UpdateEntries)) DoUpdate(pGroup, &TargetGrp, ItemFileName); // do GrpUpdate if (GrpUpdate) DoGrpUpdate(pGroup, &TargetGrp); // close the group TargetGrp.Close(false); if (GrpUpdate) { // check the result uint32_t iResChks; if (!GetFileCRC(strTarget, &iResChks)) return false; if (iResChks != GrpChks2) { #ifdef UPDATE_DEBUG char *pData; int iSize; CStdFile MyFile; MyFile.Load(strTarget, (BYTE **)&pData, &iSize, 0, true); MyFile.Create("DiesesDingIstMist.txt", false); MyFile.Write(pData, iSize); MyFile.Close(); #endif return false; } } return true; }
VOID SaveINI(HWND hwndDlg) { BOOL bStop = FALSE; char szBuffer[100]; char szINI[MAX_PATH]; char szFilename[MAX_PATH]; INT x; LVITEM lvi; HWND hwndPointers = GetDlgItem(hwndDlg, IDC_POINTERS); HWND hwndHotkeys = GetDlgItem(hwndDlg, IDC_HOTKEYS); lvi.mask = LVIF_PARAM; lvi.iSubItem = 0; GetModuleFileName(GetModuleHandle(NULL), szINI, MAX_PATH); for(x = lstrlen(szINI); x && szINI[x] != '\\'; x--); szINI[x] = '\0'; lstrcat(szINI, "\\bwh.ini"); // save wow exe location GetDlgItemText(hwndDlg, IDC_FILENAME, szFilename, MAX_PATH); WritePrivateProfileString("WOW", "EXE", szFilename, szINI); // save pointers for(lvi.iItem = 0; lvi.iItem < ListView_GetItemCount(hwndPointers); lvi.iItem++) { ListView_GetItem(hwndPointers, &lvi); wsprintf(szBuffer, "%d", PPOINTER_DATA(lvi.lParam)->dwValue); WritePrivateProfileString(PPOINTER_DATA(lvi.lParam)->pszCategory, PPOINTER_DATA(lvi.lParam)->pszName, szBuffer, szINI); } // save hotkeys for(lvi.iItem = 0; lvi.iItem < ListView_GetItemCount(hwndHotkeys); lvi.iItem++) { ListView_GetItem(hwndHotkeys, &lvi); wsprintf(szBuffer, "%d", PHOTKEY_DATA(lvi.lParam)->dwValue); WritePrivateProfileString("HOTKEYS", PHOTKEY_DATA(lvi.lParam)->pszName, szBuffer, szINI); } // save fonts WritePrivateProfileString("FONTS", "FixedFont", g_szFixedFont, szINI); wsprintf(szBuffer, "%d", g_lFixedSize); WritePrivateProfileString("FONTS", "FixedSize", szBuffer, szINI); wsprintf(szBuffer, "%d", g_bFixedBold); WritePrivateProfileString("FONTS", "FixedBold", szBuffer, szINI); WritePrivateProfileString("FONTS", "ProportionalFont", g_szProportionalFont, szINI); wsprintf(szBuffer, "%d", g_lProportionalSize); WritePrivateProfileString("FONTS", "ProportionalSize", szBuffer, szINI); wsprintf(szBuffer, "%d", g_bProportionalBold); WritePrivateProfileString("FONTS", "ProportionalBold", szBuffer, szINI); // save crc's wsprintf(szBuffer, "%d", GetFileCRC(szFilename, &bStop, NULL)); WritePrivateProfileString("WOW", "CRC", szBuffer, szINI); GetSystemDirectory(szFilename, MAX_PATH); lstrcat(szFilename, "\\d3d9.dll"); wsprintf(szBuffer, "%d", GetFileCRC(szFilename, &bStop, NULL)); WritePrivateProfileString("D3D", "CRC", szBuffer, szINI); lstrcpy(szFilename, szINI); szFilename[lstrlen(szFilename) - 3] = '\0'; lstrcat(szFilename, "dll"); wsprintf(szBuffer, "%d", GetFileCRC(szFilename, &bStop, NULL)); WritePrivateProfileString("BWH", "CRC", szBuffer, szINI); MessageBox(hwndDlg, "Saved settings to bwh.ini", "bwh_setup", MB_ICONINFORMATION); }