Merge pull request #725 from benomine/main

feat: dotnet 9, CPM, etc
This commit is contained in:
stax76
2025-05-05 14:30:44 +02:00
committed by GitHub
22 changed files with 213 additions and 128 deletions

View File

@@ -5,3 +5,6 @@ csharp_style_implicit_object_creation_when_type_is_apparent = true
# IDE0090: Use 'new(...)' # IDE0090: Use 'new(...)'
dotnet_diagnostic.IDE0090.severity = silent 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

View File

@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<Product>mpv.net</Product>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,10 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageVersion Include="NGettext" Version="0.6.7" />
<PackageVersion Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
</ItemGroup>
</Project>

View File

@@ -101,8 +101,8 @@ public class ConfParser
} }
else if (line.Contains('=')) else if (line.Contains('='))
{ {
string name = line[..line.IndexOf("=")].Trim(); string name = line[..line.IndexOf('=')].Trim();
string value = line[(line.IndexOf("=") + 1)..].Trim(); string value = line[(line.IndexOf('=') + 1)..].Trim();
currentGroup?.Items.Add(new StringPair(name, value)); currentGroup?.Items.Add(new StringPair(name, value));
} }

View File

@@ -13,7 +13,7 @@ public static class FileAssociation
string exeFilename = Path.GetFileName(exePath); string exeFilename = Path.GetFileName(exePath);
string exeFilenameNoExt = Path.GetFileNameWithoutExtension(exePath); string exeFilenameNoExt = Path.GetFileNameWithoutExtension(exePath);
string[] protocols = { "ytdl", "rtsp", "srt", "srtp" }; string[] protocols = ["ytdl", "rtsp", "srt", "srtp"];
if (perceivedType != "unreg") if (perceivedType != "unreg")
{ {

View File

@@ -198,11 +198,13 @@ public class GuiCommand
else else
{ {
string clipboard = System.Windows.Forms.Clipboard.GetText(); string clipboard = System.Windows.Forms.Clipboard.GetText();
List<string> files = new List<string>(); List<string> files = [];
foreach (string i in clipboard.Split(BR.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) foreach (string i in clipboard.Split(BR.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
if (i.Contains("://") || File.Exists(i)) if (i.Contains("://") || File.Exists(i))
files.Add(i); files.Add(i);
}
if (files.Count == 0) if (files.Count == 0)
{ {
@@ -227,10 +229,14 @@ public class GuiCommand
dialog.Multiselect = true; dialog.Multiselect = true;
if (dialog.ShowDialog() == DialogResult.OK) if (dialog.ShowDialog() != DialogResult.OK)
return;
foreach (string i in dialog.FileNames) foreach (string i in dialog.FileNames)
{
Player.CommandV("audio-add", i); Player.CommandV("audio-add", i);
} }
}
void RegisterFileAssociations(IList<string> args) void RegisterFileAssociations(IList<string> args)
{ {
@@ -313,9 +319,11 @@ public class GuiCommand
var items = new List<Item>(); var items = new List<Item>();
foreach (string file in App.Settings.RecentFiles) foreach (string file in App.Settings.RecentFiles)
{
items.Add(new Item() { title = Path.GetFileName(file), items.Add(new Item() { title = Path.GetFileName(file),
value = new string []{ "loadfile", file }, value = ["loadfile", file],
hint = file}); hint = file});
}
o.items = items.ToArray(); o.items = items.ToArray();
string json = JsonSerializer.Serialize(o); string json = JsonSerializer.Serialize(o);
@@ -326,12 +334,12 @@ public class GuiCommand
{ {
public string title { get; set; } = ""; public string title { get; set; } = "";
public int selected_index { get; set; } = 0; public int selected_index { get; set; } = 0;
public Item[] items { get; set; } = Array.Empty<Item>(); public Item[] items { get; set; } = [];
} }
class Item class Item
{ {
public string[] value { get; set; } = Array.Empty<string>(); public string[] value { get; set; } = [];
public string title { get; set; } = ""; public string title { get; set; } = "";
public string hint { get; set; } = ""; public string hint { get; set; } = "";
} }
@@ -393,16 +401,22 @@ public class GuiCommand
} }
if (App.MediaInfo && !osd && File.Exists(path) && !path.Contains(@"\\.\pipe\")) if (App.MediaInfo && !osd && File.Exists(path) && !path.Contains(@"\\.\pipe\"))
using (MediaInfo mediaInfo = new MediaInfo(path)) {
using MediaInfo mediaInfo = new MediaInfo(path);
text = Regex.Replace(mediaInfo.GetSummary(full, raw), "Unique ID.+", ""); text = Regex.Replace(mediaInfo.GetSummary(full, raw), "Unique ID.+", "");
}
else else
{ {
Player.UpdateExternalTracks(); Player.UpdateExternalTracks();
text = "N: " + Player.GetPropertyString("filename") + BR; text = "N: " + Player.GetPropertyString("filename") + BR;
lock (Player.MediaTracksLock) lock (Player.MediaTracksLock)
{
foreach (MediaTrack track in Player.MediaTracks) foreach (MediaTrack track in Player.MediaTracks)
{
text += track.Text + BR; text += track.Text + BR;
} }
}
}
text = text.TrimEx(); text = text.TrimEx();
@@ -426,7 +440,7 @@ public class GuiCommand
{ {
string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User)!; 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.")); Msg.ShowWarning(_("mpv.net is already in the Path environment variable."));
return; return;

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net9.0-windows</TargetFramework>
<RootNamespace>MpvNet.Windows</RootNamespace> <RootNamespace>MpvNet.Windows</RootNamespace>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<PublishSingleFile>true</PublishSingleFile> <PublishSingleFile>true</PublishSingleFile>
@@ -10,11 +10,9 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>mpv-icon.ico</ApplicationIcon> <ApplicationIcon>mpv-icon.ico</ApplicationIcon>
<Product>mpv.net</Product>
<FileVersion>7.1.1.3</FileVersion> <FileVersion>7.1.1.3</FileVersion>
<AssemblyVersion>7.1.1.3</AssemblyVersion> <AssemblyVersion>7.1.1.3</AssemblyVersion>
<InformationalVersion>7.1.1.3</InformationalVersion> <InformationalVersion>7.1.1.3</InformationalVersion>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -42,8 +40,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> <PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" /> <PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -13,6 +13,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2F97C77E-32E3-46FA-8D7C-3940FD9AA384}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2F97C77E-32E3-46FA-8D7C-3940FD9AA384}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig .editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
EndProjectSection EndProjectSection
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NGettext.Wpf", "NGettext.Wpf\NGettext.Wpf.csproj", "{0B7958FD-2138-482A-A21B-481AE7A0F851}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NGettext.Wpf", "NGettext.Wpf\NGettext.Wpf.csproj", "{0B7958FD-2138-482A-A21B-481AE7A0F851}"

View File

@@ -19,7 +19,7 @@ public class Chapter
_timeDisplay = TimeSpan.FromSeconds(Time).ToString(); _timeDisplay = TimeSpan.FromSeconds(Time).ToString();
if (_timeDisplay.ContainsEx(".")) if (_timeDisplay.ContainsEx("."))
_timeDisplay = _timeDisplay[.._timeDisplay.LastIndexOf(".")]; _timeDisplay = _timeDisplay[.._timeDisplay.LastIndexOf('.')];
} }
return _timeDisplay; return _timeDisplay;

View File

@@ -42,7 +42,7 @@ public class Command
{ {
if (i.Contains("://") || File.Exists(i)) if (i.Contains("://") || File.Exists(i))
{ {
Player.LoadFiles(new[] { i }, true, false); Player.LoadFiles([i], true, false);
break; break;
} }
} }

View File

@@ -17,7 +17,7 @@ public class CommandLine
if (_arguments != null) if (_arguments != null)
return _arguments; return _arguments;
_arguments = new(); _arguments = [];
foreach (string i in Environment.GetCommandLineArgs().Skip(1)) foreach (string i in Environment.GetCommandLineArgs().Skip(1))
{ {
@@ -37,7 +37,7 @@ public class CommandLine
arg += "=yes"; arg += "=yes";
} }
string left = arg[2..arg.IndexOf("=")]; string left = arg[2..arg.IndexOf('=')];
string right = arg[(left.Length + 3)..]; string right = arg[(left.Length + 3)..];
if (string.IsNullOrEmpty(left)) if (string.IsNullOrEmpty(left))
@@ -113,16 +113,19 @@ public class CommandLine
public static void ProcessCommandLineFiles() public static void ProcessCommandLineFiles()
{ {
List<string> files = new List<string>(); List<string> files = [];
foreach (string arg in Environment.GetCommandLineArgs().Skip(1)) foreach (string arg in Environment.GetCommandLineArgs().Skip(1))
{
if (!arg.StartsWith("--") && (arg == "-" || arg.Contains("://") || if (!arg.StartsWith("--") && (arg == "-" || arg.Contains("://") ||
arg.Contains(":\\") || arg.StartsWith("\\\\") || arg.StartsWith(".") || arg.Contains(":\\") || arg.StartsWith("\\\\") || arg.StartsWith('.') ||
File.Exists(arg))) File.Exists(arg)))
{
files.Add(arg); files.Add(arg);
}
}
Player.LoadFiles(files.ToArray(), !App.Queue, App.Queue); Player.LoadFiles([.. files], !App.Queue, App.Queue);
if (App.CommandLine.Contains("--shuffle")) if (App.CommandLine.Contains("--shuffle"))
{ {
@@ -134,8 +137,10 @@ public class CommandLine
public static bool Contains(string name) public static bool Contains(string name)
{ {
foreach (StringPair pair in Arguments) foreach (StringPair pair in Arguments)
{
if (pair.Name == name) if (pair.Name == name)
return true; return true;
}
return false; return false;
} }
@@ -143,8 +148,10 @@ public class CommandLine
public static string GetValue(string name) public static string GetValue(string name)
{ {
foreach (StringPair pair in Arguments) foreach (StringPair pair in Arguments)
{
if (pair.Name == name) if (pair.Name == name)
return pair.Value; return pair.Value;
}
return ""; return "";
} }

View File

@@ -9,7 +9,7 @@ public class ExtensionLoader
{ {
public event Action<Exception>? UnhandledException; public event Action<Exception>? UnhandledException;
readonly List<object?> _refs = new(); readonly List<object?> _refs = [];
void LoadDll(string path) void LoadDll(string path)
{ {
@@ -31,10 +31,14 @@ public class ExtensionLoader
public void LoadFolder(string path) public void LoadFolder(string path)
{ {
if (Directory.Exists(path)) if (Directory.Exists(path))
{
foreach (string dir in Directory.GetDirectories(path)) foreach (string dir in Directory.GetDirectories(path))
{
LoadDll(dir.AddSep() + Path.GetFileName(dir) + ".dll"); LoadDll(dir.AddSep() + Path.GetFileName(dir) + ".dll");
} }
} }
}
}
public interface IExtension public interface IExtension
{ {

View File

@@ -32,12 +32,12 @@ public static class PathStringExtension
int index = instance.LastIndexOf('\\'); int index = instance.LastIndexOf('\\');
if (index > -1) if (index > -1)
return instance.Substring(index + 1); return instance[(index + 1)..];
index = instance.LastIndexOf('/'); index = instance.LastIndexOf('/');
if (index > -1) if (index > -1)
return instance.Substring(index + 1); return instance[(index + 1)..];
return instance; return instance;
} }

View File

@@ -5,7 +5,7 @@ namespace MpvNet;
public static class FileTypes 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 IsVideo(string[] exts, string ext) => exts?.Contains(ext) ?? false;
public static bool IsAudio(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"); string exts = Player.GetPropertyString("video-exts");
if (string.IsNullOrEmpty(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); return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
} }
@@ -30,7 +30,7 @@ public static class FileTypes
string exts = Player.GetPropertyString("audio-exts"); string exts = Player.GetPropertyString("audio-exts");
if (string.IsNullOrEmpty(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); return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
} }
@@ -40,7 +40,7 @@ public static class FileTypes
string exts = Player.GetPropertyString("image-exts"); string exts = Player.GetPropertyString("image-exts");
if (string.IsNullOrEmpty(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); return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
} }

View File

@@ -8,9 +8,7 @@ public static class StringHelp
{ {
public static string GetMD5Hash(string txt) public static string GetMD5Hash(string txt)
{ {
using MD5 md5 = MD5.Create();
byte[] inputBuffer = Encoding.UTF8.GetBytes(txt); byte[] inputBuffer = Encoding.UTF8.GetBytes(txt);
byte[] hashBuffer = md5.ComputeHash(inputBuffer); return Convert.ToHexString(MD5.HashData(inputBuffer));
return BitConverter.ToString(md5.ComputeHash(inputBuffer)).Replace("-", "");
} }
} }

View File

@@ -34,17 +34,25 @@ public class InputConf
var defaultBindings = InputHelp.GetDefaults(); var defaultBindings = InputHelp.GetDefaults();
foreach (Binding defaultBinding in defaultBindings) foreach (Binding defaultBinding in defaultBindings)
{
foreach (Binding confBinding in confbindings) foreach (Binding confBinding in confbindings)
{
if (defaultBinding.Input == confBinding.Input && if (defaultBinding.Input == confBinding.Input &&
defaultBinding.Command != confBinding.Command) defaultBinding.Command != confBinding.Command)
{ {
defaultBinding.Input = ""; defaultBinding.Input = "";
} }
}
}
foreach (Binding defaultBinding in defaultBindings) foreach (Binding defaultBinding in defaultBindings)
{
foreach (Binding confBinding in confbindings) foreach (Binding confBinding in confbindings)
{
if (defaultBinding.Command == confBinding.Command) if (defaultBinding.Command == confBinding.Command)
defaultBinding.Input = confBinding.Input; defaultBinding.Input = confBinding.Input;
}
}
return (defaultBindings, confbindings); return (defaultBindings, confbindings);
} }
@@ -82,16 +90,22 @@ public class InputConf
var conf = InputHelp.Parse(Content); var conf = InputHelp.Parse(Content);
foreach (Binding defaultBinding in defaults) foreach (Binding defaultBinding in defaults)
{
foreach (Binding confBinding in conf) foreach (Binding confBinding in conf)
{
if (defaultBinding.Command == confBinding.Command && if (defaultBinding.Command == confBinding.Command &&
defaultBinding.Comment == confBinding.Comment) defaultBinding.Comment == confBinding.Comment)
{ {
defaultBinding.Input = confBinding.Input; defaultBinding.Input = confBinding.Input;
removed.Add(confBinding); removed.Add(confBinding);
} }
}
}
foreach (Binding binding in removed) foreach (Binding binding in removed)
{
conf.Remove(binding); conf.Remove(binding);
}
defaults.AddRange(conf); defaults.AddRange(conf);
return InputHelp.ConvertToString(defaults); return InputHelp.ConvertToString(defaults);

View File

@@ -1,13 +1,4 @@
 
using CommunityToolkit.Mvvm.Messaging.Messages;
namespace MpvNet.MVVM; namespace MpvNet.MVVM;
public class MainWindowIsLoadedMessage { } public class MainWindowIsLoadedMessage { }
//public class ScaleWindowMessage : ValueChangedMessage<float>
//{
// public ScaleWindowMessage(float value) : base(value)
// {
// }
//}

View File

@@ -21,11 +21,11 @@ public class MpvClient
public event Action? Seek; // seek MPV_EVENT_SEEK public event Action? Seek; // seek MPV_EVENT_SEEK
public event Action? PlaybackRestart; // playback-restart MPV_EVENT_PLAYBACK_RESTART public event Action? PlaybackRestart; // playback-restart MPV_EVENT_PLAYBACK_RESTART
public Dictionary<string, List<Action>> PropChangeActions { get; set; } = new Dictionary<string, List<Action>>(); public Dictionary<string, List<Action>> PropChangeActions { get; set; } = [];
public Dictionary<string, List<Action<int>>> IntPropChangeActions { get; set; } = new Dictionary<string, List<Action<int>>>(); public Dictionary<string, List<Action<int>>> IntPropChangeActions { get; set; } = [];
public Dictionary<string, List<Action<bool>>> BoolPropChangeActions { get; set; } = new Dictionary<string, List<Action<bool>>>(); public Dictionary<string, List<Action<bool>>> BoolPropChangeActions { get; set; } = [];
public Dictionary<string, List<Action<double>>> DoublePropChangeActions { get; set; } = new Dictionary<string, List<Action<double>>>(); public Dictionary<string, List<Action<double>>> DoublePropChangeActions { get; set; } = [];
public Dictionary<string, List<Action<string>>> StringPropChangeActions { get; set; } = new Dictionary<string, List<Action<string>>>(); public Dictionary<string, List<Action<string>>> StringPropChangeActions { get; set; } = [];
public nint Handle { get; set; } public nint Handle { get; set; }
@@ -132,48 +132,74 @@ public class MpvClient
else if (data.format == mpv_format.MPV_FORMAT_STRING) else if (data.format == mpv_format.MPV_FORMAT_STRING)
{ {
lock (StringPropChangeActions) lock (StringPropChangeActions)
{
foreach (var pair in StringPropChangeActions) foreach (var pair in StringPropChangeActions)
{
if (pair.Key == data.name) if (pair.Key == data.name)
{ {
string value = ConvertFromUtf8(Marshal.PtrToStructure<IntPtr>(data.data)); string value = ConvertFromUtf8(Marshal.PtrToStructure<IntPtr>(data.data));
foreach (var action in pair.Value) foreach (var action in pair.Value)
{
action.Invoke(value); action.Invoke(value);
} }
} }
}
}
}
else if (data.format == mpv_format.MPV_FORMAT_INT64) else if (data.format == mpv_format.MPV_FORMAT_INT64)
{ {
lock (IntPropChangeActions) lock (IntPropChangeActions)
{
foreach (var pair in IntPropChangeActions) foreach (var pair in IntPropChangeActions)
{
if (pair.Key == data.name) if (pair.Key == data.name)
{ {
int value = Marshal.PtrToStructure<int>(data.data); int value = Marshal.PtrToStructure<int>(data.data);
foreach (var action in pair.Value) foreach (var action in pair.Value)
{
action.Invoke(value); action.Invoke(value);
} }
} }
}
}
}
else if (data.format == mpv_format.MPV_FORMAT_NONE) else if (data.format == mpv_format.MPV_FORMAT_NONE)
{ {
lock (PropChangeActions) lock (PropChangeActions)
{
foreach (var pair in PropChangeActions) foreach (var pair in PropChangeActions)
{
if (pair.Key == data.name) if (pair.Key == data.name)
{
foreach (var action in pair.Value) foreach (var action in pair.Value)
{
action.Invoke(); action.Invoke();
} }
}
}
}
}
else if (data.format == mpv_format.MPV_FORMAT_DOUBLE) else if (data.format == mpv_format.MPV_FORMAT_DOUBLE)
{ {
lock (DoublePropChangeActions) lock (DoublePropChangeActions)
{
foreach (var pair in DoublePropChangeActions) foreach (var pair in DoublePropChangeActions)
{
if (pair.Key == data.name) if (pair.Key == data.name)
{ {
double value = Marshal.PtrToStructure<double>(data.data); double value = Marshal.PtrToStructure<double>(data.data);
foreach (var action in pair.Value) foreach (var action in pair.Value)
{
action.Invoke(value); action.Invoke(value);
} }
} }
} }
}
}
}
protected virtual void OnEndFile(mpv_event_end_file data) => EndFile?.Invoke((mpv_end_file_reason)data.reason); protected virtual void OnEndFile(mpv_event_end_file data) => EndFile?.Invoke((mpv_end_file_reason)data.reason);
protected virtual void OnFileLoaded() => FileLoaded?.Invoke(); protected virtual void OnFileLoaded() => FileLoaded?.Invoke();
@@ -247,7 +273,9 @@ public class MpvClient
mpv_error err = mpv_command_ret(Handle, rootPtr, resultNodePtr); mpv_error err = mpv_command_ret(Handle, rootPtr, resultNodePtr);
foreach (IntPtr ptr in pointers) foreach (IntPtr ptr in pointers)
{
Marshal.FreeHGlobal(ptr); Marshal.FreeHGlobal(ptr);
}
Marshal.FreeHGlobal(rootPtr); Marshal.FreeHGlobal(rootPtr);
@@ -409,7 +437,7 @@ public class MpvClient
if (err < 0) if (err < 0)
HandleError(err, "error observing property: " + name); HandleError(err, "error observing property: " + name);
else else
IntPropChangeActions[name] = new List<Action<int>>(); IntPropChangeActions[name] = [];
} }
if (IntPropChangeActions.ContainsKey(name)) if (IntPropChangeActions.ContainsKey(name))
@@ -428,7 +456,7 @@ public class MpvClient
if (err < 0) if (err < 0)
HandleError(err, "error observing property: " + name); HandleError(err, "error observing property: " + name);
else else
DoublePropChangeActions[name] = new List<Action<double>>(); DoublePropChangeActions[name] = [];
} }
if (DoublePropChangeActions.ContainsKey(name)) if (DoublePropChangeActions.ContainsKey(name))
@@ -447,7 +475,7 @@ public class MpvClient
if (err < 0) if (err < 0)
HandleError(err, "error observing property: " + name); HandleError(err, "error observing property: " + name);
else else
BoolPropChangeActions[name] = new List<Action<bool>>(); BoolPropChangeActions[name] = [];
} }
if (BoolPropChangeActions.ContainsKey(name)) if (BoolPropChangeActions.ContainsKey(name))
@@ -466,7 +494,7 @@ public class MpvClient
if (err < 0) if (err < 0)
HandleError(err, "error observing property: " + name); HandleError(err, "error observing property: " + name);
else else
StringPropChangeActions[name] = new List<Action<string>>(); StringPropChangeActions[name] = [];
} }
if (StringPropChangeActions.ContainsKey(name)) if (StringPropChangeActions.ContainsKey(name))
@@ -485,7 +513,7 @@ public class MpvClient
if (err < 0) if (err < 0)
HandleError(err, "error observing property: " + name); HandleError(err, "error observing property: " + name);
else else
PropChangeActions[name] = new List<Action>(); PropChangeActions[name] = [];
} }
if (PropChangeActions.ContainsKey(name)) if (PropChangeActions.ContainsKey(name))

View File

@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<AssemblyName>libmpvnet</AssemblyName> <AssemblyName>libmpvnet</AssemblyName>
<Product>mpv.net</Product>
<Nullable>enable</Nullable>
<RootNamespace>MpvNet</RootNamespace> <RootNamespace>MpvNet</RootNamespace>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup> </PropertyGroup>
@@ -20,8 +18,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> <PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="NGettext" Version="0.6.7" /> <PackageReference Include="NGettext" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -73,10 +73,12 @@ public class MainPlayer : MpvClient
MainHandle = mpv_create(); MainHandle = mpv_create();
Handle = MainHandle; Handle = MainHandle;
var events = Enum.GetValues(typeof(mpv_event_id)).Cast<mpv_event_id>(); var events = Enum.GetValues<mpv_event_id>().Cast<mpv_event_id>();
foreach (mpv_event_id i in events) foreach (mpv_event_id i in events)
{
mpv_request_event(MainHandle, i, 0); mpv_request_event(MainHandle, i, 0);
}
mpv_request_log_messages(MainHandle, "no"); mpv_request_log_messages(MainHandle, "no");
@@ -194,8 +196,10 @@ public class MainPlayer : MpvClient
mpv_destroy(Handle); mpv_destroy(Handle);
foreach (var client in Clients) foreach (var client in Clients)
{
mpv_destroy(client.Handle); mpv_destroy(client.Handle);
} }
}
public void ProcessProperty(string? name, string? value) 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<string, string>? _Conf; Dictionary<string, string>? _Conf;
public Dictionary<string, string> Conf { public Dictionary<string, string> Conf {
@@ -273,7 +279,7 @@ public class MainPlayer : MpvClient
App.ApplyInputDefaultBindingsFix(); App.ApplyInputDefaultBindingsFix();
_Conf = new Dictionary<string, string>(); _Conf = [];
if (File.Exists(ConfPath)) if (File.Exists(ConfPath))
{ {
@@ -281,12 +287,12 @@ public class MainPlayer : MpvClient
{ {
string line = it.TrimStart(' ', '-').TrimEnd(); string line = it.TrimStart(' ', '-').TrimEnd();
if (line.StartsWith("#")) if (line.StartsWith('#'))
continue; continue;
if (!line.Contains('=')) if (!line.Contains('='))
{ {
if (Regex.Match(line, "^[\\w-]+$").Success) if (ConfRegex.Match(line).Success)
line += "=yes"; line += "=yes";
else else
continue; continue;
@@ -305,7 +311,9 @@ public class MainPlayer : MpvClient
} }
foreach (var i in _Conf) foreach (var i in _Conf)
{
ProcessProperty(i.Key, i.Value); ProcessProperty(i.Key, i.Value);
}
return _Conf; return _Conf;
} }
@@ -331,8 +339,10 @@ public class MainPlayer : MpvClient
public void MainEventLoop() public void MainEventLoop()
{ {
while (true) while (true)
{
mpv_wait_event(MainHandle, -1); mpv_wait_event(MainHandle, -1);
} }
}
protected override void OnShutdown() protected override void OnShutdown()
{ {
@@ -479,14 +489,14 @@ public class MainPlayer : MpvClient
Command("stop"); Command("stop");
Thread.Sleep(500); Thread.Sleep(500);
SetPropertyString("dvd-device", path); SetPropertyString("dvd-device", path);
LoadFiles(new[] { @"dvd://" }, false, false); LoadFiles([@"dvd://"], false, false);
} }
else else
{ {
Command("stop"); Command("stop");
Thread.Sleep(500); Thread.Sleep(500);
SetPropertyString("bluray-device", path); 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")) if (Directory.Exists(path + "\\BDMV"))
{ {
SetPropertyString("bluray-device", path); SetPropertyString("bluray-device", path);
LoadFiles(new[] { @"bd://" }, false, false); LoadFiles([@"bd://"], false, false);
} }
else else
{ {
SetPropertyString("dvd-device", path); 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) static string GetNativeLanguage(string name)
{ {
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures)) foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
{
if (ci.EnglishName == name) if (ci.EnglishName == name)
return ci.NativeName; return ci.NativeName;
}
return name; return name;
} }
@@ -629,7 +641,7 @@ public class MainPlayer : MpvClient
if (_audioDevices != null) if (_audioDevices != null)
return _audioDevices; return _audioDevices;
_audioDevices = new(); _audioDevices = [];
string json = GetPropertyString("audio-device-list"); string json = GetPropertyString("audio-device-list");
var enumerator = JsonDocument.Parse(json).RootElement.EnumerateArray(); 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<MediaTrack> GetTracks(bool includeInternal = true, bool includeExternal = true) public List<MediaTrack> GetTracks(bool includeInternal = true, bool includeExternal = true)
{ {
List<MediaTrack> tracks = new List<MediaTrack>(); List<MediaTrack> tracks = new List<MediaTrack>();
@@ -697,7 +711,7 @@ public class MainPlayer : MpvClient
string filename = GetPropertyString($"filename/no-ext"); string filename = GetPropertyString($"filename/no-ext");
string title = GetPropertyString($"track-list/{i}/title").Replace(filename, ""); string title = GetPropertyString($"track-list/{i}/title").Replace(filename, "");
title = Regex.Replace(title, @"^[\._\-]", ""); title = TitleRegex.Replace(title, "");
if (type == "video") if (type == "video")
{ {
@@ -1043,7 +1057,7 @@ public class MainPlayer : MpvClient
if (_profileNames != null) if (_profileNames != null)
return _profileNames; 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"); string json = GetPropertyString("profile-list");
return _profileNames = JsonDocument.Parse(json).RootElement.EnumerateArray() return _profileNames = JsonDocument.Parse(json).RootElement.EnumerateArray()
.Select(it => it.GetProperty("name").GetString()) .Select(it => it.GetProperty("name").GetString())

View File

@@ -1,16 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net9.0-windows</TargetFramework>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" /> <PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" />
<PackageReference Include="NGettext" Version="0.6.7" /> <PackageReference Include="NGettext" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -40,7 +40,7 @@ Test (Join-Path $SourceDir 'MpvNet.sln')
$7zFile = Test 'C:\Program Files\7-Zip\7z.exe' $7zFile = Test 'C:\Program Files\7-Zip\7z.exe'
$InnoSetupCompiler = Test 'C:\Program Files (x86)\Inno Setup 6\ISCC.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' $Repo = 'github.com/mpvnet-player/mpv.net'
# Dotnet Publish # Dotnet Publish