This commit is contained in:
stax76
2017-09-02 04:35:24 +02:00
parent d84127f178
commit c4cf7ed11b
44 changed files with 7143 additions and 97 deletions

View File

@@ -23,6 +23,8 @@ using System.ComponentModel.Composition.Hosting;
using System.IO;
using System.Windows.Forms;
using static vbnet.UI.MainModule;
// MEF (Managed Extension Framework)
namespace mpvnet
@@ -36,24 +38,31 @@ namespace mpvnet
public Addon()
{
AggregateCatalog catalog = new AggregateCatalog();
string dir = Application.StartupPath + "\\Addons";
if (Directory.Exists(dir))
foreach (string i in Directory.GetDirectories(dir))
catalog.Catalogs.Add(new DirectoryCatalog(i, "*Addon.dll"));
dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\Addons";
if (Directory.Exists(dir))
foreach (string i in Directory.GetDirectories(dir))
catalog.Catalogs.Add(new DirectoryCatalog(i, "*Addon.dll"));
if (catalog.Catalogs.Count > 0)
try
{
CompositionContainer = new CompositionContainer(catalog);
CompositionContainer.ComposeParts(this);
AggregateCatalog catalog = new AggregateCatalog();
string dir = Application.StartupPath + "\\Addons";
if (Directory.Exists(dir))
foreach (string i in Directory.GetDirectories(dir))
catalog.Catalogs.Add(new DirectoryCatalog(i, "*Addon.dll"));
dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\Addons";
if (Directory.Exists(dir))
foreach (string i in Directory.GetDirectories(dir))
catalog.Catalogs.Add(new DirectoryCatalog(i, "*Addon.dll"));
if (catalog.Catalogs.Count > 0)
{
CompositionContainer = new CompositionContainer(catalog);
CompositionContainer.ComposeParts(this);
}
}
catch (Exception e)
{
MsgException(e);
}
}
}

103
mpvnet/Command.cs Normal file
View File

@@ -0,0 +1,103 @@
/**
*mpv.net
*Copyright(C) 2017 stax76
*
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see http://www.gnu.org/licenses/.
*/
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using vbnet;
namespace mpvnet
{
public class Command
{
public string Name { get; set; }
public Action<string[]> Action { get; set; }
private static List<Command> commands;
public static List<Command> Commands
{
get
{
if (commands == null)
{
commands = new List<Command>();
var type = typeof(Command);
var methods = type.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
foreach (var i in methods)
{
var parameters = i.GetParameters();
if (parameters == null || parameters.Length != 1 || parameters[0].ParameterType != typeof(string[]))
continue;
var cmd = new Command() { Name = i.Name.Replace("_","-"), Action = (Action<string[]>)i.CreateDelegate(typeof(Action<string[]>)) };
commands.Add(cmd);
}
}
return commands;
}
}
public static void open_files(string[] args)
{
MainForm.Instance.Invoke(new Action(() => {
using (var d = new OpenFileDialog())
{
d.Multiselect = true;
d.Filter = Misc.GetFilter(Misc.FileTypes);
if (d.ShowDialog() == DialogResult.OK)
mpv.LoadFiles(d.FileNames);
}
}));
}
public static void open_config_folder(string[] args)
{
ProcessHelp.Start(Folder.AppDataRoaming + "mpv");
}
public static void show_keys(string[] args)
{
ProcessHelp.Start(OS.GetTextEditor(), '"' + mpv.InputConfPath + '"');
}
public static void show_prefs(string[] args)
{
string filepath = Folder.AppDataRoaming + "mpv\\mpv.conf";
if (!File.Exists(filepath))
{
var dirPath = Folder.AppDataRoaming + "mpv\\";
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
File.WriteAllText(filepath, "# https://mpv.io/manual/master/#configuration-files");
}
ProcessHelp.Start(OS.GetTextEditor(), '"' + filepath + '"');
}
}
}

33
mpvnet/Extensions.cs Normal file
View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace mpvnet
{
public static class Extensions
{
public static string Join(this IEnumerable<string> instance, string delimiter, bool removeEmpty = false)
{
if (instance == null)
return null;
bool containsEmpty = false;
foreach (var i in instance)
{
if (string.IsNullOrEmpty(i))
{
containsEmpty = true;
break;
}
}
if (containsEmpty && removeEmpty)
instance = instance.Where(arg => !string.IsNullOrEmpty(arg));
return string.Join(delimiter, instance);
}
}
}

View File

@@ -42,11 +42,13 @@
// MainForm
//
this.AllowDrop = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(19F, 37F);
this.AutoScaleDimensions = new System.Drawing.SizeF(20F, 48F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(1517, 951);
this.ClientSize = new System.Drawing.Size(1553, 1000);
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "mpv.net";

View File

@@ -19,11 +19,16 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using vbnet;
using vbnet.UI;
using static vbnet.UI.MainModule;
namespace mpvnet
{
public partial class MainForm : Form
@@ -33,8 +38,9 @@ namespace mpvnet
private Point LastCursorPosChanged;
private int LastCursorChangedTickCount;
private bool IsCloseRequired = true;
public ContextMenuEx CM;
public ContextMenuStripEx CMS;
public MainForm()
{
@@ -50,10 +56,11 @@ namespace mpvnet
mpv.VideoSizeChanged += Mpv_VideoSizeChanged;
mpv.PlaybackRestart += Mpv_PlaybackRestart;
CM = new ContextMenuEx();
ContextMenu = CM;
CM.Popup += CM_Popup;
ContextMenu.MenuItems.Add("About mpv.net", About);
ToolStripManager.Renderer = new ToolStripRendererEx(ToolStripRenderModeEx.SystemDefault);
CMS = new ContextMenuStripEx(components);
CMS.Opened += CMS_Opened;
ContextMenuStrip = CMS;
BuildMenu();
}
catch (Exception e)
{
@@ -61,9 +68,60 @@ namespace mpvnet
}
}
public void BuildMenu()
{
if (!File.Exists(mpv.InputConfPath))
{
var dirPath = Folder.AppDataRoaming + "mpv\\";
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
File.WriteAllText(mpv.InputConfPath, Properties.Resources.input_conf);
}
foreach (var i in File.ReadAllText(mpv.InputConfPath).SplitLinesNoEmpty())
{
if (!i.Contains("#menu:"))
continue;
var left = i.Left("#menu:").Trim();
if (left.StartsWith("#"))
continue;
var cmd = left.Right(" ").Trim();
var menu = i.Right("#menu:").Trim();
var key = menu.Left(";").Trim();
var path = menu.Right(";").Trim();
if (path == "" || cmd == "")
continue;
var menuItem = CMS.Add(path, () => {
try
{
mpv.CommandString(cmd);
}
catch (Exception e)
{
MsgException(e);
}
});
if (menuItem != null)
menuItem.ShortcutKeyDisplayString = key.Replace("_","") + " ";
}
}
private void CMS_Opened(object sender, EventArgs e)
{
CursorHelp.Show();
}
private void Mpv_PlaybackRestart()
{
BeginInvoke(new Action(() => Text = mpv.GetStringProp("filename") + " - mpv.net"));
BeginInvoke(new Action(() => Text = mpv.GetStringProp("filename") + " - mpv.net " + Application.ProductVersion));
}
private void CM_Popup(object sender, EventArgs e)
@@ -78,10 +136,10 @@ namespace mpvnet
void HandleException(Exception e)
{
MessageBox.Show(e.ToString(), "mpv.net Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
MsgException(e);
}
private void About(object sender, EventArgs e)
private void About()
{
mpv.Command("show-text", Application.ProductName + " v" + Application.ProductVersion.ToString() +
"\nCopyright (c) 2017 stax76\nGPL License", "5000");
@@ -92,7 +150,11 @@ namespace mpvnet
BeginInvoke(new Action(() => SetFormPosSize()));
}
private void Mpv_AfterShutdown() => Invoke(new Action(() => Close()));
private void Mpv_AfterShutdown()
{
if (IsCloseRequired)
Invoke(new Action(() => Close()));
}
public bool IsFullscreen
{
@@ -189,20 +251,7 @@ namespace mpvnet
base.OnDragDrop(e);
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
int count = mpv.GetIntProp("playlist-count");
string[] files = e.Data.GetData(DataFormats.FileDrop) as String[];
foreach (string file in files)
mpv.Command("loadfile", file, "append");
mpv.SetIntProp("playlist-pos", count);
for (int i = 0; i < count; i++)
mpv.Command("playlist-remove", "0");
mpv.LoadFolder();
}
mpv.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as String[]);
}
protected override void OnMouseDown(MouseEventArgs e)
@@ -234,6 +283,7 @@ namespace mpvnet
protected override void OnFormClosed(FormClosedEventArgs e)
{
base.OnFormClosed(e);
IsCloseRequired = false;
mpv.Command("quit");
}
@@ -251,7 +301,7 @@ namespace mpvnet
}
else if (Environment.TickCount - LastCursorChangedTickCount > 1500 &&
!IsMouseInOSC() && ClientRectangle.Contains(PointToClient(MousePosition)) &&
Form.ActiveForm == this && !CM.Visible)
Form.ActiveForm == this && !CMS.Visible)
{
CursorHelp.Hide();
}

View File

@@ -4,6 +4,16 @@ using System.Runtime.InteropServices;
namespace mpvnet
{
public class Misc
{
public static readonly string[] FileTypes = "264 265 3gp aac ac3 avc avi avs bmp divx dts dtshd dtshr dtsma eac3 evo flac flv h264 h265 hevc hvc jpg jpeg m2t m2ts m2v m4a m4v mka mkv mlp mov mp2 mp3 mp4 mpa mpeg mpg mpv mts ogg ogm opus pcm png pva raw rmvb thd thd+ac3 true-hd truehd ts vdr vob vpy w64 wav webm wmv y4m".Split(' ');
public static string GetFilter(IEnumerable<string> values)
{
return "*." + values.Join(";*.") + "|*." + values.Join(";*.") + "|All Files|*.*";
}
}
public class StringLogicalComparer : IComparer, IComparer<string>
{
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]

View File

@@ -59,5 +59,26 @@ namespace mpvnet.Properties {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to
///#key command key caption menu path/caption
///
///o script-message mpv.net open-files #menu: O; Open Files
///
///Space pause #menu: Space ; Play/Pause
///s stop #menu: S ; Stop
///
///F11 playlist-prev #menu: F11 ; Navigate | Previous
///F12 playlist-next #menu: F12 ; Navigate | Next
///
///Ctrl++ add video-zoom 0.1 #menu: Ctrl++ ; Pan &amp;&amp; Scan | Increase Size
///Ctrl+- add video-zoom -0.1 #menu: Ct [rest of string was truncated]&quot;;.
/// </summary>
internal static string input_conf {
get {
return ResourceManager.GetString("input_conf", resourceCulture);
}
}
}
}

View File

@@ -46,7 +46,7 @@
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
@@ -60,6 +60,7 @@
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@@ -109,9 +112,13 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="input_conf" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\input_conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
</root>

View File

@@ -0,0 +1,49 @@
#key command key caption menu path/caption
o script-message mpv.net open-files #menu: O; Open Files
Space pause #menu: Space ; Play/Pause
s stop #menu: S ; Stop
F11 playlist-prev #menu: F11 ; Navigate | Previous
F12 playlist-next #menu: F12 ; Navigate | Next
Ctrl++ add video-zoom 0.1 #menu: Ctrl++ ; Pan && Scan | Increase Size
Ctrl+- add video-zoom -0.1 #menu: Ctrl+- ; Pan && Scan | Decrease Size
Enter cycle fullscreen #menu: Enter ; Cycle Fullscreen
KP7 cycle audio #menu: Numpad 7 ; Cycle Audio
KP8 cycle sub #menu: Numpad 8 ; Cycle Subtitle
+ add volume 5 #menu: + ; Volume | Up
- add volume -5 #menu: - ; Volume | Down
Axis_Up add volume 5 # wheel up
Axis_Down add volume -5 # wheel down
_ _ #menu: _ ; Volume | -
m mute #menu: M ; Volume | Mute
Alt++ add audio-delay 0.1 #menu: Alt++ ; Audio | Delay +0.1
Alt+- add audio-delay -0.1 #menu: Alt+- ; Audio | Delay -0.1
Right seek 10 #menu: Right ; Seek | 10 sec forward
Left seek -10 #menu: Left ; Seek | 10 sec backward
_ _ #menu: _ ; Seek | -
Up seek 60 #menu: Up ; Seek | 1 min forward
Down seek -60 #menu: Down ; Seek | 1 min backward
_ _ #menu: _ ; Seek | -
Ctrl+Right seek 300 #menu: Ctrl+Right ; Seek | 5 min forward
Ctrl+Left seek -300 #menu: Ctrl+Left ; Seek | 5 min backward
KP0 script-message rate-file 0 #menu: Numpad 0 ; Addons | Rating | 0stars
KP1 script-message rate-file 1 #menu: Numpad 1 ; Addons | Rating | 1stars
KP2 script-message rate-file 2 #menu: Numpad 2 ; Addons | Rating | 2stars
KP3 script-message rate-file 3 #menu: Numpad 3 ; Addons | Rating | 3stars
KP4 script-message rate-file 4 #menu: Numpad 4 ; Addons | Rating | 4stars
KP5 script-message rate-file 5 #menu: Numpad 5 ; Addons | Rating | 5stars
p script-message mpv.net show-prefs #menu: P ; Preferences
k script-message mpv.net show-keys #menu: K ; Keys
F8 script-message mpv.net open-config-folder #menu: _ ; Tools | Config Folder
Esc quit #menu: Escape ; Exit

View File

@@ -16,31 +16,641 @@
*along with this program. If not, see http://www.gnu.org/licenses/.
*/
using Microsoft.VisualBasic;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
namespace mpvnet
public static class StringExtensions
{
public static class ExtensionMethods
// public static string Multiply(this string instance, int multiplier)
// {
// StringBuilder sb = new StringBuilder(multiplier * instance.Length);
// for (var i = 0; i <= multiplier - 1; i++)
// {
// sb.Append(instance);
// }
// return sb.ToString();
// }
// public static bool IsValidFileName(string instance)
// {
// if (string.IsNullOrEmpty(instance))
// return false;
// string chars = "\"*/:<>?\\|";
// foreach (var i in instance)
// {
// if (chars.Contains(i.ToString()))
// return false;
// if (Convert.ToInt32(i) < 32)
// return false;
// }
// return true;
// }
// [Extension()]
// public static string FileName(string instance)
// {
// if (string.IsNullOrEmpty(instance))
// return "";
// dynamic index = instance.LastIndexOf(Path.DirectorySeparatorChar);
// if (index > -1)
// return instance.Substring(index + 1);
// return instance;
// }
// [Extension()]
// public static string Upper(string instance)
// {
// if (string.IsNullOrEmpty(instance))
// return "";
// return instance.ToUpperInvariant;
// }
// [Extension()]
// public static string Lower(string instance)
// {
// if (string.IsNullOrEmpty(instance))
// return "";
// return instance.ToLowerInvariant;
// }
// [Extension()]
// public static string ChangeExt(string instance, string value)
// {
// if (string.IsNullOrEmpty(instance))
// return "";
// if (string.IsNullOrEmpty(value))
// return instance;
// if (!value.StartsWith("."))
// value = "." + value;
// return instance.DirAndBase + value.ToLower;
// }
// [Extension()]
// public static string Escape(string instance)
// {
// if (string.IsNullOrEmpty(instance))
// return "";
// dynamic chars = " ()".ToCharArray;
// foreach (void i_loopVariable in chars)
// {
// i = i_loopVariable;
// if (instance.Contains(i))
// return "\"" + instance + "\"";
// }
// return instance;
// }
// [Extension()]
// public static string Parent(string instance)
// {
// return DirPath.GetParent(instance);
// }
// [Extension()]
// public static string ExistingParent(string instance)
// {
// dynamic ret = instance.Parent;
// if (!Directory.Exists(ret))
// ret = ret.Parent;
// else
// return ret;
// if (!Directory.Exists(ret))
// ret = ret.Parent;
// else
// return ret;
// if (!Directory.Exists(ret))
// ret = ret.Parent;
// else
// return ret;
// if (!Directory.Exists(ret))
// ret = ret.Parent;
// else
// return ret;
// if (!Directory.Exists(ret))
// ret = ret.Parent;
// else
// return ret;
// return ret;
// }
public static string ExtFull(this string filepath)
{
public static string Ext(this string instance)
return Ext(filepath, true);
}
public static string Ext(this string filepath)
{
return Ext(filepath, false);
}
public static string Ext(this string filepath, bool dot)
{
if (string.IsNullOrEmpty(filepath))
return "";
var chars = filepath.ToCharArray();
for (var x = filepath.Length - 1; x >= 0; x += -1)
{
if (string.IsNullOrEmpty(instance))
if (chars[x] == Path.DirectorySeparatorChar)
return "";
string ext = Path.GetExtension(instance);
if (ext == "")
return "";
return ext.ToLowerInvariant().Substring(1);
if (chars[x] == '.')
return filepath.Substring(x + (dot ? 0 : 1)).ToLower();
}
public static string ExtFull(this string instance)
{
if (string.IsNullOrEmpty(instance))
return "";
return "";
}
return Path.GetExtension(instance).ToLowerInvariant();
}
// [Extension()]
// public static string Base(string instance)
// {
// return FilePath.GetBase(instance);
// }
// [Extension()]
// public static string Dir(string instance)
// {
// return FilePath.GetDir(instance);
// }
// [Extension()]
// public static string DirName(string instance)
// {
// return DirPath.GetName(instance);
// }
// [Extension()]
// public static string DirAndBase(string instance)
// {
// return FilePath.GetDirAndBase(instance);
// }
// [Extension()]
// public static bool ContainsAll(string instance, IEnumerable<string> all)
// {
// if (!string.IsNullOrEmpty(instance))
// return all.All(arg => instance.Contains(arg));
// }
// [Extension()]
// public static bool ContainsAny(string instance, IEnumerable<string> any)
// {
// if (!string.IsNullOrEmpty(instance))
// return any.Any(arg => instance.Contains(arg));
// }
// [Extension()]
// public static string ToTitleCase(string value)
// {
// //TextInfo.ToTitleCase won't work on all upper strings
// return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value.ToLower);
// }
// [Extension()]
// public static bool IsInt(string value)
// {
// return int.TryParse(value, null);
// }
// [Extension()]
// public static int ToInt(string value, int defaultValue = 0)
// {
// if (!int.TryParse(value, null))
// return defaultValue;
// return Convert.ToInt32(value);
// }
// [Extension()]
// public static bool IsSingle(string value)
// {
// if (!string.IsNullOrEmpty(value))
// {
// if (value.Contains(","))
// value = value.Replace(",", ".");
// return float.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, null);
// }
// }
// [Extension()]
// public static float ToSingle(string value, float defaultValue = 0)
// {
// if (!string.IsNullOrEmpty(value))
// {
// if (value.Contains(","))
// value = value.Replace(",", ".");
// float ret = 0;
// if (float.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, ret))
// {
// return ret;
// }
// }
// return defaultValue;
// }
// [Extension()]
// public static bool IsDouble(string value)
// {
// if (!string.IsNullOrEmpty(value))
// {
// if (value.Contains(","))
// value = value.Replace(",", ".");
// return double.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, null);
// }
// }
// [Extension()]
// public static double ToDouble(string value, float defaultValue = 0)
// {
// if (!string.IsNullOrEmpty(value))
// {
// if (value.Contains(","))
// value = value.Replace(",", ".");
// double ret = 0;
// if (double.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, ret))
// {
// return ret;
// }
// }
// return defaultValue;
// }
public static string Left(this string value, int index)
{
if (string.IsNullOrEmpty(value) || index < 0)
return "";
if (index > value.Length)
return value;
return value.Substring(0, index);
}
public static string Left(this string value, string start)
{
if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(start))
return "";
if (!value.Contains(start))
return "";
return value.Substring(0, value.IndexOf(start));
}
public static string LeftLast(this string value, string start)
{
if (!value.Contains(start))
return "";
return value.Substring(0, value.LastIndexOf(start));
}
public static string Right(this string value, string start)
{
if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(start))
return "";
if (!value.Contains(start))
return "";
return value.Substring(value.IndexOf(start) + start.Length);
}
public static string RightLast(this string value, string start)
{
if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(start))
return "";
if (!value.Contains(start))
return "";
return value.Substring(value.LastIndexOf(start) + start.Length);
}
// [Extension()]
// public static bool EqualIgnoreCase(string a, string b)
// {
// if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b))
// return false;
// return string.Compare(a, b, StringComparison.OrdinalIgnoreCase) == 0;
// }
// [Extension()]
// public static string Shorten(string value, int maxLength)
// {
// if (string.IsNullOrEmpty(value) || value.Length <= maxLength)
// {
// return value;
// }
// return value.Substring(0, maxLength);
// }
public static string[] SplitNoEmpty(this string value, params string[] delimiters)
{
return value.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
}
public static string[] SplitKeepEmpty(this string value, params string[] delimiters)
{
return value.Split(delimiters, StringSplitOptions.None);
}
public static string[] SplitNoEmptyAndWhiteSpace(this string value, params string[] delimiters)
{
if (string.IsNullOrEmpty(value))
return null;
var a = SplitNoEmpty(value, delimiters);
for (var i = 0; i <= a.Length - 1; i++)
a[i] = a[i].Trim();
var l = a.ToList();
while (l.Contains(""))
l.Remove("");
return l.ToArray();
}
public static string[] SplitLinesNoEmpty(this string value)
{
return SplitNoEmpty(value, Environment.NewLine);
}
// [Extension()]
// public static string RemoveChars(string value, string chars)
// {
// dynamic ret = value;
// foreach (void i_loopVariable in value)
// {
// i = i_loopVariable;
// if (chars.IndexOf(i) >= 0)
// {
// ret = ret.Replace(i, "");
// }
// }
// return ret;
// }
// [Extension()]
// public static string DeleteRight(string value, int count)
// {
// return Strings.Left(value, value.Length - count);
// }
// [Extension()]
// public static string ReplaceUnicode(string value)
// {
// if (value.Contains(Convert.ToChar(0x2212)))
// {
// value = value.Replace(Convert.ToChar(0x2212), '-');
// }
// return value;
// }
// [Extension()]
// public static void ToClipboard(string value)
// {
// if (!string.IsNullOrEmpty(value))
// {
// Clipboard.SetText(value);
// }
// else
// {
// Clipboard.Clear();
// }
// }
//}
public class DirPath : PathBase
{
// public static string TrimTrailingSeparator(string path)
// {
// if (string.IsNullOrEmpty(path))
// return "";
// if (path.EndsWith(Separator) && !(path.Length <= 3))
// {
// return path.TrimEnd(Separator);
// }
// return path;
// }
// public static string FixSeperator(string path)
// {
// if (path.Contains("\\") && Separator != "\\")
// {
// path = path.Replace("\\", Separator);
// }
// if (path.Contains("/") && Separator != "/")
// {
// path = path.Replace("/", Separator);
// }
// return path;
// }
// public static string GetParent(string path)
// {
// if (string.IsNullOrEmpty(path))
// return "";
// dynamic temp = TrimTrailingSeparator(path);
// if (temp.Contains(Separator))
// path = temp.LeftLast(Separator) + Separator;
// return path;
// }
// public static string GetName(string path)
// {
// if (string.IsNullOrEmpty(path))
// return "";
// path = TrimTrailingSeparator(path);
// return path.RightLast(Separator);
// }
// public static bool IsFixedDrive(string path)
// {
// try
// {
// if (!string.IsNullOrEmpty(path))
// return new DriveInfo(path).DriveType == DriveType.Fixed;
// }
// catch (Exception ex)
// {
// }
// }
}
public class FilePath : PathBase
{
// private string Value;
// public FilePath(string path)
// {
// Value = path;
// }
// public static string GetDir(string path)
// {
// if (string.IsNullOrEmpty(path))
// return "";
// if (path.Contains("\\"))
// path = path.LeftLast("\\") + "\\";
// return path;
// }
// public static string GetDirAndBase(string path)
// {
// return GetDir(path) + GetBase(path);
// }
// public static string GetName(string path)
// {
// if ((path != null))
// {
// dynamic index = path.LastIndexOf(IO.Path.DirectorySeparatorChar);
// if (index > -1)
// {
// return path.Substring(index + 1);
// }
// }
// return path;
// }
// public static string GetDirNoSep(string path)
// {
// path = GetDir(path);
// if (path.EndsWith(Separator))
// path = TrimSep(path);
// return path;
// }
// public static string GetBase(string path)
// {
// if (string.IsNullOrEmpty(path))
// return "";
// dynamic ret = path;
// if (ret.Contains(Separator))
// ret = ret.RightLast(Separator);
// if (ret.Contains("."))
// ret = ret.LeftLast(".");
// return ret;
// }
// public static string TrimSep(string path)
// {
// if (string.IsNullOrEmpty(path))
// return "";
// if (path.EndsWith(Separator) && !path.EndsWith(":" + Separator))
// {
// return path.TrimEnd(Separator);
// }
// return path;
// }
// public static string GetDirNameOnly(string path)
// {
// return FilePath.GetDirNoSep(path).RightLast("\\");
// }
}
public class PathBase
{
//public static char Separator {
// get { return Path.DirectorySeparatorChar; }
//}
// public static bool IsSameBase(string a, string b)
// {
// return FilePath.GetBase(a).EqualIgnoreCase(FilePath.GetBase(b));
// }
// public static bool IsSameDir(string a, string b)
// {
// return FilePath.GetDir(a).EqualIgnoreCase(FilePath.GetDir(b));
// }
// public static bool IsValidFileSystemName(string name)
// {
// if (string.IsNullOrEmpty(name))
// return false;
// dynamic chars = "\"*/:<>?\\|^".ToCharArray;
// foreach (void i_loopVariable in name.ToCharArray)
// {
// i = i_loopVariable;
// if (chars.Contains(i))
// return false;
// if (Convert.ToInt32(i) < 32)
// return false;
// }
// return true;
// }
// public static string RemoveIllegalCharsFromName(string name)
// {
// if (string.IsNullOrEmpty(name))
// return "";
// dynamic chars = "\"*/:<>?\\|^".ToCharArray;
// foreach (void i_loopVariable in name.ToCharArray)
// {
// i = i_loopVariable;
// if (chars.Contains(i))
// {
// name = name.Replace(i, "_");
// }
// }
// for (x = 1; x <= 31; x++)
// {
// if (name.Contains(Convert.ToChar(x)))
// {
// name = name.Replace(Convert.ToChar(x), '_');
// }
// }
// return name;
}
}

View File

@@ -51,29 +51,4 @@ namespace mpvnet
Math.Abs(screenPos.Y - Control.MousePosition.Y) > 10;
}
}
public static class MsgBox
{
public static void MsgInfo(string text)
{
MessageBox.Show(text, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
public class ContextMenuEx : ContextMenu
{
public bool Visible { get ; set; }
protected override void OnCollapse(EventArgs e)
{
base.OnCollapse(e);
Visible = false;
}
protected override void OnPopup(EventArgs e)
{
base.OnPopup(e);
Visible = true;
}
}
}

View File

@@ -24,10 +24,13 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Drawing;
using static mpvnet.libmpv;
using static mpvnet.Native;
using System.Drawing;
using vbnet;
using static vbnet.UI.MainModule;
namespace mpvnet
{
@@ -47,6 +50,8 @@ namespace mpvnet
public static Addon Addon;
public static List<Action<bool>> BoolPropChangeActions = new List<Action<bool>>();
public static Size VideoSize;
public static string InputConfPath = Folder.AppDataRoaming + "mpv\\input.conf";
public static StringPairList BindingList = new StringPairList();
public static void Init()
{
@@ -54,7 +59,6 @@ namespace mpvnet
MpvHandle = mpv_create();
SetIntProp("input-ar-delay", 500);
SetIntProp("input-ar-rate", 20);
SetIntProp("osd-duration", 3000);
SetIntProp("volume", 50);
SetStringProp("hwdec", "auto");
SetStringProp("input-default-bindings", "yes");
@@ -110,7 +114,14 @@ namespace mpvnet
if (ClientMessage != null)
{
var client_messageData = (mpv_event_client_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_client_message));
ClientMessage?.Invoke(NativeUtf8StrArray2ManagedStrArray(client_messageData.args, client_messageData.num_args));
var args = NativeUtf8StrArray2ManagedStrArray(client_messageData.args, client_messageData.num_args);
if (args != null && args.Length > 1 && args[0] == "mpv.net")
foreach (var i in mpvnet.Command.Commands)
if (args[1] == i.Name)
i.Action(args.Skip(2).ToArray());
ClientMessage?.Invoke(args);
}
break;
@@ -151,7 +162,7 @@ namespace mpvnet
int err = mpv_command_string(MpvHandle, command);
if (err < 0)
throw new Exception($"{(mpv_error)err}");
throw new Exception($"{(mpv_error)err}" + BR2 + command);
}
public static void SetStringProp(string name, string value, bool throwException = true)
@@ -242,6 +253,21 @@ namespace mpvnet
LoadFolder();
}
public static void LoadFiles(string[] files)
{
int count = mpv.GetIntProp("playlist-count");
foreach (string file in files)
mpv.Command("loadfile", file, "append");
mpv.SetIntProp("playlist-pos", count);
for (int i = 0; i < count; i++)
mpv.Command("playlist-remove", "0");
mpv.LoadFolder();
}
public static void LoadFolder()
{
if (GetIntProp("playlist-count") == 1)

View File

@@ -104,6 +104,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Addon.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="libmpv.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
@@ -113,11 +115,11 @@
</Compile>
<Compile Include="Misc.cs" />
<Compile Include="mpv.cs" />
<Compile Include="Command.cs" />
<Compile Include="Native.cs" />
<Compile Include="NativeHelp.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="UI.cs" />
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
@@ -148,7 +150,16 @@
</ItemGroup>
<ItemGroup>
<Content Include="mpv.ico" />
<Content Include="screenshot.jpg" />
<None Include="Resources\input_conf.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\vbnet\vbnet.vbproj">
<Project>{af1b21c5-28fc-4d47-ad0b-54f6a38391a6}</Project>
<Name>vbnet</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

BIN
mpvnet/screenshot.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 KiB