diff --git a/docs/changelog.md b/docs/changelog.md index 9a3fe5d..1462f3c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,11 @@ - Support of the mpv option `title-bar`. - Command line parser fix using list options with `-add` suffix. - Fix video being rendered with black line at the bottom. +- The conf file reader/writer detects if the user prefers space before and after the equal sign. +- The portable download includes like the installer debug symbols. +- Setup questions on startup removed. +- Pressing shift while drag and drop (and clipboard import) appends + instead of replaces files in the playlist. mpv supports this as well. # v7.0.0.4 Beta (2023-12-19) diff --git a/src/MpvNet.Windows/GuiCommand.cs b/src/MpvNet.Windows/GuiCommand.cs index d5b0072..424614c 100644 --- a/src/MpvNet.Windows/GuiCommand.cs +++ b/src/MpvNet.Windows/GuiCommand.cs @@ -153,10 +153,12 @@ public class GuiCommand public void OpenFromClipboard(IList args) { + bool append = Control.ModifierKeys == Keys.Shift; + if (System.Windows.Forms.Clipboard.ContainsFileDropList()) { string[] files = System.Windows.Forms.Clipboard.GetFileDropList().Cast().ToArray(); - Player.LoadFiles(files, false, false); + Player.LoadFiles(files, false, append); } else { @@ -173,7 +175,7 @@ public class GuiCommand return; } - Player.LoadFiles(files.ToArray(), false, false); + Player.LoadFiles(files.ToArray(), false, append); } } diff --git a/src/MpvNet.Windows/Help/WinMpvHelp.cs b/src/MpvNet.Windows/Help/WinMpvHelp.cs deleted file mode 100644 index 392c1ef..0000000 --- a/src/MpvNet.Windows/Help/WinMpvHelp.cs +++ /dev/null @@ -1,55 +0,0 @@ - -using System.Windows; -using MpvNet.Windows.WPF; - -namespace MpvNet.Windows.Help; - -public class WinMpvHelp -{ - public static void Setup() - { - if (RegistryHelp.GetString("PathEnvVarCheck") == Folder.Startup || - RegistryHelp.GetString("Setup") == Folder.Startup || - App.Settings.StartupFolder == Folder.Startup || - Folder.Startup.Contains("portable_config")) - - return; - - string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User)!; - - if (!path.ToLower().Contains(Folder.Startup.TrimEnd(Path.DirectorySeparatorChar).ToLower())) - { - var result = Msg.ShowQuestion("Would you like to add mpv.net to the Path environment variable?" + BR2 + - "This will allow using mpv.net in a console/terminal.", MessageBoxButton.YesNo); - - if (result == MessageBoxResult.Yes) - { - Environment.SetEnvironmentVariable("Path", - Folder.Startup.TrimEnd(Path.DirectorySeparatorChar) + ";" + path, - EnvironmentVariableTarget.User); - - Msg.ShowInfo("mpv.net was added successfully to Path."); - } - else - Msg.ShowInfo("If you want to add mpv.net to the Path environment variable later," + BR + - "you can do so with the context menu (Settings/Setup)."); - } - - var result2 = Msg.ShowQuestion("Would you like to register video file associations?", MessageBoxButton.YesNo); - - if (result2 == MessageBoxResult.Yes) - { - Player.Command("script-message-to mpvnet reg-file-assoc video"); - - result2 = Msg.ShowQuestion("Would you like to register audio file associations?", MessageBoxButton.YesNo); - - if (result2 == MessageBoxResult.Yes) - Player.Command("script-message-to mpvnet reg-file-assoc audio"); - } - else - Msg.ShowInfo("If you want to register file associations later," + BR + - "you can do so with the context menu (Settings/Setup)."); - - App.Settings.StartupFolder = Folder.Startup; - } -} diff --git a/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs b/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs index 9d237d3..223db7f 100644 --- a/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs +++ b/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs @@ -20,13 +20,16 @@ namespace MpvNet.Windows.WPF; public partial class ConfWindow : Window, INotifyPropertyChanged { - List Settings = Conf.LoadConf(Properties.Resources.editor_conf.TrimEnd()); - List ConfItems = new List(); - string InitialContent; - string ThemeConf = GetThemeConf(); + List _settings = Conf.LoadConf(Properties.Resources.editor_conf.TrimEnd()); + List _confItems = new List(); + string _initialContent; + string _themeConf = GetThemeConf(); string? _searchText; List? _nodes; bool _shown; + int _useSpace; + int _useNoSpace; + public event PropertyChangedEventHandler? PropertyChanged; public ConfWindow() @@ -37,7 +40,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged LoadConf(App.ConfPath); LoadLibplaceboConf(); LoadSettings(); - InitialContent = GetCompareString(); + _initialContent = GetCompareString(); if (string.IsNullOrEmpty(App.Settings.ConfigEditorSearch)) SearchText = "General:"; @@ -74,7 +77,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged { var rootNode = new TreeNode(); - foreach (Setting setting in Settings) + foreach (Setting setting in _settings) AddNode(rootNode.Children, setting.Directory!); _nodes = new NodeViewModel(rootNode).Children; @@ -127,14 +130,14 @@ public partial class ConfWindow : Window, INotifyPropertyChanged void LoadSettings() { - foreach (Setting setting in Settings) + foreach (Setting setting in _settings) { setting.StartValue = setting.Value; if (!FilterStrings.Contains(setting.Directory!)) FilterStrings.Add(setting.Directory!); - foreach (ConfItem item in ConfItems) + foreach (ConfItem item in _confItems) { if (setting.Name == item.Name && setting.File == item.File && @@ -164,7 +167,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged static string GetThemeConf() => Theme.DarkMode + App.DarkTheme + App.LightTheme; - string GetCompareString() => string.Join("", Settings.Select(item => item.Name + item.Value).ToArray()); + string GetCompareString() => string.Join("", _settings.Select(item => item.Name + item.Value).ToArray()); void LoadConf(string file) { @@ -176,9 +179,12 @@ public partial class ConfWindow : Window, INotifyPropertyChanged bool isSectionItem = false; - foreach (string currentLine in File.ReadAllLines(file)) + foreach (string it in File.ReadAllLines(file)) { - string line = currentLine.Trim(); + string line = it.Trim(); + + if (line.StartsWith("-")) + line = line.TrimStart('-'); if (line == "") comment += "\r\n"; @@ -187,7 +193,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged else if (line.StartsWith("[") && line.Contains(']')) { if (!isSectionItem && comment != "" && comment != "\r\n") - ConfItems.Add(new ConfItem() { + _confItems.Add(new ConfItem() { Comment = comment, File = Path.GetFileNameWithoutExtension(file)}); section = line.Substring(0, line.IndexOf("]") + 1); @@ -197,7 +203,20 @@ public partial class ConfWindow : Window, INotifyPropertyChanged else if (line.Contains('=') || Regex.Match(line, "^[\\w-]+$").Success) { if (!line.Contains('=')) - line += "=yes"; + { + if (line.StartsWith("no-")) + { + line = line.Substring(3); + line += "=no"; + } + else + line += "=yes"; + } + + if (line.Contains(" =") || line.Contains("= ")) + _useSpace += 1; + else + _useNoSpace += 1; ConfItem item = new(); item.File = Path.GetFileNameWithoutExtension(file); @@ -207,7 +226,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged item.Section = section; section = ""; - if (line.Contains('#') && !line.Contains("'") && !line.Contains("\"")) + if (line.Contains('#') && !line.Contains('\'') && !line.Contains('"')) { item.LineComment = line.Substring(line.IndexOf("#")).Trim(); line = line.Substring(0, line.IndexOf("#")).Trim(); @@ -231,7 +250,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged item.Name = left; item.Value = right; - ConfItems.Add(item); + _confItems.Add(item); } } } @@ -240,7 +259,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged { List pairs = new(); - foreach (Setting setting in Settings) + foreach (Setting setting in _settings) { if (filename != setting.File) continue; @@ -254,7 +273,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged void LoadLibplaceboConf() { - foreach (ConfItem item in ConfItems.ToArray()) + foreach (ConfItem item in _confItems.ToArray()) if (item.Name == "libplacebo-opts") LoadKeyValueList(item.Value, "libplacebo"); } @@ -276,7 +295,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged item.Name = left; item.Value = right; item.File = file; - ConfItems.Add(item); + _confItems.Add(item); } } @@ -301,8 +320,9 @@ public partial class ConfWindow : Window, INotifyPropertyChanged { StringBuilder sb = new StringBuilder(); List namesWritten = new List(); + string equalString = _useSpace > _useNoSpace ? " = " : "="; - foreach (ConfItem item in ConfItems) + foreach (ConfItem item in _confItems) { if (filename != item.File || item.Section != "" || item.IsSectionItem) continue; @@ -314,7 +334,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged { if (item.Name != "") { - sb.Append(item.Name + " = " + EscapeValue(item.Value)); + sb.Append(item.Name + equalString + EscapeValue(item.Value)); if (item.LineComment != "") sb.Append(" " + item.LineComment); @@ -325,7 +345,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged } else if ((item.SettingBase.Value ?? "") != item.SettingBase.Default) { - sb.Append(item.Name + " = " + EscapeValue(item.SettingBase.Value!)); + sb.Append(item.Name + equalString + EscapeValue(item.SettingBase.Value!)); if (item.LineComment != "") sb.Append(" " + item.LineComment); @@ -335,16 +355,16 @@ public partial class ConfWindow : Window, INotifyPropertyChanged } } - foreach (Setting setting in Settings) + foreach (Setting setting in _settings) { if (filename != setting.File || namesWritten.Contains(setting.Name!)) continue; if ((setting.Value ?? "") != setting.Default) - sb.AppendLine(setting.Name + " = " + EscapeValue(setting.Value!)); + sb.AppendLine(setting.Name + equalString + EscapeValue(setting.Value!)); } - foreach (ConfItem item in ConfItems) + foreach (ConfItem item in _confItems) { if (filename != item.File || (item.Section == "" && !item.IsSectionItem)) continue; @@ -360,7 +380,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged if (item.Comment != "") sb.Append(item.Comment); - sb.Append(item.Name + " = " + EscapeValue(item.Value)); + sb.Append(item.Name + equalString + EscapeValue(item.Value)); if (item.LineComment != "") sb.Append(" " + item.LineComment); @@ -415,10 +435,10 @@ public partial class ConfWindow : Window, INotifyPropertyChanged base.OnClosed(e); App.Settings.ConfigEditorSearch = SearchText; - if (InitialContent == GetCompareString()) + if (_initialContent == GetCompareString()) return; - foreach (Setting setting in Settings) + foreach (Setting setting in _settings) { if (setting.Name == "libplacebo-opts") { @@ -430,7 +450,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged File.WriteAllText(Player.ConfPath, GetContent("mpv")); File.WriteAllText(App.ConfPath, GetContent("mpvnet")); - foreach (Setting it in Settings) + foreach (Setting it in _settings) { if (it.Value != it.StartValue) { @@ -447,7 +467,7 @@ public partial class ConfWindow : Window, INotifyPropertyChanged Theme.Init(); Theme.UpdateWpfColors(); - if (ThemeConf != GetThemeConf()) + if (_themeConf != GetThemeConf()) MessageBox.Show("Changed theme settings require mpv.net being restarted.", "Info"); } diff --git a/src/MpvNet.Windows/WinForms/MainForm.cs b/src/MpvNet.Windows/WinForms/MainForm.cs index 2543a97..21e581e 100644 --- a/src/MpvNet.Windows/WinForms/MainForm.cs +++ b/src/MpvNet.Windows/WinForms/MainForm.cs @@ -1352,14 +1352,8 @@ public partial class MainForm : Form InitAndBuildContextMenu(); Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y); GlobalHotkey.RegisterGlobalHotkeys(Handle); - WasShown = true; StrongReferenceMessenger.Default.Send(new MainWindowIsLoadedMessage()); - - TaskHelp.Run(() => { - System.Windows.Application.Current.Dispatcher.BeginInvoke(() => { - WinMpvHelp.Setup(); - }, DispatcherPriority.Background); - }); + WasShown = true; } void ContextMenu_Closed(object sender, System.Windows.RoutedEventArgs e) => MenuAutoResetEvent.Set(); @@ -1448,10 +1442,12 @@ public partial class MainForm : Form { base.OnDragDrop(e); + bool append = ModifierKeys == Keys.Shift; + if (e.Data!.GetDataPresent(DataFormats.FileDrop)) - Player.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as string[], true, false); + Player.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as string[], true, append); else if (e.Data.GetDataPresent(DataFormats.Text)) - Player.LoadFiles(new[] { e.Data.GetData(DataFormats.Text)!.ToString()! }, true, false); + Player.LoadFiles(new[] { e.Data.GetData(DataFormats.Text)!.ToString()! }, true, append); } protected override void OnKeyDown(KeyEventArgs e) diff --git a/src/MpvNet/Player.cs b/src/MpvNet/Player.cs index 2007209..2bdbeb6 100644 --- a/src/MpvNet/Player.cs +++ b/src/MpvNet/Player.cs @@ -452,7 +452,7 @@ public class MainPlayer : MpvClient files.Add(arg); - LoadFiles(files.ToArray(), !App.Queue, false || App.Queue); + LoadFiles(files.ToArray(), !App.Queue, App.Queue); if (App.CommandLine.Contains("--shuffle")) {