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); }