diff --git a/CSScriptAddon/CSScriptAddon.vb b/CSScriptAddon/CSScriptAddon.vb index 2be2355..d8f7aba 100644 --- a/CSScriptAddon/CSScriptAddon.vb +++ b/CSScriptAddon/CSScriptAddon.vb @@ -11,18 +11,24 @@ Public Class CSScriptAddon Implements IAddon Sub New() - Dim scriptDir = mp.MpvConfFolder + "scripts" - If Not Directory.Exists(scriptDir) Then Return - Dim csFiles = Directory.GetFiles(scriptDir, "*.cs").ToList - csFiles.AddRange(Directory.GetFiles(Application.StartupPath + "\\Scripts", "*.cs")) - If csFiles.Count = 0 Then Return + Dim scriptFiles As New List(Of String) + + If Directory.Exists(mp.MpvConfFolder + "scripts") Then + scriptFiles.AddRange(Directory.GetFiles(mp.MpvConfFolder + "scripts", "*.cs")) + End If + + If Directory.Exists(Application.StartupPath + "\scripts") Then + scriptFiles.AddRange(Directory.GetFiles(Application.StartupPath + "\scripts", "*.cs")) + End If + + If scriptFiles.Count = 0 Then Return CSScriptLibrary.CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom - For Each i In csFiles + For Each i In scriptFiles Try CSScriptLibrary.CSScript.Evaluator.LoadCode(File.ReadAllText(i)) Catch ex As Exception - MainForm.Instance.ShowMsgBox(ex.ToString(), MessageBoxIcon.Error) + Sys.Msg.ShowException(ex) End Try Next End Sub diff --git a/README.md b/README.md index 20763e3..1393c8d 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,8 @@ mpv.net bugs and requests: - all windows (main, conf, input, about, command palette) can now be closed by just pressing the Escape key - new feature added to open recent files and URLs with the context menu. [Default Binding](https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/inputConf.txt#L33) +- the info command now works also for URLs +- fix for folder \\\scripts not loading C# scripts ### 3.2 (2019-04-27) diff --git a/mpv.net/Command.cs b/mpv.net/Command.cs index 1269754..e09db10 100644 --- a/mpv.net/Command.cs +++ b/mpv.net/Command.cs @@ -116,61 +116,58 @@ namespace mpvnet { try { - FileInfo fileInfo = new FileInfo(mp.get_property_string("path")); + string performer, title, album, genre, date, duration, text = ""; + int fileSize = 0; + string path = mp.get_property_string("path"); + int width = mp.get_property_int("video-params/w"); + int height = mp.get_property_int("video-params/h"); - using (MediaInfo mediaInfo = new MediaInfo(fileInfo.FullName)) + if (File.Exists(path)) { - string width = mediaInfo.GetInfo(MediaInfoStreamKind.Video, "Width"); + fileSize = (int)(new FileInfo(path).Length); - if (width == "") + if (FileAssociation.AudioTypes.Contains(Path.GetExtension(path).ToLower().TrimStart('.'))) { - string performer = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Performer"); - string title = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Title"); - string album = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Album"); - string genre = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Genre"); - string date = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Recorded_Date"); - string duration = mediaInfo.GetInfo(MediaInfoStreamKind.Audio, "Duration/String"); + using (MediaInfo mediaInfo = new MediaInfo(path)) + { + performer = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Performer"); + title = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Title"); + album = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Album"); + genre = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Genre"); + date = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Recorded_Date"); + duration = mediaInfo.GetInfo(MediaInfoStreamKind.Audio, "Duration/String"); - string text = ""; + if (performer != "") text += "Artist: " + performer + "\n"; + if (title != "") text += "Title: " + title + "\n"; + if (album != "") text += "Album: " + album + "\n"; + if (genre != "") text += "Genre: " + genre + "\n"; + if (date != "") text += "Year: " + date + "\n"; + if (duration != "") text += "Length: " + duration + "\n"; - if (performer != "") text += "Artist: " + performer + "\n"; - if (title != "") text += "Title: " + title + "\n"; - if (album != "") text += "Album: " + album + "\n"; - if (genre != "") text += "Genre: " + genre + "\n"; - if (date != "") text += "Year: " + date + "\n"; - if (duration != "") text += "Length: " + duration + "\n"; - - mp.commandv("show-text", text, "5000"); + mp.commandv("show-text", text, "5000"); + return; + } } - else - { - string height = mediaInfo.GetInfo(MediaInfoStreamKind.Video, "Height"); - TimeSpan position = TimeSpan.FromSeconds(mp.get_property_number("time-pos")); - TimeSpan duration = TimeSpan.FromSeconds(mp.get_property_number("duration")); - string bitrate = mediaInfo.GetInfo(MediaInfoStreamKind.Video, "BitRate"); - - if (bitrate == "") - bitrate = "0"; - - double bitrate2 = Convert.ToDouble(bitrate) / 1000.0 / 1000.0; - string videoCodec = mp.get_property_string("video-format").ToUpper(); - string filename = fileInfo.Name; - - string text = filename + "\n" + - FormatTime(position.TotalMinutes) + ":" + - FormatTime(position.Seconds) + " / " + - FormatTime(duration.TotalMinutes) + ":" + - FormatTime(duration.Seconds) + "\n" + - $"{width} x {height}\n" + - $"{bitrate2.ToString("f1")} Mb/s\n" + - Convert.ToInt32(fileInfo.Length / 1024 / 1024).ToString() + " MB\n" + - $"{videoCodec}\n"; - - mp.commandv("show-text", text, "5000"); - } - - string FormatTime(double value) => ((int)value).ToString("00"); } + + TimeSpan position = TimeSpan.FromSeconds(mp.get_property_number("time-pos")); + TimeSpan duration2 = TimeSpan.FromSeconds(mp.get_property_number("duration")); + string videoCodec = mp.get_property_string("video-format").ToUpper(); + + text = Path.GetFileName(path) + "\n" + + FormatTime(position.TotalMinutes) + ":" + + FormatTime(position.Seconds) + " / " + + FormatTime(duration2.TotalMinutes) + ":" + + FormatTime(duration2.Seconds) + "\n" + + $"{width} x {height}\n"; + + if (fileSize > 0) + text += Convert.ToInt32(fileSize / 1024 / 1024).ToString() + " MB\n"; + + text += $"{videoCodec}\n"; + + mp.commandv("show-text", text, "5000"); + string FormatTime(double value) => ((int)value).ToString("00"); } catch (Exception) { @@ -180,8 +177,9 @@ namespace mpvnet public static void execute_mpv_command(string[] args) { MainForm.Instance.Invoke(new Action(() => { - string command = Microsoft.VisualBasic.Interaction.InputBox("Enter a mpv command to be executed."); + string command = Microsoft.VisualBasic.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegistryHelp.GetString("HKCU\\Software\\" + Application.ProductName, "RecentExecutedCommand")); if (string.IsNullOrEmpty(command)) return; + RegistryHelp.SetObject("HKCU\\Software\\" + Application.ProductName, "RecentExecutedCommand", command); mp.command_string(command, false); })); } diff --git a/mpv.net/MainForm.cs b/mpv.net/MainForm.cs index bbd42d0..93ebdc7 100644 --- a/mpv.net/MainForm.cs +++ b/mpv.net/MainForm.cs @@ -41,6 +41,13 @@ namespace mpvnet try { + object recent = RegistryHelp.GetObject("HKCU\\Software\\" + Application.ProductName, "Recent"); + + if (recent is string[]) + RecentFiles = new List((string[])recent); + else + RecentFiles = new List(); + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ThreadException += Application_ThreadException; Msg.SupportURL = "https://github.com/stax76/mpv.net#support"; @@ -50,12 +57,7 @@ namespace mpvnet Hwnd = Handle; MinimumSize = new Size(FontHeight * 16, FontHeight * 9); Text += " " + Application.ProductVersion; - object recent = RegistryHelp.GetObject("HKCU\\Software\\" + Application.ProductName, "Recent"); - if (recent is string[]) - RecentFiles = new List((string[])recent); - else - RecentFiles = new List(); foreach (var i in mp.mpvConf) ProcessMpvProperty(i.Key, i.Value); @@ -530,14 +532,6 @@ namespace mpvnet } } - public DialogResult ShowMsgBox(string message, MessageBoxIcon icon) - { - var buttons = MessageBoxButtons.OK; - if (icon == MessageBoxIcon.Question) buttons = MessageBoxButtons.OKCancel; - var fn = new Func(() => MessageBox.Show(message, Application.ProductName, buttons, icon)); - return (DialogResult)Invoke(fn); - } - protected override void OnLoad(EventArgs e) { base.OnLoad(e); diff --git a/mpv.net/Program.cs b/mpv.net/Program.cs index 582c7dc..710bfc4 100644 --- a/mpv.net/Program.cs +++ b/mpv.net/Program.cs @@ -19,16 +19,15 @@ namespace mpvnet if (args[2] == "unregister") FileAssociation.Unregister(); return; } + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); } catch (Exception ex) { MessageBox.Show(ex.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; } - - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); } } } \ No newline at end of file diff --git a/mpv.net/Sys/TaskDialog.cs b/mpv.net/Sys/TaskDialog.cs index 142a8df..dbb0fca 100644 --- a/mpv.net/Sys/TaskDialog.cs +++ b/mpv.net/Sys/TaskDialog.cs @@ -9,8 +9,6 @@ using System.Text.RegularExpressions; using System.Threading; using System.Windows.Forms; -using Microsoft.VisualBasic.CompilerServices; - namespace Sys { public class Msg @@ -44,10 +42,10 @@ namespace Sys } td.MainIcon = MsgIcon.Error; - td.Footer = "[copymsg Copy Message]"; + td.Footer = "[Copy Message](copymsg)"; if (!string.IsNullOrEmpty(Msg.SupportURL)) - td.Footer += $" [{SupportURL} Contact Support]"; + td.Footer += $" [Contact Support]({SupportURL})"; td.Show(); } @@ -63,10 +61,10 @@ namespace Sys td.Content = e.Message; td.MainIcon = MsgIcon.Error; td.ExpandedInformation = e.ToString(); - td.Footer = "[copymsg Copy Message]"; + td.Footer = "[Copy Message](copymsg)"; if (!string.IsNullOrEmpty(Msg.SupportURL)) - td.Footer += $" [{SupportURL} Contact Support]"; + td.Footer += $" [Contact Support]({SupportURL})"; td.Show(); } @@ -244,12 +242,12 @@ namespace Sys public string Content { get => Config.pszContent; - set => Config.pszContent = ExpandWikiMarkup(value); + set => Config.pszContent = ExpandMarkdownMarkup(value); } public string ExpandedInformation { get => Config.pszExpandedInformation; - set => Config.pszExpandedInformation = ExpandWikiMarkup(value); + set => Config.pszExpandedInformation = ExpandMarkdownMarkup(value); } public string VerificationText { @@ -264,7 +262,7 @@ namespace Sys public string Footer { get => Config.pszFooter; - set => Config.pszFooter = ExpandWikiMarkup(value); + set => Config.pszFooter = ExpandMarkdownMarkup(value); } public MsgIcon MainIcon { @@ -329,16 +327,16 @@ namespace Sys Buttons.Add(new TaskDialogNative.TASKDIALOG_BUTTON(n, text)); } - public string ExpandWikiMarkup(string value) + public string ExpandMarkdownMarkup(string value) { if (value.Contains("[")) { - Regex regex = new Regex("\\[(.*?) (.+?)\\]"); + Regex regex = new Regex(@"\[(.+)\]\((.+)\)"); if (regex.Match(value).Success) { Config.dwFlags |= TaskDialogNative.TASKDIALOG_FLAGS.TDF_ENABLE_HYPERLINKS; - value = regex.Replace(value, "$2"); + value = regex.Replace(value, "$1"); } } return value; @@ -398,10 +396,9 @@ namespace Sys break; case 3: //TDN_HYPERLINK_CLICKED string stringUni = Marshal.PtrToStringUni(lParam); - if (stringUni.StartsWith("mailto") || stringUni.StartsWith("http")) Process.Start(stringUni); - if (Operators.CompareString(stringUni, "copymsg", false) == 0) + if (stringUni == "copymsg") { Thread thread = new Thread((ThreadStart)(() => { Clipboard.SetText(MainInstruction + "\r\n\r\n" + Content + "\r\n\r\n" + ExpandedInformation); diff --git a/mpv.net/mp.cs b/mpv.net/mp.cs index f31e4f6..6f05171 100644 --- a/mpv.net/mp.cs +++ b/mpv.net/mp.cs @@ -85,7 +85,7 @@ namespace mpvnet using (TaskDialog td = new TaskDialog()) { td.MainInstruction = "Choose a settings folder."; - td.Content = "[https://mpv.io/manual/master/#files-on-windows MPV documentation about files on Windows.]"; + td.Content = "[MPV documentation about files on Windows.](https://mpv.io/manual/master/#files-on-windows)"; td.AddCommandLink("appdata", appdataFolder, appdataFolder); td.AddCommandLink("portable", portableFolder, portableFolder); td.AllowCancel = false; @@ -278,7 +278,7 @@ namespace mpvnet { List names = mpvnet.Command.Commands.Select((item) => item.Name).ToList(); names.Sort(); - Msg.ShowError($"No command '{args[1]}' found.", $"Available commands are:\n\n{string.Join("\n", names)}\n\nHow to bind these commands can be seen in the [https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/inputConf.txt default input bindings and menu definition]."); + Msg.ShowError($"No command '{args[1]}' found.", $"Available commands are:\n\n{string.Join("\n", names)}\n\nHow to bind these commands can be seen in the [default input bindings and menu definition](https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/inputConf.txt)."); } } ClientMessage?.Invoke(args);