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