public void Open(string szFile) { using (BinaryReader br = new BinaryReader(File.OpenRead(szFile), Encoding.Default)) { byte nCipherIndex = 0; while (br.PeekChar() != -1) { CSDATA_INDEX index = new CSDATA_INDEX(); byte nStrLen = br.ReadByte(); Cipher(ref nStrLen, ref nCipherIndex); byte[] szHash = br.ReadBytes(nStrLen); Cipher(ref szHash, ref nCipherIndex); byte[] nVal = br.ReadBytes(8); Cipher(ref nVal, ref nCipherIndex); index.szHash = Encoding.Default.GetString(szHash); index.nOffset = BitConverter.ToUInt32(nVal, 0); index.nSize = BitConverter.ToUInt32(nVal, 4); index.nFile = GetFileID(index.szHash); m_lClient.Add(index); } } }
public void Patch(string szFile, string szPath, CSPATCH_INDEX patchIndex) { FileInfo pInfo = new FileInfo(szFile); var index = m_lClient.Find(r => r.szHash == patchIndex.hashedName); bool bIsNew = false; if (index == null) { bIsNew = true; index = new CSDATA_INDEX(); index.szHash = patchIndex.hashedName; index.nFile = GetFileID(index.szHash); } else { m_lClient.Remove(index); } string szDataFile = Path.Combine(szPath, "data.00" + index.nFile); FileStream tFileStream = (!bIsNew && pInfo.Length <= index.nSize) ? new FileStream(szDataFile, FileMode.Open) : new FileStream(szDataFile, FileMode.Append); using (BinaryWriter bWriter = new BinaryWriter(tFileStream)) { if (!bIsNew && pInfo.Length <= index.nSize) { // Replace bWriter.BaseStream.Position = index.nOffset; index.nSize = (uint)pInfo.Length; } else { // Append bWriter.BaseStream.Position = new FileInfo(szDataFile).Length; index.nSize = (uint)pInfo.Length; index.nOffset = (uint)bWriter.BaseStream.Position; } using (BinaryReader bReader = new BinaryReader(File.OpenRead(szFile))) { byte[] pBuffer = bReader.ReadBytes((int)bReader.BaseStream.Length); if (Encrypted(pInfo.Extension)) { byte nCipherIndex = 0; Cipher(ref pBuffer, ref nCipherIndex); } bWriter.Write(pBuffer); } m_lClient.Add(index); } }