Skip to content

Commit

Permalink
enable nullable refs
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonyCorbett committed Jun 8, 2021
1 parent 7558484 commit e195172
Show file tree
Hide file tree
Showing 72 changed files with 499 additions and 310 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,6 @@ dotnet_diagnostic.SA1201.severity = none

# SA1601: Partial elements should be documented
dotnet_diagnostic.SA1601.severity = none

# SA1011: Closing square brackets should be spaced correctly
dotnet_diagnostic.SA1011.severity = none
2 changes: 1 addition & 1 deletion OnlyM.Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace OnlyM.Core.Extensions
{
public static class StringExtensions
{
public static string GetNumericPrefix(this string value)
public static string? GetNumericPrefix(this string? value)
{
if (string.IsNullOrEmpty(value))
{
Expand Down
4 changes: 2 additions & 2 deletions OnlyM.Core/Extensions/UriExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public static string ToRelative(this Uri uri)
return uri.IsAbsoluteUri ? uri.PathAndQuery : uri.OriginalString;
}

public static string ToAbsolute(this Uri uri, string baseUrl)
public static string? ToAbsolute(this Uri uri, string baseUrl)
{
var baseUri = new Uri(baseUrl);
return uri.ToAbsolute(baseUri);
}

public static string ToAbsolute(this Uri uri, Uri baseUri)
public static string? ToAbsolute(this Uri uri, Uri baseUri)
{
var relative = uri.ToRelative();

Expand Down
8 changes: 4 additions & 4 deletions OnlyM.Core/Models/DisplayDeviceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
{
internal class DisplayDeviceData
{
public string Name { get; set; }
public string? Name { get; set; }

public string DeviceId { get; set; }
public string? DeviceId { get; set; }

public string DeviceString { get; set; }
public string? DeviceString { get; set; }

public string DeviceKey { get; set; }
public string? DeviceKey { get; set; }
}
}
4 changes: 2 additions & 2 deletions OnlyM.Core/Models/MediaFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{
public class MediaFile
{
public string FullPath { get; set; }
public string? FullPath { get; set; }

public SupportedMediaType MediaType { get; set; }
public SupportedMediaType? MediaType { get; set; }

public long LastChanged { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions OnlyM.Core/Models/MediaFolders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
public class MediaFolders
{
public string MediaFolder { get; set; }
public string? MediaFolder { get; set; }

public string DatedSubFolder { get; set; }
public string? DatedSubFolder { get; set; }
}
}
2 changes: 1 addition & 1 deletion OnlyM.Core/Models/MediaMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace OnlyM.Core.Models
{
public class MediaMetaData
{
public string Title { get; set; }
public string? Title { get; set; }

public TimeSpan Duration { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions OnlyM.Core/Models/SupportedMediaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
{
public class SupportedMediaType
{
public string Name { get; set; }
public string? Name { get; set; }

public MediaClassification Classification { get; set; }

public string FileExtension { get; set; }
public string? FileExtension { get; set; }
}
}
8 changes: 4 additions & 4 deletions OnlyM.Core/Models/SystemMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace OnlyM.Core.Models
{
public class SystemMonitor
{
public Screen Monitor { get; set; }
public Screen? Monitor { get; set; }

public string MonitorName { get; set; }
public string? MonitorName { get; set; }

public string MonitorId { get; set; }
public string? MonitorId { get; set; }

public string FriendlyName { get; set; }
public string? FriendlyName { get; set; }
}
}
1 change: 1 addition & 0 deletions OnlyM.Core/OnlyM.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWpf>true</UseWpf>
<UseWindowsForms>true</UseWindowsForms>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
10 changes: 5 additions & 5 deletions OnlyM.Core/Services/CommandLine/CommandLineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public CommandLineService()
p.Setup<bool>("nogpu")
.Callback(s => NoGpu = s).SetDefault(false);

p.Setup<string>("id")
p.Setup<string?>("id")
.Callback(s => OptionsIdentifier = s).SetDefault(null);

p.Setup<bool>("nosettings")
Expand All @@ -23,7 +23,7 @@ public CommandLineService()
p.Setup<bool>("nofolder")
.Callback(s => NoFolder = s).SetDefault(false);

p.Setup<string>("source")
p.Setup<string?>("source")
.Callback(s => SourceFolder = GetFullSourcePath(s)).SetDefault(null);

p.Setup<bool>("novidfix")
Expand All @@ -34,17 +34,17 @@ public CommandLineService()

public bool NoGpu { get; set; }

public string OptionsIdentifier { get; set; }
public string? OptionsIdentifier { get; set; }

public bool NoSettings { get; set; }

public bool NoFolder { get; set; }

public string SourceFolder { get; set; }
public string? SourceFolder { get; set; }

public bool DisableVideoRenderingFix { get; set; }

private static string GetFullSourcePath(string sourcePath)
private static string? GetFullSourcePath(string? sourcePath)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions OnlyM.Core/Services/CommandLine/ICommandLineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ public interface ICommandLineService
{
bool NoGpu { get; set; }

string OptionsIdentifier { get; set; }
string? OptionsIdentifier { get; set; }

bool NoSettings { get; set; }

bool NoFolder { get; set; }

string SourceFolder { get; set; }
string? SourceFolder { get; set; }

bool DisableVideoRenderingFix { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion OnlyM.Core/Services/Database/BrowserData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class BrowserData

public int Id { get; set; }

public string Url { get; set; }
public string? Url { get; set; }

public double ZoomLevel { get; set; }

Expand Down
6 changes: 3 additions & 3 deletions OnlyM.Core/Services/Database/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void AddThumbnailToCache(string originalPath, long originalLastChanged, b
}
}

public byte[] GetThumbnailFromCache(string originalPath, long originalLastChanged)
public byte[]? GetThumbnailFromCache(string originalPath, long originalLastChanged)
{
using (var c = CreateConnection())
using (var cmd = c.CreateCommand())
Expand Down Expand Up @@ -127,7 +127,7 @@ public void AddMediaStartOffsetData(string fileName, string startOffsets, int le
}
}

public MediaStartOffsetData GetMediaStartOffsetData(string fileName)
public MediaStartOffsetData? GetMediaStartOffsetData(string fileName)
{
using (var c = CreateConnection())
using (var cmd = c.CreateCommand())
Expand Down Expand Up @@ -158,7 +158,7 @@ public MediaStartOffsetData GetMediaStartOffsetData(string fileName)
return null;
}

public BrowserData GetBrowserData(string url)
public BrowserData? GetBrowserData(string url)
{
using (var c = CreateConnection())
using (var cmd = c.CreateCommand())
Expand Down
6 changes: 3 additions & 3 deletions OnlyM.Core/Services/Database/IDatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ public interface IDatabaseService

void AddThumbnailToCache(string originalPath, long originalLastChanged, byte[] thumbnail);

byte[] GetThumbnailFromCache(string originalPath, long originalLastChanged);
byte[]? GetThumbnailFromCache(string originalPath, long originalLastChanged);

// browser data...
void AddBrowserData(string url, double zoomLevel);

BrowserData GetBrowserData(string url);
BrowserData? GetBrowserData(string url);

// media file start offset data...
void AddMediaStartOffsetData(string fileName, string startOffsets, int lengthSeconds);

MediaStartOffsetData GetMediaStartOffsetData(string fileName);
MediaStartOffsetData? GetMediaStartOffsetData(string fileName);
}
}
4 changes: 2 additions & 2 deletions OnlyM.Core/Services/Database/MediaStartOffsetData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ public class MediaStartOffsetData
{
public int Id { get; set; }

public string FileName { get; set; }
public string? FileName { get; set; }

public int LengthSeconds { get; set; }

public List<int> StartOffsets { get; set; }
public List<int>? StartOffsets { get; set; }

#pragma warning disable CA1822 // Mark members as static
#pragma warning disable U2U1002 // Mark members as static
Expand Down
2 changes: 1 addition & 1 deletion OnlyM.Core/Services/Media/DatedSubFolders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OnlyM.Core.Services.Media
{
internal static class DatedSubFolders
{
public static string GetDatedSubFolder(string rootFolder, DateTime theDate)
public static string? GetDatedSubFolder(string rootFolder, DateTime theDate)
{
if (Directory.Exists(rootFolder))
{
Expand Down
19 changes: 12 additions & 7 deletions OnlyM.Core/Services/Media/FolderWatcherService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public sealed class FolderWatcherService : IFolderWatcherService, IDisposable
private readonly IOptionsService _optionsService;
private readonly IMediaProviderService _mediaProviderService;
private readonly ManualResetEventSlim _signalFolderChange = new(false);
private FileSystemWatcher _watcher;
private FileSystemWatcher? _watcher;
private int _changeVersion;
private MediaFolders _foldersToWatch;
private MediaFolders? _foldersToWatch;

public FolderWatcherService(IOptionsService optionsService, IMediaProviderService mediaProviderService)
{
Expand All @@ -31,7 +31,7 @@ public FolderWatcherService(IOptionsService optionsService, IMediaProviderServic
InitWatcher();
}

public event EventHandler ChangesFoundEvent;
public event EventHandler? ChangesFoundEvent;

public bool IsEnabled
{
Expand All @@ -52,7 +52,7 @@ public bool IsEnabled

public void Dispose()
{
_signalFolderChange?.Dispose();
_signalFolderChange.Dispose();
_watcher?.Dispose();
}

Expand Down Expand Up @@ -90,7 +90,7 @@ private void InitWatcher(MediaFolders mediaFolders)
_watcher.Renamed += HandleContentRenamed;
}

if (Directory.Exists(mediaFolders.MediaFolder))
if (mediaFolders.MediaFolder != null && Directory.Exists(mediaFolders.MediaFolder))
{
_watcher.Path = mediaFolders.MediaFolder;
_watcher.EnableRaisingEvents = true;
Expand Down Expand Up @@ -121,6 +121,11 @@ private void HandleContentRenamed(object sender, RenamedEventArgs e)

private bool IsWatchingFilesFolder(string path)
{
if (_foldersToWatch == null)
{
return false;
}

var directory = Path.GetDirectoryName(path);

if (directory == null)
Expand Down Expand Up @@ -157,13 +162,13 @@ private void HandleContentModified(object sender, FileSystemEventArgs e)
_signalFolderChange.Set();
}

private void HandleMediaFolderChangedEvent(object sender, EventArgs e)
private void HandleMediaFolderChangedEvent(object? sender, EventArgs e)
{
// Main Media Folder has changed.
InitWatcher();
}

private void HandleOperatingDateChangedEvent(object sender, EventArgs e)
private void HandleOperatingDateChangedEvent(object? sender, EventArgs e)
{
// Operating date has changed (so we may need to watch
// a different Calendar folder).
Expand Down
2 changes: 1 addition & 1 deletion OnlyM.Core/Services/Media/IMediaMetaDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace OnlyM.Core.Services.Media
{
public interface IMediaMetaDataService
{
MediaMetaData GetMetaData(
MediaMetaData? GetMetaData(
string mediaItemFilePath,
SupportedMediaType mediaType,
string ffmpegFolder);
Expand Down
2 changes: 1 addition & 1 deletion OnlyM.Core/Services/Media/IMediaProviderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IMediaProviderService

IReadOnlyCollection<SupportedMediaType> GetSupportedMediaTypes();

SupportedMediaType GetSupportedMediaType(string fileName);
SupportedMediaType? GetSupportedMediaType(string fileName);

MediaFolders GetMediaFolders(DateTime theDate);
}
Expand Down
2 changes: 1 addition & 1 deletion OnlyM.Core/Services/Media/IThumbnailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface IThumbnailService
{
event EventHandler ThumbnailsPurgedEvent;

byte[] GetThumbnail(
byte[]? GetThumbnail(
string originalPath,
string ffmpegFolder,
MediaClassification mediaClassification,
Expand Down
6 changes: 3 additions & 3 deletions OnlyM.Core/Services/Media/MediaMetaDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OnlyM.Core.Services.Media
// ReSharper disable once ClassNeverInstantiated.Global
public class MediaMetaDataService : IMediaMetaDataService
{
public MediaMetaData GetMetaData(
public MediaMetaData? GetMetaData(
string mediaItemFilePath,
SupportedMediaType mediaType,
string ffmpegFolder)
Expand Down Expand Up @@ -49,7 +49,7 @@ public MediaMetaData GetMetaData(
return null;
}

private static string StripNewLines(string s)
private static string? StripNewLines(string? s)
{
if (string.IsNullOrEmpty(s))
{
Expand All @@ -68,7 +68,7 @@ private static MediaMetaData GetVideoMetaData(string mediaItemFilePath, string f
{
var info = Unosquare.FFME.Library.RetrieveMediaInfo(FFmpegUtils.FixUnicodeString(mediaItemFilePath));

string title = null;
string? title = null;
info.Metadata?.TryGetValue("title", out title);

if (string.IsNullOrEmpty(title))
Expand Down
Loading

0 comments on commit e195172

Please sign in to comment.