Skip to content

Commit

Permalink
Fix all warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sabihoshi committed Jan 20, 2022
1 parent 9ddb784 commit 79ff4c3
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 102 deletions.
3 changes: 2 additions & 1 deletion GenshinLyreMidiPlayer.Data/GenshinLyreMidiPlayer.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion>10.0.17763.0</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="Melanchall.DryWetMidi" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.1" />
Expand Down
6 changes: 4 additions & 2 deletions GenshinLyreMidiPlayer.Data/Git/GitVersion.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using System;
using System.Text.Json.Serialization;
using JetBrains.Annotations;

namespace GenshinLyreMidiPlayer.Data.Git;

[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public class GitVersion
{
[JsonPropertyName("draft")] public bool Draft { get; set; }

[JsonPropertyName("prerelease")] public bool Prerelease { get; set; }

[JsonPropertyName("name")] public string Name { get; set; } = null!;
[JsonPropertyName("name")] public string Name { get; set; } = "Unknown";

[JsonPropertyName("tag_name")] public string TagName { get; set; } = null!;
[JsonPropertyName("tag_name")] public string TagName { get; set; } = "0";

[JsonPropertyName("html_url")] public string Url { get; set; } = null!;

Expand Down
2 changes: 1 addition & 1 deletion GenshinLyreMidiPlayer.WPF/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override void ConfigureIoC(IStyletIoCBuilder builder)

var path = Path.GetDirectoryName(config.FilePath);
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
Directory.CreateDirectory(path!);

builder.Bind<LyreContext>().ToFactory(_ =>
{
Expand Down
6 changes: 3 additions & 3 deletions GenshinLyreMidiPlayer.WPF/Core/LyrePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public static int TransposeNote(int noteId,
{
return direction switch
{
Transpose.Ignore => noteId,
Transpose.Up => ++noteId,
Transpose.Down => --noteId
Transpose.Up => ++noteId,
Transpose.Down => --noteId,
_ => noteId
};
}
}
Expand Down
24 changes: 11 additions & 13 deletions GenshinLyreMidiPlayer.WPF/Core/WindowHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
Expand All @@ -14,26 +15,23 @@ public static class WindowHelper
.OpenSubKey(@"SOFTWARE\launcher", false)
?.GetValue("InstPath") as string;

[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
private static string GenshinProcessName
=> Path.GetFileNameWithoutExtension(Settings.Default.GenshinLocation)!;
=> Path.GetFileNameWithoutExtension(Settings.Default.GenshinLocation);

public static bool EnsureGameOnTop()
public static bool IsGameFocused()
{
var genshinWindow = FindWindowByProcessName(GenshinProcessName);

if (genshinWindow is null)
return false;

SwitchToThisWindow((IntPtr) genshinWindow, true);

return GetForegroundWindow().Equals(genshinWindow);
return genshinWindow != null &&
IsWindowFocused((IntPtr) genshinWindow);
}

public static bool IsGameFocused()
public static void EnsureGameOnTop()
{
var genshinWindow = FindWindowByProcessName(GenshinProcessName);
return genshinWindow != null &&
IsWindowFocused((IntPtr) genshinWindow);
if (genshinWindow is null) return;

SwitchToThisWindow((IntPtr) genshinWindow, true);
}

private static bool IsWindowFocused(IntPtr windowPtr)
Expand All @@ -45,7 +43,7 @@ private static bool IsWindowFocused(IntPtr windowPtr)
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr GetForegroundWindow();

private static IntPtr? FindWindowByProcessName(string processName)
private static IntPtr? FindWindowByProcessName(string? processName)
{
var process = Process.GetProcessesByName(processName);
return process.FirstOrDefault(p => p.MainWindowHandle != IntPtr.Zero)?.MainWindowHandle;
Expand Down
5 changes: 3 additions & 2 deletions GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<StartupObject>GenshinLyreMidiPlayer.WPF.App</StartupObject>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>3.1.0</Version>
<Version>3.1.1</Version>
<ApplicationIcon>item_windsong_lyre.ico</ApplicationIcon>
<Nullable>enable</Nullable>
<RepositoryUrl>https://github.com/sabihoshi/GenshinLyreMidiPlayer</RepositoryUrl>
Expand All @@ -18,12 +18,13 @@
<LangVersion>latest</LangVersion>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion>10.0.18362.0</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Humanizer.Core" Version="2.13.14" />
<PackageReference Include="InputSimulator" Version="1.0.4" />
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="Melanchall.DryWetMidi" Version="6.0.1" />
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
<PackageReference Include="ModernWpfUI.MahApps" Version="0.9.4" />
Expand Down
24 changes: 12 additions & 12 deletions GenshinLyreMidiPlayer.WPF/ModernWPF/Errors/ExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using Melanchall.DryWetMidi.Common;
using Melanchall.DryWetMidi.Core;
using ModernWpf.Controls;

Expand Down Expand Up @@ -91,32 +92,31 @@ public static async Task<bool> TryHandleException(Exception e, ReadingSettings s

var option = result switch
{
ContentDialogResult.Primary => command?.ElementAtOrDefault(0),
ContentDialogResult.Secondary => command?.ElementAtOrDefault(1)
ContentDialogResult.Primary => command.ElementAtOrDefault(0),
ContentDialogResult.Secondary => command.ElementAtOrDefault(1),
_ => null
};

if (option is null) return false;

switch (e)
{
// User selectable policy
case InvalidChannelEventParameterValueException:
settings.InvalidChannelEventParameterValuePolicy =
(InvalidChannelEventParameterValuePolicy) option!;
settings.InvalidChannelEventParameterValuePolicy = (InvalidChannelEventParameterValuePolicy) option;
break;
case InvalidMetaEventParameterValueException:
settings.InvalidMetaEventParameterValuePolicy =
(InvalidMetaEventParameterValuePolicy) option!;
settings.InvalidMetaEventParameterValuePolicy = (InvalidMetaEventParameterValuePolicy) option;
break;
case InvalidSystemCommonEventParameterValueException:
settings.InvalidSystemCommonEventParameterValuePolicy =
(InvalidSystemCommonEventParameterValuePolicy) option!;
settings.InvalidSystemCommonEventParameterValuePolicy
= (InvalidSystemCommonEventParameterValuePolicy) option;
break;
case UnknownChannelEventException:
settings.UnknownChannelEventPolicy =
(UnknownChannelEventPolicy) option!;
settings.UnknownChannelEventPolicy = (UnknownChannelEventPolicy) option;
break;
case UnknownChunkException:
settings.UnknownChunkIdPolicy =
(UnknownChunkIdPolicy) option!;
settings.UnknownChunkIdPolicy = (UnknownChunkIdPolicy) option;
break;

// Ignorable policies
Expand Down
26 changes: 13 additions & 13 deletions GenshinLyreMidiPlayer.WPF/ViewModels/LyrePlayerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public bool CanHitPlayPause
{
get
{
var hasNotes = MidiTracks?
var hasNotes = MidiTracks
.Where(t => t.IsChecked)
.Any(t => t.CanBePlayed) ?? false;
.Any(t => t.CanBePlayed);

return Playback is not null
&& hasNotes
Expand Down Expand Up @@ -405,31 +405,31 @@ await Application.Current.Dispatcher.Invoke(async () =>

SettingsView.Transpose = result switch
{
ContentDialogResult.None => TransposeNames.ElementAt(0),
ContentDialogResult.Primary => TransposeNames.ElementAt(1),
ContentDialogResult.Secondary => TransposeNames.ElementAt(2)
ContentDialogResult.Secondary => TransposeNames.ElementAt(2),
_ => TransposeNames.ElementAt(0)
};
});
}

Playback = midi.GetPlayback();
Playback.Speed = SettingsView.SelectedSpeed.Speed;
var playback = midi.GetPlayback();

Playback.InterruptNotesOnStop = true;
Playback = playback;
playback.Speed = SettingsView.SelectedSpeed.Speed;
playback.InterruptNotesOnStop = true;
playback.Finished += (_, _) => { Next(); };
playback.EventPlayed += OnNoteEvent;

Playback.Finished += (_, _) => { Next(); };
Playback.EventPlayed += OnNoteEvent;

Playback.Started += (_, _) =>
playback.Started += (_, _) =>
{
_timeWatcher.RemoveAllPlaybacks();
_timeWatcher.AddPlayback(Playback, TimeSpanType.Metric);
_timeWatcher.AddPlayback(playback, TimeSpanType.Metric);
_timeWatcher.Start();

UpdateButtons();
};

Playback.Stopped += (_, _) =>
playback.Stopped += (_, _) =>
{
_timeWatcher.Stop();

Expand Down
4 changes: 3 additions & 1 deletion GenshinLyreMidiPlayer.WPF/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
using System.Linq;
using GenshinLyreMidiPlayer.Data;
using GenshinLyreMidiPlayer.WPF.Views;
using JetBrains.Annotations;
using ModernWpf.Controls;
using Stylet;
using StyletIoC;

namespace GenshinLyreMidiPlayer.WPF.ViewModels;

[UsedImplicitly]
public class MainWindowViewModel : Conductor<IScreen>.StackNavigation
{
private readonly IContainer _ioc;
private readonly Stack<NavigationViewItem> _history = new();
private NavigationView _navView = null!;

public MainWindowViewModel(IContainer ioc, IEventAggregator events)
public MainWindowViewModel(IContainer ioc)
{
_ioc = ioc;

Expand Down
7 changes: 4 additions & 3 deletions GenshinLyreMidiPlayer.WPF/ViewModels/PlaylistViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public PlaylistViewModel(IContainer ioc, MainWindowViewModel main)
LoopMode.Once => "\xF5E7",
LoopMode.Track => "\xE8ED",
LoopMode.Playlist => "\xEBE7",
LoopMode.All => "\xE8EE"
LoopMode.All => "\xE8EE",
_ => string.Empty
};

public string? FilterText { get; set; }
Expand Down Expand Up @@ -150,7 +151,7 @@ public async Task RemoveTrack()
db.History.Remove(SelectedFile.History);
await db.SaveChangesAsync();

OpenedFile = OpenedFile == SelectedFile ? null : OpenedFile;
OpenedFile = OpenedFile == SelectedFile ? null : OpenedFile;
Tracks.Remove(SelectedFile);

RefreshPlaylist();
Expand Down Expand Up @@ -223,7 +224,7 @@ private async Task AddFile(History history, ReadingSettings? settings = null)
}
}

private async Task AddFile(string fileName, ReadingSettings? settings = null)
private async Task AddFile(string fileName)
{
var history = new History(fileName, _main.SettingsView.KeyOffset);

Expand Down
Loading

0 comments on commit 79ff4c3

Please sign in to comment.