diff --git a/Changelog.md b/Changelog.md index 3fd0c0e..9f19edc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,4 @@ -### 4.7.6.1 +### 4.7.6.3 - fix for mouse button back/forward causing freeze - fix for WM_APPCOMMAND not working but crashing in input editor learn window @@ -7,6 +7,7 @@ the theme color from the Registry on Win 7 - new option dark-color was added to overwrite the OS theme color used in dark mode, find the option under 'General' - new option light-color was added to overwrite the OS theme color used in non dark mode, find the option under 'General' +- it's now possible to use a custom folder as config folder ### 4.7.3 diff --git a/Manual.md b/Manual.md index b45b669..3686177 100644 --- a/Manual.md +++ b/Manual.md @@ -822,25 +822,23 @@ mpvnet --mute=yes ## Settings -mpv.net is able to share the settings with mpv and mpv.net uses the same logic to decide from where the settings are loaded. The default location is: - -```Text -C:\Users\%username%\AppData\Roaming\mpv\mpv.conf -``` +mpv.net is able to share the settings with mpv. If a directory named portable_config next to the mpvnet.exe exists, all config will be loaded from this directory only. ```Text -\portable_config\mpv.conf +\portable_config\ ``` -In case there isn't any config folder mpv.net asks where to create it. If no mpv.conf file exists mpv.net generates it with the following defaults: +On first start if no portable config folder exists mpv.net asks which folder should be used as config folder. + +If no mpv.conf file exists mpv.net generates it with the following defaults: -Config files located in the same directory as mpvnet.exe are loaded with lower priority. Some config files are loaded only once, which means that e.g. of 2 input.conf files located in two config directories, only the one from the directory with higher priority will be loaded. - The key bindings and the context menu definitions are stored in the input.conf file, if it's missing mpv.net generates it with the following defaults: - \ No newline at end of file + + +mpv.net supports almost all mpv settings and features, [limitations are listed in the wiki](https://github.com/stax76/mpv.net/wiki/Limitations). \ No newline at end of file diff --git a/README.md b/README.md index 6daa3ee..ffe39b8 100644 --- a/README.md +++ b/README.md @@ -136,24 +136,20 @@ input.conf defines mpv's key and mouse bindings and mpv.net uses comments to def ### Settings -mpv.net is able to share the settings with mpv and mpv.net uses the same logic to decide from where the settings are loaded. The default location is: - -```Text -C:\Users\%username%\AppData\Roaming\mpv\mpv.conf -``` +mpv.net is able to share the settings with mpv. If a directory named portable_config next to the mpvnet.exe exists, all config will be loaded from this directory only. ```Text -\portable_config\mpv.conf +\portable_config\ ``` -In case there isn't any config folder mpv.net asks where to create it. If no mpv.conf file exists mpv.net generates it with the following defaults: +On first start if no portable config folder exists mpv.net asks which folder should be used as config folder. + +If no mpv.conf file exists mpv.net generates it with the following defaults: -Config files located in the same directory as mpvnet.exe are loaded with lower priority. Some config files are loaded only once, which means that e.g. of 2 input.conf files located in two config directories, only the one from the directory with higher priority will be loaded. - The key bindings and the context menu definitions are stored in the input.conf file, if it's missing mpv.net generates it with the following defaults: diff --git a/addons/CSScriptAddon/CSScriptAddon.vb b/addons/CSScriptAddon/CSScriptAddon.vb index 2a1b909..b2eb93c 100644 --- a/addons/CSScriptAddon/CSScriptAddon.vb +++ b/addons/CSScriptAddon/CSScriptAddon.vb @@ -16,8 +16,8 @@ Public Class CSScriptAddon Sub New() Dim scriptFiles As New List(Of String) - If Directory.Exists(mp.ConfFolder + "scripts") Then - scriptFiles.AddRange(Directory.GetFiles(mp.ConfFolder + "scripts", "*.cs")) + If Directory.Exists(mp.ConfigFolder + "scripts") Then + scriptFiles.AddRange(Directory.GetFiles(mp.ConfigFolder + "scripts", "*.cs")) End If If Directory.Exists(Application.StartupPath + "\scripts") Then diff --git a/mpv.net/DynamicGUI/StringSettingControl.xaml.cs b/mpv.net/DynamicGUI/StringSettingControl.xaml.cs index 24cbe4a..6ba3570 100644 --- a/mpv.net/DynamicGUI/StringSettingControl.xaml.cs +++ b/mpv.net/DynamicGUI/StringSettingControl.xaml.cs @@ -56,7 +56,7 @@ namespace DynamicGUI { d.Description = "Choose a folder."; d.SelectedPath = ValueTextBox.Text; - if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) + if (d.ShowDialog() == WinForms.DialogResult.OK) ValueTextBox.Text = d.SelectedPath; } break; diff --git a/mpv.net/Misc/Addon.cs b/mpv.net/Misc/Addon.cs index dfe75e0..38ef321 100644 --- a/mpv.net/Misc/Addon.cs +++ b/mpv.net/Misc/Addon.cs @@ -26,7 +26,7 @@ namespace mpvnet foreach (string i in Directory.GetDirectories(dir)) catalog.Catalogs.Add(new DirectoryCatalog(i, "*Addon.dll")); - dir = mp.ConfFolder + "\\Addons"; + dir = mp.ConfigFolder + "\\Addons"; if (Directory.Exists(dir)) foreach (string i in Directory.GetDirectories(dir)) diff --git a/mpv.net/Misc/Command.cs b/mpv.net/Misc/Command.cs index 25de5bd..09afded 100644 --- a/mpv.net/Misc/Command.cs +++ b/mpv.net/Misc/Command.cs @@ -28,7 +28,7 @@ namespace mpvnet case "show-about": ShowDialog(typeof(AboutWindow)); break; case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break; case "show-input-editor": ShowDialog(typeof(InputWindow)); break; - case "open-conf-folder": Process.Start(mp.ConfFolder); break; + case "open-conf-folder": Process.Start(mp.ConfigFolder); break; case "open-files": OpenFiles(args); break; case "shell-execute": Process.Start(args[0]); break; case "show-info": ShowInfo(); break; @@ -68,7 +68,7 @@ namespace mpvnet public static void ShowHistory() { - var fp = mp.ConfFolder + "history.txt"; + var fp = mp.ConfigFolder + "history.txt"; if (File.Exists(fp)) Process.Start(fp); diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index 1b01adc..0fdb79f 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -18,8 +18,8 @@ namespace mpvnet { public class App { - public static string ConfFilePath { get; } = mp.ConfFolder + "\\mpvnet.conf"; public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName; + public static string ConfFilePath { 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; } @@ -41,7 +41,7 @@ namespace mpvnet public static void Init() { - string dummy = mp.ConfFolder; + string dummy = mp.ConfigFolder; var dummy2 = mp.Conf; foreach (var i in Conf) @@ -51,7 +51,7 @@ namespace mpvnet { try { - string filePath = mp.ConfFolder + "\\mpvnet-debug.log"; + string filePath = mp.ConfigFolder + "\\mpvnet-debug.log"; if (File.Exists(filePath)) File.Delete(filePath); Trace.Listeners.Add(new TextWriterTraceListener(filePath)); Trace.AutoFlush = true; diff --git a/mpv.net/Misc/Program.cs b/mpv.net/Misc/Program.cs index 36e92d9..0ab8508 100644 --- a/mpv.net/Misc/Program.cs +++ b/mpv.net/Misc/Program.cs @@ -15,6 +15,9 @@ namespace mpvnet { try { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray(); if (args.Length == 2 && args[0] == "--reg-file-assoc") @@ -61,8 +64,6 @@ namespace mpvnet return; } - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); mutex.Dispose(); } diff --git a/mpv.net/Properties/AssemblyInfo.cs b/mpv.net/Properties/AssemblyInfo.cs index 1dac3cf..47b8d0d 100644 --- a/mpv.net/Properties/AssemblyInfo.cs +++ b/mpv.net/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.7.6.1")] -[assembly: AssemblyFileVersion("4.7.6.1")] +[assembly: AssemblyVersion("4.7.6.3")] +[assembly: AssemblyFileVersion("4.7.6.3")] diff --git a/mpv.net/Resources/inputConf.txt b/mpv.net/Resources/inputConf.txt index 047388b..5ebbc12 100644 --- a/mpv.net/Resources/inputConf.txt +++ b/mpv.net/Resources/inputConf.txt @@ -166,23 +166,25 @@ Esc quit #menu: Exit Q quit-watch-later #menu: Exit Watch Later - > playlist-next - < playlist-prev - Power quit - Play cycle pause - Pause cycle pause - PlayPause cycle pause - Stop stop - Forward seek 60 - Rewind seek -60 - Mute cycle mute - Volume_Up add volume 10 - Volume_Down add volume -10 - Wheel_Up add volume 10 - Wheel_Down add volume -10 - Prev playlist-prev - Next playlist-next + Power quit + Play cycle pause + Pause cycle pause + PlayPause cycle pause + Stop stop + Forward seek 60 + Rewind seek -60 + Mute cycle mute + Volume_Up add volume 10 + Volume_Down add volume -10 + Wheel_Up add volume 10 + Wheel_Down add volume -10 + Prev playlist-prev + Next playlist-next + MBTN_Forward playlist-next + MBTN_Back playlist-prev + > playlist-next + < playlist-prev Ctrl+Wheel_Up no-osd seek 7 Ctrl+Wheel_Down no-osd seek -7 - MBTN_LEFT_DBL cycle fullscreen - KP_ENTER cycle fullscreen \ No newline at end of file + MBTN_Left_DBL cycle fullscreen + KP_Enter cycle fullscreen \ No newline at end of file diff --git a/mpv.net/WPF/LearnWindow.xaml.cs b/mpv.net/WPF/LearnWindow.xaml.cs index dbd72cd..5506e29 100644 --- a/mpv.net/WPF/LearnWindow.xaml.cs +++ b/mpv.net/WPF/LearnWindow.xaml.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.InteropServices; -using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Interop; @@ -61,59 +60,59 @@ namespace mpvnet case WF.Keys.NumPad9: text = "KP" + e.KeyCode.ToString()[6].ToString(); break; case WF.Keys.Space: - text = "Space"; break; + text = "SPACE"; break; case WF.Keys.Enter: - text = "Enter"; break; + text = "ENTER"; break; case WF.Keys.Tab: - text = "Tab"; break; + text = "TAB"; break; case WF.Keys.Back: text = "BS"; break; case WF.Keys.Delete: - text = "Del"; break; + text = "DEL"; break; case WF.Keys.Insert: - text = "Ins"; break; + text = "INS"; break; case WF.Keys.Home: - text = "Home"; break; + text = "HOME"; break; case WF.Keys.End: - text = "End"; break; + text = "END"; break; case WF.Keys.PageUp: text = "PGUP"; break; case WF.Keys.PageDown: text = "PGDWN"; break; case WF.Keys.Escape: - text = "Esc"; break; + text = "ESC"; break; case WF.Keys.PrintScreen: - text = "Print"; break; + text = "PRINT"; break; case WF.Keys.Play: - text = "Play"; break; + text = "PLAY"; break; case WF.Keys.Pause: - text = "Pause"; break; + text = "PAUSE"; break; case WF.Keys.MediaPlayPause: - text = "PlayPause"; break; + text = "PLAYPAUSE"; break; case WF.Keys.MediaStop: - text = "Stop"; break; + text = "STOP"; break; case WF.Keys.MediaNextTrack: - text = "Next"; break; + text = "NEXT"; break; case WF.Keys.MediaPreviousTrack: - text = "Prev"; break; + text = "PREV"; break; case WF.Keys.VolumeUp: - text = "Volume_Up"; break; + text = "VOLUME_UP"; break; case WF.Keys.VolumeDown: - text = "Volume_Down"; break; + text = "VOLUME_DOWN"; break; case WF.Keys.VolumeMute: - text = "Mute"; break; + text = "MUTE"; break; case WF.Keys.BrowserHome: - text = "Homepage"; break; + text = "HOMEPAGE"; break; case WF.Keys.LaunchMail: - text = "Mail"; break; + text = "MAIL"; break; case WF.Keys.BrowserFavorites: - text = "Favorites"; break; + text = "FAVORITES"; break; case WF.Keys.BrowserSearch: - text = "Search"; break; + text = "SEARCH"; break; case WF.Keys.Sleep: - text = "Sleep"; break; + text = "SLEEP"; break; case WF.Keys.Cancel: - text = "Cancel"; break; + text = "CANCEL"; break; } bool shiftWasHandled = false; @@ -138,11 +137,14 @@ namespace mpvnet SetKey(text); } + DateTime LastKeyUp; + void SetKey(string key) { NewKey = key; MenuTextBlock.Text = InputItem.Path; KeyTextBlock.Text = key; + LastKeyUp = DateTime.Now; } [DllImport("user32.dll")] @@ -191,50 +193,62 @@ namespace mpvnet switch (value) { - case AppCommand.MEDIA_CHANNEL_DOWN: - SetKey("Channel_Down"); + case AppCommand.APPCOMMAND_MEDIA_CHANNEL_DOWN: + SetKey("CHANNEL_DOWN"); break; - case AppCommand.MEDIA_CHANNEL_UP: - SetKey("Channel_Up"); + case AppCommand.APPCOMMAND_MEDIA_CHANNEL_UP: + SetKey("CHANNEL_UP"); break; - case AppCommand.MEDIA_FAST_FORWARD: - SetKey("Forward"); + case AppCommand.APPCOMMAND_MEDIA_FAST_FORWARD: + SetKey("FORWARD"); break; - case AppCommand.MEDIA_REWIND: - SetKey("Rewind"); + case AppCommand.APPCOMMAND_MEDIA_REWIND: + SetKey("REWIND"); break; - case AppCommand.MEDIA_PAUSE: - SetKey("Pause"); + case AppCommand.APPCOMMAND_MEDIA_PAUSE: + SetKey("PAUSE"); break; - case AppCommand.MEDIA_PLAY: - SetKey("Play"); + case AppCommand.APPCOMMAND_MEDIA_PLAY: + SetKey("PLAY"); break; - case AppCommand.MEDIA_PLAY_PAUSE: - SetKey("PlayPause"); + case AppCommand.APPCOMMAND_MEDIA_PLAY_PAUSE: + SetKey("PLAYPAUSE"); break; - case AppCommand.MEDIA_NEXTTRACK: - SetKey("Next"); + case AppCommand.APPCOMMAND_MEDIA_NEXTTRACK: + SetKey("NEXT"); break; - case AppCommand.MEDIA_PREVIOUSTRACK: - SetKey("Prev"); + case AppCommand.APPCOMMAND_MEDIA_PREVIOUSTRACK: + SetKey("PREV"); break; - case AppCommand.MEDIA_RECORD: - SetKey("Record"); + case AppCommand.APPCOMMAND_MEDIA_RECORD: + SetKey("RECORD"); break; - case AppCommand.MEDIA_STOP: - SetKey("Stop"); + case AppCommand.APPCOMMAND_MEDIA_STOP: + SetKey("STOP"); break; - case AppCommand.VolumeUp: - SetKey("Volume_Up"); + case AppCommand.APPCOMMAND_VOLUME_UP: + SetKey("VOLUME_UP"); break; - case AppCommand.VolumeDown: - SetKey("Volume_Down"); + case AppCommand.APPCOMMAND_VOLUME_DOWN: + SetKey("VOLUME_DOWN"); break; - case AppCommand.VolumeMute: - SetKey("Mute"); + case AppCommand.APPCOMMAND_VOLUME_MUTE: + SetKey("MUTE"); break; - default: - Msg.ShowError($"AppCommand {value} not supported,\nplease contact support."); + case AppCommand.APPCOMMAND_BROWSER_HOME: + SetKey("HOMEPAGE"); + break; + case AppCommand.APPCOMMAND_LAUNCH_MAIL: + SetKey("MAIL"); + break; + case AppCommand.APPCOMMAND_BROWSER_FAVORITES: + SetKey("FAVORITES"); + break; + case AppCommand.APPCOMMAND_BROWSER_SEARCH: + SetKey("SEARCH"); + break; + case AppCommand.APPCOMMAND_PRINT: + SetKey("PRINT"); break; } } @@ -242,20 +256,58 @@ namespace mpvnet internal enum AppCommand { - MEDIA_CHANNEL_DOWN = 52, - MEDIA_CHANNEL_UP = 51, - MEDIA_FAST_FORWARD = 49, - MEDIA_NEXTTRACK = 11, - MEDIA_PAUSE = 47, - MEDIA_PLAY = 46, - MEDIA_PLAY_PAUSE = 14, - MEDIA_PREVIOUSTRACK = 12, - MEDIA_RECORD = 48, - MEDIA_REWIND = 50, - MEDIA_STOP = 13, - VolumeMute = 8, - VolumeDown = 9, - VolumeUp = 10 + APPCOMMAND_BASS_BOOST = 20, + APPCOMMAND_BASS_DOWN = 19, + APPCOMMAND_BASS_UP = 21, + APPCOMMAND_BROWSER_BACKWARD = 1, + APPCOMMAND_BROWSER_FAVORITES = 6, + APPCOMMAND_BROWSER_FORWARD = 2, + APPCOMMAND_BROWSER_HOME = 7, + APPCOMMAND_BROWSER_REFRESH = 3, + APPCOMMAND_BROWSER_SEARCH = 5, + APPCOMMAND_BROWSER_STOP = 4, + APPCOMMAND_CLOSE = 31, + APPCOMMAND_COPY = 36, + APPCOMMAND_CORRECTION_LIST = 45, + APPCOMMAND_CUT = 37, + APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE = 43, + APPCOMMAND_FIND = 28, + APPCOMMAND_FORWARD_MAIL = 40, + APPCOMMAND_HELP = 27, + APPCOMMAND_LAUNCH_APP1 = 17, + APPCOMMAND_LAUNCH_APP2 = 18, + APPCOMMAND_LAUNCH_MAIL = 15, + APPCOMMAND_LAUNCH_MEDIA_SELECT = 16, + APPCOMMAND_MEDIA_CHANNEL_DOWN = 52, + APPCOMMAND_MEDIA_CHANNEL_UP = 51, + APPCOMMAND_MEDIA_FAST_FORWARD = 49, + APPCOMMAND_MEDIA_NEXTTRACK = 11, + APPCOMMAND_MEDIA_PAUSE = 47, + APPCOMMAND_MEDIA_PLAY = 46, + APPCOMMAND_MEDIA_PLAY_PAUSE = 14, + APPCOMMAND_MEDIA_PREVIOUSTRACK = 12, + APPCOMMAND_MEDIA_RECORD = 48, + APPCOMMAND_MEDIA_REWIND = 50, + APPCOMMAND_MEDIA_STOP = 13, + APPCOMMAND_MIC_ON_OFF_TOGGLE = 44, + APPCOMMAND_MICROPHONE_VOLUME_DOWN = 25, + APPCOMMAND_MICROPHONE_VOLUME_MUTE = 24, + APPCOMMAND_MICROPHONE_VOLUME_UP = 26, + APPCOMMAND_NEW = 29, + APPCOMMAND_OPEN = 30, + APPCOMMAND_PASTE = 38, + APPCOMMAND_PRINT = 33, + APPCOMMAND_REDO = 35, + APPCOMMAND_REPLY_TO_MAIL = 39, + APPCOMMAND_SAVE = 32, + APPCOMMAND_SEND_MAIL = 41, + APPCOMMAND_SPELL_CHECK = 42, + APPCOMMAND_TREBLE_DOWN = 22, + APPCOMMAND_TREBLE_UP = 23, + APPCOMMAND_UNDO = 34, + APPCOMMAND_VOLUME_DOWN = 9, + APPCOMMAND_VOLUME_MUTE = 8, + APPCOMMAND_VOLUME_UP = 10 } [DllImport("user32.dll", CharSet = CharSet.Auto)] diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index a56a628..a0e0b39 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -80,8 +80,8 @@ namespace mpvnet mp.VideoSizeChanged += VideoSizeChanged; mp.FileLoaded += FileLoaded; mp.Idle += Idle; - mp.VideoSizeAutoResetEvent.WaitOne(3000); - if (Height < FontHeight * 3) SetFormPosAndSize(); + mp.VideoSizeAutoResetEvent.WaitOne(1500); + if (Height < FontHeight * 4) SetFormPosAndSize(); mp.observe_property_bool("fullscreen", PropChangeFullscreen); mp.observe_property_bool("ontop", PropChangeOnTop); mp.observe_property_bool("border", PropChangeBorder); @@ -246,7 +246,7 @@ namespace mpvnet if (mp.VideoSize.Height == 0 || mp.VideoSize.Width == 0 || mp.VideoSize.Width / (float)mp.VideoSize.Height < 1.3) - mp.VideoSize = new Size((int)(autoFitHeight * 1.7), autoFitHeight); + mp.VideoSize = new Size((int)(autoFitHeight * (16 / 9.0)), autoFitHeight); Size size = mp.VideoSize; @@ -387,11 +387,14 @@ namespace mpvnet case 0x0202: // WM_LBUTTONUP case 0x0207: // WM_MBUTTONDOWN case 0x0208: // WM_MBUTTONUP + case 0x020b: // WM_XBUTTONDOWN + case 0x020c: // WM_XBUTTONUP case 0x020A: // WM_MOUSEWHEEL case 0x0100: // WM_KEYDOWN case 0x0101: // WM_KEYUP case 0x0104: // WM_SYSKEYDOWN case 0x0105: // WM_SYSKEYUP + case 0x319: // WM_APPCOMMAND if (mp.WindowHandle != IntPtr.Zero) Native.SendMessage(mp.WindowHandle, m.Msg, m.WParam, m.LParam); break; @@ -405,10 +408,6 @@ namespace mpvnet case 0x2a3: // WM_MOUSELEAVE mp.command_string("mouse 1 1"); // osc won't always auto hide break; - case 0x319: // WM_APPCOMMAND - if (mp.WindowHandle != IntPtr.Zero) - Native.PostMessage(mp.WindowHandle, m.Msg, m.WParam, m.LParam); - break; case 0x203: // Native.WM.LBUTTONDBLCLK { Point pos = PointToClient(Cursor.Position); @@ -567,12 +566,6 @@ namespace mpvnet Native.PostMessage(Handle, 0xA1 /* WM_NCLBUTTONDOWN */, HTCAPTION, IntPtr.Zero); } - if (e.Button == MouseButtons.XButton1) - mp.command_string($"mouse {e.Location.X} {e.Location.Y} 7 single"); - - if (e.Button == MouseButtons.XButton2) - mp.command_string($"mouse {e.Location.X} {e.Location.Y} 8 single"); - if (Width - e.Location.X < 10 && e.Location.Y < 10) mp.commandv("quit"); } diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 1df08b9..44ff18e 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -13,6 +13,8 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using WinForms = System.Windows.Forms; + using static mpvnet.libmpv; using static mpvnet.Native; @@ -66,8 +68,8 @@ namespace mpvnet public static List MediaTracks { get; set; } = new List(); public static List> Chapters { get; set; } = new List>(); - public static string InputConfPath { get; } = ConfFolder + "\\input.conf"; - public static string ConfPath { get; } = ConfFolder + "\\mpv.conf"; + public static string InputConfPath { get; } = ConfigFolder + "\\input.conf"; + public static string ConfPath { get; } = ConfigFolder + "\\mpv.conf"; public static string Sid { get; set; } = ""; public static string Aid { get; set; } = ""; public static string Vid { get; set; } = ""; @@ -86,6 +88,7 @@ namespace mpvnet { LoadLibrary("mpv-1.dll"); Handle = mpv_create(); + set_property_string("config-dir", ConfigFolder); set_property_string("osc", "yes"); set_property_string("config", "yes"); set_property_string("wid", MainForm.Hwnd.ToString()); @@ -115,48 +118,61 @@ namespace mpvnet } } - static string _ConfFolder; + static string _ConfigFolder; - public static string ConfFolder { + public static string ConfigFolder { get { - if (_ConfFolder == null) + if (_ConfigFolder == null) { - string portableFolder = Application.StartupPath + "\\portable_config\\"; - string appdataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\"; - string startupFolder = Application.StartupPath + "\\"; + _ConfigFolder = Application.StartupPath + "\\portable_config\\"; - if (!Directory.Exists(appdataFolder) && !Directory.Exists(portableFolder) && - Sys.IsDirectoryWritable(Application.StartupPath) && - !File.Exists(startupFolder + "mpv.conf")) + if (!Directory.Exists(_ConfigFolder)) + _ConfigFolder = RegHelp.GetString(App.RegPath, "ConfigFolder"); + + if (!Directory.Exists(_ConfigFolder)) { + string portableFolder = Application.StartupPath + "\\portable_config\\"; + string appdataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv.net\\"; + string appdataFolderMpv = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\"; + string startupFolder = Application.StartupPath + "\\"; + using (TaskDialog td = new TaskDialog()) { td.MainInstruction = "Choose a settings folder."; - td.Content = "[MPV documentation about files on Windows.](https://mpv.io/manual/master/#files-on-windows)"; - td.AddCommandLink("appdata", appdataFolder, appdataFolder); - td.AddCommandLink("portable", portableFolder, portableFolder); - td.AddCommandLink("startup", startupFolder, startupFolder); + td.AddCommandLink(@"AppData\Roaming\mpv.net", appdataFolder, appdataFolder); + td.AddCommandLink(@"AppData\Roaming\mpv", appdataFolderMpv, appdataFolderMpv); + td.AddCommandLink("\\portable_config", portableFolder, portableFolder); + td.AddCommandLink("", startupFolder, startupFolder); + td.AddCommandLink("Choose custom folder", "custom"); td.AllowCancel = false; - _ConfFolder = td.Show(); + _ConfigFolder = td.Show(); + } + + if (_ConfigFolder == "custom") + { + using (var d = new WinForms.FolderBrowserDialog()) + { + d.Description = "Choose a folder."; + if (d.ShowDialog() == WinForms.DialogResult.OK) + _ConfigFolder = d.SelectedPath + "\\"; + else + _ConfigFolder = appdataFolder; + } } } - else if (Directory.Exists(portableFolder)) - _ConfFolder = portableFolder; - else if (Directory.Exists(appdataFolder)) - _ConfFolder = appdataFolder; - else if (File.Exists(Application.StartupPath + "\\mpv.conf")) - _ConfFolder = Application.StartupPath + "\\"; - if (string.IsNullOrEmpty(_ConfFolder)) _ConfFolder = appdataFolder; - if (!Directory.Exists(_ConfFolder)) Directory.CreateDirectory(_ConfFolder); + if (!Directory.Exists(_ConfigFolder)) + Directory.CreateDirectory(_ConfigFolder); - if (!File.Exists(_ConfFolder + "\\input.conf")) - File.WriteAllText(_ConfFolder + "\\input.conf", Properties.Resources.inputConf); + RegHelp.SetObject(App.RegPath, "ConfigFolder", _ConfigFolder); - if (!File.Exists(_ConfFolder + "\\mpv.conf")) - File.WriteAllText(_ConfFolder + "\\mpv.conf", Properties.Resources.mpvConf); + if (!File.Exists(_ConfigFolder + "\\input.conf")) + File.WriteAllText(_ConfigFolder + "\\input.conf", Properties.Resources.inputConf); + + if (!File.Exists(_ConfigFolder + "\\mpv.conf")) + File.WriteAllText(_ConfigFolder + "\\mpv.conf", Properties.Resources.mpvConf); } - return _ConfFolder; + return _ConfigFolder; } } @@ -182,22 +198,26 @@ namespace mpvnet public static void LoadScripts() { - string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts"); - foreach (string scriptPath in startupScripts) - if (scriptPath.EndsWith(".lua") || scriptPath.EndsWith(".js")) - commandv("load-script", $"{scriptPath}"); + if (Directory.Exists(Application.StartupPath + "\\Scripts")) + { + string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts"); - foreach (string scriptPath in startupScripts) - if (Path.GetExtension(scriptPath) == ".py") - PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath))); + foreach (string scriptPath in startupScripts) + if (scriptPath.EndsWith(".lua") || scriptPath.EndsWith(".js")) + commandv("load-script", $"{scriptPath}"); - foreach (string scriptPath in startupScripts) - if (Path.GetExtension(scriptPath) == ".ps1") - PowerShellScript.Init(scriptPath); + foreach (string scriptPath in startupScripts) + if (Path.GetExtension(scriptPath) == ".py") + PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath))); - if (Directory.Exists(ConfFolder + "Scripts")) - foreach (string scriptPath in Directory.GetFiles(ConfFolder + "Scripts")) + foreach (string scriptPath in startupScripts) + if (Path.GetExtension(scriptPath) == ".ps1") + PowerShellScript.Init(scriptPath); + } + + if (Directory.Exists(ConfigFolder + "Scripts")) + foreach (string scriptPath in Directory.GetFiles(ConfigFolder + "Scripts")) if (Path.GetExtension(scriptPath) == ".py") PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath))); else if (Path.GetExtension(scriptPath) == ".ps1") @@ -657,7 +677,7 @@ namespace mpvnet if (File.Exists(LastHistoryPath) && totalMinutes > 1) { - string historyFilepath = ConfFolder + "history.txt"; + string historyFilepath = ConfigFolder + "history.txt"; File.AppendAllText(historyFilepath, DateTime.Now.ToString().Substring(0, 16) + " " + totalMinutes.ToString().PadLeft(3) + " " + @@ -698,7 +718,6 @@ namespace mpvnet lock (MediaTracks) { MediaTracks.Clear(); - string path = get_property_string("path"); if (File.Exists(path)) @@ -779,7 +798,6 @@ namespace mpvnet } } } - } lock (Chapters)