diff --git a/README.md b/README.md index 1393c8d..4f253b4 100644 --- a/README.md +++ b/README.md @@ -122,9 +122,7 @@ Scripting is supported via Python, C#, Lua, JavaScript and PowerShell Add-ons have to be located at: -C:\Users\\\AppData\Roaming\mpv\Addons\ExampleAddon\ExampleAddon.dll - -\\Addons\ExampleAddon\ExampleAddon.dll +C:\Users\%username%\AppData\Roaming\mpv\Addons\ExampleAddon\ExampleAddon.dll \\portable_config\Addons\ExampleAddon\ExampleAddon.dll @@ -204,8 +202,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 +- the info command (i key) now works also for URLs +- CSScriptAddon add-on didn't load cs scripts from \\\scripts and it didn't use the task dialog api to show errors ### 3.2 (2019-04-27) diff --git a/mpv.net/Command.cs b/mpv.net/Command.cs index e09db10..fb9393e 100644 --- a/mpv.net/Command.cs +++ b/mpv.net/Command.cs @@ -117,14 +117,14 @@ namespace mpvnet try { string performer, title, album, genre, date, duration, text = ""; - int fileSize = 0; + long 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"); if (File.Exists(path)) { - fileSize = (int)(new FileInfo(path).Length); + fileSize = new FileInfo(path).Length; if (FileAssociation.AudioTypes.Contains(Path.GetExtension(path).ToLower().TrimStart('.'))) { @@ -162,7 +162,7 @@ namespace mpvnet $"{width} x {height}\n"; if (fileSize > 0) - text += Convert.ToInt32(fileSize / 1024 / 1024).ToString() + " MB\n"; + text += Convert.ToInt32(fileSize / 1024.0 / 1024.0).ToString() + " MB\n"; text += $"{videoCodec}\n"; diff --git a/mpv.net/Program.cs b/mpv.net/Program.cs index 710bfc4..77a4f56 100644 --- a/mpv.net/Program.cs +++ b/mpv.net/Program.cs @@ -1,6 +1,8 @@ using System; using System.Windows.Forms; +using Sys; + namespace mpvnet { static class Program @@ -26,7 +28,7 @@ namespace mpvnet } catch (Exception ex) { - MessageBox.Show(ex.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); + Msg.ShowException(ex); } } } diff --git a/mpv.net/Sys/TaskDialog.cs b/mpv.net/Sys/TaskDialog.cs index dbb0fca..2d10530 100644 --- a/mpv.net/Sys/TaskDialog.cs +++ b/mpv.net/Sys/TaskDialog.cs @@ -24,30 +24,38 @@ namespace Sys public static void ShowError(string mainInstruction, string content = null) { - using (TaskDialog td = new TaskDialog()) + try { - td.AllowCancel = false; - - if (string.IsNullOrEmpty(content)) + using (TaskDialog td = new TaskDialog()) { - if (mainInstruction.Length < 80) - td.MainInstruction = mainInstruction; + td.AllowCancel = false; + + if (string.IsNullOrEmpty(content)) + { + if (mainInstruction.Length < 80) + td.MainInstruction = mainInstruction; + else + td.Content = mainInstruction; + } else - td.Content = mainInstruction; + { + td.MainInstruction = mainInstruction; + td.Content = content; + } + + td.MainIcon = MsgIcon.Error; + td.Footer = "[Copy Message](copymsg)"; + + if (!string.IsNullOrEmpty(Msg.SupportURL)) + td.Footer += $" [Contact Support]({SupportURL})"; + + td.Show(); } - else - { - td.MainInstruction = mainInstruction; - td.Content = content; - } - - td.MainIcon = MsgIcon.Error; - td.Footer = "[Copy Message](copymsg)"; - - if (!string.IsNullOrEmpty(Msg.SupportURL)) - td.Footer += $" [Contact Support]({SupportURL})"; - - td.Show(); + } + catch (Exception ex) + { + MessageBox.Show(ex.GetType().Name + "\n\n" + ex.Message + "\n\n" + ex.ToString(), + Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -71,7 +79,7 @@ namespace Sys } catch (Exception ex) { - MessageBox.Show(ex.GetType().Name + "\n\n" + e.Message + "\n\n" + e.ToString(), + MessageBox.Show(ex.GetType().Name + "\n\n" + ex.Message + "\n\n" + ex.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -108,32 +116,40 @@ namespace Sys MsgButtons buttons, MsgResult defaultButton = MsgResult.None) { - using (TaskDialog td = new TaskDialog()) + try { - td.AllowCancel = false; - td.DefaultButton = defaultButton; - td.MainIcon = icon; + using (TaskDialog td = new TaskDialog()) + { + td.AllowCancel = false; + td.DefaultButton = defaultButton; + td.MainIcon = icon; - if (content == null) - { - if (mainInstruction.Length < 80) - td.MainInstruction = mainInstruction; + if (content == null) + { + if (mainInstruction.Length < 80) + td.MainInstruction = mainInstruction; + else + td.Content = mainInstruction; + } else - td.Content = mainInstruction; + { + td.MainInstruction = mainInstruction; + td.Content = content; + } + if (buttons == MsgButtons.OkCancel) + { + td.AddButton("OK", MsgResult.OK); + td.AddButton("Cancel", MsgResult.Cancel); + } + else + td.CommonButtons = buttons; + return td.Show(); } - else - { - td.MainInstruction = mainInstruction; - td.Content = content; - } - if (buttons == MsgButtons.OkCancel) - { - td.AddButton("OK", MsgResult.OK); - td.AddButton("Cancel", MsgResult.Cancel); - } - else - td.CommonButtons = buttons; - return td.Show(); + } + catch (Exception ex) + { + return (MsgResult)MessageBox.Show(ex.GetType().Name + "\n\n" + ex.Message + "\n\n" + ex.ToString(), + Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/mpv.net/Windows/ConfWindow.xaml.cs b/mpv.net/Windows/ConfWindow.xaml.cs index 7b94ea0..bc74729 100644 --- a/mpv.net/Windows/ConfWindow.xaml.cs +++ b/mpv.net/Windows/ConfWindow.xaml.cs @@ -3,14 +3,13 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; -using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using DynamicGUI; -using Microsoft.Win32; +using Sys; namespace mpvnet { @@ -154,8 +153,7 @@ namespace mpvnet WriteToDisk(mp.MpvConfPath, MpvConf, MpvSettingsDefinitions); WriteToDisk(mp.MpvNetConfPath, MpvNetConf, MpvNetSettingsDefinitions); - MessageBox.Show("Changes will be available on next mpv.net startup.", - Title, MessageBoxButton.OK, MessageBoxImage.Information); + Msg.Show("Changes will be available on next mpv.net startup."); } void WriteToDisk(string filePath, diff --git a/mpv.net/Windows/InputWindow.xaml.cs b/mpv.net/Windows/InputWindow.xaml.cs index bfa57ce..975a0e9 100644 --- a/mpv.net/Windows/InputWindow.xaml.cs +++ b/mpv.net/Windows/InputWindow.xaml.cs @@ -7,6 +7,8 @@ using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; +using Sys; + namespace mpvnet { public partial class InputWindow : Window @@ -32,7 +34,7 @@ namespace mpvnet CollectionView.Refresh(); if (SearchControl.SearchTextBox.Text == "?") - MessageBox.Show("Filtering works by searching in the Input, Menu and Command but it's possible to reduce the filter scope to either of Input, Menu or Command by prefixing as follows:\n\ni \ni: \n\nm \nm: \n\nc \nc: \n\nIf only one character is entered the search will be performed only in the input.", "Filtering", MessageBoxButton.OK, MessageBoxImage.Information); + Msg.Show("Filtering works by searching in the Input, Menu and Command but it's possible to reduce the filter scope to either of Input, Menu or Command by prefixing as follows:\n\ni \ni: \n\nm \nm: \n\nc \nc: \n\nIf only one character is entered the search will be performed only in the input.", "Filtering"); } bool Filter(CommandItem item) @@ -77,7 +79,7 @@ namespace mpvnet foreach (CommandItem i in CommandItem.Items) if (items.ContainsKey(i.Input) && i.Input != "") - MessageBox.Show($"Duplicate found:\n\n{i.Input}: {i.Path}\n\n{items[i.Input].Input}: {items[i.Input].Path}\n\nPlease note that you can chain multiple commands in the same line by using a semicolon as separator.", "Duplicate Found", MessageBoxButton.OK, MessageBoxImage.Warning); + Msg.Show($"Duplicate found:\n\n{i.Input}: {i.Path}\n\n{items[i.Input].Input}: {items[i.Input].Path}\n\nPlease note that you can chain multiple commands in the same line by using a semicolon as separator.", "Duplicate Found"); else items[i.Input] = i; } @@ -110,8 +112,7 @@ namespace mpvnet { if (InitialInputConfContent == GetInputConfContent()) return; File.WriteAllText(mp.InputConfPath, GetInputConfContent()); - MessageBox.Show("Changes will be available on next mpv.net startup.", - Title, MessageBoxButton.OK, MessageBoxImage.Information); + Msg.Show("Changes will be available on next mpv.net startup."); } private void DataGrid_PreviewCanExecute(object sender, CanExecuteRoutedEventArgs e) @@ -119,7 +120,7 @@ namespace mpvnet DataGrid grid = (DataGrid)sender; if (e.Command == DataGrid.DeleteCommand) - if (MessageBox.Show($"Confirm to delete: {(grid.SelectedItem as CommandItem).Input} ({(grid.SelectedItem as CommandItem).Path})", "Confirm Delete", MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK) + if (Msg.ShowQuestion($"Confirm to delete: {(grid.SelectedItem as CommandItem).Input} ({(grid.SelectedItem as CommandItem).Path})") != MsgResult.OK) e.Handled = true; } diff --git a/mpv.net/mpv.net.csproj b/mpv.net/mpv.net.csproj index 0fe876c..0bbe521 100644 --- a/mpv.net/mpv.net.csproj +++ b/mpv.net/mpv.net.csproj @@ -35,6 +35,7 @@ TRACE prompt 4 + false