private async Task <bool> UnzipDemo(FaceItGameInfo faceItGameInfo) { var sourceFile = faceItGameInfo.GetPathTempGz(); var destinationFile = faceItGameInfo.GetPathTempDemo(); var gzipFileName = new FileInfo(sourceFile); using (var fileToDecompressAsStream = gzipFileName.OpenRead()) { using (var decompressedStream = File.Create(destinationFile)) { using (var decompressionStream = new GZipStream(fileToDecompressAsStream, CompressionMode.Decompress)) { try { await decompressionStream.CopyToAsync(decompressedStream); } catch (Exception e) { if (_dataService.RSettings.ProgramSettings.Debug) { await _log.LogMessage( "Failed to unzip. Will retry if the limit was not reached. " + sourceFile, false, color : LOG_COLOR); } //Delete the file so we can re-download it if (File.Exists(sourceFile)) { File.Delete(sourceFile); } faceItGameInfo.SetUnzipSuccess(false); faceItGameInfo.SetUnzipResponse(e.ToString()); return(false); } } } await _log.LogMessage($"Unzipped {destinationFile}", false, color : LOG_COLOR); } //Unzipped file, can delete the GZ if (File.Exists(sourceFile)) { File.Delete(sourceFile); } faceItGameInfo.SetUnzipResponse("Unzip Successful"); faceItGameInfo.SetUnzipSuccess(true); return(true); }
private async Task <bool> DownloadDemo(FaceItGameInfo faceItGameInfo) { var localPath = faceItGameInfo.GetPathTempGz(); var remotePath = faceItGameInfo.GetDemoUrl(); Directory.CreateDirectory(Path.GetDirectoryName(localPath)); await _log.LogMessage($"Downloading: {remotePath}", false, color : LOG_COLOR); using (var client = new WebClient()) { client.Headers.Add("User-Agent: Other"); try { await client.DownloadFileTaskAsync(remotePath, localPath); faceItGameInfo.SetDownloadSize(new FileInfo(localPath).Length); } catch (Exception e) { if (_dataService.RSettings.ProgramSettings.Debug) { await _log.LogMessage("Error downloading demo, retrying. " + remotePath, false, color : LOG_COLOR); } if (File.Exists(localPath)) { File.Delete(localPath); } client.Dispose(); faceItGameInfo.SetDownloadSuccess(false); faceItGameInfo.SetDownloadResponse(e.ToString()); return(false); } await _log.LogMessage($"Downloaded {remotePath}", false, color : LOG_COLOR); } faceItGameInfo.SetDownloadResponse("Download Successful"); faceItGameInfo.SetDownloadSuccess(true); return(true); }
private async Task DownloadAndUnzipDemo(FaceItGameInfo faceItGameInfo) { for (var i = 0; i < DL_UNZIP_RETRY_LIMIT; i++) { var downloadResult = await DownloadDemo(faceItGameInfo); var unzipResult = false; //Only unzip if download was a success if (downloadResult) { unzipResult = await UnzipDemo(faceItGameInfo); } //Unzip was a success, return if (unzipResult) { return; } await Task.Delay(5000); } }
private void SetHubTagOnGame(FaceItGameInfo game) { //Get the hub with the desired date and season tags. //Ensure that we don't place any games into a "subscriber" tag. //Subscriber tags run on the same hub GUID, but are their own response tag from FaceIt. We want to group all games into 1 tag. var targetTag = _hubTags.FirstOrDefault(x => x.StartDate <game.GetStartDate() && x.EndDate> game.GetStartDate() && x.HubGuid.Equals(game.Hub.HubGUID, StringComparison.OrdinalIgnoreCase) && !x.TagName.Contains("subscriber", StringComparison.OrdinalIgnoreCase)) ?? new FaceItHubTag(); //Makes a default, unknown tag. game.SetHubTag(targetTag); //targetTag was unknown, so default it. if (game.Tag.TagName == "UNKNOWN") { _ = _log.LogMessage( $"Hub seasons have no definitions in the database for date `{game.GetStartDate()}`!\n`{game.GetGameUid()}`\n" + $"I set it to unknown tag for this match...", false, color: LOG_COLOR); } }