From 01477d8b25c40d31f23a9569d8e4897c83ee58c4 Mon Sep 17 00:00:00 2001 From: Benjamin Nomine <115967+benomine@users.noreply.github.com> Date: Sat, 11 Jan 2025 14:05:54 -0500 Subject: [PATCH] feat: dotnet 9, CPM, etc --- src/.editorconfig | 3 + src/Directory.Build.props | 6 ++ src/Directory.Packages.props | 10 +++ src/MpvNet.Windows/Conf.cs | 4 +- src/MpvNet.Windows/FileAssociation.cs | 2 +- src/MpvNet.Windows/GuiCommand.cs | 36 +++++++--- src/MpvNet.Windows/MpvNet.Windows.csproj | 72 +++++++++---------- src/MpvNet.sln | 1 + src/MpvNet/Chapter.cs | 2 +- src/MpvNet/Command.cs | 2 +- src/MpvNet/CommandLine.cs | 19 +++-- src/MpvNet/ExtensionLoader.cs | 6 +- .../ExtensionMethod/PathStringExtension.cs | 4 +- src/MpvNet/FileTypes.cs | 8 +-- src/MpvNet/Help/StringHelp.cs | 4 +- src/MpvNet/InputConf.cs | 14 ++++ src/MpvNet/MVVM/Messages.cs | 9 --- src/MpvNet/MpvClient.cs | 48 ++++++++++--- src/MpvNet/MpvNet.csproj | 32 ++++----- src/MpvNet/Player.cs | 36 +++++++--- src/NGettext.Wpf/NGettext.Wpf.csproj | 21 +++--- src/Tools/release-mpv.net.ps1 | 2 +- 22 files changed, 213 insertions(+), 128 deletions(-) create mode 100644 src/Directory.Build.props create mode 100644 src/Directory.Packages.props diff --git a/src/.editorconfig b/src/.editorconfig index 6eff39d..dc6cbf5 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -5,3 +5,6 @@ csharp_style_implicit_object_creation_when_type_is_apparent = true # IDE0090: Use 'new(...)' dotnet_diagnostic.IDE0090.severity = silent + +# WFO1000: A property should determine its property content serialization with the DesignerSerializationVisibilityAttribute, DefaultValueAttribute or the ShouldSerializeProperty method +dotnet_diagnostic.WFO1000.severity = silent \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 0000000..f355a94 --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,6 @@ + + + mpv.net + enable + + \ No newline at end of file diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props new file mode 100644 index 0000000..0c327fb --- /dev/null +++ b/src/Directory.Packages.props @@ -0,0 +1,10 @@ + + + true + + + + + + + \ No newline at end of file diff --git a/src/MpvNet.Windows/Conf.cs b/src/MpvNet.Windows/Conf.cs index c752aa6..18314fb 100644 --- a/src/MpvNet.Windows/Conf.cs +++ b/src/MpvNet.Windows/Conf.cs @@ -101,8 +101,8 @@ public class ConfParser } else if (line.Contains('=')) { - string name = line[..line.IndexOf("=")].Trim(); - string value = line[(line.IndexOf("=") + 1)..].Trim(); + string name = line[..line.IndexOf('=')].Trim(); + string value = line[(line.IndexOf('=') + 1)..].Trim(); currentGroup?.Items.Add(new StringPair(name, value)); } diff --git a/src/MpvNet.Windows/FileAssociation.cs b/src/MpvNet.Windows/FileAssociation.cs index b285b45..1893056 100644 --- a/src/MpvNet.Windows/FileAssociation.cs +++ b/src/MpvNet.Windows/FileAssociation.cs @@ -13,7 +13,7 @@ public static class FileAssociation string exeFilename = Path.GetFileName(exePath); string exeFilenameNoExt = Path.GetFileNameWithoutExtension(exePath); - string[] protocols = { "ytdl", "rtsp", "srt", "srtp" }; + string[] protocols = ["ytdl", "rtsp", "srt", "srtp"]; if (perceivedType != "unreg") { diff --git a/src/MpvNet.Windows/GuiCommand.cs b/src/MpvNet.Windows/GuiCommand.cs index ef3124d..fe95ef9 100644 --- a/src/MpvNet.Windows/GuiCommand.cs +++ b/src/MpvNet.Windows/GuiCommand.cs @@ -198,11 +198,13 @@ public class GuiCommand else { string clipboard = System.Windows.Forms.Clipboard.GetText(); - List files = new List(); + List files = []; foreach (string i in clipboard.Split(BR.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) + { if (i.Contains("://") || File.Exists(i)) files.Add(i); + } if (files.Count == 0) { @@ -227,9 +229,13 @@ public class GuiCommand dialog.Multiselect = true; - if (dialog.ShowDialog() == DialogResult.OK) - foreach (string i in dialog.FileNames) - Player.CommandV("audio-add", i); + if (dialog.ShowDialog() != DialogResult.OK) + return; + + foreach (string i in dialog.FileNames) + { + Player.CommandV("audio-add", i); + } } void RegisterFileAssociations(IList args) @@ -313,9 +319,11 @@ public class GuiCommand var items = new List(); foreach (string file in App.Settings.RecentFiles) + { items.Add(new Item() { title = Path.GetFileName(file), - value = new string []{ "loadfile", file }, - hint = file}); + value = ["loadfile", file], + hint = file}); + } o.items = items.ToArray(); string json = JsonSerializer.Serialize(o); @@ -326,12 +334,12 @@ public class GuiCommand { public string title { get; set; } = ""; public int selected_index { get; set; } = 0; - public Item[] items { get; set; } = Array.Empty(); + public Item[] items { get; set; } = []; } class Item { - public string[] value { get; set; } = Array.Empty(); + public string[] value { get; set; } = []; public string title { get; set; } = ""; public string hint { get; set; } = ""; } @@ -393,15 +401,21 @@ public class GuiCommand } if (App.MediaInfo && !osd && File.Exists(path) && !path.Contains(@"\\.\pipe\")) - using (MediaInfo mediaInfo = new MediaInfo(path)) - text = Regex.Replace(mediaInfo.GetSummary(full, raw), "Unique ID.+", ""); + { + using MediaInfo mediaInfo = new MediaInfo(path); + text = Regex.Replace(mediaInfo.GetSummary(full, raw), "Unique ID.+", ""); + } else { Player.UpdateExternalTracks(); text = "N: " + Player.GetPropertyString("filename") + BR; lock (Player.MediaTracksLock) + { foreach (MediaTrack track in Player.MediaTracks) + { text += track.Text + BR; + } + } } text = text.TrimEx(); @@ -426,7 +440,7 @@ public class GuiCommand { string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User)!; - if (path.ToLower().Contains(Folder.Startup.TrimEnd(Path.DirectorySeparatorChar).ToLower())) + if (path.Contains(Folder.Startup.TrimEnd(Path.DirectorySeparatorChar), StringComparison.CurrentCultureIgnoreCase)) { Msg.ShowWarning(_("mpv.net is already in the Path environment variable.")); return; diff --git a/src/MpvNet.Windows/MpvNet.Windows.csproj b/src/MpvNet.Windows/MpvNet.Windows.csproj index 9bbd3a1..41c38b7 100644 --- a/src/MpvNet.Windows/MpvNet.Windows.csproj +++ b/src/MpvNet.Windows/MpvNet.Windows.csproj @@ -1,49 +1,47 @@  - - WinExe - net6.0-windows - MpvNet.Windows + + WinExe + net9.0-windows + MpvNet.Windows false true - mpvnet - true - true - mpv-icon.ico - mpv.net - 7.1.1.3 - 7.1.1.3 + mpvnet + true + true + mpv-icon.ico + 7.1.1.3 + 7.1.1.3 7.1.1.3 - enable - + - - - - - - + + + + + + - - - + + + - - - - + + + + - - - MSBuild:Compile - Wpf - Designer - - + + + MSBuild:Compile + Wpf + Designer + + - - - - + + + + diff --git a/src/MpvNet.sln b/src/MpvNet.sln index 5891b3d..8c1dd13 100644 --- a/src/MpvNet.sln +++ b/src/MpvNet.sln @@ -13,6 +13,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2F97C77E-32E3-46FA-8D7C-3940FD9AA384}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig + Directory.Build.props = Directory.Build.props EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NGettext.Wpf", "NGettext.Wpf\NGettext.Wpf.csproj", "{0B7958FD-2138-482A-A21B-481AE7A0F851}" diff --git a/src/MpvNet/Chapter.cs b/src/MpvNet/Chapter.cs index 21bdedc..adb62e5 100644 --- a/src/MpvNet/Chapter.cs +++ b/src/MpvNet/Chapter.cs @@ -19,7 +19,7 @@ public class Chapter _timeDisplay = TimeSpan.FromSeconds(Time).ToString(); if (_timeDisplay.ContainsEx(".")) - _timeDisplay = _timeDisplay[.._timeDisplay.LastIndexOf(".")]; + _timeDisplay = _timeDisplay[.._timeDisplay.LastIndexOf('.')]; } return _timeDisplay; diff --git a/src/MpvNet/Command.cs b/src/MpvNet/Command.cs index 0c83ec6..16a1d2b 100644 --- a/src/MpvNet/Command.cs +++ b/src/MpvNet/Command.cs @@ -42,7 +42,7 @@ public class Command { if (i.Contains("://") || File.Exists(i)) { - Player.LoadFiles(new[] { i }, true, false); + Player.LoadFiles([i], true, false); break; } } diff --git a/src/MpvNet/CommandLine.cs b/src/MpvNet/CommandLine.cs index dac2f42..5a995bb 100644 --- a/src/MpvNet/CommandLine.cs +++ b/src/MpvNet/CommandLine.cs @@ -17,7 +17,7 @@ public class CommandLine if (_arguments != null) return _arguments; - _arguments = new(); + _arguments = []; foreach (string i in Environment.GetCommandLineArgs().Skip(1)) { @@ -37,7 +37,7 @@ public class CommandLine arg += "=yes"; } - string left = arg[2..arg.IndexOf("=")]; + string left = arg[2..arg.IndexOf('=')]; string right = arg[(left.Length + 3)..]; if (string.IsNullOrEmpty(left)) @@ -113,16 +113,19 @@ public class CommandLine public static void ProcessCommandLineFiles() { - List files = new List(); + List files = []; foreach (string arg in Environment.GetCommandLineArgs().Skip(1)) + { if (!arg.StartsWith("--") && (arg == "-" || arg.Contains("://") || - arg.Contains(":\\") || arg.StartsWith("\\\\") || arg.StartsWith(".") || + arg.Contains(":\\") || arg.StartsWith("\\\\") || arg.StartsWith('.') || File.Exists(arg))) - + { files.Add(arg); + } + } - Player.LoadFiles(files.ToArray(), !App.Queue, App.Queue); + Player.LoadFiles([.. files], !App.Queue, App.Queue); if (App.CommandLine.Contains("--shuffle")) { @@ -134,8 +137,10 @@ public class CommandLine public static bool Contains(string name) { foreach (StringPair pair in Arguments) + { if (pair.Name == name) return true; + } return false; } @@ -143,8 +148,10 @@ public class CommandLine public static string GetValue(string name) { foreach (StringPair pair in Arguments) + { if (pair.Name == name) return pair.Value; + } return ""; } diff --git a/src/MpvNet/ExtensionLoader.cs b/src/MpvNet/ExtensionLoader.cs index a5cb5f3..a162275 100644 --- a/src/MpvNet/ExtensionLoader.cs +++ b/src/MpvNet/ExtensionLoader.cs @@ -9,7 +9,7 @@ public class ExtensionLoader { public event Action? UnhandledException; - readonly List _refs = new(); + readonly List _refs = []; void LoadDll(string path) { @@ -31,8 +31,12 @@ public class ExtensionLoader public void LoadFolder(string path) { if (Directory.Exists(path)) + { foreach (string dir in Directory.GetDirectories(path)) + { LoadDll(dir.AddSep() + Path.GetFileName(dir) + ".dll"); + } + } } } diff --git a/src/MpvNet/ExtensionMethod/PathStringExtension.cs b/src/MpvNet/ExtensionMethod/PathStringExtension.cs index 32e29fb..9850514 100644 --- a/src/MpvNet/ExtensionMethod/PathStringExtension.cs +++ b/src/MpvNet/ExtensionMethod/PathStringExtension.cs @@ -32,12 +32,12 @@ public static class PathStringExtension int index = instance.LastIndexOf('\\'); if (index > -1) - return instance.Substring(index + 1); + return instance[(index + 1)..]; index = instance.LastIndexOf('/'); if (index > -1) - return instance.Substring(index + 1); + return instance[(index + 1)..]; return instance; } diff --git a/src/MpvNet/FileTypes.cs b/src/MpvNet/FileTypes.cs index 0ee136b..0f7e378 100644 --- a/src/MpvNet/FileTypes.cs +++ b/src/MpvNet/FileTypes.cs @@ -5,7 +5,7 @@ namespace MpvNet; public static class FileTypes { - public static string[] Subtitle { get; } = { "srt", "ass", "idx", "sub", "sup", "ttxt", "txt", "ssa", "smi", "mks" }; + public static string[] Subtitle { get; } = ["srt", "ass", "idx", "sub", "sup", "ttxt", "txt", "ssa", "smi", "mks"]; public static bool IsVideo(string[] exts, string ext) => exts?.Contains(ext) ?? false; public static bool IsAudio(string[] exts, string ext) => exts?.Contains(ext) ?? false; @@ -20,7 +20,7 @@ public static class FileTypes string exts = Player.GetPropertyString("video-exts"); if (string.IsNullOrEmpty(exts)) - return "mkv mp4 avi mov flv mpg webm wmv ts vob 264 265 asf avc avs dav h264 h265 hevc m2t m2ts m2v m4v mpeg mpv mts vpy y4m".Split(' '); + return ["mkv", "mp4", "avi", "mov", "flv", "mpg", "webm", "wmv", "ts", "vob", "264", "265", "asf", "avc", "avs", "dav", "h264", "h265", "hevc", "m2t", "m2ts", "m2v", "m4v", "mpeg", "mpv", "mts", "vpy", "y4m"]; return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); } @@ -30,7 +30,7 @@ public static class FileTypes string exts = Player.GetPropertyString("audio-exts"); if (string.IsNullOrEmpty(exts)) - return "mp3 flac m4a mka mp2 ogg opus aac ac3 dts dtshd dtshr dtsma eac3 mpa mpc thd w64 wav".Split(' '); + return ["mp3", "flac", "m4a", "mka", "mp2", "ogg", "opus", "aac", "ac3", "dts", "dtshd", "dtshr", "dtsma", "eac3", "mpa", "mpc", "thd", "w64", "wav"]; return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); } @@ -40,7 +40,7 @@ public static class FileTypes string exts = Player.GetPropertyString("image-exts"); if (string.IsNullOrEmpty(exts)) - return new string[]{ "jpg", "bmp", "png", "gif", "webp" }; + return ["jpg", "bmp", "png", "gif", "webp"]; return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); } diff --git a/src/MpvNet/Help/StringHelp.cs b/src/MpvNet/Help/StringHelp.cs index 2dfc37d..cc77a0f 100644 --- a/src/MpvNet/Help/StringHelp.cs +++ b/src/MpvNet/Help/StringHelp.cs @@ -8,9 +8,7 @@ public static class StringHelp { public static string GetMD5Hash(string txt) { - using MD5 md5 = MD5.Create(); byte[] inputBuffer = Encoding.UTF8.GetBytes(txt); - byte[] hashBuffer = md5.ComputeHash(inputBuffer); - return BitConverter.ToString(md5.ComputeHash(inputBuffer)).Replace("-", ""); + return Convert.ToHexString(MD5.HashData(inputBuffer)); } } diff --git a/src/MpvNet/InputConf.cs b/src/MpvNet/InputConf.cs index 2b456dc..61f6feb 100644 --- a/src/MpvNet/InputConf.cs +++ b/src/MpvNet/InputConf.cs @@ -34,17 +34,25 @@ public class InputConf var defaultBindings = InputHelp.GetDefaults(); foreach (Binding defaultBinding in defaultBindings) + { foreach (Binding confBinding in confbindings) + { if (defaultBinding.Input == confBinding.Input && defaultBinding.Command != confBinding.Command) { defaultBinding.Input = ""; } + } + } foreach (Binding defaultBinding in defaultBindings) + { foreach (Binding confBinding in confbindings) + { if (defaultBinding.Command == confBinding.Command) defaultBinding.Input = confBinding.Input; + } + } return (defaultBindings, confbindings); } @@ -82,16 +90,22 @@ public class InputConf var conf = InputHelp.Parse(Content); foreach (Binding defaultBinding in defaults) + { foreach (Binding confBinding in conf) + { if (defaultBinding.Command == confBinding.Command && defaultBinding.Comment == confBinding.Comment) { defaultBinding.Input = confBinding.Input; removed.Add(confBinding); } + } + } foreach (Binding binding in removed) + { conf.Remove(binding); + } defaults.AddRange(conf); return InputHelp.ConvertToString(defaults); diff --git a/src/MpvNet/MVVM/Messages.cs b/src/MpvNet/MVVM/Messages.cs index 68e70ab..d6d8bf2 100644 --- a/src/MpvNet/MVVM/Messages.cs +++ b/src/MpvNet/MVVM/Messages.cs @@ -1,13 +1,4 @@  -using CommunityToolkit.Mvvm.Messaging.Messages; - namespace MpvNet.MVVM; public class MainWindowIsLoadedMessage { } - -//public class ScaleWindowMessage : ValueChangedMessage -//{ -// public ScaleWindowMessage(float value) : base(value) -// { -// } -//} diff --git a/src/MpvNet/MpvClient.cs b/src/MpvNet/MpvClient.cs index 6b2dd6b..a4890a4 100644 --- a/src/MpvNet/MpvClient.cs +++ b/src/MpvNet/MpvClient.cs @@ -21,11 +21,11 @@ public class MpvClient public event Action? Seek; // seek MPV_EVENT_SEEK public event Action? PlaybackRestart; // playback-restart MPV_EVENT_PLAYBACK_RESTART - public Dictionary> PropChangeActions { get; set; } = new Dictionary>(); - public Dictionary>> IntPropChangeActions { get; set; } = new Dictionary>>(); - public Dictionary>> BoolPropChangeActions { get; set; } = new Dictionary>>(); - public Dictionary>> DoublePropChangeActions { get; set; } = new Dictionary>>(); - public Dictionary>> StringPropChangeActions { get; set; } = new Dictionary>>(); + public Dictionary> PropChangeActions { get; set; } = []; + public Dictionary>> IntPropChangeActions { get; set; } = []; + public Dictionary>> BoolPropChangeActions { get; set; } = []; + public Dictionary>> DoublePropChangeActions { get; set; } = []; + public Dictionary>> StringPropChangeActions { get; set; } = []; public nint Handle { get; set; } @@ -132,46 +132,72 @@ public class MpvClient else if (data.format == mpv_format.MPV_FORMAT_STRING) { lock (StringPropChangeActions) + { foreach (var pair in StringPropChangeActions) + { if (pair.Key == data.name) { string value = ConvertFromUtf8(Marshal.PtrToStructure(data.data)); foreach (var action in pair.Value) + { action.Invoke(value); + } } + } + } } else if (data.format == mpv_format.MPV_FORMAT_INT64) { lock (IntPropChangeActions) + { foreach (var pair in IntPropChangeActions) + { if (pair.Key == data.name) { int value = Marshal.PtrToStructure(data.data); foreach (var action in pair.Value) + { action.Invoke(value); + } } + } + } } else if (data.format == mpv_format.MPV_FORMAT_NONE) { lock (PropChangeActions) + { foreach (var pair in PropChangeActions) + { if (pair.Key == data.name) + { foreach (var action in pair.Value) + { action.Invoke(); + } + } + } + } } else if (data.format == mpv_format.MPV_FORMAT_DOUBLE) { lock (DoublePropChangeActions) + { foreach (var pair in DoublePropChangeActions) + { if (pair.Key == data.name) { double value = Marshal.PtrToStructure(data.data); foreach (var action in pair.Value) + { action.Invoke(value); + } } + } + } } } @@ -247,7 +273,9 @@ public class MpvClient mpv_error err = mpv_command_ret(Handle, rootPtr, resultNodePtr); foreach (IntPtr ptr in pointers) + { Marshal.FreeHGlobal(ptr); + } Marshal.FreeHGlobal(rootPtr); @@ -409,7 +437,7 @@ public class MpvClient if (err < 0) HandleError(err, "error observing property: " + name); else - IntPropChangeActions[name] = new List>(); + IntPropChangeActions[name] = []; } if (IntPropChangeActions.ContainsKey(name)) @@ -428,7 +456,7 @@ public class MpvClient if (err < 0) HandleError(err, "error observing property: " + name); else - DoublePropChangeActions[name] = new List>(); + DoublePropChangeActions[name] = []; } if (DoublePropChangeActions.ContainsKey(name)) @@ -447,7 +475,7 @@ public class MpvClient if (err < 0) HandleError(err, "error observing property: " + name); else - BoolPropChangeActions[name] = new List>(); + BoolPropChangeActions[name] = []; } if (BoolPropChangeActions.ContainsKey(name)) @@ -466,7 +494,7 @@ public class MpvClient if (err < 0) HandleError(err, "error observing property: " + name); else - StringPropChangeActions[name] = new List>(); + StringPropChangeActions[name] = []; } if (StringPropChangeActions.ContainsKey(name)) @@ -485,7 +513,7 @@ public class MpvClient if (err < 0) HandleError(err, "error observing property: " + name); else - PropChangeActions[name] = new List(); + PropChangeActions[name] = []; } if (PropChangeActions.ContainsKey(name)) diff --git a/src/MpvNet/MpvNet.csproj b/src/MpvNet/MpvNet.csproj index 6eaa0ea..153563d 100644 --- a/src/MpvNet/MpvNet.csproj +++ b/src/MpvNet/MpvNet.csproj @@ -1,27 +1,25 @@  - - net6.0 + + net9.0 libmpvnet - mpv.net - enable MpvNet false - + - - - - - + + + + + - - - + + + - - - - + + + + diff --git a/src/MpvNet/Player.cs b/src/MpvNet/Player.cs index 0e4439c..9b1deb3 100644 --- a/src/MpvNet/Player.cs +++ b/src/MpvNet/Player.cs @@ -73,10 +73,12 @@ public class MainPlayer : MpvClient MainHandle = mpv_create(); Handle = MainHandle; - var events = Enum.GetValues(typeof(mpv_event_id)).Cast(); + var events = Enum.GetValues().Cast(); foreach (mpv_event_id i in events) + { mpv_request_event(MainHandle, i, 0); + } mpv_request_log_messages(MainHandle, "no"); @@ -194,7 +196,9 @@ public class MainPlayer : MpvClient mpv_destroy(Handle); foreach (var client in Clients) + { mpv_destroy(client.Handle); + } } public void ProcessProperty(string? name, string? value) @@ -263,6 +267,8 @@ public class MainPlayer : MpvClient } } + private readonly Regex ConfRegex = new Regex("^[\\w-]+$", RegexOptions.Compiled); + Dictionary? _Conf; public Dictionary Conf { @@ -273,7 +279,7 @@ public class MainPlayer : MpvClient App.ApplyInputDefaultBindingsFix(); - _Conf = new Dictionary(); + _Conf = []; if (File.Exists(ConfPath)) { @@ -281,12 +287,12 @@ public class MainPlayer : MpvClient { string line = it.TrimStart(' ', '-').TrimEnd(); - if (line.StartsWith("#")) + if (line.StartsWith('#')) continue; if (!line.Contains('=')) { - if (Regex.Match(line, "^[\\w-]+$").Success) + if (ConfRegex.Match(line).Success) line += "=yes"; else continue; @@ -305,7 +311,9 @@ public class MainPlayer : MpvClient } foreach (var i in _Conf) + { ProcessProperty(i.Key, i.Value); + } return _Conf; } @@ -331,7 +339,9 @@ public class MainPlayer : MpvClient public void MainEventLoop() { while (true) + { mpv_wait_event(MainHandle, -1); + } } protected override void OnShutdown() @@ -479,14 +489,14 @@ public class MainPlayer : MpvClient Command("stop"); Thread.Sleep(500); SetPropertyString("dvd-device", path); - LoadFiles(new[] { @"dvd://" }, false, false); + LoadFiles([@"dvd://"], false, false); } else { Command("stop"); Thread.Sleep(500); SetPropertyString("bluray-device", path); - LoadFiles(new[] { @"bd://" }, false, false); + LoadFiles([@"bd://"], false, false); } } @@ -498,12 +508,12 @@ public class MainPlayer : MpvClient if (Directory.Exists(path + "\\BDMV")) { SetPropertyString("bluray-device", path); - LoadFiles(new[] { @"bd://" }, false, false); + LoadFiles([@"bd://"], false, false); } else { SetPropertyString("dvd-device", path); - LoadFiles(new[] { @"dvd://" }, false, false); + LoadFiles([@"dvd://"], false, false); } } @@ -601,8 +611,10 @@ public class MainPlayer : MpvClient static string GetNativeLanguage(string name) { foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures)) + { if (ci.EnglishName == name) return ci.NativeName; + } return name; } @@ -629,7 +641,7 @@ public class MainPlayer : MpvClient if (_audioDevices != null) return _audioDevices; - _audioDevices = new(); + _audioDevices = []; string json = GetPropertyString("audio-device-list"); var enumerator = JsonDocument.Parse(json).RootElement.EnumerateArray(); @@ -680,6 +692,8 @@ public class MainPlayer : MpvClient } } + private readonly Regex TitleRegex = new Regex(@"^[\._\-]", RegexOptions.Compiled); + public List GetTracks(bool includeInternal = true, bool includeExternal = true) { List tracks = new List(); @@ -697,7 +711,7 @@ public class MainPlayer : MpvClient string filename = GetPropertyString($"filename/no-ext"); string title = GetPropertyString($"track-list/{i}/title").Replace(filename, ""); - title = Regex.Replace(title, @"^[\._\-]", ""); + title = TitleRegex.Replace(title, ""); if (type == "video") { @@ -1043,7 +1057,7 @@ public class MainPlayer : MpvClient if (_profileNames != null) return _profileNames; - string[] ignore = { "builtin-pseudo-gui", "encoding", "libmpv", "pseudo-gui", "default" }; + string[] ignore = ["builtin-pseudo-gui", "encoding", "libmpv", "pseudo-gui", "default"]; string json = GetPropertyString("profile-list"); return _profileNames = JsonDocument.Parse(json).RootElement.EnumerateArray() .Select(it => it.GetProperty("name").GetString()) diff --git a/src/NGettext.Wpf/NGettext.Wpf.csproj b/src/NGettext.Wpf/NGettext.Wpf.csproj index 349b5dc..a0b84ba 100644 --- a/src/NGettext.Wpf/NGettext.Wpf.csproj +++ b/src/NGettext.Wpf/NGettext.Wpf.csproj @@ -1,16 +1,15 @@ - - net6.0-windows - true - enable - enable - false - + + net9.0-windows + true + enable + false + - - - - + + + + diff --git a/src/Tools/release-mpv.net.ps1 b/src/Tools/release-mpv.net.ps1 index b1bc107..750bfb1 100644 --- a/src/Tools/release-mpv.net.ps1 +++ b/src/Tools/release-mpv.net.ps1 @@ -40,7 +40,7 @@ Test (Join-Path $SourceDir 'MpvNet.sln') $7zFile = Test 'C:\Program Files\7-Zip\7z.exe' $InnoSetupCompiler = Test 'C:\Program Files (x86)\Inno Setup 6\ISCC.exe' -$ReleaseNotes = "- [.NET Desktop Runtime 6.0](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)`n- [Changelog](https://github.com/mpvnet-player/mpv.net/blob/main/docs/changelog.md)" +$ReleaseNotes = "- [.NET Desktop Runtime 9.0](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)`n- [Changelog](https://github.com/mpvnet-player/mpv.net/blob/main/docs/changelog.md)" $Repo = 'github.com/mpvnet-player/mpv.net' # Dotnet Publish