private void GetNextPatch() { if( _index == _patchList.Count ) ExtractFiles(); else { string[] patchAndCrc = _patchList[_index].Split('|'); if( patchAndCrc.Length < 2 ) { MessageBox.Show("Patch listing on line " + ( (int)( _index + 1 ) ).ToString() + " is invalid, Aborting..."); _index++; GetNextPatch(); } string patch = patchAndCrc[0]; string scrc = patchAndCrc[1]; string fileName = Path.GetFileName(patch); uint crc; if( !uint.TryParse(scrc, out crc) ) { MessageBox.Show("Patch CRC on line " + ( (int)( _index + 1 ) ).ToString() + " is invalid, Aborting..."); OnPatchingComplete(null, new OperationCompleteArgs()); } if( File.Exists(Path.Combine(_patchFolder, fileName)) ) { CRC32 crc32 = new CRC32(); FileStream fs = new FileStream(Path.Combine(_patchFolder, fileName), FileMode.Open); uint fileCRC = crc32.GetCrc32(fs); fs.Close(); if( fileCRC != crc ) { _needsPatching = true; DownloadFile(patch, Path.Combine(_patchFolder, fileName)); } else { _index++; GetNextPatch(); } } else { _needsPatching = true; DownloadFile(patch, Path.Combine(_patchFolder, fileName)); } } }
private void OnPatchingComplete( object sender, OperationCompleteArgs args ) { if (!_oldPatchingStyle && _needsPatching) { DirectoryInfo dir = new DirectoryInfo(_patchFolder); FileInfo[] patches = dir.GetFiles("*.patch"); for (int i = 0; i < patches.Length; i++) if( patches[i].FullName != _patcher.CombinedPatchFile) File.Delete(patches[i].FullName); string tempFile = _patcher.CombinedPatchFile; CRC32 crc32 = new CRC32(); ulong hash = 0; for( int i = 0; i < _allPatchFiles.Count; i++ ) hash += (ulong)crc32.GetCrc32(File.Open(_allPatchFiles[i].FullName, FileMode.Open)); _patchFile = Path.Combine(_patchFolder, hash.ToString() + ".patch"); File.Move(tempFile, _patchFile); } else { DirectoryInfo dir = new DirectoryInfo(_patchFolder); FileInfo[] patch = dir.GetFiles("*.patch"); if (patch.Length >= 1) _patchFile = patch[0].FullName; } if (this.Visible) Invoke((MethodInvoker)delegate { cancelBtn.Text = "Close"; _closeTimer = new System.Timers.Timer(1000); _closeTimer.Elapsed += new System.Timers.ElapsedEventHandler(closeTimer_Elapsed); _closeTimer.Start(); }); }
private bool CrcCheck(List<FileInfo> _allPatchFiles) { CRC32 crc32 = new CRC32(); ulong hash = 0; for( int i = 0; i < _allPatchFiles.Count; i++ ) { FileStream fs = new FileStream(_allPatchFiles[i].FullName, FileMode.Open); hash += (ulong)crc32.GetCrc32(fs); fs.Close(); } _patchFile = Path.Combine(_patchFolder, hash.ToString() + ".patch"); return File.Exists(_patchFile); }