diff --git a/docs/Changelog.md b/docs/Changelog.md index 39f2b18..d93f3b7 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -8,17 +8,19 @@ - The CS-Script library was replaced with my own C# scripting implementation. - If a player window border is near to a screen border and the window size changes, the player windows sticks to that near screen border location. - Furthermore the `remember-position` option remembers a near screen border - position instead of remembering the window center position. + Furthermore the `remember-window-position` option remembers a near screen + border position instead of remembering the window center position. - High DPI multi monitor fix. - `start-size` option has new options, see config editor and manual. - Improved `script-message mpv.net cycle-audio` OSD info. - The logic for finding the config directory has changed, see manual. -- The native TaskDialog/MessageBox was replaced with the themed VB.NET - implementation of StaxRip. - The dotnet script and extension host was redesigned, existing scripts and extensions must be fixed. All example scripts were updated and a new script delete-current-file.cs was added. +- Fix console not working due to incorrect mpv.conf value generated + (script-opts=console-scale=0). +- Registry usage is not portable and also not popular, so settings + are stored in the file settings.xml now instead of the Registry. 5.4.8.8 Beta (2021-05-09) diff --git a/docs/Manual.md b/docs/Manual.md index a6eae1f..83097f1 100644 --- a/docs/Manual.md +++ b/docs/Manual.md @@ -77,7 +77,7 @@ mpvnet.exe is platform agnostic, users that need x86 have to replace 4 native to #### File Associations -File Associations can be created using the setup or with the context menu under 'Tools > Setup'. +File Associations can be created using the context menu under 'Tools > Setup'. After the file associations were registered, go to the Windows settings under 'Settings > Apps > Default apps' or shell execute `ms-settings:defaultapps` and choose @@ -254,7 +254,7 @@ the window AR is set to 16/9. This avoids a square window for Music with cover art. Default: 1.2 -#### --remember-position=\ +#### --remember-window-position=\ Save the window position on exit. Default: no diff --git a/src/Misc/App.cs b/src/Misc/App.cs index 345a83d..f011fc9 100644 --- a/src/Misc/App.cs +++ b/src/Misc/App.cs @@ -19,7 +19,7 @@ namespace mpvnet public static string LightTheme { get; set; } = "light"; public static string StartSize { get; set; } = "height-session"; - public static bool RememberPosition { get; set; } + public static bool RememberWindowPosition { get; set; } public static bool DebugMode { get; set; } public static bool IsStartedFromTerminal { get; } = Environment.GetEnvironmentVariable("_started_from_console") == "yes"; public static bool RememberVolume { get; set; } = true; @@ -39,6 +39,17 @@ namespace mpvnet get => (DarkMode == "system" && Sys.IsDarkTheme) || DarkMode == "always"; } + static AppSettings _Settings; + + public static AppSettings Settings { + get { + if (_Settings == null) + _Settings = SettingsManager.Load(); + + return _Settings; + } + } + public static void Init() { string dummy = Core.ConfigFolder; @@ -132,18 +143,17 @@ namespace mpvnet { if (RememberVolume) { - Core.set_property_int("volume", RegistryHelp.GetInt("volume", 70)); - Core.set_property_string("mute", RegistryHelp.GetString("mute", "no")); + Core.set_property_int("volume", Settings.Volume); + Core.set_property_string("mute", Settings.Mute); } } static void Shutdown() { - if (RememberVolume) - { - RegistryHelp.SetInt("volume", Core.get_property_int("volume")); - RegistryHelp.SetString("mute", Core.get_property_string("mute")); - } + Settings.Volume = Core.get_property_int("volume"); + Settings.Mute = Core.get_property_string("mute"); + + SettingsManager.Save(Settings); } static Dictionary _Conf; @@ -167,7 +177,7 @@ namespace mpvnet { switch (name) { - case "remember-position": RememberPosition = value == "yes"; return true; + case "remember-window-position": RememberWindowPosition = value == "yes"; return true; case "debug-mode": DebugMode = value == "yes"; return true; case "remember-volume": RememberVolume = value == "yes"; return true; case "queue": Queue = value == "yes"; return true; @@ -190,23 +200,5 @@ namespace mpvnet return false; } } - - public static void ShowSetup() - { - int value = RegistryHelp.GetInt("location: " + Folder.Startup); - - if (value != 1) - { - if (Msg.ShowQuestion("Would you like to setup mpv.net?", - "The setup allows to create a start menu shortcut, file associations and " + - "adding mpv.net to the Path environment variable.") == DialogResult.OK) - - Commands.Execute("show-setup-dialog"); - else - Msg.ShowInfo("The setup dialog can be found at:\n\nContext Menu > Tools > Setup"); - - RegistryHelp.SetInt("location: " + Folder.Startup, 1); - } - } } } diff --git a/src/mpv/CorePlayer.cs b/src/Misc/CorePlayer.cs similarity index 100% rename from src/mpv/CorePlayer.cs rename to src/Misc/CorePlayer.cs diff --git a/src/Misc/Program.cs b/src/Misc/Program.cs index 9b09d8d..37c4a47 100644 --- a/src/Misc/Program.cs +++ b/src/Misc/Program.cs @@ -6,8 +6,6 @@ using System.Collections.Generic; using System.Threading; using System.Diagnostics; -using static mpvnet.Global; - namespace mpvnet { static class Program @@ -23,9 +21,6 @@ namespace mpvnet if (App.IsStartedFromTerminal) Native.AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/); - if (Core.ConfigFolder == "") - return; - string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray(); if (args.Length >= 2 && args[0] == "--reg-file-assoc") diff --git a/src/Misc/Settings.cs b/src/Misc/Settings.cs new file mode 100644 index 0000000..57d9b76 --- /dev/null +++ b/src/Misc/Settings.cs @@ -0,0 +1,56 @@ + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Text; +using System.Xml.Serialization; +using System.Xml; + +using static mpvnet.Global; + +namespace mpvnet +{ + [Serializable()] + public class AppSettings + { + public int LastUpdateCheck; + public int Volume = 70; + public List RecentFiles = new List(); + public Point WindowLocation; + public Point WindowPosition; + public Size WindowSize; + public string ConfigEditorSearch = ""; + public string Mute = "no"; + public string UpdateCheckVersion = ""; + } + + class SettingsManager + { + public static string SettingsFile { + get => Core.ConfigFolder + "settings.xml"; + } + + public static AppSettings Load() + { + if (!File.Exists(SettingsFile)) + return new AppSettings(); + + XmlSerializer serializer = new XmlSerializer(typeof(AppSettings)); + + using (FileStream fs = new FileStream(SettingsFile, FileMode.Open)) + return (AppSettings)serializer.Deserialize(fs); + } + + public static void Save(object obj) + { + using (XmlTextWriter writer = new XmlTextWriter(SettingsFile, Encoding.UTF8)) + { + writer.Formatting = Formatting.Indented; + writer.Indentation = 4; + XmlSerializer serializer = new XmlSerializer(obj.GetType()); + serializer.Serialize(writer, obj); + } + } + } +} diff --git a/src/Misc/UpdateCheck.cs b/src/Misc/UpdateCheck.cs index f04a7ed..2fa0bd5 100644 --- a/src/Misc/UpdateCheck.cs +++ b/src/Misc/UpdateCheck.cs @@ -15,9 +15,7 @@ namespace mpvnet { public static void DailyCheck() { - if (App.UpdateCheck && RegistryHelp.GetInt("last-update-check") - != DateTime.Now.DayOfYear) - + if (App.UpdateCheck && App.Settings.LastUpdateCheck != DateTime.Now.DayOfYear) CheckOnline(); } @@ -27,7 +25,7 @@ namespace mpvnet { using (HttpClient client = new HttpClient()) { - RegistryHelp.SetValue("last-update-check", DateTime.Now.DayOfYear); + App.Settings.LastUpdateCheck = DateTime.Now.DayOfYear; client.DefaultRequestHeaders.Add("User-Agent", "mpv.net"); var response = await client.GetAsync("https://api.github.com/repos/stax76/mpv.net/releases/latest"); response.EnsureSuccessStatusCode(); @@ -51,8 +49,8 @@ namespace mpvnet return; } - if ((RegistryHelp.GetString("update-check-version") - != onlineVersion.ToString() || showUpToDateMessage) && Msg.ShowQuestion( + if ((App.Settings.UpdateCheckVersion != onlineVersion.ToString() || + showUpToDateMessage) && Msg.ShowQuestion( $"New version {onlineVersion} is available, update now?") == DialogResult.OK) { string url = $"https://github.com/stax76/mpv.net/releases/download/{onlineVersion}/mpv.net-{onlineVersion}-portable.zip"; @@ -73,7 +71,7 @@ namespace mpvnet Core.command("quit"); } - RegistryHelp.SetValue("update-check-version", onlineVersion.ToString()); + App.Settings.UpdateCheckVersion = onlineVersion.ToString(); } } catch (Exception ex) diff --git a/src/mpv/libmpv.cs b/src/Native/libmpv.cs similarity index 100% rename from src/mpv/libmpv.cs rename to src/Native/libmpv.cs diff --git a/src/Resources/editor.toml.txt b/src/Resources/editor.toml.txt index fbe25b1..d025f67 100644 --- a/src/Resources/editor.toml.txt +++ b/src/Resources/editor.toml.txt @@ -362,7 +362,7 @@ filter = "Screen" help = " Minimum aspect ratio, if the AR is smaller than the defined value then the window AR is set to 16/9. This avoids a square window for Music with cover art. Default: 1.2 (mpv.net specific setting)" [[settings]] -name = "remember-position" +name = "remember-window-position" file = "mpvnet" default = "no" filter = "Screen" diff --git a/src/WPF/ConfWindow.xaml.cs b/src/WPF/ConfWindow.xaml.cs index f570155..8fff3e3 100644 --- a/src/WPF/ConfWindow.xaml.cs +++ b/src/WPF/ConfWindow.xaml.cs @@ -31,7 +31,7 @@ namespace mpvnet LoadConf(App.ConfPath); LoadSettings(); InitialContent = GetCompareString(); - SearchControl.Text = RegistryHelp.GetString("config-editor-search"); + SearchControl.Text = App.Settings.ConfigEditorSearch; FilterListBox.SelectedItem = SearchControl.Text.TrimEnd(':'); } @@ -68,7 +68,7 @@ namespace mpvnet protected override void OnClosed(EventArgs e) { base.OnClosed(e); - RegistryHelp.SetValue("config-editor-search", SearchControl.Text); + App.Settings.ConfigEditorSearch = SearchControl.Text; if (InitialContent == GetCompareString()) return; diff --git a/src/WinForms/MainForm.cs b/src/WinForms/MainForm.cs index 7efe1fb..0ca16e5 100644 --- a/src/WinForms/MainForm.cs +++ b/src/WinForms/MainForm.cs @@ -28,7 +28,6 @@ namespace mpvnet int ShownTickCount; Taskbar Taskbar; - List RecentFiles; bool WasMaximized; public MainForm() @@ -38,9 +37,6 @@ namespace mpvnet try { - object recent = RegistryHelp.GetValue("recent"); - RecentFiles = recent is string[] r ? new List(r) : new List(); - Instance = this; Hwnd = Handle; Core.Init(); @@ -100,21 +96,19 @@ namespace mpvnet if (!Core.Border) FormBorderStyle = FormBorderStyle.None; - int posX = RegistryHelp.GetInt("position-x"); - int posY = RegistryHelp.GetInt("position-y"); + Point pos = App.Settings.WindowPosition; - if ((posX != 0 || posY != 0) && App.RememberPosition) + if ((pos.X != 0 || pos.Y != 0) && App.RememberWindowPosition) { - Left = posX - Width / 2; - Top = posY - Height / 2; + Left = pos.X - Width / 2; + Top = pos.Y - Height / 2; - int horizontal = RegistryHelp.GetInt("location-horizontal"); - int vertical = RegistryHelp.GetInt("location-vertical"); + Point location = App.Settings.WindowLocation; - if (horizontal == -1) Left = posX; - if (horizontal == 1) Left = posX - Width; - if (vertical == -1) Top = posY; - if (vertical == 1) Top = posY - Height; + if (location.X == -1) Left = pos.X; + if (location.X == 1) Left = pos.X - Width; + if (location.Y == -1) Top = pos.Y; + if (location.Y == 1) Top = pos.Y - Height; } if (Core.WindowMaximized) @@ -273,12 +267,12 @@ namespace mpvnet { recent.DropDownItems.Clear(); - foreach (string path in RecentFiles) + foreach (string path in App.Settings.RecentFiles) MenuItem.Add(recent.DropDownItems, path, () => Core.LoadFiles(new[] { path }, true, Control.ModifierKeys.HasFlag(Keys.Control))); recent.DropDownItems.Add(new ToolStripSeparator()); MenuItem mi = new MenuItem("Clear List"); - mi.Action = () => RecentFiles.Clear(); + mi.Action = () => App.Settings.RecentFiles.Clear(); recent.DropDownItems.Add(mi); } @@ -377,12 +371,11 @@ namespace mpvnet } else { - int savedHeight = RegistryHelp.GetInt("window-height"); - int savedWidth = RegistryHelp.GetInt("window-width"); + Size windowSize = App.Settings.WindowSize; - if (App.StartSize == "height-always" && savedHeight != 0) + if (App.StartSize == "height-always" && windowSize.Height != 0) { - height = savedHeight; + height = windowSize.Height; width = height * videoSize.Width / videoSize.Height; } else if (App.StartSize == "height-session") @@ -390,9 +383,9 @@ namespace mpvnet height = autoFitHeight; width = height * videoSize.Width / videoSize.Height; } - if (App.StartSize == "width-always" && savedHeight != 0) + if (App.StartSize == "width-always" && windowSize.Height != 0) { - width = savedWidth; + width = windowSize.Width; height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width); } else if (App.StartSize == "width-session") @@ -400,10 +393,10 @@ namespace mpvnet width = autoFitHeight / 9 * 16; height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width); } - else if (App.StartSize == "always" && savedHeight != 0) + else if (App.StartSize == "always" && windowSize.Height != 0) { - height = savedHeight; - width = savedWidth; + height = windowSize.Height; + width = windowSize.Width; } Core.WasInitialSizeSet = true; @@ -495,7 +488,7 @@ namespace mpvnet Rectangle workingArea = screen.WorkingArea; Rectangle rect = new Rectangle(Left - workingArea.X, Top - workingArea.Y, Width, Height); - if (workingArea.Width / (float)Width < 1.2) + if (workingArea.Width / (float)Width < 1.1) return 0; if (rect.X * 3 < workingArea.Width - rect.Right) @@ -512,7 +505,7 @@ namespace mpvnet Rectangle workingArea = screen.WorkingArea; Rectangle rect = new Rectangle(Left - workingArea.X, Top - workingArea.Y, Width, Height); - if (workingArea.Height / (float)Height < 1.2) + if (workingArea.Height / (float)Height < 1.1) return 0; if (rect.Y * 3 < workingArea.Height - rect.Bottom) @@ -619,13 +612,13 @@ namespace mpvnet UpdateProgressBar(); })); - if (RecentFiles.Contains(path)) - RecentFiles.Remove(path); + if (App.Settings.RecentFiles.Contains(path)) + App.Settings.RecentFiles.Remove(path); - RecentFiles.Insert(0, path); + App.Settings.RecentFiles.Insert(0, path); - while (RecentFiles.Count > App.RecentCount) - RecentFiles.RemoveAt(App.RecentCount); + while (App.Settings.RecentFiles.Count > App.RecentCount) + App.Settings.RecentFiles.RemoveAt(App.RecentCount); } void SetTitle() => BeginInvoke(new Action(() => Text = Core.expand(Title))); @@ -635,32 +628,25 @@ namespace mpvnet if (WindowState == FormWindowState.Normal) { SavePosition(); - - RegistryHelp.SetInt("window-width", ClientSize.Width); - RegistryHelp.SetInt("window-height", ClientSize.Height); + App.Settings.WindowSize = ClientSize; } } void SavePosition() { - int posX = Left + Width / 2; - int posY = Top + Height / 2; - + Point pos = new Point(Left + Width / 2, Top + Height / 2); Screen screen = Screen.FromControl(this); int x = GetHorizontalLocation(screen); int y = GetVerticalLocation(screen); - if (x == -1) posX = Left; - if (x == 1) posX = Left + Width; - if (y == -1) posY = Top; - if (y == 1) posY = Top + Height; + if (x == -1) pos.X = Left; + if (x == 1) pos.X = Left + Width; + if (y == -1) pos.Y = Top; + if (y == 1) pos.Y = Top + Height; - RegistryHelp.SetInt("position-x", posX); - RegistryHelp.SetInt("position-y", posY); - - RegistryHelp.SetInt("location-horizontal", x); - RegistryHelp.SetInt("location-vertical", y); + App.Settings.WindowPosition = pos; + App.Settings.WindowLocation = new Point(x, y); } protected override CreateParams CreateParams { @@ -952,7 +938,6 @@ namespace mpvnet App.RunTask(() => App.Extension = new Extension()); CSharpScriptHost.ExecuteScriptsInFolder(Core.ConfigFolder + "scripts-cs"); ShownTickCount = Environment.TickCount; - App.ShowSetup(); //if (Debugger.IsAttached) //{ @@ -1005,7 +990,6 @@ namespace mpvnet { base.OnFormClosing(e); SaveWindowProperties(); - RegistryHelp.SetValue("recent", RecentFiles.ToArray()); if (Core.IsQuitNeeded) Core.commandv("quit"); diff --git a/src/WinForms/Menu.cs b/src/WinForms/Menu.cs index ca5aac0..06e5866 100644 --- a/src/WinForms/Menu.cs +++ b/src/WinForms/Menu.cs @@ -189,6 +189,7 @@ public class ToolStripRendererEx : ToolStripSystemRenderer e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; rect = new Rectangle(rect.X + 2, rect.Y, rect.Width - 4, rect.Height - 1); rect.Inflate(-1, -1); + using (SolidBrush b = new SolidBrush(SelectionColor)) e.Graphics.FillRectangle(b, rect); } @@ -205,12 +206,12 @@ public class ToolStripRendererEx : ToolStripSystemRenderer float y3 = e.Item.Height * 0.75f; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; - using (Brush b = new SolidBrush(ForegroundColor)) + using (Brush brush = new SolidBrush(ForegroundColor)) { - using (Pen p = new Pen(b, Control.DefaultFont.Height / 20f)) + using (Pen pen = new Pen(brush, Control.DefaultFont.Height / 20f)) { - e.Graphics.DrawLine(p, x1, y1, x2, y2); - e.Graphics.DrawLine(p, x2, y2, x3, y3); + e.Graphics.DrawLine(pen, x1, y1, x2, y2); + e.Graphics.DrawLine(pen, x2, y2, x3, y3); } } } @@ -221,7 +222,6 @@ public class ToolStripRendererEx : ToolStripSystemRenderer return; MenuItem item = e.Item as MenuItem; - e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; if (!item.Checked) @@ -250,6 +250,7 @@ public class ToolStripRendererEx : ToolStripSystemRenderer int top = e.Item.Height / 2; top -= 1; int offset = Convert.ToInt32(e.Item.Font.Height * 0.7); + using (Pen p = new Pen(BorderColor)) e.Graphics.DrawLine(p, new Point(offset, top), @@ -298,6 +299,7 @@ public struct HSLColor value = 0; else if (value > 1) value = 1; + return value; } @@ -388,9 +390,9 @@ public struct HSLColor public void SetRGB(int red, int green, int blue) { - HSLColor hc = HSLColor.Convert(Color.FromArgb(red, green, blue)); + HSLColor hc = Convert(Color.FromArgb(red, green, blue)); _Hue = hc._Hue; _Saturation = hc._Saturation; _Luminosity = hc._Luminosity; } -} \ No newline at end of file +} diff --git a/src/mpv.net.csproj b/src/mpv.net.csproj index 388a4ef..c89bab6 100644 --- a/src/mpv.net.csproj +++ b/src/mpv.net.csproj @@ -114,6 +114,7 @@ + @@ -141,7 +142,7 @@ True Resources.resx - + Form @@ -149,7 +150,7 @@ MainForm.cs - +