diff --git a/Emby.Dlna/ConfigurationExtension.cs b/Emby.Dlna/ConfigurationExtension.cs
index e224d10bd3..dba9019677 100644
--- a/Emby.Dlna/ConfigurationExtension.cs
+++ b/Emby.Dlna/ConfigurationExtension.cs
@@ -1,3 +1,4 @@
+#nullable enable
#pragma warning disable CS1591
using System.Collections.Generic;
diff --git a/Emby.Drawing/Emby.Drawing.csproj b/Emby.Drawing/Emby.Drawing.csproj
index f48507b34c..092f8580a6 100644
--- a/Emby.Drawing/Emby.Drawing.csproj
+++ b/Emby.Drawing/Emby.Drawing.csproj
@@ -10,6 +10,7 @@
false
true
true
+ enable
diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs
index ba14b4dcab..0b3bbe29ef 100644
--- a/Emby.Drawing/ImageProcessor.cs
+++ b/Emby.Drawing/ImageProcessor.cs
@@ -116,11 +116,6 @@ namespace Emby.Drawing
///
public async Task<(string path, string mimeType, DateTime dateModified)> ProcessImage(ImageProcessingOptions options)
{
- if (options == null)
- {
- throw new ArgumentNullException(nameof(options));
- }
-
ItemImageInfo originalImage = options.Image;
BaseItem item = options.Item;
@@ -325,19 +320,12 @@ namespace Emby.Drawing
///
public string GetImageCacheTag(BaseItem item, ChapterInfo chapter)
{
- try
+ return GetImageCacheTag(item, new ItemImageInfo
{
- return GetImageCacheTag(item, new ItemImageInfo
- {
- Path = chapter.ImagePath,
- Type = ImageType.Chapter,
- DateModified = chapter.ImageDateModified
- });
- }
- catch
- {
- return null;
- }
+ Path = chapter.ImagePath,
+ Type = ImageType.Chapter,
+ DateModified = chapter.ImageDateModified
+ });
}
private async Task<(string path, DateTime dateModified)> GetSupportedImage(string originalImagePath, DateTime dateModified)
diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
index 80889879fe..ca5cd6fdd5 100644
--- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
@@ -1990,7 +1990,14 @@ namespace Emby.Server.Implementations.Data
if (!string.IsNullOrEmpty(chapter.ImagePath))
{
- chapter.ImageTag = _imageProcessor.GetImageCacheTag(item, chapter);
+ try
+ {
+ chapter.ImageTag = _imageProcessor.GetImageCacheTag(item, chapter);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex, "Failed to create image cache tag.");
+ }
}
}
diff --git a/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj b/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj
index 6326278f59..a6e1f490ad 100644
--- a/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj
+++ b/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj
@@ -10,6 +10,7 @@
false
true
true
+ enable
diff --git a/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs b/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs
index 5084fd211c..7eed5f4f79 100644
--- a/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs
+++ b/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs
@@ -26,7 +26,7 @@ namespace Jellyfin.Drawing.Skia
{
paint.Color = SKColor.Parse("#CC00A4DC");
paint.Style = SKPaintStyle.Fill;
- canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
+ canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
}
using (var paint = new SKPaint())
@@ -39,16 +39,13 @@ namespace Jellyfin.Drawing.Skia
// or:
// var emojiChar = 0x1F680;
- var text = "✔️";
- var emojiChar = StringUtilities.GetUnicodeCharacterCode(text, SKTextEncoding.Utf32);
+ const string Text = "✔️";
+ var emojiChar = StringUtilities.GetUnicodeCharacterCode(Text, SKTextEncoding.Utf32);
// ask the font manager for a font with that character
- var fontManager = SKFontManager.Default;
- var emojiTypeface = fontManager.MatchCharacter(emojiChar);
+ paint.Typeface = SKFontManager.Default.MatchCharacter(emojiChar);
- paint.Typeface = emojiTypeface;
-
- canvas.DrawText(text, (float)x - 20, OffsetFromTopRightCorner + 12, paint);
+ canvas.DrawText(Text, (float)x - 20, OffsetFromTopRightCorner + 12, paint);
}
}
}
diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.cs
index 97717e6263..5c7462ee29 100644
--- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs
+++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs
@@ -214,11 +214,6 @@ namespace Jellyfin.Drawing.Skia
/// The file at the specified path could not be used to generate a codec.
public ImageDimensions GetImageSize(string path)
{
- if (path == null)
- {
- throw new ArgumentNullException(nameof(path));
- }
-
if (!File.Exists(path))
{
throw new FileNotFoundException("File not found", path);
@@ -306,7 +301,7 @@ namespace Jellyfin.Drawing.Skia
/// The orientation of the image.
/// The detected origin of the image.
/// The resulting bitmap of the image.
- internal SKBitmap Decode(string path, bool forceCleanBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
+ internal SKBitmap? Decode(string path, bool forceCleanBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
{
if (!File.Exists(path))
{
@@ -357,12 +352,17 @@ namespace Jellyfin.Drawing.Skia
return resultBitmap;
}
- private SKBitmap GetBitmap(string path, bool cropWhitespace, bool forceAnalyzeBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
+ private SKBitmap? GetBitmap(string path, bool cropWhitespace, bool forceAnalyzeBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
{
if (cropWhitespace)
{
using (var bitmap = Decode(path, forceAnalyzeBitmap, orientation, out origin))
{
+ if (bitmap == null)
+ {
+ return null;
+ }
+
return CropWhiteSpace(bitmap);
}
}
@@ -370,13 +370,11 @@ namespace Jellyfin.Drawing.Skia
return Decode(path, forceAnalyzeBitmap, orientation, out origin);
}
- private SKBitmap GetBitmap(string path, bool cropWhitespace, bool autoOrient, ImageOrientation? orientation)
+ private SKBitmap? GetBitmap(string path, bool cropWhitespace, bool autoOrient, ImageOrientation? orientation)
{
- SKEncodedOrigin origin;
-
if (autoOrient)
{
- var bitmap = GetBitmap(path, cropWhitespace, true, orientation, out origin);
+ var bitmap = GetBitmap(path, cropWhitespace, true, orientation, out var origin);
if (bitmap != null && origin != SKEncodedOrigin.TopLeft)
{
@@ -389,7 +387,7 @@ namespace Jellyfin.Drawing.Skia
return bitmap;
}
- return GetBitmap(path, cropWhitespace, false, orientation, out origin);
+ return GetBitmap(path, cropWhitespace, false, orientation, out _);
}
private SKBitmap OrientImage(SKBitmap bitmap, SKEncodedOrigin origin)
@@ -526,14 +524,14 @@ namespace Jellyfin.Drawing.Skia
///
public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation? orientation, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
{
- if (string.IsNullOrWhiteSpace(inputPath))
+ if (inputPath.Length == 0)
{
- throw new ArgumentNullException(nameof(inputPath));
+ throw new ArgumentException("String can't be empty.", nameof(inputPath));
}
- if (string.IsNullOrWhiteSpace(inputPath))
+ if (outputPath.Length == 0)
{
- throw new ArgumentNullException(nameof(outputPath));
+ throw new ArgumentException("String can't be empty.", nameof(outputPath));
}
var skiaOutputFormat = GetImageFormat(selectedOutputFormat);
@@ -547,7 +545,7 @@ namespace Jellyfin.Drawing.Skia
{
if (bitmap == null)
{
- throw new ArgumentOutOfRangeException($"Skia unable to read image {inputPath}");
+ throw new InvalidDataException($"Skia unable to read image {inputPath}");
}
var originalImageSize = new ImageDimensions(bitmap.Width, bitmap.Height);
diff --git a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs
index 0735ef194a..61bef90ec5 100644
--- a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs
+++ b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs
@@ -120,13 +120,13 @@ namespace Jellyfin.Drawing.Skia
}
// resize to the same aspect as the original
- int iWidth = (int)Math.Abs(iHeight * currentBitmap.Width / currentBitmap.Height);
+ int iWidth = Math.Abs(iHeight * currentBitmap.Width / currentBitmap.Height);
using (var resizeBitmap = new SKBitmap(iWidth, iHeight, currentBitmap.ColorType, currentBitmap.AlphaType))
{
currentBitmap.ScalePixels(resizeBitmap, SKFilterQuality.High);
// crop image
- int ix = (int)Math.Abs((iWidth - iSlice) / 2);
+ int ix = Math.Abs((iWidth - iSlice) / 2);
using (var image = SKImage.FromBitmap(resizeBitmap))
using (var subset = image.Subset(SKRectI.Create(ix, 0, iSlice, iHeight)))
{
@@ -141,10 +141,10 @@ namespace Jellyfin.Drawing.Skia
return bitmap;
}
- private SKBitmap GetNextValidImage(string[] paths, int currentIndex, out int newIndex)
+ private SKBitmap? GetNextValidImage(string[] paths, int currentIndex, out int newIndex)
{
var imagesTested = new Dictionary();
- SKBitmap bitmap = null;
+ SKBitmap? bitmap = null;
while (imagesTested.Count < paths.Length)
{
@@ -153,7 +153,7 @@ namespace Jellyfin.Drawing.Skia
currentIndex = 0;
}
- bitmap = _skiaEncoder.Decode(paths[currentIndex], false, null, out var origin);
+ bitmap = _skiaEncoder.Decode(paths[currentIndex], false, null, out _);
imagesTested[currentIndex] = 0;
diff --git a/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs b/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
index a10fff9dfe..cf3dbde2c0 100644
--- a/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
+++ b/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
@@ -32,7 +32,7 @@ namespace Jellyfin.Drawing.Skia
{
paint.Color = SKColor.Parse("#CC00A4DC");
paint.Style = SKPaintStyle.Fill;
- canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
+ canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
}
using (var paint = new SKPaint())
@@ -61,7 +61,7 @@ namespace Jellyfin.Drawing.Skia
paint.TextSize = 18;
}
- canvas.DrawText(text, (float)x, y, paint);
+ canvas.DrawText(text, x, y, paint);
}
}
}
diff --git a/MediaBrowser.Common/Extensions/ShuffleExtensions.cs b/MediaBrowser.Common/Extensions/ShuffleExtensions.cs
index 0432f36b57..459bec1105 100644
--- a/MediaBrowser.Common/Extensions/ShuffleExtensions.cs
+++ b/MediaBrowser.Common/Extensions/ShuffleExtensions.cs
@@ -1,3 +1,5 @@
+#nullable enable
+
using System;
using System.Collections.Generic;