/// <summary>
/// Processes the specified depot key by decrypting the data with the given depot encryption key, and then by decompressing the data.
/// If the chunk has already been processed, this function does nothing.
/// </summary>
/// <param name="depotKey">The depot decryption key.</param>
/// <exception cref="System.IO.InvalidDataException">Thrown if the processed data does not match the expected checksum given in it's chunk information.</exception>
public void Process(byte[] depotKey)
{
if (depotKey == null)
{
throw new ArgumentNullException(nameof(depotKey));
}
if (IsProcessed)
{
return;
}
byte[] processedData = CryptoHelper.SymmetricDecrypt(Data, depotKey);
if (processedData.Length > 1 && processedData[0] == 'V' && processedData[1] == 'Z')
{
processedData = VZipUtil.Decompress(processedData);
}
else
{
processedData = ZipUtil.Decompress(processedData);
}
byte[] dataCrc = CryptoHelper.AdlerHash(processedData);
if (!dataCrc.SequenceEqual(ChunkInfo.Checksum))
{
throw new InvalidDataException("Processed data checksum is incorrect! Downloaded depot chunk is corrupt or invalid/wrong depot key?");
}
Data = processedData;
IsProcessed = true;
}