From 13198a687df2d3c3c61148bf769649c35bc23b15 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 27 Aug 2013 22:31:49 -0400 Subject: [PATCH] use existing font when possible --- .../MediaEncoder/MediaEncoder.cs | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs index 2ce49aabb9..1eeade08dc 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs @@ -236,26 +236,49 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder if (!File.Exists(fontFile)) { - var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions - { - Url = FontUrl, - Progress = new Progress() - }); + await DownloadFontFile(fontsDirectory, fontFilename).ConfigureAwait(false); + } - _zipClient.ExtractAll(tempFile, fontsDirectory, true); + await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false); + } + private async Task DownloadFontFile(string fontsDirectory, string fontFilename) + { + var existingFile = Directory + .EnumerateFiles(_appPaths.ProgramDataPath, fontFilename, SearchOption.AllDirectories) + .FirstOrDefault(); + + if (existingFile != null) + { try { - File.Delete(tempFile); + File.Copy(existingFile, Path.Combine(fontsDirectory, fontFilename), true); + return; } catch (IOException ex) { // Log this, but don't let it fail the operation - _logger.ErrorException("Error deleting temp file {0}", ex, tempFile); + _logger.ErrorException("Error copying file", ex); } } - await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false); + var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions + { + Url = FontUrl, + Progress = new Progress() + }); + + _zipClient.ExtractAll(tempFile, fontsDirectory, true); + + try + { + File.Delete(tempFile); + } + catch (IOException ex) + { + // Log this, but don't let it fail the operation + _logger.ErrorException("Error deleting temp file {0}", ex, tempFile); + } } private async Task WriteFontConfigFile(string fontsDirectory)