Refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
|
||||
using MpvNet.ExtensionMethod;
|
||||
using MpvNet.Extensions;
|
||||
|
||||
namespace MpvNet.Windows;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Windows.Forms;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows;
|
||||
|
||||
using MpvNet.ExtensionMethod;
|
||||
using MpvNet.Extensions;
|
||||
using MpvNet.Windows.WinForms;
|
||||
using MpvNet.Windows.WPF.Views;
|
||||
using MpvNet.Windows.WPF;
|
||||
@@ -332,7 +332,7 @@ public class GuiCommand
|
||||
int width = Player.GetPropertyInt("video-params/w");
|
||||
int height = Player.GetPropertyInt("video-params/h");
|
||||
TimeSpan len = TimeSpan.FromSeconds(Player.GetPropertyDouble("duration"));
|
||||
text = path.FileName() + "\n";
|
||||
text = path.FileName + "\n";
|
||||
text += FormatTime(len.TotalMinutes) + ":" + FormatTime(len.Seconds) + "\n";
|
||||
if (fileSize > 0)
|
||||
text += Convert.ToInt32(fileSize / 1024.0 / 1024.0) + " MB\n";
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using MpvNet.ExtensionMethod;
|
||||
using MpvNet.Extensions;
|
||||
|
||||
namespace MpvNet.Windows.UI;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Text.RegularExpressions;
|
||||
using MpvNet.Windows.WPF;
|
||||
using MpvNet.Windows.UI;
|
||||
using MpvNet.Help;
|
||||
using MpvNet.ExtensionMethod;
|
||||
using MpvNet.Extensions;
|
||||
using MpvNet.MVVM;
|
||||
using MpvNet.Windows.WPF.MsgBox;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
|
||||
using MpvNet.ExtensionMethod;
|
||||
using MpvNet.Extensions;
|
||||
using MpvNet.Help;
|
||||
using MpvNet.MVVM;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
using MpvNet.ExtensionMethod;
|
||||
using MpvNet.Extensions;
|
||||
|
||||
namespace MpvNet;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
using MpvNet.ExtensionMethod;
|
||||
using MpvNet.Extensions;
|
||||
|
||||
namespace MpvNet;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ExtensionLoader
|
||||
{
|
||||
foreach (string dir in Directory.GetDirectories(path))
|
||||
{
|
||||
LoadDll(dir.AddSep() + Path.GetFileName(dir) + ".dll");
|
||||
LoadDll(dir.Separator + Path.GetFileName(dir) + ".dll");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
namespace MpvNet.ExtensionMethod;
|
||||
|
||||
public static class ObjectExtension
|
||||
{
|
||||
public static string ToStringEx(this object instance) => instance?.ToString() ?? "";
|
||||
}
|
||||
10
src/MpvNet/ExtensionMethod/ObjectExtensions.cs
Normal file
10
src/MpvNet/ExtensionMethod/ObjectExtensions.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
namespace MpvNet.Extensions;
|
||||
|
||||
public static class ObjectExtensions
|
||||
{
|
||||
extension(object instance)
|
||||
{
|
||||
public string ToStringEx() => instance?.ToString() ?? "";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
namespace MpvNet.ExtensionMethod;
|
||||
namespace MpvNet.Extensions;
|
||||
|
||||
public static class PathStringExtensions
|
||||
{
|
||||
@@ -18,56 +18,60 @@ public static class PathStringExtensions
|
||||
{
|
||||
if (chars[x] == '/')
|
||||
return "";
|
||||
|
||||
if (chars[x] == '\\')
|
||||
return "";
|
||||
|
||||
if (chars[x] == '.')
|
||||
return path[(x + (includeDot ? 0 : 1))..].ToLowerInvariant();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static string FileName(this string instance)
|
||||
{
|
||||
if (string.IsNullOrEmpty(instance))
|
||||
return "";
|
||||
public string FileName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(filepath))
|
||||
return "";
|
||||
|
||||
int index = instance.LastIndexOf('\\');
|
||||
int index = filepath.LastIndexOf('\\');
|
||||
|
||||
if (index > -1)
|
||||
return instance[(index + 1)..];
|
||||
if (index > -1)
|
||||
return filepath[(index + 1)..];
|
||||
|
||||
index = instance.LastIndexOf('/');
|
||||
index = filepath.LastIndexOf('/');
|
||||
|
||||
if (index > -1)
|
||||
return instance[(index + 1)..];
|
||||
if (index > -1)
|
||||
return filepath[(index + 1)..];
|
||||
|
||||
return instance;
|
||||
}
|
||||
return filepath;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ShortPath(this string instance, int maxLength)
|
||||
{
|
||||
if (string.IsNullOrEmpty(instance))
|
||||
return "";
|
||||
public string ShortPath(int maxLength)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filepath))
|
||||
return "";
|
||||
|
||||
if (instance.Length > maxLength && instance.Substring(1, 2) == ":\\")
|
||||
instance = instance[..3] + "...\\" + instance.FileName();
|
||||
if (filepath.Length > maxLength && filepath.Substring(1, 2) == ":\\")
|
||||
filepath = $"{filepath[..3]}...\\{filepath.FileName}";
|
||||
|
||||
return instance;
|
||||
}
|
||||
return filepath;
|
||||
}
|
||||
|
||||
// Ensure trailing directory separator char
|
||||
public static string AddSep(this string instance)
|
||||
{
|
||||
if (string.IsNullOrEmpty(instance))
|
||||
return "";
|
||||
// Ensure trailing directory separator char
|
||||
public string Separator
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(filepath))
|
||||
return "";
|
||||
|
||||
if (!instance.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
instance = instance + Path.DirectorySeparatorChar;
|
||||
if (!filepath.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
filepath = filepath + Path.DirectorySeparatorChar;
|
||||
|
||||
return instance;
|
||||
return filepath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
|
||||
using System.Globalization;
|
||||
|
||||
namespace MpvNet.ExtensionMethod;
|
||||
namespace MpvNet.Extensions;
|
||||
|
||||
public static class StringExtension
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static string ToUpperEx(this string instance) => (instance != null) ? instance.ToUpperInvariant() : "";
|
||||
public static string ToUpperEx(this string instance) => instance?.ToUpperInvariant() ?? "";
|
||||
|
||||
public static string ToLowerEx(this string instance) => (instance != null) ? instance.ToLowerInvariant() : "";
|
||||
public static string ToLowerEx(this string instance) => instance?.ToLowerInvariant() ?? "";
|
||||
|
||||
public static string TrimEx(this string? instance) => (instance == null) ? "" : instance.Trim();
|
||||
public static string TrimEx(this string? instance) => instance?.Trim() ?? "";
|
||||
|
||||
public static int ToInt(this string instance, int defaultValue = 0)
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
using MpvNet.ExtensionMethod;
|
||||
using MpvNet.Extensions;
|
||||
|
||||
namespace MpvNet;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
using MpvNet.ExtensionMethod;
|
||||
using MpvNet.Extensions;
|
||||
|
||||
namespace MpvNet;
|
||||
|
||||
public class Folder
|
||||
{
|
||||
public static string Startup { get; } = Path.GetDirectoryName(Environment.ProcessPath)!.AddSep();
|
||||
public static string AppData { get; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).AddSep();
|
||||
public static string Startup { get; } = Path.GetDirectoryName(Environment.ProcessPath)!.Separator;
|
||||
public static string AppData { get; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Separator;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
|
||||
using MpvNet.ExtensionMethod;
|
||||
using MpvNet.Extensions;
|
||||
using MpvNet.Help;
|
||||
using MpvNet.Native;
|
||||
|
||||
@@ -127,7 +127,7 @@ public class MainPlayer : MpvClient
|
||||
{
|
||||
string configDir = CommandLine.GetValue("config-dir");
|
||||
string fullPath = System.IO.Path.GetFullPath(configDir);
|
||||
App.InputConf.Path = fullPath.AddSep() + "input.conf";
|
||||
App.InputConf.Path = fullPath.Separator + "input.conf";
|
||||
string content = App.InputConf.GetContent();
|
||||
|
||||
if (!string.IsNullOrEmpty(content))
|
||||
@@ -250,7 +250,7 @@ public class MainPlayer : MpvClient
|
||||
string? mpvnet_home = Environment.GetEnvironmentVariable("MPVNET_HOME");
|
||||
|
||||
if (Directory.Exists(mpvnet_home))
|
||||
return _configFolder = mpvnet_home.AddSep();
|
||||
return _configFolder = mpvnet_home.Separator;
|
||||
|
||||
_configFolder = Folder.Startup + "portable_config";
|
||||
|
||||
@@ -260,7 +260,7 @@ public class MainPlayer : MpvClient
|
||||
if (!Directory.Exists(_configFolder))
|
||||
Directory.CreateDirectory(_configFolder);
|
||||
|
||||
_configFolder = _configFolder.AddSep();
|
||||
_configFolder = _configFolder.Separator;
|
||||
}
|
||||
|
||||
return _configFolder;
|
||||
|
||||
Reference in New Issue
Block a user