Skip to content

Commit

Permalink
analyser warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonyCorbett committed Jul 29, 2023
1 parent e4f0133 commit 40122f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
6 changes: 1 addition & 5 deletions OnlyM.Core/Services/Options/OptionsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,7 @@ private Options WriteDefaultOptions()
var result = new Options();

// first time launched so set the monitor to the first one we find
var monitorService = Ioc.Default.GetService<IMonitorsService>();
if (monitorService == null)
{
throw new NotSupportedException("Could not get monitor service!");
}
var monitorService = Ioc.Default.GetService<IMonitorsService>() ?? throw new NotSupportedException("Could not get monitor service!");

result.MediaMonitorId = monitorService.GetSystemMonitors().First().MonitorId;

Expand Down
21 changes: 4 additions & 17 deletions OnlyM.Slides/SlideFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ private SlidesConfig Load()
{
using (var zip = ZipFile.OpenRead(FilePath))
{
var configEntry = zip.GetEntry(ConfigEntryName);
if (configEntry == null)
{
throw new Exception($"Could not find {ConfigEntryName} entry");
}
var configEntry = zip.GetEntry(ConfigEntryName) ?? throw new Exception($"Could not find {ConfigEntryName} entry");

using (var stream = configEntry.Open())
{
Expand All @@ -134,25 +130,16 @@ private SlidesConfig Load()
using (var sr = new StreamReader(stream))
using (var jsonTextReader = new JsonTextReader(sr))
{
var config = serializer.Deserialize<SlidesConfig>(jsonTextReader);
if (config == null)
{
throw new Exception($"Could not read {ConfigEntryName} entry");
}

return config;
return serializer.Deserialize<SlidesConfig>(jsonTextReader)
?? throw new Exception($"Could not read {ConfigEntryName} entry");
}
}
}
}

private static BitmapImage ReadBackgroundImage(ZipArchive zip, string entryName)
{
var entry = zip.GetEntry(entryName);
if (entry == null)
{
throw new Exception($"Could not read {entryName} entry");
}
var entry = zip.GetEntry(entryName) ?? throw new Exception($"Could not read {entryName} entry");

using (var stream = entry.Open())
using (var memoryStream = new MemoryStream())
Expand Down
14 changes: 12 additions & 2 deletions OnlyM/Services/MediaWindowPositionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ private static void PrepareForWindowedDisplay(Window mediaWindow, Size windowSiz
private static void PositionWindowUsingHack(
Window mediaWindow, Grid? mainGrid, Screen monitor, int left, int top, int width, int height)
{
Log.Logger.Verbose("Positioning media window according to WPF Media Foundation hack");

var primaryMonitor = Screen.PrimaryScreen;

if (primaryMonitor == null)
{
return;
}

Log.Logger.Verbose("Positioning media window according to WPF Media Foundation hack");

if (MonitorToRightOf(monitor, primaryMonitor))
{
Expand Down Expand Up @@ -184,6 +189,11 @@ private static bool WpfMediaFoundationHackRequired(
{
var primaryMonitor = Screen.PrimaryScreen;

if (primaryMonitor == null)
{
return false;
}

return
optionsService.RenderingMethod == RenderingMethod.MediaFoundation &&
isVideo &&
Expand Down

0 comments on commit 40122f1

Please sign in to comment.