Quellcode durchsuchen

use existing font when possible

Luke Pulverenti vor 12 Jahren
Ursprung
Commit
13198a687d
1 geänderte Dateien mit 32 neuen und 9 gelöschten Zeilen
  1. 32 9
      MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs

+ 32 - 9
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<double>()
-                });
+                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<double>()
+            });
+
+            _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)