public void PatchGame(Game game, string installDir) { if (string.IsNullOrWhiteSpace(game?.Patch)) return; string patch = DownloadPatch(game); UnpackPatch(patch, installDir); AutorunIfNeeded(installDir); _updateStatusFunc(null, 100.0, false); }
private string DownloadPatch(Game game) { _updateStatusFunc("Downloade Dateien ...", 0.0, true); string file = Path.Combine(CACHE_FOLDER, game.Id, Path.GetFileName(game.Patch)); if (!File.Exists(file) || _hikariApiService.GetFileLength(game.Patch) != new FileInfo(file).Length) using (WebClient webClient = new WebClient()) { // ReSharper disable once AccessToModifiedClosure webClient.DownloadProgressChanged += (sender, args) => _updateStatusFunc(null, ((double)args.BytesReceived / (double)args.TotalBytesToReceive) * 100.0, true); webClient.DownloadFileTaskAsync(game.Patch, file).Wait(); } return file; }
public bool CheckIfGameIsPatched(Game game, string installDir) { if (!Directory.Exists(installDir)) return false; if (game.FileChecks != null) foreach (FileCheck check in game.FileChecks) { if (string.IsNullOrWhiteSpace(check.File)) continue; string file = Path.Combine(installDir, check.File); if (!File.Exists(file)) return false; if (check.IntSize.HasValue && check.IntSize != new FileInfo(file).Length) return false; if (!string.IsNullOrWhiteSpace(check.Hash) && !string.Equals(check.Hash, HashHelper.CalcMd5(file), StringComparison.OrdinalIgnoreCase)) return false; } return true; }