diff --git a/Changelog.md b/Changelog.md index e3c98f0..4dc22d6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,7 @@ screenshot-format, screenshot-tag-colorspace, screenshot-high-bit-depth, screenshot-jpeg-source-chroma, screenshot-template, screenshot-jpeg-quality, screenshot-png-compression, screenshot-png-filter +- mpv.conf preview feature added to config editor, it previews the mpv.conf content ### 4.7.7 diff --git a/mpv.net/DynamicGUI/DynamicGUI.cs b/mpv.net/DynamicGUI/DynamicGUI.cs index 2890e27..71a14b2 100644 --- a/mpv.net/DynamicGUI/DynamicGUI.cs +++ b/mpv.net/DynamicGUI/DynamicGUI.cs @@ -29,7 +29,6 @@ namespace DynamicGUI baseSetting = optionSetting; optionSetting.Default = setting["default"]; optionSetting.Value = optionSetting.Default; - optionSetting.StartValue = optionSetting.Default; foreach (TomlTable option in setting["options"]) { @@ -70,7 +69,6 @@ namespace DynamicGUI { public string Name { get; set; } public string Value { get; set; } - public string StartValue { get; set; } public string Help { get; set; } public string Default { get; set; } public string URL { get; set; } diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index f967c41..adba568 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -19,7 +19,7 @@ namespace mpvnet public class App { public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName; - public static string ConfFilePath { get; } = mp.ConfigFolder + "\\mpvnet.conf"; + public static string ConfPath { get; } = mp.ConfigFolder + "\\mpvnet.conf"; public static string DarkMode { get; set; } = "always"; public static string ProcessInstance { get; set; } = "single"; public static string DarkColor { get; set; } @@ -73,8 +73,8 @@ namespace mpvnet { _Conf = new Dictionary(); - if (File.Exists(ConfFilePath)) - foreach (string i in File.ReadAllLines(ConfFilePath)) + if (File.Exists(ConfPath)) + foreach (string i in File.ReadAllLines(ConfPath)) if (i.Contains("=") && !i.StartsWith("#")) _Conf[i.Substring(0, i.IndexOf("=")).Trim()] = i.Substring(i.IndexOf("=") + 1).Trim(); } diff --git a/mpv.net/WPF/ConfWindow.xaml b/mpv.net/WPF/ConfWindow.xaml index 20fae96..432f292 100644 --- a/mpv.net/WPF/ConfWindow.xaml +++ b/mpv.net/WPF/ConfWindow.xaml @@ -29,6 +29,7 @@ Open config folder + Preview mpv.conf Show mpv manual Show support forum diff --git a/mpv.net/WPF/ConfWindow.xaml.cs b/mpv.net/WPF/ConfWindow.xaml.cs index 5fbe0a2..f9d1e06 100644 --- a/mpv.net/WPF/ConfWindow.xaml.cs +++ b/mpv.net/WPF/ConfWindow.xaml.cs @@ -17,10 +17,9 @@ namespace mpvnet { private List SettingsDefinitions = Settings.LoadSettings(Properties.Resources.mpvConfToml); private List NetSettingsDefinitions = Settings.LoadSettings(Properties.Resources.mpvNetConfToml); - private Dictionary> Comments = new Dictionary>(); - public ObservableCollection FilterStrings { get; } = new ObservableCollection(); - + string InitialContent; + public ConfWindow() { InitializeComponent(); @@ -28,6 +27,8 @@ namespace mpvnet SearchControl.SearchTextBox.TextChanged += SearchTextBox_TextChanged; LoadSettings(SettingsDefinitions, Conf); LoadSettings(NetSettingsDefinitions, NetConf); + InitialContent = GetContent(mp.ConfPath, Conf, SettingsDefinitions) + + GetContent(App.ConfPath, NetConf, NetSettingsDefinitions); SearchControl.Text = RegHelp.GetString(App.RegPath, "config editor search"); if (App.IsDarkMode) @@ -59,7 +60,6 @@ namespace mpvnet if (setting.Name == pair.Key) { setting.Value = pair.Value.Trim('\'', '"'); - setting.StartValue = pair.Value.Trim('\'', '"'); continue; } } @@ -93,7 +93,7 @@ namespace mpvnet public Dictionary NetConf { get { - if (_NetConf == null) _NetConf = LoadConf(App.ConfFilePath); + if (_NetConf == null) _NetConf = LoadConf(App.ConfPath); return _NetConf; } } @@ -101,7 +101,6 @@ namespace mpvnet private Dictionary LoadConf(string filePath) { Dictionary conf = new Dictionary(); - Comments[filePath] = new Dictionary(); if (File.Exists(filePath)) { @@ -110,15 +109,9 @@ namespace mpvnet if (i.Contains("=")) { int pos = i.IndexOf("="); - string left = i.Substring(0, pos).Replace(" ", "").ToLower(); + string left = i.Substring(0, pos).Trim().ToLower(); string right = i.Substring(pos + 1).Trim(); - - if (left.StartsWith("#")) - { - Comments[filePath][left.TrimStart('#')] = right; - continue; - } - + if (left.StartsWith("#")) continue; if (left == "fs") left = "fullscreen"; if (left == "loop") left = "loop-file"; conf[left] = right; @@ -131,40 +124,20 @@ namespace mpvnet protected override void OnClosed(EventArgs e) { base.OnClosed(e); - WriteToDisk(); + string content = GetContent(mp.ConfPath, Conf, SettingsDefinitions); + string netContent = GetContent(App.ConfPath, NetConf, NetSettingsDefinitions); + if (InitialContent == content + netContent) return; + string header = "\r\n# manual: https://mpv.io/manual/master/\r\n\r\n# defaults: https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpvConf.txt\r\n\r\n"; + File.WriteAllText(mp.ConfPath, header + content); + File.WriteAllText(App.ConfPath, netContent); + Msg.Show("Changes will be available on next mpv.net startup."); RegHelp.SetObject(App.RegPath, "config editor search", SearchControl.Text); } - void WriteToDisk() - { - bool isDirty = false; - - foreach (SettingBase i in SettingsDefinitions) - if (i.StartValue != i.Value) - isDirty = true; - - foreach (SettingBase i in NetSettingsDefinitions) - if (i.StartValue != i.Value) - isDirty = true; - - if (!isDirty) - return; - - WriteToDisk(mp.ConfPath, Conf, SettingsDefinitions); - WriteToDisk(App.ConfFilePath, NetConf, NetSettingsDefinitions); - - Msg.Show("Changes will be available on next mpv.net startup."); - } - - void WriteToDisk(string filePath, - Dictionary confSettings, - List settings) + string GetContent(string filePath, Dictionary confSettings, List settings) { string content = ""; - foreach (var i in Comments[filePath]) - content += $"#{i.Key} = {i.Value}\r\n"; - foreach (SettingBase setting in settings) { if ((setting.Value ?? "") != setting.Default) @@ -186,7 +159,7 @@ namespace mpvnet foreach (var i in confSettings) content = content + $"{i.Key} = {i.Value}\r\n"; - File.WriteAllText(filePath, content); + return content; } private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e) @@ -236,6 +209,11 @@ namespace mpvnet Process.Start(Path.GetDirectoryName(mp.ConfPath)); } + private void PreviewTextBlock_MouseUp(object sender, MouseButtonEventArgs e) + { + Msg.Show("mpv.conf Preview", GetContent(mp.ConfPath, Conf, SettingsDefinitions)); + } + private void ShowManualTextBlock_MouseUp(object sender, MouseButtonEventArgs e) { Process.Start("https://mpv.io/manual/master/");