From 89351010583c8cec941ddac7f6489757835b9f5e Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sat, 28 Sep 2019 04:01:10 +0200 Subject: [PATCH] fix issue with clipboard url detection --- extensions/RatingExtension/RatingExtension.cs | 4 ++-- mpv.net/Misc/Command.cs | 2 +- mpv.net/Native/TaskDialog.cs | 21 ++++++++++--------- mpv.net/WPF/ConfWindow.xaml.cs | 3 +-- mpv.net/WPF/LearnWindow.xaml.cs | 4 ++-- mpv.net/WinForms/MainForm.cs | 6 +++--- mpv.net/mpv/mp.cs | 1 - 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/extensions/RatingExtension/RatingExtension.cs b/extensions/RatingExtension/RatingExtension.cs index ddcd32e..439bee1 100644 --- a/extensions/RatingExtension/RatingExtension.cs +++ b/extensions/RatingExtension/RatingExtension.cs @@ -35,8 +35,8 @@ namespace RatingExtension // the assembly name must end with 'Extension' string basename = Path.GetFileNameWithoutExtension(filepath); for (int x = 0; x < 6; x++) - if (basename.Contains(" (" + x.ToString() + "stars)")) - basename = basename.Replace(" (" + x.ToString() + "stars)", ""); + if (basename.Contains(" (" + x + "stars)")) + basename = basename.Replace(" (" + x + "stars)", ""); basename += $" ({rating}stars)"; string newPath = Path.Combine(Path.GetDirectoryName(filepath), basename + Path.GetExtension(filepath)); diff --git a/mpv.net/Misc/Command.cs b/mpv.net/Misc/Command.cs index 95c81d0..1f2b05e 100644 --- a/mpv.net/Misc/Command.cs +++ b/mpv.net/Misc/Command.cs @@ -176,7 +176,7 @@ namespace mpvnet $"{width} x {height}\n"; if (fileSize > 0) - text += Convert.ToInt32(fileSize / 1024.0 / 1024.0).ToString() + " MB\n"; + text += Convert.ToInt32(fileSize / 1024.0 / 1024.0) + " MB\n"; text += $"{videoFormat}\n{audioCodec}"; diff --git a/mpv.net/Native/TaskDialog.cs b/mpv.net/Native/TaskDialog.cs index bccdd68..878935e 100644 --- a/mpv.net/Native/TaskDialog.cs +++ b/mpv.net/Native/TaskDialog.cs @@ -50,23 +50,23 @@ public class Msg td.Show(); } } - catch (Exception ex) + catch (Exception e) { - MessageBox.Show(ex.GetType().Name + "\n\n" + ex.Message + "\n\n" + ex.ToString(), + MessageBox.Show(e.GetType().Name + "\n\n" + e.Message + "\n\n" + e, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } - public static void ShowException(Exception e) + public static void ShowException(Exception exception) { try { using (TaskDialog td = new TaskDialog()) { - td.MainInstruction = e.GetType().Name; - td.Content = e.Message; + td.MainInstruction = exception.GetType().Name; + td.Content = exception.Message; td.MainIcon = MsgIcon.Error; - td.ExpandedInformation = e.ToString(); + td.ExpandedInformation = exception.ToString(); td.Footer = "[Copy Message](copymsg)"; if (!string.IsNullOrEmpty(Msg.SupportURL)) @@ -75,9 +75,9 @@ public class Msg td.Show(); } } - catch (Exception ex) + catch (Exception e) { - MessageBox.Show(ex.GetType().Name + "\n\n" + ex.Message + "\n\n" + ex.ToString(), + MessageBox.Show(e.GetType().Name + "\n\n" + e.Message + "\n\n" + e, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -144,9 +144,9 @@ public class Msg return td.Show(); } } - catch (Exception ex) + catch (Exception e) { - return (MsgResult)MessageBox.Show(ex.GetType().Name + "\n\n" + ex.Message + "\n\n" + ex.ToString(), + return (MsgResult)MessageBox.Show(e.GetType().Name + "\n\n" + e.Message + "\n\n" + e, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -235,6 +235,7 @@ public class TaskDialog : TaskDialogNative, IDisposable if (Path.GetFileName(lpszFileName.ToString().Replace(".vshost", "")) == Path.GetFileName(Assembly.GetEntryAssembly().Location)) + return foregroundWindow; return IntPtr.Zero; diff --git a/mpv.net/WPF/ConfWindow.xaml.cs b/mpv.net/WPF/ConfWindow.xaml.cs index a866850..09aacac 100644 --- a/mpv.net/WPF/ConfWindow.xaml.cs +++ b/mpv.net/WPF/ConfWindow.xaml.cs @@ -200,8 +200,7 @@ namespace mpvnet private void FilterListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { - if (e.AddedItems.Count > 0) - SearchControl.Text = e.AddedItems[0].ToString() + ":"; // TODO: remove ToString() + if (e.AddedItems.Count > 0) SearchControl.Text = e.AddedItems[0] + ":"; } private void OpenSettingsTextBlock_MouseUp(object sender, MouseButtonEventArgs e) diff --git a/mpv.net/WPF/LearnWindow.xaml.cs b/mpv.net/WPF/LearnWindow.xaml.cs index 5e9c628..eafac5f 100644 --- a/mpv.net/WPF/LearnWindow.xaml.cs +++ b/mpv.net/WPF/LearnWindow.xaml.cs @@ -44,7 +44,7 @@ namespace mpvnet } catch {} for (int i = 0; i < 13; i++) - if ("D" + i.ToString() == text) + if ("D" + i == text) text = text.Substring(1); switch (e.KeyCode) @@ -59,7 +59,7 @@ namespace mpvnet case WF.Keys.NumPad7: case WF.Keys.NumPad8: case WF.Keys.NumPad9: - text = "KP" + e.KeyCode.ToString()[6].ToString(); break; + text = "KP" + e.KeyCode.ToString()[6]; break; case WF.Keys.Space: text = "Space"; break; case WF.Keys.Enter: diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 7b62c1c..676e042 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -571,7 +571,6 @@ namespace mpvnet ContextMenuStrip = ContextMenu; WPF.WPF.Init(); System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; - CheckClipboardForURL(); Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y); WasShown = true; mp.LoadScripts(); @@ -660,10 +659,11 @@ namespace mpvnet !clipboard.Contains(" ") && clipboard.Contains(url.ToLower().Trim()) && RegHelp.GetString(App.RegPath, "LastURL") != clipboard && Visible) { - RegHelp.SetObject(App.RegPath, "LastURL", clipboard); - if (Msg.ShowQuestion("Play URL?", clipboard) == MsgResult.OK) mp.Load(new[] { clipboard }, true, Control.ModifierKeys.HasFlag(Keys.Control)); + + RegHelp.SetObject(App.RegPath, "LastURL", clipboard); + break; } } } diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 2ff5857..25296eb 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -631,7 +631,6 @@ namespace mpvnet i.Contains(":\\") || i.StartsWith("\\\\") || File.Exists(i))) { files.Add(i); - if (i.Contains("://")) RegHelp.SetObject(App.RegPath, "LastURL", i); } }