Convert extension method to extension property

This commit is contained in:
stax76
2026-01-09 07:29:19 +01:00
parent 96afc62165
commit 03d0aeb879
5 changed files with 24 additions and 21 deletions

View File

@@ -303,20 +303,20 @@ public class GuiCommand
if (File.Exists(path) && osd) if (File.Exists(path) && osd)
{ {
if (FileTypes.IsAudio(path.Ext())) if (FileTypes.IsAudio(path.Ext))
{ {
text = Player.GetPropertyOsdString("filtered-metadata"); text = Player.GetPropertyOsdString("filtered-metadata");
Player.CommandV("show-text", text, "5000"); Player.CommandV("show-text", text, "5000");
return; return;
} }
else if (FileTypes.IsImage(path.Ext())) else if (FileTypes.IsImage(path.Ext))
{ {
fileSize = new FileInfo(path).Length; fileSize = new FileInfo(path).Length;
text = "Width: " + Player.GetPropertyInt("width") + "\n" + text = "Width: " + Player.GetPropertyInt("width") + "\n" +
"Height: " + Player.GetPropertyInt("height") + "\n" + "Height: " + Player.GetPropertyInt("height") + "\n" +
"Size: " + Convert.ToInt32(fileSize / 1024.0) + " KB\n" + "Size: " + Convert.ToInt32(fileSize / 1024.0) + " KB\n" +
"Type: " + path.Ext().ToUpper(); "Type: " + path.Ext.ToUpper();
Player.CommandV("show-text", text, "5000"); Player.CommandV("show-text", text, "5000");
return; return;

View File

@@ -556,12 +556,12 @@ public partial class MainForm : Form
if (App.AutofitImage > 1) if (App.AutofitImage > 1)
App.AutofitImage = 1; App.AutofitImage = 1;
bool isAudio = FileTypes.IsAudio(Player.Path.Ext()); bool isAudio = FileTypes.IsAudio(Player.Path.Ext);
if (isAudio) if (isAudio)
autoFitHeight = Convert.ToInt32(workingArea.Height * App.AutofitAudio); autoFitHeight = Convert.ToInt32(workingArea.Height * App.AutofitAudio);
if (FileTypes.IsImage(Player.Path.Ext())) if (FileTypes.IsImage(Player.Path.Ext))
autoFitHeight = Convert.ToInt32(workingArea.Height * App.AutofitImage); autoFitHeight = Convert.ToInt32(workingArea.Height * App.AutofitImage);
if (Player.VideoSize.Height == 0 || Player.VideoSize.Width == 0) if (Player.VideoSize.Height == 0 || Player.VideoSize.Width == 0)

View File

@@ -1,27 +1,30 @@
 
namespace MpvNet.ExtensionMethod; namespace MpvNet.ExtensionMethod;
public static class PathStringExtension public static class PathStringExtensions
{ {
public static string Ext(this string filepath) => filepath.Ext(false); extension(string filepath)
public static string Ext(this string filepath, bool includeDot)
{ {
if (string.IsNullOrEmpty(filepath)) public string Ext => GetExt(filepath, false);
return "";
char[] chars = filepath.ToCharArray(); static string GetExt(string path, bool includeDot)
for (int x = filepath.Length - 1; x >= 0; x--)
{ {
if (chars[x] == Path.DirectorySeparatorChar) if (string.IsNullOrEmpty(path))
return ""; return "";
if (chars[x] == '.') char[] chars = path.ToCharArray();
return filepath.Substring(x + (includeDot ? 0 : 1)).ToLowerInvariant();
}
return ""; for (int x = path.Length - 1; x >= 0; x--)
{
if (chars[x] == Path.DirectorySeparatorChar)
return "";
if (chars[x] == '.')
return path[(x + (includeDot ? 0 : 1))..].ToLowerInvariant();
}
return "";
}
} }
public static string FileName(this string instance) public static string FileName(this string instance)

View File

@@ -49,5 +49,5 @@ public static class FileTypes
IsVideo(exts, ext) || IsAudio(exts, ext) || IsImage(exts, ext); IsVideo(exts, ext) || IsAudio(exts, ext) || IsImage(exts, ext);
public static IEnumerable<string> GetMediaFiles(string[] files) => public static IEnumerable<string> GetMediaFiles(string[] files) =>
files.Where(i => IsMedia(files, i.Ext())); files.Where(i => IsMedia(files, i.Ext));
} }

View File

@@ -441,7 +441,7 @@ public class MainPlayer : MpvClient
file = ConvertFilePath(file); file = ConvertFilePath(file);
string ext = file.Ext(); string ext = file.Ext;
if (OperatingSystem.IsWindows()) if (OperatingSystem.IsWindows())
{ {