diff --git a/.gitignore b/.gitignore index 49f18f2..8511779 100644 --- a/.gitignore +++ b/.gitignore @@ -301,3 +301,4 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk + diff --git a/README.md b/README.md index 596e494..0de8aea 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,8 @@ mpv.net is a modern desktop media player for Windows based on the popular [mpv](https://mpv.io) player. -mpv.net is designed to be mpv compatible, almost all mpv features are available -because they are all contained in libmpv, this means the official -[mpv manual](https://mpv.io/manual/master/) applies to mpv.net. +mpv.net is designed to be mpv compatible, almost all mpv features are available, +this means the official [mpv manual](https://mpv.io/manual/master/) applies to mpv.net. mpv focuses on the usage of the command line and the terminal, mpv.net retains the ability to be used from the command line and @@ -43,11 +42,6 @@ Play controls with a modern flat design. Leverages the FFmpeg hwaccel APIs to support DXVA2 video decoding acceleration. -#### Active development - -mpv.net is under active development. - - #### Based on libmpv mpv.net is based on libmpv which offers a straightforward C API that @@ -69,8 +63,7 @@ Table of contents Features that mpv and mpv.net have in common -------------------------------------------- -- Lua and JavaScript Scripting -- Hundreds available user scripts make mpv the most feature rich desktop video player +- Lua and JavaScript Scripting ([awesome-mpv lists available user scripts](https://github.com/stax76/awesome-mpv)) - Simple config files that are easy to read and edit - JSON IPC to control the player with a external programs - On Screen Controler (OSC, play control buttons) with modern flat design @@ -99,26 +92,25 @@ Features exclusiv to mpv.net - Searchable input (shorcut keys) editor - C# and PowerShell Scripting - Global keyboard shortcuts -- Command palette to quickly and easily find commands and keys - Extension API for .NET languages (C#, VB.NET and F#) - Portable, MS Store or WinGet download and installation - File history feature to log time and filename - Files can be enqueued from File Explorer -## [Support](docs/Manual.md#support) +## [Support](docs/manual.md#support) -[Support section of the manual.](docs/Manual.md#support) +[Support section of the manual.](docs/manual.md#support) -## [Download](docs/Manual.md#download) +## [Download](docs/manual.md#download) -[Download section of the manual.](docs/Manual.md#download) +[Download section of the manual.](docs/manual.md#download) -## [Manual](docs/Manual.md) +## [Manual](docs/manual.md) -[The mpv.net documentation.](docs/Manual.md) +[The mpv.net documentation.](docs/manual.md) Screenshots @@ -155,23 +147,3 @@ OSD console and status printed on the terminal. Searchable key and mouse binding editor. ![Input Editor](docs/img/InputEditor.webp) - - -#### Command Palette - -Command Palette to easily find commands and shortcut keys. - -![Command Palette](docs/img/CommandPalette.webp) - - -#### Playlist - -The command palette based playlist showing my favorite artist of the stax record label. - -![Playlist](docs/img/Playlist.png) - - -List of my apps ---------------- - -https://stax76.github.io/frankskare diff --git a/docs/Changelog.md b/docs/Changelog.md index 3721779..8775eb6 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,9 +1,32 @@ -# v6.0.4.0 Stable (2023-08-17) +# v7.0.0.0 Beta (2023-??-??) + +- [.NET 6 is a new requirement](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) + (Windows 7 is still supported) +- The command palette was removed because of a compatibility problem with + the .NET 6 platform. There are user scripts as replacement: + [command_palette](https://github.com/stax76/mpv-scripts#command_palette) or + [search_menu](https://github.com/stax76/mpv-scripts#search_menu). + Unfortunately the user scripts don't support IME mode which is a problem for asian users. +- The blue mpv.net logo was removed for better mpv compatibility. +- Fix message box exceding working area size. +- C# and PowerShell scripting was removed because of a compatibility problem + with the .NET 6 platform. .NET extensions are supported with a new host + (not backward compatible). A example extension is available under \src\MpvNet.Extension\ExampleExtension +- Redesigned bindings and context menu, the default bindings and context menu + are now defined internally, no longer is a default input.conf file generated. + It means mpv.net no longer loses control over the default bindings and menu. + The new design, is ready for localization. Defining the context menu in + input.conf is still supported, but discouraged and undocumented. +- auto-play option removed, mpv supports it with the option reset-on-next-file. +- Dark mode title bar enabled on Windows 10.0.18985 or higher. +- The navigation bar on the left side of the config editor was changed + from a simple list to a tree view. +- Support of the MPV_HOME environment variable that allows + customizing the conf directory location. +- Improved support for third party osc scripts like uosc. +- Support of the mpv property `focused`. -- libmpv-2.dll support -- MediaInfo v23.07 -- libmpv shinchiro 2023-08-16 # v6.0.3.2 Beta (2022-10-14) @@ -174,11 +197,11 @@ All occurrences of `script-message mpv.net` were changed to `script-message-to m - Media Info isn't shown directly, instead the command palette shows several choices. The command palette can be bypassed using the arguments: msgbox, editor, full, raw. - https://github.com/mpvnet-player/mpv.net/blob/master/docs/Manual.md#show-media-info-flags + https://github.com/mpvnet-player/mpv.net/blob/master/docs/manual.md#show-media-info-flags - mpv.net specific commands, the command palette, auto-play property and various other things are documented in the manual. - The action used for the right mouse button can be configured. - https://github.com/mpvnet-player/mpv.net/blob/master/docs/Manual.md#show-menu + https://github.com/mpvnet-player/mpv.net/blob/master/docs/manual.md#show-menu - Workaround not reproducible logo drawing crash. - Info command shows the length. - New mpv.net specific option `show-logo` that allows to disable diff --git a/docs/Manual.md b/docs/Manual.md index c3d5795..3d2e593 100644 --- a/docs/Manual.md +++ b/docs/Manual.md @@ -2,7 +2,7 @@ mpv.net manual ============== -**ENGLISH** | **[简体中文](Manual_chs.md)** +**ENGLISH** | **[简体中文](manual_chs.md)** Table of contents ----------------- @@ -13,7 +13,6 @@ Table of contents * [Support](#support) * [Settings](#settings) * [Input and context menu](#input-and-context-menu) -* [Command Palette](#command-palette) * [Command Line Interface](#command-line-interface) * [Terminal](#terminal) * [mpv.net specific commands](#mpvnet-specific-commands) @@ -42,8 +41,6 @@ mpv focuses on the usage of the command line and the terminal, mpv.net retains the ability to be used from the command line and the terminal and adds a modern Windows GUI on top of it. -Like mpv, mpv.net is designed for power users. - Download -------- @@ -54,12 +51,16 @@ Download 3. `winget install mpv.net` -[Changelog](Changelog.md) +[Changelog](changelog.md) + Installation ------------ -mpv.net requires the .NET Framework 4.8 and Windows 7 or higher and a modern graphics card. +1. Windows 7 or higher is required (Windows 10 or higher is recommended). +2. mpv.net since version 7.0 requires the + [.NET Desktop Runtime 6.0](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) + being installed. mpv.net before version 7.0 requires .NET Framework 4.8. Internet streaming requires: @@ -121,14 +122,6 @@ mpv.net options are documented [here](#mpvnet-specific-options). Input and context menu ---------------------- -The input (key/mouse) bindings and the context menu definitions are stored in the -input.conf file, if it's missing mpv.net generates it with default values. - -Please be aware that once input.conf exists, mpv.net cannot update it, this means -the menu becomes outdated when mpv.net is updated with new or changed default menu -items. The only way to get an up-to-date menu is either resetting the menu by -deleting input.conf or updating it by manually editing input.conf. - Global keyboard shortcuts are supported via global-input.conf file. The config folder can be opened from the context menu: `Settings > Open Config Folder` @@ -137,52 +130,18 @@ A input and config editor can be found in the context menu under 'Settings'. The input test mode can be started via command line: --input-test -The input key list can be printed with --input-keylist or -shown from the context menu under: View > Advanced > Show Keys +The input key list can be printed with --input-keylist -mpv.net input.conf defaults: -https://github.com/mpvnet-player/mpv.net/blob/master/src/Resources/input.conf.txt - -mpv input.conf defaults: +mpv input.conf defaults: https://github.com/mpv-player/mpv/blob/master/etc/input.conf -mpv input commands: +mpv input commands: https://mpv.io/manual/master/#list-of-input-commands -mpv input options: +mpv input options: https://mpv.io/manual/master/#input -Command Palette ---------------- - -The command palette is designed to quickly find, -select and execute commands. - -It can also be used to easily find shortcut keys. - -The following functionality is presented with the Command Palette: - -- Show media info in different ways. -- Show and select audio tracks. -- Show and select subtitle tracks. -- Show and select playlist files. -- Show and select recent files. -- Show available mpv properties. -- Show available decoders. -- Show available demuxers. -- Show available keys. -- Show available protocols. - -| Key | Action | -| ------ | --------------------------- | -| F1 | Shows the command palette. | -| Escape | Hides the command palette. | -| Enter | Executes the selected item. | -| Up | Moves the selection up. | -| Down | Moves the selection down. | - - Command Line Interface ---------------------- @@ -208,11 +167,6 @@ Supported are all mpv properties, they are documented here: https://mpv.io/manual/master/#properties -mpv.net has a feature to list all available properties: - -_Context Menu > View > Advanced > Show Properties_ - - mpv has a few non property based switches which are generally not supported in mpv.net. @@ -232,9 +186,6 @@ mpv.net specific commands mpv.net commands are used when mpv commands don't exist or lack a feature. -### cycle-audio -Switches to the next audio track and shows info about that track. - ### load-audio Shows a file browser dialog to open external audio files. @@ -268,36 +219,12 @@ or multiple files in the file clipboard format. Cycles the pause property. In case the playlist is empty, the most recent file from the recent files list is loaded. -### playlist-add \ -Changes the playlist position by adding the supplied integer value. -If the position goes out of range, it jumpes to the opposite end. - -### playlist-first -Jumps to the first playlist entry, if the loaded file is -already the first entry, nothing happens. - -### playlist-last -Jumps to the last playlist entry, if the loaded file is -already the last entry, nothing happens. - -### playlist-random -Jumps to a random playlist entry. - -### quick-bookmark - -On the first press a bookmark is saved, on the second -press it is restored and removed. When a new file is -loaded the bookmark is removed. - ### reg-file-assoc \ Registers the file associations. ### scale-window \ Decreases or increases the Window size. -### select-profile -Shows the command palette to select a profile. - ### shell-execute \ Shell executes a single file or URL. @@ -307,16 +234,6 @@ Shows the about dialog. ### show-audio-devices Shows available audio devices in a message box. -### show-audio-tracks -Shows available audio tracks in the command palette -and allows to load the selected audio track. - -### show-chapters -Shows chapters in the command palette. - -### show-command-palette -Shows the command palette. - ### show-commands Shows available mpv input commands. @@ -329,25 +246,18 @@ Shows available decoders. ### show-demuxers Shows available demuxers. -### show-history - -Shows the history file when existing. - ### show-input-editor Shows the input editor. -### show-keys -Shows available keys (as shown with `--input-keylist`) in the command palette. - ### show-media-info [\] **msgbox** Shows media info in a messsage box. **editor** -Shows media info in the text editor. +Shows media info in a text editor. **osd** -Displays media info on screen. +Shows media info on screen. **full** Shows fully detailed media info. @@ -358,31 +268,9 @@ Shows media info with raw property names. ### show-menu Shows the context menu. -### show-playlist -Shows the playlist in the command palette -and allows to play the selected entry. - ### show-profiles Shows available profiles with a message box. -### show-progress -Shows a simple OSD progress message with time and date. - -### show-properties -Shows available properties in the command palette and -allows to display the property value of the selected property. - -### show-protocols -Shows available protocols in the command palette. - -### show-recent -Shows recently played files and URLs in the -command palette and allows to select and play entries. - -### show-subtitle-tracks -Shows available subtitles in the command palette -and allows to activate the selected subtitle. - ### show-text \ \ \ Shows a OSD message with given text, duration and font size. @@ -471,12 +359,6 @@ are used as defined by autofit and start-size. Default: 1500 #### --auto-load-folder=\ For single files automatically load the entire directory into the playlist. -Can be suppressed via shift key. Default: yes - -#### --auto-play=\ - -If the player is paused and another file is loaded, -playback automatically resumes. ### General @@ -508,10 +390,6 @@ Amount of recent files to be remembered. Default: 15 Usage of the media info library instead of mpv to access media information. Default: yes (mpv.net specific option) -#### --history-filter - -Semicolon separated list of paths to be excluded from the history log feature. - #### --video-file-extensions=\ Video file extensions used to create file associations and used by the auto-load-folder feature. @@ -555,14 +433,6 @@ Color theme used in light mode. Default: light [Color Themes](#color-theme) -#### --show-logo=\ - -Draws the blue mpv.net logo ontop of the native OSC logo. Default: yes - -#### --show-santa-logo=\ - -Draws the blue mpv.net logo with a santa hat in december, -the option is called greenandgrumpy in mpv. Default: yes External Tools -------------- @@ -611,51 +481,17 @@ Lua scripting is documented in the mpv.net wiki [here](https://github.com/mpvnet [mpv JavaScript documentation](https://mpv.io/manual/master/#javascript) -#### PowerShell - -Location: `\scripts-ps` - -The PowerShell scripting host is not initialized before media files are loaded. - -[Example Scripts](../../../tree/master/src/Scripts) - - -#### C# - -Location: `\scripts-cs` - -There are no compatibility guaranties. - -Script code can be written within a C# [extension](../../../tree/master/src/Extensions), -that way full code completion and debugger support is available. -Once the code was developed and debugged, it can be moved -from the extension to a lightweight standalone script. -The script host uses an old C# version, modern features -like string interpolation are not available. - -There are synchronous and asynchronous events, prefer asynchronous events -and don't block synchronous events and observed properties, as it would -block the main event loop. - -The C# scripting host is like [extensions](../../../tree/master/src/Extensions) -not initialized before media files are loaded. - -[Example Scripts](../../../tree/master/src/Scripts) - Extensions ---------- -Extensions are located in a subfolder _extensions_ in the config folder -and the filename must have the same name as the directory: +Extensions are located in a subfolder _extensions_ in the config folder, +the filename must have the same name as the directory: ```Text \extensions\ExampleExtension\ExampleExtension.dll ``` -There are synchronous and asynchronous events, prefer asynchronous events -and don't block synchronous events and observed properties, as it would -block the main event loop. ### Walkthrough creating an extension @@ -726,13 +562,6 @@ Selecting multiple files in File Explorer and pressing enter will open the files in mpv.net. Explorer restricts this to maximum 15 files and the order will be random. -Whenever the control key is pressed when files or URLs are opened, -the playlist is not cleared but the files or URLs are appended to the playlist. -This works in all mpv.net features that open files or URLs. - -Pressing the shift key while opening a single file will suppress loading -all files of the folder into the playlist. - In fullscreen mode clicking the top right corner closes the player. @@ -831,20 +660,6 @@ Third party components are: - [MediaInfo](https://mediaarea.net/en/MediaInfo) -Context Menu ------------- - -The context menu of mpv.net is defined in the file input.conf which is -located in the config directory. - -If the input.conf file does not exists mpv.net generates it with the following defaults: - - - -input.conf defines mpv's key and mouse bindings and mpv.net uses -comments to define the context menu. - - ### Open > Open Files The Open Files menu entry is one way to open files in mpv.net, it supports multi selection. @@ -854,12 +669,6 @@ File Explorer for existing associations. A third way is to drag and drop files on the main window. -Whenever the control key is pressed when files or URLs are opened, -the playlist is not cleared but the files or URLs are appended to the -playlist. This works in all mpv.net features that open files or URLs. - -Pressing the shift key while opening a single file will suppress loading all files in the folder. - Blu-ray and DVD ISO image files are supported. @@ -1228,17 +1037,6 @@ Adds a negative audio delay using the following command: [audio-delay property](https://mpv.io/manual/master/#options-audio-delay) -### Subtitle > Cycle/Next - -Shows the next subtitle track using the following command: - -`script-message-to mpvnet cycle-subtitles` - -[cycle command](https://mpv.io/manual/master/#command-interface-cycle-%3Cname%3E-[%3Cvalue%3E]) - -[sub/sid property](https://mpv.io/manual/master/#options-sid) - - ### Subtitle > Toggle Visibility Cycles the subtitle visibility using the following command: @@ -1404,11 +1202,6 @@ Resets the speed using the following command: [speed property](https://mpv.io/manual/master/#options-speed) -### Extensions > Rating > 0stars - -A plugin the writes the rating to the filename. - - ### View > On Top > Enable Forces the player to stay on top of other windows using the following command: @@ -1463,24 +1256,6 @@ Toggles OSC Visibility using the following command: [script-binding command](https://mpv.io/manual/master/#command-interface-script-binding) -### View > Show Playlist - -Shows the playlist for 5 seconds using the following command: - -`show-text ${playlist} 5000` - -[show-text command](https://mpv.io/manual/master/#command-interface-show-text) - - -### View > Show Audio/Video/Subtitle List - -Shows the Audio/Video/Subtitle list for 5 seconds using the following command: - -`show-text ${track-list} 5000` - -[show-text command](https://mpv.io/manual/master/#command-interface-show-text) - - ### Settings > Show Config Editor Shows mpv.net's config editor. @@ -1503,23 +1278,6 @@ input.conf containing mpv key and mouse bindings User scripts and user extensions - -### Tools > Command Palette - -Shows the command palette window which allows to quickly find and execute commands and key shortcuts. - - -### Tools > Show History - -Shows a text file that contains the file history. If the file don't exist -it asks if the file should be created in the settings folder. Once the file -exist then the history is logged. It logges the playback history containing -the time and filename. - -To ignore certain paths: - -script-opt = history-discard=path1;path2 - ### Tools > Set/clear A-B loop points Enables to set loop start and end points using the following command: @@ -1563,12 +1321,12 @@ Shows the [mpv manual](https://mpv.io/manual/stable/). ### Help > Show mpv.net web site -Shows the [mpv.net web site](https://mpv-net.github.io/mpv.net-web-site/). +Shows the [mpv.net web site](https://github.com/mpvnet-player/mpv.net). ### Help > Show mpv.net manual -Shows the [mpv.net manual](https://github.com/mpvnet-player/mpv.net/blob/master/Manual.md). +Shows the [mpv.net manual](https://github.com/mpvnet-player/mpv.net/blob/master/manual.md). ### Help > About mpv.net diff --git a/docs/img/CommandPalette.webp b/docs/img/CommandPalette.webp deleted file mode 100644 index 8f66731..0000000 Binary files a/docs/img/CommandPalette.webp and /dev/null differ diff --git a/docs/img/Playlist.png b/docs/img/Playlist.png deleted file mode 100644 index 2efd970..0000000 Binary files a/docs/img/Playlist.png and /dev/null differ diff --git a/docs/img/mpvnet-santa.png b/docs/img/mpvnet-santa.png deleted file mode 100644 index 634c297..0000000 Binary files a/docs/img/mpvnet-santa.png and /dev/null differ diff --git a/docs/img/mpvnet.ico b/docs/img/mpvnet.ico deleted file mode 100644 index a70ca15..0000000 Binary files a/docs/img/mpvnet.ico and /dev/null differ diff --git a/docs/img/mpvnet.pdn b/docs/img/mpvnet.pdn deleted file mode 100644 index 0a3dd6d..0000000 Binary files a/docs/img/mpvnet.pdn and /dev/null differ diff --git a/docs/img/mpvnet.png b/docs/img/mpvnet.png deleted file mode 100644 index 4c08c44..0000000 Binary files a/docs/img/mpvnet.png and /dev/null differ diff --git a/src/.editorconfig b/src/.editorconfig index 82d0636..6eff39d 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -1,22 +1,7 @@ [*.cs] -# IDE0058: Expression value is never used -dotnet_diagnostic.IDE0058.severity = none +# IDE0090: Use 'new(...)' +csharp_style_implicit_object_creation_when_type_is_apparent = true -# IDE0055: Fix formatting -dotnet_diagnostic.IDE0055.severity = none - -# IDE0022: Use block body for methods -dotnet_diagnostic.IDE0022.severity = none - -# IDE0040: Add accessibility modifiers -dotnet_diagnostic.IDE0040.severity = none - -# IDE0011: Add braces -dotnet_diagnostic.IDE0011.severity = none - -# IDE0010: Add missing cases -dotnet_diagnostic.IDE0010.severity = none - -# IDE0044: Add readonly modifier -dotnet_diagnostic.IDE0044.severity = silent +# IDE0090: Use 'new(...)' +dotnet_diagnostic.IDE0090.severity = silent diff --git a/src/Extensions/RatingExtension/Properties/AssemblyInfo.cs b/src/Extensions/RatingExtension/Properties/AssemblyInfo.cs deleted file mode 100644 index 1510960..0000000 --- a/src/Extensions/RatingExtension/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("RatingExtension")] -[assembly: AssemblyDescription("RatingExtension")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Frank Skare (stax76)")] -[assembly: AssemblyProduct("RatingExtension")] -[assembly: AssemblyCopyright("Copyright (C) 2017-2020 Frank Skare (stax76)")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("55c88710-539d-4402-84c8-31694841c731")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// 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("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Extensions/RatingExtension/RatingExtension.cs b/src/Extensions/RatingExtension/RatingExtension.cs deleted file mode 100644 index 094467a..0000000 --- a/src/Extensions/RatingExtension/RatingExtension.cs +++ /dev/null @@ -1,135 +0,0 @@ - -// This extension writes a rating to the filename of rated videos when mpv.net shuts down. - -// The input.conf setup: - -// KP0 script-message rate-file 0 #menu: Extensions > Rating > 0stars -// KP1 script-message rate-file 1 #menu: Extensions > Rating > 1stars -// KP2 script-message rate-file 2 #menu: Extensions > Rating > 2stars -// KP3 script-message rate-file 3 #menu: Extensions > Rating > 3stars -// KP4 script-message rate-file 4 #menu: Extensions > Rating > 4stars -// KP5 script-message rate-file 5 #menu: Extensions > Rating > 5stars -// _ ignore #menu: Extensions > Rating > - -// _ script-message rate-file about #menu: Extensions > Rating > About - -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.IO; -using System.Threading; -using System.Windows.Forms; - -using Microsoft.VisualBasic.FileIO; - -using mpvnet; -using static mpvnet.Global; - -namespace RatingExtension // the assembly name must end with 'Extension'! -{ - [Export(typeof(IExtension))] - public class RatingExtension : IExtension - { - //Script script = new Script(); - - // dictionory to store the filename and the rating - Dictionary Dic = new Dictionary(); - - string FileToDelete; - DateTime DeleteTime; - - public RatingExtension() // plugin initialization - { - Core.ClientMessage += ClientMessage; //handles keys defined in input.conf - Core.Shutdown += Shutdown; // handles MPV_EVENT_SHUTDOWN - } - - // handles MPV_EVENT_SHUTDOWN - void Shutdown() - { - foreach (var i in Dic) - { - string filepath = i.Key; - int rating = i.Value; - - if (string.IsNullOrEmpty(filepath) || !File.Exists(filepath)) - return; - - string basename = Path.GetFileNameWithoutExtension(filepath); - - for (int x = 0; x < 6; x++) - if (basename.Contains(" (" + x + "stars)")) - basename = basename.Replace(" (" + x + "stars)", ""); - - basename += $" ({rating}stars)"; - - string newPath = Path.Combine(Path.GetDirectoryName(filepath), - basename + Path.GetExtension(filepath)); - - if (filepath.ToLower() != newPath.ToLower()) - File.Move(filepath, newPath); - - File.SetLastWriteTime(newPath, DateTime.Now); - } - } - - //handles keys defined in input.conf - void ClientMessage(string[] args) - { - if (args[0] != "rate-file") - return; - - if (int.TryParse(args[1], out int rating)) - { - string path = Core.GetPropertyString("path"); - - if (!File.Exists(path)) - return; - - if (rating == 0 || rating == 1) - Delete(rating); - else - { - Dic[path] = rating; - Core.CommandV("show-text", $"Rating: {rating}"); - } - } - else if (args[1] == "about") - MessageBox.Show($"This extension writes a rating to the filename of rated videos " + - "when mpv.net shuts down." + BR2 + - "The input.conf defaults contain key bindings for this extension to set ratings.", - "Rating Extension"); - } - - void Delete(int rating) - { - if (rating == 0) - { - FileToDelete = Core.GetPropertyString("path"); - DeleteTime = DateTime.Now; - Core.CommandV("show-text", "Press 1 to delete file", "5000"); - } - else - { - TimeSpan ts = DateTime.Now - DeleteTime; - string path = Core.GetPropertyString("path"); - - if (FileToDelete == path && ts.TotalSeconds < 5 && File.Exists(FileToDelete)) - { - Core.Command("playlist-remove current"); - int pos = Core.GetPropertyInt("playlist-pos"); - - if (pos == -1) - { - int count = Core.GetPropertyInt("playlist-count"); - - if (count > 0) - Core.SetPropertyInt("playlist-pos", count - 1); - } - - Thread.Sleep(2000); - FileSystem.DeleteFile(FileToDelete, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); - } - } - } - } -} diff --git a/src/Extensions/RatingExtension/RatingExtension.csproj b/src/Extensions/RatingExtension/RatingExtension.csproj deleted file mode 100644 index 6c0af2c..0000000 --- a/src/Extensions/RatingExtension/RatingExtension.csproj +++ /dev/null @@ -1,63 +0,0 @@ - - - - - Debug - AnyCPU - {55C88710-539D-4402-84C8-31694841C731} - Library - Properties - RatingExtension - RatingExtension - v4.8 - 512 - - - - true - bin\ - DEBUG;TRACE - full - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - - - - - - - - - - - - - - - - - - - - - - - {1751f378-8edf-4b62-be6d-304c7c287089} - mpv.net - False - - - - \ No newline at end of file diff --git a/src/Extensions/RatingExtension/ScriptDevelopment.cs b/src/Extensions/RatingExtension/ScriptDevelopment.cs deleted file mode 100644 index 1eb06c7..0000000 --- a/src/Extensions/RatingExtension/ScriptDevelopment.cs +++ /dev/null @@ -1,42 +0,0 @@ - -//// This script adds dynamic menu items for profile switching. - -//// In input.conf add a menu item called 'Profiles' - -//using mpvnet; -//using System.ComponentModel; -//using System.Linq; - -//class Script -//{ -// MainForm MainForm; -// CorePlayer Core; - -// public Script() -// { -// Core = Global.Core; -// MainForm = MainForm.Instance; -// MainForm.ContextMenu.Opening += ContextMenu_Opening; -// } - -// void ContextMenu_Opening(object sender, CancelEventArgs e) -// { -// MenuItem menuItem = MainForm.FindMenuItem("My Menu"); - -// if (menuItem == null) -// { -// Terminal.WriteError("Profiles menu item not found.", "switch-profile-context-menu.cs"); -// return; -// } - -// menuItem.DropDownItems.Clear(); -// var editionTracks = Core.MediaTracks.Where(track => track.Type == "e"); - -// foreach (int i in new[] {1, 2, 3}) -// { -// MenuItem mi = new MenuItem(i.ToString()); -// mi.Action = () => { Core.commandv("show-text", i.ToString()); }; -// menuItem.DropDownItems.Add(mi); -// } -// } -//} diff --git a/src/Misc/App.cs b/src/Misc/App.cs deleted file mode 100644 index 485ffbd..0000000 --- a/src/Misc/App.cs +++ /dev/null @@ -1,298 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Windows.Forms; -using System.Threading.Tasks; - -using static mpvnet.Global; - -namespace mpvnet -{ - public static class App - { - public static List TempFiles { get; } = new List(); - - public static string[] HistoryFilter { get; set; } - - public static string ConfPath { get => Core.ConfigFolder + "mpvnet.conf"; } - public static string ProcessInstance { get; set; } = "single"; - public static string DarkMode { get; set; } = "always"; - public static string DarkTheme { get; set; } = "dark"; - public static string LightTheme { get; set; } = "light"; - public static string StartSize { get; set; } = "height-session"; - - public static bool AutoLoadFolder { get; set; } = true; - public static bool AutoPlay { get; set; } - public static bool DebugMode { get; set; } - public static bool Exit { get; set; } - public static bool IsTerminalAttached { get; } = Environment.GetEnvironmentVariable("_started_from_console") == "yes"; - public static bool MediaInfo { get; set; } = true; - public static bool Queue { get; set; } - public static bool RememberVolume { get; set; } = true; - public static bool RememberWindowPosition { get; set; } - public static bool ShowLogo { get; set; } = true; - public static bool ShowSantaLogo { get; set; } = true; - - public static int StartThreshold { get; set; } = 1500; - public static int RecentCount { get; set; } = 15; - - public static float AutofitAudio { get; set; } = 0.7f; - public static float AutofitImage { get; set; } = 0.8f; - public static float MinimumAspectRatio { get; set; } - public static float MinimumAspectRatioAudio { get; set; } - public static float QuickBookmark { get; set; } - - public static Extension Extension { get; set; } - - public static bool IsDarkMode => (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() - { - var useless1 = Core.ConfigFolder; - var useless2 = Core.Conf; - - foreach (var i in Conf) - ProcessProperty(i.Key, i.Value, true); - - if (DebugMode) - { - try - { - string filePath = Core.ConfigFolder + "mpvnet-debug.log"; - - if (File.Exists(filePath)) - File.Delete(filePath); - - Trace.Listeners.Add(new TextWriterTraceListener(filePath)); - Trace.AutoFlush = true; - - //if (App.DebugMode) - // Trace.WriteLine(""); - } - catch (Exception e) - { - Msg.ShowException(e); - } - } - - InitTheme(); - - Core.Shutdown += Core_Shutdown; - Core.Initialized += Core_Initialized; - } - - public static void InitTheme() - { - string themeContent = null; - - if (File.Exists(Core.ConfigFolder + "theme.conf")) - themeContent = File.ReadAllText(Core.ConfigFolder + "theme.conf"); - - Theme.Init( - themeContent, - Properties.Resources.theme, - IsDarkMode ? DarkTheme : LightTheme); - } - - public static void UpdateWpfColors() - { - var dic = System.Windows.Application.Current.Resources; - - dic.Remove("BorderColor"); - dic.Add("BorderColor", Theme.Current.GetColor("menu-highlight")); - - dic.Remove("RegionColor"); - dic.Add("RegionColor", Theme.Current.GetColor("menu-background")); - - dic.Remove("SecondaryRegionColor"); - dic.Add("SecondaryRegionColor", Theme.Current.GetColor("menu-highlight")); - - dic.Remove("PrimaryTextColor"); - dic.Add("PrimaryTextColor", Theme.Current.GetColor("menu-foreground")); - - dic.Remove("HighlightColor"); - dic.Add("HighlightColor", Theme.Current.GetColor("highlight")); - } - - public static void RunTask(Action action) - { - Task.Run(() => { - try { - action.Invoke(); - } - catch (Exception e) { - ShowException(e); - } - }); - } - - public static string Version => "Copyright (C) 2000-2022 mpv.net/mpv/mplayer\n" + - $"mpv.net {Application.ProductVersion}" + GetLastWriteTime(Application.ExecutablePath) + "\n" + - $"{Core.GetPropertyString("mpv-version")}" + GetLastWriteTime(Folder.Startup + "libmpv-2.dll") + "\n" + - $"ffmpeg {Core.GetPropertyString("ffmpeg-version")}\n" + - $"MediaInfo {FileVersionInfo.GetVersionInfo(Path.Combine(Application.StartupPath, "MediaInfo.dll")).FileVersion}" + - GetLastWriteTime(Path.Combine(Application.StartupPath , "MediaInfo.dll")) + "\nGPL v2 License"; - - static string GetLastWriteTime(string path) - { - if (IsStoreVrsion) - return ""; - - return $" ({File.GetLastWriteTime(path).ToShortDateString()})"; - } - - static bool IsStoreVrsion => Application.StartupPath.Contains("FrankSkare.mpv.net"); - - public static void ShowException(object obj) - { - if (IsTerminalAttached) - Terminal.WriteError(obj.ToString()); - else - { - if (obj is Exception e) - InvokeOnMainThread(() => Msg.ShowException(e)); - else - InvokeOnMainThread(() => Msg.ShowError(obj.ToString())); - } - } - - public static void InvokeOnMainThread(Action action) - { - if (action == null) - return; - - if (MainForm.Instance == null) - action.Invoke(); - else - MainForm.Instance.BeginInvoke(action); - } - - public static void ShowInfo(string msg) - { - if (IsTerminalAttached) - { - if (msg != null) - Terminal.Write(msg); - } - else - InvokeOnMainThread(() => Msg.ShowInfo(msg)); - } - - public static void ShowError(string msg) - { - if (IsTerminalAttached) - { - if (msg != null) - Terminal.WriteError(msg); - } - else - InvokeOnMainThread(() => Msg.ShowError(msg)); - } - - static void Core_Initialized() - { - if (RememberVolume) - { - Core.SetPropertyInt("volume", Settings.Volume); - Core.SetPropertyString("mute", Settings.Mute); - } - } - - static void Core_Shutdown() - { - Settings.Volume = Core.GetPropertyInt("volume"); - Settings.Mute = Core.GetPropertyString("mute"); - - SettingsManager.Save(Settings); - - foreach (string file in TempFiles) - FileHelp.Delete(file); - } - - static Dictionary _Conf; - - public static Dictionary Conf { - get { - if (_Conf == null) - { - _Conf = new Dictionary(); - - 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(); - } - return _Conf; - } - } - - public static bool ProcessProperty(string name, string value, bool writeError = false) - { - switch (name) - { - case "audio-file-extensions": CorePlayer.AudioTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; - case "auto-load-folder": AutoLoadFolder = value == "yes"; return true; - case "auto-play": AutoPlay = value == "yes"; return true; - case "autofit-audio": AutofitAudio = value.Trim('%').ToInt() / 100f; return true; - case "autofit-image": AutofitImage = value.Trim('%').ToInt() / 100f; return true; - case "dark-mode": DarkMode = value; return true; - case "dark-theme": DarkTheme = value.Trim('\'', '"'); return true; - case "debug-mode": DebugMode = value == "yes"; return true; - case "history-filter": HistoryFilter = value.Split(';'); return true; - case "image-file-extensions": CorePlayer.ImageTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; - case "light-theme": LightTheme = value.Trim('\'', '"'); return true; - case "media-info": MediaInfo = value == "yes"; return true; - case "minimum-aspect-ratio-audio": MinimumAspectRatioAudio = value.ToFloat(); return true; - case "minimum-aspect-ratio": MinimumAspectRatio = value.ToFloat(); return true; - case "process-instance": ProcessInstance = value; return true; - case "queue": Queue = value == "yes"; return true; - case "recent-count": RecentCount = value.ToInt(); return true; - case "remember-volume": RememberVolume = value == "yes"; return true; - case "remember-window-position": RememberWindowPosition = value == "yes"; return true; - case "show-logo": ShowLogo = value == "yes"; return true; - case "show-santa-logo": ShowSantaLogo = value == "yes"; return true; - case "start-size": StartSize = value; return true; - case "start-threshold": StartThreshold = value.ToInt(); return true; - case "video-file-extensions": CorePlayer.VideoTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; - - default: - if (writeError) - Terminal.WriteError($"unknown mpvnet.conf property: {name}"); - return false; - } - } - - public static void CopyMpvnetCom() - { - string dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).AddSep() + - "Microsoft\\WindowsApps\\"; - - if (File.Exists(dir + "mpvnet.exe") && !File.Exists(dir + "mpvnet.com")) - File.Copy(Folder.Startup + "mpvnet.com", dir + "mpvnet.com"); - } - - public static (string Title, string Path) GetTitleAndPath(string input) - { - if (input.Contains("|")) - { - var a = input.Split('|'); - return (a[1], a[0]); - } - - return (input, input); - } - } -} diff --git a/src/Misc/CSharpScriptHost.cs b/src/Misc/CSharpScriptHost.cs deleted file mode 100644 index f9a6a7a..0000000 --- a/src/Misc/CSharpScriptHost.cs +++ /dev/null @@ -1,71 +0,0 @@ - -using System.CodeDom.Compiler; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; - -using Microsoft.CSharp; - -using static mpvnet.Global; - -namespace mpvnet -{ - class CSharpScriptHost - { - static List References = new List(); - - public static void ExecuteScriptsInFolder(string folder) - { - if (Directory.Exists(folder)) - foreach (string file in Directory.GetFiles(folder, "*.cs")) - App.RunTask(() => Execute(file)); - } - - static void Execute(string file) - { - string code = File.ReadAllText(file); - string filename = Path.GetFileNameWithoutExtension(file) + " " + StringHelp.GetMD5Hash(code) + "-v6.dll"; - string outputFile = Path.Combine(Path.GetTempPath(), filename); - - if (!File.Exists(outputFile)) - Compile(outputFile, file); - - if (File.Exists(outputFile)) - { - object instance = Assembly.LoadFile(outputFile).CreateInstance("Script"); - - if (instance != null) - References.Add(instance); - else - Terminal.WriteError("Failed to initialize script.", outputFile.FileName()); - } - } - - public static void Compile(string outputFile, string file) - { - CSharpCodeProvider provider = new CSharpCodeProvider(); - CompilerParameters parameters = new CompilerParameters(); - - string[] dependencies = { - Folder.Startup + "mpvnet.exe", - "Microsoft.VisualBasic.dll", - "System.Core.dll", "System.Data.dll", "System.dll", "System.Drawing.dll", "System.Web.dll", - "System.Windows.Forms.dll", "System.Xaml.dll", "System.Xml.dll", "System.Xml.Linq.dll", - "WPF\\PresentationCore.dll", "WPF\\PresentationFramework.dll", "WPF\\WindowsBase.dll" - }; - - foreach (string i in dependencies) - parameters.ReferencedAssemblies.Add(i); - - parameters.OutputAssembly = outputFile; - CompilerResults results = provider.CompileAssemblyFromFile(parameters, file); - - var errors = results.Errors.Cast().Select(i => "Line Number " + - i.Line + "\n" + "Error Number: " + i.ErrorNumber + "\n" + i.ErrorText); - - if (errors.Count() > 0) - Terminal.WriteError(string.Join(BR2, errors), Path.GetFileName(file)); - } - } -} diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs deleted file mode 100644 index d4fe735..0000000 --- a/src/Misc/Commands.cs +++ /dev/null @@ -1,769 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Windows; -using System.Windows.Forms; -using System.Windows.Interop; -using System.Windows.Media; - -using WinForms = System.Windows.Forms; - -using static mpvnet.Global; - -namespace mpvnet -{ - public class Commands - { - public static void Execute(string id, string[] args) - { - switch (id) - { - case "cycle-audio": CycleAudio(); break; - case "cycle-subtitles": CycleSubtitles(); break; - case "load-audio": LoadAudio(); break; - case "load-sub": LoadSubtitle(); break; - case "move-window": MoveWindow(args[0]); break; - case "open-clipboard": OpenFromClipboard(); break; - case "open-conf-folder": ProcessHelp.ShellExecute(Core.ConfigFolder); break; - case "open-files": OpenFiles(args); break; - case "open-optical-media": Open_DVD_Or_BD_Folder(); break; - case "play-pause": PlayPause(); break; - case "playlist-add": PlaylistAdd(Convert.ToInt32(args[0])); break; - case "playlist-first": PlaylistFirst(); break; - case "playlist-last": PlaylistLast(); break; - case "playlist-random": PlaylistRandom(); break; - case "quick-bookmark": QuickBookmark(); break; - case "reg-file-assoc": RegisterFileAssociations(args[0]); break; - case "scale-window": ScaleWindow(float.Parse(args[0], CultureInfo.InvariantCulture)); break; - case "select-profile": SelectProfile(); break; - case "shell-execute": ProcessHelp.ShellExecute(args[0]); break; - case "show-about": ShowDialog(typeof(AboutWindow)); break; - case "show-audio-devices": Msg.ShowInfo(Core.GetPropertyOsdString("audio-device-list")); break; - case "show-audio-tracks": ShowAudioTracks(); break; - case "show-chapters": ShowChapters(); break; - case "show-command-palette": ShowCommandPalette(); break; - case "show-commands": ShowCommands(); break; - case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break; - case "show-decoders": ShowStrings(mpvHelp.GetDecoders().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); break; - case "show-demuxers": ShowStrings(mpvHelp.GetDemuxers().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); break; - case "show-history": ShowHistory(); break; - case "show-info": ShowInfo(); break; - case "show-input-editor": ShowDialog(typeof(InputWindow)); break; - case "show-keys": ShowStrings(Core.GetPropertyString("input-key-list").Split(',')); break; - case "show-media-info": ShowMediaInfo(args); break; - case "show-menu": ShowMenu(); break; - case "show-playlist": ShowPlaylist(); break; - case "show-profiles": Msg.ShowInfo(mpvHelp.GetProfiles()); break; - case "show-progress": ShowProgress(); break; - case "show-properties": ShowProperties(); break; - case "show-protocols": ShowStrings(mpvHelp.GetProtocols().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); break; - case "show-recent": ShowRecent(); break; - case "show-subtitle-tracks": ShowSubtitleTracks(); break; - case "show-text": ShowText(args[0], Convert.ToInt32(args[1]), Convert.ToInt32(args[2])); break; - case "window-scale": WindowScale(float.Parse(args[0], CultureInfo.InvariantCulture)); break; - - // deprecated 2019 - case "add-files-to-playlist": OpenFiles("append"); break; - - // deprecated 2020 - case "execute-mpv-command": Msg.ShowError("command was removed, reset input.conf by deleting it, in the new menu use the on screen console."); break; - case "key-binding": if (args[0] == "show-playlist") ShowPlaylist(); break; - - // deprecated 2022 - case "show-setup-dialog": ShowSetupDialog(); break; - case "open-url": OpenFromClipboard(); break; - } - } - - public static void ShowTextWithEditor(string name, string text) - { - string file = Path.Combine(Path.GetTempPath(), name + ".txt"); - App.TempFiles.Add(file); - File.WriteAllText(file, BR + text.Trim() + BR); - ProcessHelp.ShellExecute(file); - } - - public static void ShowDialog(Type winType) => App.InvokeOnMainThread(() => - { - Window win = Activator.CreateInstance(winType) as Window; - new WindowInteropHelper(win).Owner = MainForm.Instance.Handle; - win.ShowDialog(); - }); - - public static void OpenFiles(params string[] args) - { - bool append = Control.ModifierKeys.HasFlag(Keys.Control); - - foreach (string arg in args) - if (arg == "append") - append = true; - - App.InvokeOnMainThread(new Action(() => { - using (var d = new OpenFileDialog() { Multiselect = true }) - if (d.ShowDialog() == DialogResult.OK) - Core.LoadFiles(d.FileNames, true, append); - })); - } - - public static void Open_DVD_Or_BD_Folder() => App.InvokeOnMainThread(() => - { - var dialog = new FolderBrowser(); - - if (dialog.Show()) - Core.LoadDiskFolder(dialog.SelectedPath); - }); - - public static void PlaylistFirst() - { - if (Core.PlaylistPos != 0) - Core.SetPropertyInt("playlist-pos", 0); - } - - public static void PlaylistLast() - { - int count = Core.GetPropertyInt("playlist-count"); - - if (Core.PlaylistPos < count - 1) - Core.SetPropertyInt("playlist-pos", count - 1); - } - - public static void PlayPause() - { - int count = Core.GetPropertyInt("playlist-count"); - - if (count > 0) - Core.Command("cycle pause"); - else if (App.Settings.RecentFiles.Count > 0) - { - foreach (string i in App.Settings.RecentFiles) - { - if (i.Contains("://") || File.Exists(i)) - { - Core.LoadFiles(new[] { i }, true, false); - break; - } - } - } - } - - public static void ShowHistory() - { - if (File.Exists(Core.ConfigFolder + "history.txt")) - ProcessHelp.ShellExecute(Core.ConfigFolder + "history.txt"); - else - { - if (Msg.ShowQuestion("Create a 'history.txt' file in the config folder?" + BR2 + - "mpv.net will write the date, time, play length and path of watched files to it.") == MessageBoxResult.OK) - - File.WriteAllText(Core.ConfigFolder + "history.txt", ""); - } - } - - public static void ShowInfo() - { - if (Core.PlaylistPos == -1) - return; - - string text; - long fileSize = 0; - string path = Core.GetPropertyString("path"); - - if (File.Exists(path)) - { - if (CorePlayer.AudioTypes.Contains(path.Ext())) - { - text = Core.GetPropertyOsdString("filtered-metadata"); - Core.CommandV("show-text", text, "5000"); - return; - } - else if (CorePlayer.ImageTypes.Contains(path.Ext())) - { - fileSize = new FileInfo(path).Length; - text = "Width: " + Core.GetPropertyInt("width") + "\n" + - "Height: " + Core.GetPropertyInt("height") + "\n" + - "Size: " + Convert.ToInt32(fileSize / 1024.0) + " KB\n" + - "Type: " + path.Ext().ToUpper(); - - Core.CommandV("show-text", text, "5000"); - return; - } - else - { - Core.Command("script-message-to mpvnet show-media-info osd"); - return; - } - } - - if (path.Contains("://")) path = Core.GetPropertyString("media-title"); - string videoFormat = Core.GetPropertyString("video-format").ToUpper(); - string audioCodec = Core.GetPropertyString("audio-codec-name").ToUpper(); - int width = Core.GetPropertyInt("video-params/w"); - int height = Core.GetPropertyInt("video-params/h"); - TimeSpan len = TimeSpan.FromSeconds(Core.GetPropertyDouble("duration")); - text = path.FileName() + "\n"; - text += FormatTime(len.TotalMinutes) + ":" + FormatTime(len.Seconds) + "\n"; - if (fileSize > 0) text += Convert.ToInt32(fileSize / 1024.0 / 1024.0) + " MB\n"; - text += $"{width} x {height}\n"; - text += $"{videoFormat}\n{audioCodec}"; - Core.CommandV("show-text", text, "5000"); - } - - static string FormatTime(double value) => ((int)value).ToString("00"); - - public static void ShowProgress() - { - TimeSpan position = TimeSpan.FromSeconds(Core.GetPropertyDouble("time-pos")); - TimeSpan duration = TimeSpan.FromSeconds(Core.GetPropertyDouble("duration")); - - string text = FormatTime(position.TotalMinutes) + ":" + - FormatTime(position.Seconds) + " / " + - FormatTime(duration.TotalMinutes) + ":" + - FormatTime(duration.Seconds) + " " + - DateTime.Now.ToString("H:mm dddd d MMMM", CultureInfo.InvariantCulture); - - Core.CommandV("show-text", text, "5000"); - } - - public static void OpenFromClipboard() => App.InvokeOnMainThread(() => - { - if (WinForms.Clipboard.ContainsFileDropList()) - { - string[] files = WinForms.Clipboard.GetFileDropList().Cast().ToArray(); - Core.LoadFiles(files, false, Control.ModifierKeys.HasFlag(Keys.Control)); - } - else - { - string clipboard = WinForms.Clipboard.GetText(); - List files = new List(); - - foreach (string i in clipboard.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) - if (i.Contains("://") || File.Exists(i)) - files.Add(i); - - if (files.Count == 0) - { - App.ShowError("The clipboard does not contain a valid URL or file."); - return; - } - - Core.LoadFiles(files.ToArray(), false, Control.ModifierKeys.HasFlag(Keys.Control)); - } - }); - - public static void LoadSubtitle() => App.InvokeOnMainThread(() => - { - using (var d = new OpenFileDialog()) - { - string path = Core.GetPropertyString("path"); - - if (File.Exists(path)) - d.InitialDirectory = Path.GetDirectoryName(path); - - d.Multiselect = true; - - if (d.ShowDialog() == DialogResult.OK) - foreach (string filename in d.FileNames) - Core.CommandV("sub-add", filename); - } - }); - - public static void LoadAudio() => App.InvokeOnMainThread(() => - { - using (var d = new OpenFileDialog()) - { - string path = Core.GetPropertyString("path"); - - if (File.Exists(path)) - d.InitialDirectory = Path.GetDirectoryName(path); - - d.Multiselect = true; - - if (d.ShowDialog() == DialogResult.OK) - foreach (string i in d.FileNames) - Core.CommandV("audio-add", i); - } - }); - - public static void CycleAudio() - { - Core.UpdateExternalTracks(); - - lock (Core.MediaTracksLock) - { - MediaTrack[] tracks = Core.MediaTracks.Where(track => track.Type == "a").ToArray(); - - if (tracks.Length < 1) - { - Core.CommandV("show-text", "No audio tracks"); - return; - } - - int aid = Core.GetPropertyInt("aid"); - - if (tracks.Length > 1) - { - if (++aid > tracks.Length) - aid = 1; - - Core.SetPropertyInt("aid", aid); - } - - Core.CommandV("show-text", aid + "/" + tracks.Length + ": " + tracks[aid - 1].Text.Substring(3), "5000"); - } - } - - public static void CycleSubtitles() - { - Core.UpdateExternalTracks(); - - lock (Core.MediaTracksLock) - { - MediaTrack[] tracks = Core.MediaTracks.Where(track => track.Type == "s").ToArray(); - - if (tracks.Length < 1) - { - Core.CommandV("show-text", "No subtitles"); - return; - } - - int sid = Core.GetPropertyInt("sid"); - - if (tracks.Length > 1) - { - if (++sid > tracks.Length) - sid = 0; - - Core.SetPropertyInt("sid", sid); - } - - if (sid == 0) - Core.CommandV("show-text", "No subtitle"); - else - Core.CommandV("show-text", sid + "/" + tracks.Length + ": " + tracks[sid - 1].Text.Substring(3), "5000"); - } - } - - public static void ShowCommands() - { - string jsonString = Core.GetPropertyString("command-list"); - var jsonObject = jsonString.FromJson>>().OrderBy(i => i["name"]); - StringBuilder sb = new StringBuilder(); - - foreach (Dictionary dic in jsonObject) - { - sb.AppendLine(); - sb.AppendLine(dic["name"].ToString()); - - foreach (Dictionary i2 in dic["args"] as List) - { - string value = i2["name"].ToString() + " <" + i2["type"].ToString().ToLower() + ">"; - - if ((bool)i2["optional"] == true) - value = "[" + value + "]"; - - sb.AppendLine(" " + value); - } - } - - ShowTextWithEditor("command-list", sb.ToString()); - } - - public static void ScaleWindow(float factor) => Core.RaiseScaleWindow(factor); - - public static void WindowScale(float value) => Core.RaiseWindowScaleNET(value); - - public static void ShowText(string text, int duration = 0, int fontSize = 0) - { - if (string.IsNullOrEmpty(text)) - return; - - if (duration == 0) - duration = Core.GetPropertyInt("osd-duration"); - - if (fontSize == 0) - fontSize = Core.GetPropertyInt("osd-font-size"); - - Core.Command("show-text \"${osd-ass-cc/0}{\\\\fs" + fontSize + - "}${osd-ass-cc/1}" + text + "\" " + duration); - } - - public static void ShowMediaInfo(string[] args) => App.InvokeOnMainThread(() => - { - if (args == null || args.Length == 0) - { - (string Name, string Value)[] pairs = { - ("Show text box", "script-message-to mpvnet show-media-info default"), - ("Show text editor", "script-message-to mpvnet show-media-info editor"), - ("Show on screen", "script-message-to mpvnet show-media-info osd"), - ("Show full", "script-message-to mpvnet show-media-info editor full"), - ("Show raw", "script-message-to mpvnet show-media-info editor full raw") }; - - var list = pairs.Select(i => new CommandPaletteItem(i.Name, () => Core.Command(i.Value))); - CommandPalette.Instance.SetItems(list); - MainForm.Instance.ShowCommandPalette(); - CommandPalette.Instance.SelectFirst(); - return; - } - - string path = Core.GetPropertyString("path"); - string text = ""; - - bool full = args.Contains("full"); - bool raw = args.Contains("raw"); - bool editor = args.Contains("editor"); - bool osd = args.Contains("osd"); - - if (App.MediaInfo && !osd && File.Exists(path) && !path.Contains(@"\\.\pipe\")) - using (MediaInfo mediaInfo = new MediaInfo(path)) - text = Regex.Replace(mediaInfo.GetSummary(full, raw), "Unique ID.+", ""); - else - { - Core.UpdateExternalTracks(); - text = "N: " + Core.GetPropertyString("filename") + BR; - lock (Core.MediaTracksLock) - foreach (MediaTrack track in Core.MediaTracks) - text += track.Text + BR; - } - - text = text.TrimEx(); - - if (editor) - ShowTextWithEditor("media-info", text); - else if (osd) - ShowText(text.Replace("\r", ""), 5000, 16); - else - { - MsgBoxEx.MessageBoxEx.MsgFontFamily = new FontFamily("Consolas"); - Msg.ShowInfo(text); - MsgBoxEx.MessageBoxEx.MsgFontFamily = new FontFamily("Segoe UI"); - } - }); - - public static void ShowCommandPalette() => App.InvokeOnMainThread(() => - { - CommandPalette.Instance.SetItems(CommandPalette.GetItems()); - MainForm.Instance.ShowCommandPalette(); - CommandPalette.Instance.SelectFirst(); - }); - - public static void ShowAudioTracks() => App.InvokeOnMainThread(() => - { - Core.UpdateExternalTracks(); - - lock (Core.MediaTracksLock) - { - MediaTrack[] tracks = Core.MediaTracks.Where(track => track.Type == "a").ToArray(); - - if (tracks.Length < 1) - { - Core.CommandV("show-text", "No audio tracks"); - return; - } - - List items = new List(); - - foreach (MediaTrack i in tracks) - { - MediaTrack track = i; - - CommandPaletteItem item = new CommandPaletteItem() - { - Text = track.Text, - Action = () => { - Core.CommandV("set", "aid", track.ID.ToString()); - Core.CommandV("show-text", track.ID + "/" + tracks.Length + ": " + - tracks[track.ID - 1].Text.Substring(3), "5000"); - } - }; - - items.Add(item); - } - - CommandPalette.Instance.SetItems(items); - MainForm.Instance.ShowCommandPalette(); - CommandPalette.Instance.SelectFirst(); - } - - }); - - public static void ShowSubtitleTracks() => App.InvokeOnMainThread(() => - { - Core.UpdateExternalTracks(); - - lock (Core.MediaTracksLock) - { - MediaTrack[] tracks = Core.MediaTracks.Where(track => track.Type == "s").ToArray(); - - if (tracks.Length < 1) - { - Core.CommandV("show-text", "No subtitle tracks"); - return; - } - - List items = new List(); - - foreach (MediaTrack i in tracks) - { - MediaTrack track = i; - - CommandPaletteItem item = new CommandPaletteItem() - { - Text = track.Text, - Action = () => { - Core.CommandV("set", "sid", track.ID.ToString()); - Core.CommandV("show-text", track.ID + "/" + tracks.Length + ": " + - tracks[track.ID - 1].Text.Substring(3), "5000"); - } - }; - - items.Add(item); - } - - CommandPalette.Instance.SetItems(items); - MainForm.Instance.ShowCommandPalette(); - CommandPalette.Instance.SelectFirst(); - } - }); - - public static void ShowPlaylist() => App.InvokeOnMainThread(() => - { - int count = Core.GetPropertyInt("playlist-count"); - string currentPath = Core.GetPropertyString("path"); - CommandPaletteItem currentItem = null; - - if (count < 1) - return; - - List items = new List(); - - for (int i = 0; i < count; i++) - { - int index = i; - string file = Core.GetPropertyString($"playlist/{i}/filename"); - string title = Core.GetPropertyString($"playlist/{i}/title"); - - CommandPaletteItem item = new CommandPaletteItem() - { - Text = title, - Action = () => Core.SetPropertyInt("playlist-pos", index) - }; - - if (string.IsNullOrEmpty(item.Text)) - item.Text = file.FileName(); - if (string.IsNullOrEmpty(item.Text)) - item.Text = file; - - items.Add(item); - - if (currentPath.ToLowerEx() == file.ToLowerEx()) - currentItem = item; - } - - CommandPalette.Instance.SetItems(items); - - if (currentItem != null) - { - CommandPalette.Instance.MainListView.SelectedItem = currentItem; - CommandPalette.Instance.MainListView.ScrollIntoView( - CommandPalette.Instance.MainListView.SelectedItem); - } - - MainForm.Instance.ShowCommandPalette(); - }); - - public static void ShowProperties() => App.InvokeOnMainThread(() => - { - var props = Core.GetPropertyString("property-list").Split(',').OrderBy(prop => prop); - List items = new List(); - - foreach (string i in props) - { - string prop = i; - - CommandPaletteItem item = new CommandPaletteItem() - { - Text = prop, - Action = () => - { - string propValue = Core.GetPropertyString(prop); - - if (propValue.ContainsEx("${")) - propValue += BR2 + Core.Expand(propValue); - - App.ShowInfo(prop + "\n\n" + propValue); - } - }; - - items.Add(item); - } - - CommandPalette.Instance.SetItems(items); - MainForm.Instance.ShowCommandPalette(); - }); - - public static void ShowRecent() => App.InvokeOnMainThread(() => - { - List items = new List(); - - foreach (string path in App.Settings.RecentFiles) - { - var file = App.GetTitleAndPath(path); - - CommandPaletteItem item = new CommandPaletteItem() - { - Text = file.Title.ShortPath(60), - Action = () => Core.LoadFiles(new[] { file.Path }, true, Control.ModifierKeys.HasFlag(Keys.Control)) - }; - - items.Add(item); - } - - CommandPalette.Instance.SetItems(items); - MainForm.Instance.ShowCommandPalette(); - CommandPalette.Instance.SelectFirst(); - }); - - public static void RegisterFileAssociations(string perceivedType) - { - string[] extensions = { }; - - switch (perceivedType) - { - case "video": extensions = CorePlayer.VideoTypes; break; - case "audio": extensions = CorePlayer.AudioTypes; break; - case "image": extensions = CorePlayer.ImageTypes; break; - } - - try - { - using (Process proc = new Process()) - { - proc.StartInfo.FileName = WinForms.Application.ExecutablePath; - proc.StartInfo.Arguments = "--register-file-associations " + - perceivedType + " " + string.Join(" ", extensions); - proc.StartInfo.Verb = "runas"; - proc.StartInfo.UseShellExecute = true; - proc.Start(); - proc.WaitForExit(); - - if (proc.ExitCode == 0) - Msg.ShowInfo("File associations were successfully " + - (perceivedType == "unreg" ? "removed" : "created") + - ".\n\nFile Explorer icons will refresh after process restart."); - else - Msg.ShowError("Error creating file associations."); - } - } catch { } - } - - public static void ShowStrings(string[] strings) => App.InvokeOnMainThread(() => - { - List items = new List(); - - foreach (string i in strings) - { - string str = i; - - CommandPaletteItem item = new CommandPaletteItem() - { - Text = str, - Action = () => Msg.ShowInfo(str) - }; - - items.Add(item); - } - - CommandPalette.Instance.SetItems(items); - MainForm.Instance.ShowCommandPalette(); - CommandPalette.Instance.SelectFirst(); - }); - - public static void ShowSetupDialog() => App.InvokeOnMainThread(() => - { - (string Name, string Value)[] pairs = { - ("Register video file associations", "script-message-to mpvnet reg-file-assoc video"), - ("Register audio file associations", "script-message-to mpvnet reg-file-assoc audio"), - ("Register image file associations", "script-message-to mpvnet reg-file-assoc image"), - ("Unregister file associations", "script-message-to mpvnet reg-file-assoc unreg") }; - - var list = pairs.Select(i => new CommandPaletteItem(i.Name, () => Core.Command(i.Value))); - CommandPalette.Instance.SetItems(list); - MainForm.Instance.ShowCommandPalette(); - CommandPalette.Instance.SelectFirst(); - }); - - public static void SelectProfile() => App.InvokeOnMainThread(() => - { - var items = Core.ProfileNames.Where(i => !i.StartsWith("extension.")) - .Select(i => new CommandPaletteItem(i, () => { - Core.CommandV("show-text", i); - Core.CommandV("apply-profile", i); - })); - - CommandPalette.Instance.SetItems(items); - MainForm.Instance.ShowCommandPalette(); - CommandPalette.Instance.SelectFirst(); - }); - - public static void ShowChapters() => App.InvokeOnMainThread(() => - { - var items = Core.GetChapters().Select(i => new CommandPaletteItem(i.Title, i.TimeDisplay, () => - Core.CommandV("seek", i.Time.ToString(CultureInfo.InvariantCulture), "absolute"))); - - CommandPalette.Instance.SetItems(items); - MainForm.Instance.ShowCommandPalette(); - CommandPalette.Instance.SelectFirst(); - }); - - public static void ShowMenu() => Core.RaiseShowMenu(); - - public static void PlaylistAdd(int value) - { - int pos = Core.PlaylistPos; - int count = Core.GetPropertyInt("playlist-count"); - - if (count < 2) - return; - - pos = pos + value; - - if (pos < 0) - pos = count - 1; - - if (pos > count - 1) - pos = 0; - - Core.SetPropertyInt("playlist-pos", pos); - } - - public static void PlaylistRandom() - { - int count = Core.GetPropertyInt("playlist-count"); - Core.SetPropertyInt("playlist-pos", new Random().Next(count)); - } - - public static void QuickBookmark() - { - if (App.QuickBookmark == 0) - { - App.QuickBookmark = (float)Core.GetPropertyDouble("time-pos"); - - if (App.QuickBookmark != 0) - Core.Command("show-text 'Bookmark Saved'"); - } - else - { - Core.SetPropertyDouble("time-pos", App.QuickBookmark); - App.QuickBookmark = 0; - } - } - - public static void MoveWindow(string direction) => Core.RaiseMoveWindow(direction); - } -} diff --git a/src/Misc/Common.cs b/src/Misc/Common.cs deleted file mode 100644 index 4aacda6..0000000 --- a/src/Misc/Common.cs +++ /dev/null @@ -1,65 +0,0 @@ - -using System.Collections.Generic; -using System.Linq; - -namespace mpvnet -{ - public class StringPair - { - public string Name { get; set; } - public string Value { get; set; } - } - - public class ConfParser - { - public static List Parse(string content) - { - string[] lines = content.Split(new[] { "\r\n" }, System.StringSplitOptions.None); - var sections = new List(); - ConfSection currentGroup = null; - - foreach (string i in lines) - { - string line = i.Trim(); - - if (line == "") - { - currentGroup = new ConfSection(); - sections.Add(currentGroup); - } - else if (line.Contains("=")) - { - string name = line.Substring(0, line.IndexOf("=")).Trim(); - string value = line.Substring(line.IndexOf("=") + 1).Trim(); - - currentGroup.Items.Add(new StringPair() { Name = name, Value = value }); - } - } - - return sections; - } - } - - public class ConfSection - { - public List Items { get; set; } = new List(); - - public bool HasName(string name) - { - foreach (var i in Items) - if (i.Name == name) - return true; - return false; - } - - public string GetValue(string name) - { - foreach (var i in Items) - if (i.Name == name) - return i.Value; - return null; - } - - public List GetValues(string name) => Items.Where(i => i.Name == name).ToList(); - } -} diff --git a/src/Misc/Conf.cs b/src/Misc/Conf.cs deleted file mode 100644 index 742f2da..0000000 --- a/src/Misc/Conf.cs +++ /dev/null @@ -1,164 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Windows; -using System.Windows.Documents; -using System.Windows.Navigation; - -namespace mpvnet -{ - public class Conf - { - public static List LoadConf(string content) - { - List settingsList = new List(); - - foreach (ConfSection section in ConfParser.Parse(content)) - { - SettingBase baseSetting = null; - - if (section.HasName("option")) - { - OptionSetting optionSetting = new OptionSetting(); - baseSetting = optionSetting; - optionSetting.Default = section.GetValue("default"); - optionSetting.Value = optionSetting.Default; - - foreach (var i in section.GetValues("option")) - { - var opt = new OptionSettingOption(); - - if (i.Value.Contains(" ")) - { - opt.Name = i.Value.Substring(0, i.Value.IndexOf(" ")); - opt.Help = i.Value.Substring(i.Value.IndexOf(" ")).Trim(); - } - else - opt.Name = i.Value; - - if (opt.Name == optionSetting.Default) - opt.Text = opt.Name + " (Default)"; - - opt.OptionSetting = optionSetting; - optionSetting.Options.Add(opt); - } - } - else - { - StringSetting stringSetting = new StringSetting(); - baseSetting = stringSetting; - stringSetting.Default = section.HasName("default") ? section.GetValue("default") : ""; - } - - baseSetting.Name = section.GetValue("name"); - baseSetting.File = section.GetValue("file"); - baseSetting.Filter = section.GetValue("filter"); - - if (section.HasName("help")) baseSetting.Help = section.GetValue("help"); - if (section.HasName("url")) baseSetting.URL = section.GetValue("url"); - if (section.HasName("width")) baseSetting.Width = Convert.ToInt32(section.GetValue("width")); - if (section.HasName("type")) baseSetting.Type = section.GetValue("type"); - - if (baseSetting.Help.ContainsEx("\\n")) - baseSetting.Help = baseSetting.Help.Replace("\\n", "\n"); - - settingsList.Add(baseSetting); - } - - return settingsList; - } - } - - public class ConfItem - { - public string Comment { get; set; } = ""; - public string File { get; set; } = ""; - public string LineComment { get; set; } = ""; - public string Name { get; set; } = ""; - public string Section { get; set; } = ""; - public string Value { get; set; } = ""; - - public bool IsSectionItem { get; set; } - public SettingBase SettingBase { get; set; } - } - - public abstract class SettingBase - { - public string Default { get; set; } - public string File { get; set; } - public string Filter { get; set; } - public string Help { get; set; } - public string Name { get; set; } - public string StartValue { get; set; } - public string Type { get; set; } - public string URL { get; set; } - public string Value { get; set; } - - public int Width { get; set; } - public ConfItem ConfItem { get; set; } - } - - public class StringSetting : SettingBase - { - } - - public class OptionSetting : SettingBase - { - public List Options = new List(); - } - - public class OptionSettingOption - { - public string Name { get; set; } - public string Help { get; set; } - - public OptionSetting OptionSetting { get; set; } - - string _Text; - - public string Text - { - get => string.IsNullOrEmpty(_Text) ? Name : _Text; - set => _Text = value; - } - - public bool Checked - { - get => OptionSetting.Value == Name ; - set { - if (value) - OptionSetting.Value = Name; - } - } - - public Visibility Visibility - { - get => string.IsNullOrEmpty(Help) ? Visibility.Collapsed : Visibility.Visible; - } - } - - interface ISettingControl - { - bool Contains(string searchString); - SettingBase SettingBase { get; } - } - - public class HyperlinkEx : Hyperlink - { - void HyperLinkEx_RequestNavigate(object sender, RequestNavigateEventArgs e) - { - ProcessHelp.ShellExecute(e.Uri.AbsoluteUri); - } - - public void SetURL(string url) - { - if (string.IsNullOrEmpty(url)) - return; - - NavigateUri = new Uri(url); - RequestNavigate += HyperLinkEx_RequestNavigate; - Inlines.Clear(); - Inlines.Add(url); - } - } -} diff --git a/src/Misc/Extension.cs b/src/Misc/Extension.cs deleted file mode 100644 index da826ca..0000000 --- a/src/Misc/Extension.cs +++ /dev/null @@ -1,46 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.ComponentModel.Composition.Hosting; -using System.IO; - -using static mpvnet.Global; - -namespace mpvnet -{ - public class Extension - { - [ImportMany] - public IEnumerable Extensions = null; - - readonly CompositionContainer CompositionContainer; - - public Extension() - { - try - { - AggregateCatalog catalog = new AggregateCatalog(); - string dir = Core.ConfigFolder + "extensions"; - - if (Directory.Exists(dir)) - foreach (string extDir in Directory.GetDirectories(dir)) - catalog.Catalogs.Add(new DirectoryCatalog(extDir, Path.GetFileName(extDir) + ".dll")); - - if (catalog.Catalogs.Count > 0) - { - CompositionContainer = new CompositionContainer(catalog); - CompositionContainer.ComposeParts(this); - } - } - catch (Exception ex) - { - App.ShowException(ex); - } - } - } - - public interface IExtension - { - } -} diff --git a/src/Misc/ExtensionMethods.cs b/src/Misc/ExtensionMethods.cs deleted file mode 100644 index 51f6fc9..0000000 --- a/src/Misc/ExtensionMethods.cs +++ /dev/null @@ -1,133 +0,0 @@ - -using System.Globalization; -using System.IO; -using System.Text.RegularExpressions; - -public static class TestStringExtension -{ - public static bool ContainsEx(this string instance, string value) - { - if (!string.IsNullOrEmpty(instance) && !string.IsNullOrEmpty(value)) - return instance.Contains(value); - - return false; - } - - public static bool StartsWithEx(this string instance, string value) - { - if (instance != null && value != null) - return instance.StartsWith(value); - - return false; - } -} - -public static class ConvertToStringExtension -{ - public static string ToUpperEx(this string instance) - { - if (instance != null) - return instance.ToUpperInvariant(); - - return ""; - } - - public static string ToLowerEx(this string instance) - { - if (instance != null) - return instance.ToLowerInvariant(); - - return ""; - } - - public static string TrimEx(this string instance) - { - if (instance == null) - return ""; - - return instance.Trim(); - } - - public static string ToStringEx(this object instance) => instance?.ToString() ?? ""; -} - -public static class ConvertStringExtension -{ - public static int ToInt(this string instance) - { - int.TryParse(instance, out int result); - return result; - } - - public static float ToFloat(this string instance) - { - float.TryParse(instance.Replace(",", "."), NumberStyles.Float, - CultureInfo.InvariantCulture, out float result); - - return result; - } -} - -public static class PathStringExtension -{ - public static string Ext(this string filepath) => Ext(filepath, false); - - public static string Ext(this string filepath, bool includeDot) - { - if (string.IsNullOrEmpty(filepath)) - return ""; - - char[] chars = filepath.ToCharArray(); - - for (int x = filepath.Length - 1; x >= 0; x--) - { - if (chars[x] == Path.DirectorySeparatorChar) - return ""; - - if (chars[x] == '.') - return filepath.Substring(x + (includeDot ? 0 : 1)).ToLowerInvariant(); - } - - return ""; - } - - public static string FileName(this string instance) - { - if (string.IsNullOrEmpty(instance)) - return ""; - - int index = instance.LastIndexOf('\\'); - - if (index > -1) - return instance.Substring(index + 1); - - index = instance.LastIndexOf('/'); - - if (index > -1) - return instance.Substring(index + 1); - - return instance; - } - - public static string ShortPath(this string instance, int maxLength) - { - if (string.IsNullOrEmpty(instance)) - return ""; - - if (instance.Length > maxLength && instance.Substring(1, 2) == ":\\") - instance = instance.Substring(0, 3) + "...\\" + instance.FileName(); - - return instance; - } - - public static string AddSep(this string instance) - { - if (string.IsNullOrEmpty(instance)) - return ""; - - if (!instance.EndsWith(Path.DirectorySeparatorChar.ToString())) - instance += Path.DirectorySeparatorChar; - - return instance; - } -} diff --git a/src/Misc/FileAssociation.cs b/src/Misc/FileAssociation.cs deleted file mode 100644 index 8944610..0000000 --- a/src/Misc/FileAssociation.cs +++ /dev/null @@ -1,70 +0,0 @@ - -using System.IO; -using System.Windows.Forms; - -using Microsoft.Win32; - -namespace mpvnet -{ - public class FileAssociation - { - static string ExePath = Application.ExecutablePath; - static string ExeFilename = Path.GetFileName(Application.ExecutablePath); - static string ExeFilenameNoExt = Path.GetFileNameWithoutExtension(Application.ExecutablePath); - - public static void Register(string perceivedType, string[] extensions) - { - string[] protocols = { "ytdl", "rtsp", "srt", "srtp" }; - - if (perceivedType != "unreg") - { - foreach (string i in protocols) - { - RegistryHelp.SetValue($@"HKCR\{i}", $"{i.ToUpper()} Protocol", ""); - RegistryHelp.SetValue($@"HKCR\{i}\shell\open\command", null, $"\"{ExePath}\" \"%1\""); - } - - RegistryHelp.SetValue(@"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename, null, ExePath); - RegistryHelp.SetValue(@"HKCR\Applications\" + ExeFilename, "FriendlyAppName", "mpv.net media player"); - RegistryHelp.SetValue(@"HKCR\Applications\" + ExeFilename + @"\shell\open\command", null, $"\"{ExePath}\" \"%1\""); - RegistryHelp.SetValue(@"HKCR\SystemFileAssociations\video\OpenWithList\" + ExeFilename, null, ""); - RegistryHelp.SetValue(@"HKCR\SystemFileAssociations\audio\OpenWithList\" + ExeFilename, null, ""); - RegistryHelp.SetValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net", @"SOFTWARE\Clients\Media\mpv.net\Capabilities"); - RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationDescription", "mpv.net media player"); - RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationName", "mpv.net"); - - foreach (string ext in extensions) - { - RegistryHelp.SetValue(@"HKCR\Applications\" + ExeFilename + @"\SupportedTypes", "." + ext, ""); - RegistryHelp.SetValue(@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext); - RegistryHelp.SetValue(@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, ""); - RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", perceivedType); - RegistryHelp.SetValue(@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open\command", null, $"\"{ExePath}\" \"%1\""); - RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities\FileAssociations", "." + ext, ExeFilenameNoExt + "." + ext); - } - } - else - { - foreach (string i in protocols) - RegistryHelp.RemoveKey($@"HKCR\{i}"); - - RegistryHelp.RemoveKey(@"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename); - RegistryHelp.RemoveKey(@"HKCR\Applications\" + ExeFilename); - RegistryHelp.RemoveKey(@"HKLM\SOFTWARE\Clients\Media\mpv.net"); - RegistryHelp.RemoveKey(@"HKCR\SystemFileAssociations\video\OpenWithList\" + ExeFilename); - RegistryHelp.RemoveKey(@"HKCR\SystemFileAssociations\audio\OpenWithList\" + ExeFilename); - - RegistryHelp.RemoveValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net"); - - foreach (string id in Registry.ClassesRoot.GetSubKeyNames()) - { - if (id.StartsWith(ExeFilenameNoExt + ".")) - Registry.ClassesRoot.DeleteSubKeyTree(id); - - RegistryHelp.RemoveValue($@"HKCR\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id); - RegistryHelp.RemoveValue($@"HKLM\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id); - } - } - } - } -} diff --git a/src/Misc/FolderBrowser.cs b/src/Misc/FolderBrowser.cs deleted file mode 100644 index cf283d2..0000000 --- a/src/Misc/FolderBrowser.cs +++ /dev/null @@ -1,124 +0,0 @@ - -using System; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Windows.Forms; - -namespace mpvnet -{ - public class FolderBrowser - { - public string SelectedPath { get; set; } - - string _initialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); - - public string InitialDirectory { - get => _initialDirectory; - set { - if (Directory.Exists(value)) - _initialDirectory = value; - } - } - - public bool Show() => Show(GetOwnerHandle()); - - public bool Show(IntPtr hWndOwner) - { - ShowDialogResult result = VistaDialog.Show(hWndOwner, InitialDirectory); - - if (result.Result) - SelectedPath = result.FileName; - - return result.Result; - } - - struct ShowDialogResult - { - public bool Result { get; set; } - public string FileName { get; set; } - } - - public static IntPtr GetOwnerHandle() - { - IntPtr foregroundWindow = GetForegroundWindow(); - GetWindowThreadProcessId(foregroundWindow, out var procID); - - using (var proc = Process.GetCurrentProcess()) - if (proc.Id == procID) - return foregroundWindow; - - return IntPtr.Zero; - } - - [DllImport("user32.dll")] - public static extern IntPtr GetForegroundWindow(); - - [DllImport("user32.dll")] - public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); - - static class VistaDialog - { - const string foldersFilter = "Folders|\n"; - const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; - static Assembly windowsFormsAssembly = typeof(FileDialog).Assembly; - static Type iFileDialogType = windowsFormsAssembly.GetType("System.Windows.Forms.FileDialogNative+IFileDialog"); - static MethodInfo createVistaDialogMethodInfo = typeof(OpenFileDialog).GetMethod("CreateVistaDialog", flags); - static MethodInfo onBeforeVistaDialogMethodInfo = typeof(OpenFileDialog).GetMethod("OnBeforeVistaDialog", flags); - static MethodInfo getOptionsMethodInfo = typeof(FileDialog).GetMethod("GetOptions", flags); - static MethodInfo setOptionsMethodInfo = iFileDialogType.GetMethod("SetOptions", flags); - static uint fosPickFoldersBitFlag = (uint)windowsFormsAssembly - .GetType("System.Windows.Forms.FileDialogNative+FOS") - .GetField("FOS_PICKFOLDERS") - .GetValue(null); - static ConstructorInfo vistaDialogEventsConstructorInfo = windowsFormsAssembly - .GetType("System.Windows.Forms.FileDialog+VistaDialogEvents") - .GetConstructor(flags, null, new[] { typeof(FileDialog) }, null); - static MethodInfo adviseMethodInfo = iFileDialogType.GetMethod("Advise"); - static MethodInfo unAdviseMethodInfo = iFileDialogType.GetMethod("Unadvise"); - static MethodInfo showMethodInfo = iFileDialogType.GetMethod("Show"); - - public static ShowDialogResult Show(IntPtr ownerHandle, string initialDirectory) - { - var openFileDialog = new OpenFileDialog - { - AddExtension = false, - CheckFileExists = false, - DereferenceLinks = true, - Filter = foldersFilter, - InitialDirectory = initialDirectory, - Multiselect = false, - }; - - var iFileDialog = createVistaDialogMethodInfo.Invoke(openFileDialog, new object[] { }); - onBeforeVistaDialogMethodInfo.Invoke(openFileDialog, new[] { iFileDialog }); - setOptionsMethodInfo.Invoke(iFileDialog, new object[] { (uint)getOptionsMethodInfo.Invoke(openFileDialog, new object[] { }) | fosPickFoldersBitFlag }); - var adviseParametersWithOutputConnectionToken = new[] { vistaDialogEventsConstructorInfo.Invoke(new object[] { openFileDialog }), 0U }; - adviseMethodInfo.Invoke(iFileDialog, adviseParametersWithOutputConnectionToken); - - try - { - int retVal = (int)showMethodInfo.Invoke(iFileDialog, new object[] { ownerHandle }); - - return new ShowDialogResult - { - Result = retVal == 0, - FileName = openFileDialog.FileName - }; - } - finally - { - unAdviseMethodInfo.Invoke(iFileDialog, new[] { adviseParametersWithOutputConnectionToken[1] }); - } - } - } - - class WindowWrapper : IWin32Window - { - IntPtr _handle; - public WindowWrapper(IntPtr handle) { _handle = handle; } - public IntPtr Handle => _handle; - } - } -} diff --git a/src/Misc/Global.cs b/src/Misc/Global.cs deleted file mode 100644 index 61d3250..0000000 --- a/src/Misc/Global.cs +++ /dev/null @@ -1,13 +0,0 @@ - -using System; - -namespace mpvnet -{ - public class Global - { - public static string BR = Environment.NewLine; - public static string BR2 = Environment.NewLine + Environment.NewLine; - - public static CorePlayer Core { get; } = new CorePlayer(); - } -} diff --git a/src/Misc/GlobalHotkey.cs b/src/Misc/GlobalHotkey.cs deleted file mode 100644 index e598b9b..0000000 --- a/src/Misc/GlobalHotkey.cs +++ /dev/null @@ -1,188 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Runtime.InteropServices; - -using static mpvnet.Global; - -namespace mpvnet -{ - class GlobalHotkey - { - public static Dictionary Commands { get; set; } - static int ID; - static IntPtr HWND; - - public static void RegisterGlobalHotkeys(IntPtr hwnd) - { - HWND = hwnd; - string path = Core.ConfigFolder + "global-input.conf"; - - if (!File.Exists(path)) - return; - - foreach (string i in File.ReadAllLines(path)) - { - string line = i.Trim(); - - if (line.StartsWith("#") || !line.Contains(" ")) - continue; - - ProcessGlobalHotkeyLine(line); - } - } - - static void ProcessGlobalHotkeyLine(string line) - { - string key = line.Substring(0, line.IndexOf(" ")); - string command = line.Substring(line.IndexOf(" ") + 1); - string[] parts = key.Split('+'); - KeyModifiers mod = KeyModifiers.None; - int vk; - - for (int i = 0; i < parts.Length - 1; i++) - { - string umod = parts[i].ToUpper(); - - if (umod == "ALT") mod |= KeyModifiers.Alt; - if (umod == "CTRL") mod |= KeyModifiers.Ctrl; - if (umod == "SHIFT") mod |= KeyModifiers.Shift; - if (umod == "WIN") mod |= KeyModifiers.Win; - } - - key = parts[parts.Length - 1]; - - if (key.Length == 1) - { - short result = VkKeyScanEx(key[0], GetKeyboardLayout(0)); - - int hi = result >> 8; - int lo = result & 0xFF; - - vk = lo; - - if ((hi & 1) == 1) mod |= KeyModifiers.Shift; - if ((hi & 2) == 2) mod |= KeyModifiers.Ctrl; - if ((hi & 4) == 4) mod |= KeyModifiers.Alt; - } - else - vk = mpv_to_VK(key); - - if (Commands == null) - Commands = new Dictionary(); - - if (vk > 0) - { - Commands[ID] = command.Trim(); - bool success = RegisterHotKey(HWND, ID++, mod, vk); - - if (!success) - Terminal.WriteError(line + ": " + new Win32Exception().Message + "\n", "global-input.conf"); - } - } - - public static void Execute(int id) - { - if (Commands.ContainsKey(id)) - Core.Command(Commands[id]); - } - - static int mpv_to_VK(string value) - { - switch (value.ToUpperEx()) - { - case "NEXT" : return 0xB0; // VK_MEDIA_NEXT_TRACK - case "PREV" : return 0xB1; // VK_MEDIA_PREV_TRACK - case "STOP" : return 0xB2; // VK_MEDIA_STOP - case "PLAYPAUSE" : return 0xB3; // VK_MEDIA_PLAY_PAUSE - case "SLEEP" : return 0x5F; // VK_SLEEP - case "RIGHT" : return 0x27; // VK_RIGHT - case "UP" : return 0x26; // VK_UP - case "LEFT" : return 0x25; // VK_LEFT - case "DOWN" : return 0x28; // VK_DOWN - case "PGUP" : return 0x21; // VK_PRIOR - case "PGDWN" : return 0x22; // VK_NEXT - case "PAUSE" : return 0x13; // VK_PAUSE - case "PRINT" : return 0x2A; // VK_PRINT - case "HOME" : return 0x24; // VK_HOME - case "INS" : return 0x2D; // VK_INSERT - case "KP_INS" : return 0x2D; // VK_INSERT - case "DEL" : return 0x2E; // VK_DELETE - case "KP_DEL" : return 0x2E; // VK_DELETE - case "END" : return 0x23; // VK_END - case "F1" : return 0x70; // VK_F1 - case "F2" : return 0x71; // VK_F2 - case "F3" : return 0x72; // VK_F3 - case "F4" : return 0x73; // VK_F4 - case "F5" : return 0x74; // VK_F5 - case "F6" : return 0x75; // VK_F6 - case "F7" : return 0x76; // VK_F7 - case "F8" : return 0x77; // VK_F8 - case "F9" : return 0x78; // VK_F9 - case "F10" : return 0x79; // VK_F10 - case "F11" : return 0x7A; // VK_F11 - case "F12" : return 0x7B; // VK_F12 - case "F13" : return 0x7C; // VK_F13 - case "F14" : return 0x7D; // VK_F14 - case "F15" : return 0x7E; // VK_F15 - case "F16" : return 0x7F; // VK_F16 - case "F17" : return 0x80; // VK_F17 - case "F18" : return 0x81; // VK_F18 - case "F19" : return 0x82; // VK_F19 - case "F20" : return 0x83; // VK_F20 - case "F21" : return 0x84; // VK_F21 - case "F22" : return 0x85; // VK_F22 - case "F23" : return 0x86; // VK_F23 - case "F24" : return 0x87; // VK_F24 - case "ENTER" : return 0x0D; // VK_RETURN - case "KP_ENTER" : return 0x0D; // VK_RETURN - case "TAB" : return 0x09; // VK_TAB - case "MENU" : return 0x5D; // VK_APPS - case "CANCEL" : return 0x03; // VK_CANCEL - case "BS" : return 0x08; // VK_BACK - case "KP_DEC" : return 0x6E; // VK_DECIMAL - case "ESC" : return 0x1B; // VK_ESCAPE - case "KP0" : return 0x60; // VK_NUMPAD0 - case "KP1" : return 0x61; // VK_NUMPAD1 - case "KP2" : return 0x62; // VK_NUMPAD2 - case "KP3" : return 0x63; // VK_NUMPAD3 - case "KP4" : return 0x64; // VK_NUMPAD4 - case "KP5" : return 0x65; // VK_NUMPAD5 - case "KP6" : return 0x66; // VK_NUMPAD6 - case "KP7" : return 0x67; // VK_NUMPAD7 - case "KP8" : return 0x68; // VK_NUMPAD8 - case "KP9" : return 0x69; // VK_NUMPAD9 - case "FAVORITES" : return 0xAB; // VK_BROWSER_FAVORITES - case "SEARCH" : return 0xAA; // VK_BROWSER_SEARCH - case "MAIL" : return 0xB4; // VK_LAUNCH_MAIL - case "VOLUME_UP" : return 0xAF; // VK_VOLUME_UP - case "VOLUME_DOWN": return 0xAE; // VK_VOLUME_DOWN - case "MUTE" : return 0xAD; // VK_VOLUME_MUTE - case "SPACE" : return 0x20; // VK_SPACE - case "IDEOGRAPHIC_SPACE": return 0x20; // VK_SPACE - default: return 0; - } - } - - [DllImport("user32.dll", CharSet = CharSet.Unicode)] - static extern short VkKeyScanEx(char ch, IntPtr dwhkl); - - [DllImport("user32.dll")] - static extern IntPtr GetKeyboardLayout(uint idThread); - - [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, int vk); - - [Flags] - enum KeyModifiers - { - None = 0, - Alt = 1, - Ctrl = 2, - Shift = 4, - Win = 8 - } - } -} diff --git a/src/Misc/Help.cs b/src/Misc/Help.cs deleted file mode 100644 index 4a1d4a6..0000000 --- a/src/Misc/Help.cs +++ /dev/null @@ -1,217 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Security.Cryptography; -using System.Text; -using System.Windows.Forms; - -using Microsoft.Win32; - -using static mpvnet.Global; - -namespace mpvnet -{ - public static class StringHelp - { - public static string GetMD5Hash(string txt) - { - using (MD5 md5 = MD5.Create()) - { - byte[] inputBuffer = Encoding.UTF8.GetBytes(txt); - byte[] hashBuffer = md5.ComputeHash(inputBuffer); - return BitConverter.ToString(md5.ComputeHash(inputBuffer)).Replace("-", ""); - } - } - } - - public static class FileHelp - { - public static void Delete(string path) - { - try { - if (File.Exists(path)) - File.Delete(path); - } catch (Exception ex) { - Terminal.WriteError("Failed to delete file:" + BR + path + BR + ex.Message); - } - } - } - - public static class ProcessHelp - { - public static void Execute(string file, string arguments = null) - { - using (Process proc = new Process()) - { - proc.StartInfo.FileName = file; - proc.StartInfo.Arguments = arguments; - proc.StartInfo.UseShellExecute = false; - proc.Start(); - } - } - - public static void ShellExecute(string file, string arguments = null) - { - using (Process proc = new Process()) - { - proc.StartInfo.FileName = file; - proc.StartInfo.Arguments = arguments; - proc.StartInfo.UseShellExecute = true; - proc.Start(); - } - } - } - - public class CursorHelp - { - static bool IsVisible = true; - - public static void Show() - { - if (!IsVisible) - { - Cursor.Show(); - IsVisible = true; - } - } - - public static void Hide() - { - if (IsVisible) - { - Cursor.Hide(); - IsVisible = false; - } - } - - public static bool IsPosDifferent(Point screenPos) - { - return Math.Abs(screenPos.X - Control.MousePosition.X) > 10 || - Math.Abs(screenPos.Y - Control.MousePosition.Y) > 10; - } - } - - public class mpvHelp - { - public static string GetProfiles() - { - string json = Core.GetPropertyString("profile-list"); - var o = json.FromJson>>().OrderBy(i => i["name"]); - StringBuilder sb = new StringBuilder(); - - foreach (Dictionary i in o) - { - sb.Append(i["name"].ToString() + BR2); - - foreach (Dictionary i2 in i["options"] as List) - sb.AppendLine(" " + i2["key"] + " = " + i2["value"]); - - sb.Append(BR); - } - - return sb.ToString(); - } - - public static string GetDecoders() - { - string json = Core.GetPropertyString("decoder-list"); - var o = json.FromJson>>().OrderBy(i => i["codec"]); - StringBuilder sb = new StringBuilder(); - - foreach (Dictionary i in o) - sb.AppendLine(i["codec"] + " - " + i["description"]); - - return sb.ToString(); - } - - public static string GetProtocols() - { - string list = Core.GetPropertyString("protocol-list"); - return string.Join(BR, list.Split(',').OrderBy(a => a)); - } - - public static string GetDemuxers() - { - string list = Core.GetPropertyString("demuxer-lavf-list"); - return string.Join(BR, list.Split(',').OrderBy(a => a)); - } - } - - public class RegistryHelp - { - public static string ApplicationKey { get; } = @"HKCU\Software\" + Application.ProductName; - - public static void SetInt(string name, object value) - { - SetValue(ApplicationKey, name, value); - } - - public static void SetString(string name, string value) - { - SetValue(ApplicationKey, name, value); - } - - public static void SetValue(string name, object value) - { - using (RegistryKey regKey = GetRootKey(ApplicationKey).CreateSubKey(ApplicationKey.Substring(5), RegistryKeyPermissionCheck.ReadWriteSubTree)) - regKey.SetValue(name, value); - } - - public static void SetValue(string path, string name, object value) - { - using (RegistryKey regKey = GetRootKey(path).CreateSubKey(path.Substring(5), RegistryKeyPermissionCheck.ReadWriteSubTree)) - regKey.SetValue(name, value); - } - - public static string GetString(string name, string defaultValue = "") - { - object value = GetValue(ApplicationKey, name, defaultValue); - return !(value is string) ? defaultValue : value.ToString(); - } - - public static int GetInt(string name, int defaultValue = 0) - { - object value = GetValue(ApplicationKey, name, defaultValue); - return !(value is int) ? defaultValue : (int)value; - } - - public static object GetValue(string name) => GetValue(ApplicationKey, name, null); - - public static object GetValue(string path, string name, object defaultValue = null) - { - using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5))) - return regKey == null ? null : regKey.GetValue(name, defaultValue); - } - - public static void RemoveKey(string path) - { - try { - GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false); - } catch { } - } - - public static void RemoveValue(string path, string name) - { - try { - using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5), true)) - if (regKey != null) - regKey.DeleteValue(name, false); - } catch { } - } - - static RegistryKey GetRootKey(string path) - { - switch (path.Substring(0, 4)) - { - case "HKLM": return Registry.LocalMachine; - case "HKCU": return Registry.CurrentUser; - case "HKCR": return Registry.ClassesRoot; - default: throw new Exception(); - } - } - } -} diff --git a/src/Misc/JSONParser.cs b/src/Misc/JSONParser.cs deleted file mode 100644 index 3e2f365..0000000 --- a/src/Misc/JSONParser.cs +++ /dev/null @@ -1,415 +0,0 @@ - -// https://github.com/zanders3/json - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using System.Runtime.Serialization; -using System.Text; - -namespace mpvnet -{ - public static class JSONParser - { - [ThreadStatic] static Stack> splitArrayPool; - [ThreadStatic] static StringBuilder stringBuilder; - [ThreadStatic] static Dictionary> fieldInfoCache; - [ThreadStatic] static Dictionary> propertyInfoCache; - - public static T FromJson(this string json) - { - // Initialize, if needed, the ThreadStatic variables - if (propertyInfoCache == null) - propertyInfoCache = new Dictionary>(); - - if (fieldInfoCache == null) - fieldInfoCache = new Dictionary>(); - - if (stringBuilder == null) - stringBuilder = new StringBuilder(); - - if (splitArrayPool == null) - splitArrayPool = new Stack>(); - - //Remove all whitespace not within strings to make parsing simpler - stringBuilder.Length = 0; - - for (int i = 0; i < json.Length; i++) - { - char c = json[i]; - - if (c == '"') - { - i = AppendUntilStringEnd(true, i, json); - continue; - } - - if (char.IsWhiteSpace(c)) - continue; - - stringBuilder.Append(c); - } - - //Parse the thing! - return (T)ParseValue(typeof(T), stringBuilder.ToString()); - } - - static int AppendUntilStringEnd(bool appendEscapeCharacter, int startIdx, string json) - { - stringBuilder.Append(json[startIdx]); - - for (int i = startIdx + 1; i < json.Length; i++) - { - if (json[i] == '\\') - { - if (appendEscapeCharacter) - stringBuilder.Append(json[i]); - stringBuilder.Append(json[i + 1]); - i++;//Skip next character as it is escaped - } - else if (json[i] == '"') - { - stringBuilder.Append(json[i]); - return i; - } - else - stringBuilder.Append(json[i]); - } - - return json.Length - 1; - } - - //Splits { :, : } and [ , ] into a list of strings - static List Split(string json) - { - List splitArray = splitArrayPool.Count > 0 ? splitArrayPool.Pop() : new List(); - splitArray.Clear(); - - if (json.Length == 2) - return splitArray; - - int parseDepth = 0; - stringBuilder.Length = 0; - - for (int i = 1; i < json.Length - 1; i++) - { - switch (json[i]) - { - case '[': - case '{': - parseDepth++; - break; - case ']': - case '}': - parseDepth--; - break; - case '"': - i = AppendUntilStringEnd(true, i, json); - continue; - case ',': - case ':': - if (parseDepth == 0) - { - splitArray.Add(stringBuilder.ToString()); - stringBuilder.Length = 0; - continue; - } - break; - } - - stringBuilder.Append(json[i]); - } - - splitArray.Add(stringBuilder.ToString()); - - return splitArray; - } - - internal static object ParseValue(Type type, string json) - { - if (type == typeof(string)) - { - if (json.Length <= 2) - return string.Empty; - - StringBuilder parseStringBuilder = new StringBuilder(json.Length); - - for (int i = 1; i < json.Length - 1; ++i) - { - if (json[i] == '\\' && i + 1 < json.Length - 1) - { - int j = "\"\\nrtbf/".IndexOf(json[i + 1]); - - if (j >= 0) - { - parseStringBuilder.Append("\"\\\n\r\t\b\f/"[j]); - ++i; - continue; - } - if (json[i + 1] == 'u' && i + 5 < json.Length - 1) - { - uint c = 0; - - if (uint.TryParse(json.Substring(i + 2, 4), System.Globalization.NumberStyles.AllowHexSpecifier, null, out c)) - { - parseStringBuilder.Append((char)c); - i += 5; - continue; - } - } - } - - parseStringBuilder.Append(json[i]); - } - - return parseStringBuilder.ToString(); - } - - if (type.IsPrimitive) - { - var result = Convert.ChangeType(json, type, System.Globalization.CultureInfo.InvariantCulture); - return result; - } - - if (type == typeof(decimal)) - { - decimal result; - decimal.TryParse(json, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out result); - return result; - } - - if (json == "null") - return null; - - if (type.IsEnum) - { - if (json[0] == '"') - json = json.Substring(1, json.Length - 2); - - try - { - return Enum.Parse(type, json, false); - } - catch - { - return 0; - } - } - - if (type.IsArray) - { - Type arrayType = type.GetElementType(); - - if (json[0] != '[' || json[json.Length - 1] != ']') - return null; - - List elems = Split(json); - Array newArray = Array.CreateInstance(arrayType, elems.Count); - - for (int i = 0; i < elems.Count; i++) - newArray.SetValue(ParseValue(arrayType, elems[i]), i); - - splitArrayPool.Push(elems); - return newArray; - } - - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>)) - { - Type listType = type.GetGenericArguments()[0]; - - if (json[0] != '[' || json[json.Length - 1] != ']') - return null; - - List elems = Split(json); - var list = (IList)type.GetConstructor(new Type[] { typeof(int) }).Invoke(new object[] { elems.Count }); - - for (int i = 0; i < elems.Count; i++) - list.Add(ParseValue(listType, elems[i])); - - splitArrayPool.Push(elems); - return list; - } - - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>)) - { - Type keyType, valueType; - { - Type[] args = type.GetGenericArguments(); - keyType = args[0]; - valueType = args[1]; - } - - //Refuse to parse dictionary keys that aren't of type string - if (keyType != typeof(string)) - return null; - - //Must be a valid dictionary element - if (json[0] != '{' || json[json.Length - 1] != '}') - return null; - - //The list is split into key/value pairs only, this means the split must be divisible by 2 to be valid JSON - List elems = Split(json); - - if (elems.Count % 2 != 0) - return null; - - var dictionary = (IDictionary)type.GetConstructor(new Type[] { typeof(int) }).Invoke(new object[] { elems.Count / 2 }); - - for (int i = 0; i < elems.Count; i += 2) - { - if (elems[i].Length <= 2) - continue; - string keyValue = elems[i].Substring(1, elems[i].Length - 2); - object val = ParseValue(valueType, elems[i + 1]); - dictionary[keyValue] = val; - } - - return dictionary; - } - - if (type == typeof(object)) - return ParseAnonymousValue(json); - - if (json[0] == '{' && json[json.Length - 1] == '}') - return ParseObject(type, json); - - return null; - } - - static object ParseAnonymousValue(string json) - { - if (json.Length == 0) - return null; - - if (json[0] == '{' && json[json.Length - 1] == '}') - { - List elems = Split(json); - - if (elems.Count % 2 != 0) - return null; - - var dict = new Dictionary(elems.Count / 2); - - for (int i = 0; i < elems.Count; i += 2) - dict[elems[i].Substring(1, elems[i].Length - 2)] = ParseAnonymousValue(elems[i + 1]); - - return dict; - } - - if (json[0] == '[' && json[json.Length - 1] == ']') - { - List items = Split(json); - var finalList = new List(items.Count); - - for (int i = 0; i < items.Count; i++) - finalList.Add(ParseAnonymousValue(items[i])); - - return finalList; - } - - if (json[0] == '"' && json[json.Length - 1] == '"') - { - string str = json.Substring(1, json.Length - 2); - return str.Replace("\\", string.Empty); - } - - if (char.IsDigit(json[0]) || json[0] == '-') - { - if (json.Contains(".")) - { - double result; - double.TryParse(json, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out result); - return result; - } - else - { - int result; - int.TryParse(json, out result); - return result; - } - } - - if (json == "true") - return true; - - if (json == "false") - return false; - - // handles json == "null" as well as invalid JSON - return null; - } - - static Dictionary CreateMemberNameDictionary(T[] members) where T : MemberInfo - { - Dictionary nameToMember = new Dictionary(StringComparer.OrdinalIgnoreCase); - - for (int i = 0; i < members.Length; i++) - { - T member = members[i]; - - if (member.IsDefined(typeof(IgnoreDataMemberAttribute), true)) - continue; - - string name = member.Name; - - if (member.IsDefined(typeof(DataMemberAttribute), true)) - { - DataMemberAttribute dataMemberAttribute = (DataMemberAttribute)Attribute.GetCustomAttribute(member, typeof(DataMemberAttribute), true); - - if (!string.IsNullOrEmpty(dataMemberAttribute.Name)) - name = dataMemberAttribute.Name; - } - - nameToMember.Add(name, member); - } - - return nameToMember; - } - - static object ParseObject(Type type, string json) - { - object instance = FormatterServices.GetUninitializedObject(type); - - //The list is split into key/value pairs only, this means the split must be divisible by 2 to be valid JSON - List elems = Split(json); - - if (elems.Count % 2 != 0) - return instance; - - Dictionary nameToField; - Dictionary nameToProperty; - - if (!fieldInfoCache.TryGetValue(type, out nameToField)) - { - nameToField = CreateMemberNameDictionary(type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)); - fieldInfoCache.Add(type, nameToField); - } - - if (!propertyInfoCache.TryGetValue(type, out nameToProperty)) - { - nameToProperty = CreateMemberNameDictionary(type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)); - propertyInfoCache.Add(type, nameToProperty); - } - - for (int i = 0; i < elems.Count; i += 2) - { - if (elems[i].Length <= 2) - continue; - - string key = elems[i].Substring(1, elems[i].Length - 2); - string value = elems[i + 1]; - - FieldInfo fieldInfo; - PropertyInfo propertyInfo; - - if (nameToField.TryGetValue(key, out fieldInfo)) - fieldInfo.SetValue(instance, ParseValue(fieldInfo.FieldType, value)); - else if (nameToProperty.TryGetValue(key, out propertyInfo)) - propertyInfo.SetValue(instance, ParseValue(propertyInfo.PropertyType, value), null); - } - - return instance; - } - } -} diff --git a/src/Misc/Misc.cs b/src/Misc/Misc.cs deleted file mode 100644 index 0901fee..0000000 --- a/src/Misc/Misc.cs +++ /dev/null @@ -1,253 +0,0 @@ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Serialization; -using System.Windows.Forms; - -using Microsoft.Win32; - -using static mpvnet.Global; - -namespace mpvnet -{ - public class Sys - { - public static bool IsDarkTheme { - get { - object value = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1); - - if (value is null) - value = 1; - - return (int)value == 0; - } - } - } - - public class StringLogicalComparer : IComparer, IComparer - { - [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] - public static extern int StrCmpLogical(string x, string y); - - int IComparer_Compare(object x, object y) => StrCmpLogical(x.ToString(), y.ToString()); - int IComparer.Compare(object x, object y) => IComparer_Compare(x, y); - int IComparerOfString_Compare(string x, string y) => StrCmpLogical(x, y); - int IComparer.Compare(string x, string y) => IComparerOfString_Compare(x, y); - } - - public class Input - { - public static string WM_APPCOMMAND_to_mpv_key(int value) - { - switch (value) - { - case 5: return "SEARCH"; // BROWSER_SEARCH - case 6: return "FAVORITES"; // BROWSER_FAVORITES - case 7: return "HOMEPAGE"; // BROWSER_HOME - case 15: return "MAIL"; // LAUNCH_MAIL - case 33: return "PRINT"; // PRINT - case 11: return "NEXT"; // MEDIA_NEXTTRACK - case 12: return "PREV"; // MEDIA_PREVIOUSTRACK - case 13: return "STOP"; // MEDIA_STOP - case 14: return "PLAYPAUSE"; // MEDIA_PLAY_PAUSE - case 46: return "PLAY"; // MEDIA_PLAY - case 47: return "PAUSE"; // MEDIA_PAUSE - case 48: return "RECORD"; // MEDIA_RECORD - case 49: return "FORWARD"; // MEDIA_FAST_FORWARD - case 50: return "REWIND"; // MEDIA_REWIND - case 51: return "CHANNEL_UP"; // MEDIA_CHANNEL_UP - case 52: return "CHANNEL_DOWN"; // MEDIA_CHANNEL_DOWN - } - - return null; - } - } - - public class MediaTrack - { - public int ID { get; set; } - public bool External { get; set; } - public string Text { get; set; } = ""; - public string Type { get; set; } - } - - public class CommandItem : INotifyPropertyChanged - { - public event PropertyChangedEventHandler PropertyChanged; - - public string Path { get; set; } = ""; - public string Command { get; set; } = ""; - - public string Display { - get { - if (string.IsNullOrEmpty(Path)) - { - if (Command.Length > 47) - return Command.Substring(0, 47) + "..."; - return Command; - } - else - return Path; - } - } - - public CommandItem() { } - - public CommandItem(SerializationInfo info, StreamingContext context) { } - - void NotifyPropertyChanged([CallerMemberName] string propertyName = "") - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - - string _Input = ""; - - public string Input { - get => _Input; - set { - _Input = value; - NotifyPropertyChanged(); - } - } - - public string Alias { - get { - if (Input.Contains("SHARP") || Input.Contains("sharp") || Input.Contains("Sharp")) - return "#"; - return null; - } - } - - public static ObservableCollection GetItems(string content) - { - var items = new ObservableCollection(); - - if (!string.IsNullOrEmpty(content)) - { - foreach (string line in content.Split('\r', '\n')) - { - string val = line.Trim(); - - if (val.StartsWith("#")) - continue; - - if (!val.Contains(" ")) - continue; - - CommandItem item = new CommandItem(); - item.Input = val.Substring(0, val.IndexOf(" ")); - - if (item.Input == "_") - item.Input = ""; - - val = val.Substring(val.IndexOf(" ") + 1); - - if (val.Contains("#menu:")) - { - item.Path = val.Substring(val.IndexOf("#menu:") + 6).Trim(); - val = val.Substring(0, val.IndexOf("#menu:")); - - if (item.Path.Contains(";")) - item.Path = item.Path.Substring(item.Path.IndexOf(";") + 1).Trim(); - } - - item.Command = val.Trim(); - - if (item.Command == "") - continue; - - if (item.Command.ToLower() == "ignore") - item.Command = ""; - - items.Add(item); - } - } - return items; - } - - static ObservableCollection _Items; - - public static ObservableCollection Items { - get { - if (_Items is null) - _Items = GetItems(File.ReadAllText(Core.InputConfPath)); - return _Items; - } - } - } - - public class Folder - { - public static string Startup { get; } = Application.StartupPath.AddSep(); - public static string AppData { get; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).AddSep(); - } - - public class CommandPaletteItem - { - public CommandPaletteItem() {} - - public CommandPaletteItem(string text, Action action) - { - Text = text; - Action = action; - } - - public CommandPaletteItem(string text, string secondaryText, Action action) - { - Text = text; - Action = action; - SecondaryText = secondaryText; - } - - public string Text { get; set; } = ""; - public string SecondaryText { get; set; } = ""; - public Action Action { get; set; } - public CommandItem CommandItem { get; set; } - } - - public class CommandPalette - { - public static CommandPaletteControl Instance { get; } = new CommandPaletteControl(); - - public static IEnumerable GetItems() - { - return CommandItem.Items - .Where(i => i.Command != "") - .Select(i => new CommandPaletteItem() { - Text = i.Display, - SecondaryText = i.Input, - Action = () => Core.Command(i.Command), - CommandItem = i - }); - } - } - - public class Chapter - { - public string Title { get; set; } - public double Time { get; set; } - - string _TimeDisplay; - - public string TimeDisplay { - get { - if (_TimeDisplay == null) - { - _TimeDisplay = TimeSpan.FromSeconds(Time).ToString(); - - if (_TimeDisplay.ContainsEx(".")) - _TimeDisplay = _TimeDisplay.Substring(0, _TimeDisplay.LastIndexOf(".")); - } - - return _TimeDisplay; - } - } - } -} diff --git a/src/Misc/Player.cs b/src/Misc/Player.cs deleted file mode 100644 index c00caff..0000000 --- a/src/Misc/Player.cs +++ /dev/null @@ -1,1890 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading; -using System.Windows.Forms; - -using static libmpv; -using static mpvnet.Global; -using System.Text.RegularExpressions; - -namespace mpvnet -{ - public class CorePlayer - { - public static string[] VideoTypes { get; set; } = "mkv mp4 avi mov flv mpg webm wmv ts vob 264 265 asf avc avs dav h264 h265 hevc m2t m2ts m2v m4v mpeg mpv mts vpy y4m".Split(' '); - public static string[] AudioTypes { get; set; } = "mp3 flac m4a mka mp2 ogg opus aac ac3 dts dtshd dtshr dtsma eac3 mpa mpc thd w64 wav".Split(' '); - public static string[] ImageTypes { get; set; } = { "jpg", "bmp", "png", "gif", "webp" }; - public static string[] SubtitleTypes { get; } = { "srt", "ass", "idx", "sub", "sup", "ttxt", "txt", "ssa", "smi", "mks" }; - - public event Action LogMessageAsync; // log-message MPV_EVENT_LOG_MESSAGE - public event Action EndFileAsync; // end-file MPV_EVENT_END_FILE - public event Action ClientMessageAsync; // client-message MPV_EVENT_CLIENT_MESSAGE - public event Action GetPropertyReplyAsync; // get-property-reply MPV_EVENT_GET_PROPERTY_REPLY - public event Action SetPropertyReplyAsync; // set-property-reply MPV_EVENT_SET_PROPERTY_REPLY - public event Action CommandReplyAsync; // command-reply MPV_EVENT_COMMAND_REPLY - public event Action StartFileAsync; // start-file MPV_EVENT_START_FILE - public event Action FileLoadedAsync; // file-loaded MPV_EVENT_FILE_LOADED - public event Action VideoReconfigAsync; // video-reconfig MPV_EVENT_VIDEO_RECONFIG - public event Action AudioReconfigAsync; // audio-reconfig MPV_EVENT_AUDIO_RECONFIG - public event Action SeekAsync; // seek MPV_EVENT_SEEK - public event Action PlaybackRestartAsync; // playback-restart MPV_EVENT_PLAYBACK_RESTART - - public event ActionLogMessage; // log-message MPV_EVENT_LOG_MESSAGE - public event Action EndFile; // end-file MPV_EVENT_END_FILE - public event Action ClientMessage; // client-message MPV_EVENT_CLIENT_MESSAGE - public event Action Shutdown; // shutdown MPV_EVENT_SHUTDOWN - public event Action GetPropertyReply; // get-property-reply MPV_EVENT_GET_PROPERTY_REPLY - public event Action SetPropertyReply; // set-property-reply MPV_EVENT_SET_PROPERTY_REPLY - public event Action CommandReply; // command-reply MPV_EVENT_COMMAND_REPLY - public event Action StartFile; // start-file MPV_EVENT_START_FILE - public event Action FileLoaded; // file-loaded MPV_EVENT_FILE_LOADED - public event Action VideoReconfig; // video-reconfig MPV_EVENT_VIDEO_RECONFIG - public event Action AudioReconfig; // audio-reconfig MPV_EVENT_AUDIO_RECONFIG - public event Action Seek; // seek MPV_EVENT_SEEK - public event Action PlaybackRestart; // playback-restart MPV_EVENT_PLAYBACK_RESTART - - public event Action Initialized; - public event Action InitializedAsync; - public event Action Pause; - public event Action ShowMenu; - public event Action WindowScaleMpv; - public event Action ScaleWindow; - public event Action WindowScaleNET; - public event Action PlaylistPosChanged; - public event Action PlaylistPosChangedAsync; - public event Action VideoSizeChanged; - public event Action VideoSizeChangedAsync; - public event Action MoveWindow; - - public Dictionary> PropChangeActions { get; set; } = new Dictionary>(); - public Dictionary>> IntPropChangeActions { get; set; } = new Dictionary>>(); - public Dictionary>> BoolPropChangeActions { get; set; } = new Dictionary>>(); - public Dictionary>> DoublePropChangeActions { get; set; } = new Dictionary>>(); - public Dictionary>> StringPropChangeActions { get; set; } = new Dictionary>>(); - - public AutoResetEvent ShutdownAutoResetEvent { get; } = new AutoResetEvent(false); - public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false); - public DateTime HistoryTime; - public IntPtr Handle { get; set; } - public IntPtr NamedHandle { get; set; } - public List MediaTracks { get; set; } = new List(); - public List BluRayTitles { get; } = new List(); - public object MediaTracksLock { get; } = new object(); - public Size VideoSize { get; set; } - public TimeSpan Duration; - - public string ConfPath { get => ConfigFolder + "mpv.conf"; } - public string GPUAPI { get; set; } = "auto"; - public string InputConfPath => ConfigFolder + "input.conf"; - public string Path { get; set; } = ""; - public string VO { get; set; } = "gpu"; - - public string VID { get; set; } = ""; - public string AID { get; set; } = ""; - public string SID { get; set; } = ""; - - public bool Border { get; set; } = true; - public bool FileEnded { get; set; } - public bool Fullscreen { get; set; } - public bool IsQuitNeeded { set; get; } = true; - public bool KeepaspectWindow { get; set; } - public bool Paused { get; set; } - public bool Shown { get; set; } - public bool SnapWindow { get; set; } - public bool TaskbarProgress { get; set; } = true; - public bool WasInitialSizeSet; - public bool WindowMaximized { get; set; } - public bool WindowMinimized { get; set; } - - public int Edition { get; set; } - public int PlaylistPos { get; set; } = -1; - public int Screen { get; set; } = -1; - public int VideoRotate { get; set; } - - public float Autofit { get; set; } = 0.6f; - public float AutofitSmaller { get; set; } = 0.3f; - public float AutofitLarger { get; set; } = 0.8f; - - public void Init(IntPtr handle) - { - ApplyShowMenuFix(); - - Handle = mpv_create(); - - var events = Enum.GetValues(typeof(mpv_event_id)).Cast(); - - foreach (mpv_event_id i in events) - mpv_request_event(Handle, i, 0); - - mpv_request_log_messages(Handle, "no"); - - App.RunTask(() => MainEventLoop()); - - if (Handle == IntPtr.Zero) - throw new Exception("error mpv_create"); - - if (App.IsTerminalAttached) - { - SetPropertyString("terminal", "yes"); - SetPropertyString("input-terminal", "yes"); - } - - SetPropertyInt("osd-duration", 2000); - SetPropertyLong("wid", handle.ToInt64()); - - SetPropertyBool("input-default-bindings", true); - SetPropertyBool("input-builtin-bindings", false); - - SetPropertyString("watch-later-options", "mute"); - SetPropertyString("screenshot-directory", "~~desktop/"); - SetPropertyString("osd-playing-msg", "${media-title}"); - SetPropertyString("osc", "yes"); - SetPropertyString("force-window", "yes"); - SetPropertyString("config-dir", ConfigFolder); - SetPropertyString("config", "yes"); - - ProcessCommandLine(true); - - Environment.SetEnvironmentVariable("MPVNET_VERSION", Application.ProductVersion); - - mpv_error err = mpv_initialize(Handle); - - if (err < 0) - throw new Exception("mpv_initialize error" + BR2 + GetError(err) + BR); - - string idle = GetPropertyString("idle"); - App.Exit = idle == "no" || idle == "once"; - - NamedHandle = mpv_create_client(Handle, "mpvnet"); - - if (NamedHandle == IntPtr.Zero) - throw new Exception("mpv_create_client error"); - - mpv_request_log_messages(NamedHandle, "terminal-default"); - - App.RunTask(() => EventLoop()); - - // otherwise shutdown is raised before media files are loaded, - // this means Lua scripts that use idle might not work correctly - SetPropertyString("idle", "yes"); - - ObservePropertyDouble("window-scale", value => WindowScaleMpv(value)); - - ObservePropertyString("path", value => { - if (HistoryTime == DateTime.MinValue) - { - HistoryTime = DateTime.Now; - HistoryPath = value; - } - Path = value; - }); - - ObservePropertyBool("pause", value => { - Paused = value; - Pause(); - }); - - ObservePropertyInt("video-rotate", value => { - VideoRotate = value; - UpdateVideoSize("dwidth", "dheight"); - }); - - ObservePropertyInt("playlist-pos", value => { - PlaylistPos = value; - InvokeEvent(PlaylistPosChanged, PlaylistPosChangedAsync, value); - - if (value == -1 && Core.Shown) - ShowLogo(); - - if (value != -1) - HideLogo(); - - if (FileEnded && value == -1) - { - if (GetPropertyString("keep-open") == "no" && App.Exit) - Core.CommandV("quit"); - } - }); - - if (!GetPropertyBool("osd-scale-by-window")) - App.StartThreshold = 0; - - Initialized?.Invoke(); - InvokeAsync(InitializedAsync); - } - - public void Destroy() - { - mpv_destroy(Handle); - mpv_destroy(NamedHandle); - } - - void ApplyShowMenuFix() - { - if (App.Settings.ShowMenuFixApplied) - return; - - if (File.Exists(InputConfPath)) - { - string content = File.ReadAllText(InputConfPath); - - if (!content.Contains("script-message mpv.net show-menu") && - !content.Contains("script-message-to mpvnet show-menu")) - - File.WriteAllText(InputConfPath, BR + content.Trim() + BR + - "MBTN_Right script-message-to mpvnet show-menu" + BR); - } - - App.Settings.ShowMenuFixApplied = true; - } - - void ApplyInputDefaultBindingsFix() - { - if (App.Settings.InputDefaultBindingsFixApplied) - return; - - if (File.Exists(ConfPath)) - { - string content = File.ReadAllText(ConfPath); - - if (content.Contains("input-default-bindings = no")) - File.WriteAllText(ConfPath, content.Replace("input-default-bindings = no", "")); - - if (content.Contains("input-default-bindings=no")) - File.WriteAllText(ConfPath, content.Replace("input-default-bindings=no", "")); - } - - App.Settings.InputDefaultBindingsFixApplied = true; - } - - public void ProcessProperty(string name, string value) - { - switch (name) - { - case "autofit": - { - if (int.TryParse(value.Trim('%'), out int result)) - Autofit = result / 100f; - } - break; - case "autofit-smaller": - { - if (int.TryParse(value.Trim('%'), out int result)) - AutofitSmaller = result / 100f; - } - break; - case "autofit-larger": - { - if (int.TryParse(value.Trim('%'), out int result)) - AutofitLarger = result / 100f; - } - break; - case "border": Border = value == "yes"; break; - case "fs": - case "fullscreen": Fullscreen = value == "yes"; break; - case "gpu-api": GPUAPI = value; break; - case "keepaspect-window": KeepaspectWindow = value == "yes"; break; - case "screen": Screen = Convert.ToInt32(value); break; - case "snap-window": SnapWindow = value == "yes"; break; - case "taskbar-progress": TaskbarProgress = value == "yes"; break; - case "vo": VO = value; break; - case "window-maximized": WindowMaximized = value == "yes"; break; - case "window-minimized": WindowMinimized = value == "yes"; break; - } - - if (AutofitLarger > 1) - AutofitLarger = 1; - } - - bool? _UseNewMsgModel; - - public bool UseNewMsgModel { - get { - if (!_UseNewMsgModel.HasValue) - _UseNewMsgModel = InputConfContent.Contains("script-message-to mpvnet"); - return _UseNewMsgModel.Value; - } - } - - string _InputConfContent; - - public string InputConfContent { - get { - if (_InputConfContent == null) - _InputConfContent = File.ReadAllText(Core.InputConfPath); - return _InputConfContent; - } - } - - string _ConfigFolder; - - public string ConfigFolder { - get { - if (_ConfigFolder == null) - { - _ConfigFolder = Folder.Startup + "portable_config"; - - if (!Directory.Exists(_ConfigFolder)) - _ConfigFolder = Folder.AppData + "mpv.net"; - - if (!Directory.Exists(_ConfigFolder)) - { - try { - using (Process proc = new Process()) - { - proc.StartInfo.UseShellExecute = false; - proc.StartInfo.CreateNoWindow = true; - proc.StartInfo.FileName = "powershell.exe"; - proc.StartInfo.Arguments = $@"-Command New-Item -Path '{_ConfigFolder}' -ItemType Directory"; - proc.Start(); - proc.WaitForExit(); - } - } catch (Exception) {} - - if (!Directory.Exists(_ConfigFolder)) - Directory.CreateDirectory(_ConfigFolder); - } - - _ConfigFolder = _ConfigFolder.AddSep(); - - if (!File.Exists(_ConfigFolder + "input.conf")) - { - File.WriteAllText(_ConfigFolder + "input.conf", Properties.Resources.input_conf); - - string scriptOptsPath = _ConfigFolder + "script-opts" + System.IO.Path.DirectorySeparatorChar; - - if (!Directory.Exists(scriptOptsPath)) - { - Directory.CreateDirectory(scriptOptsPath); - File.WriteAllText(scriptOptsPath + "console.conf", BR + "scale=1.5" + BR); - string content = BR + "scalewindowed=1.5" + BR + "hidetimeout=2000" + BR + - "idlescreen=no" + BR; - File.WriteAllText(scriptOptsPath + "osc.conf", content); - } - } - } - - return _ConfigFolder; - } - } - - Dictionary _Conf; - - public Dictionary Conf { - get { - if (_Conf == null) - { - ApplyInputDefaultBindingsFix(); - - _Conf = new Dictionary(); - - if (File.Exists(ConfPath)) - foreach (var i in File.ReadAllLines(ConfPath)) - if (i.Contains("=") && !i.TrimStart().StartsWith("#")) - { - string key = i.Substring(0, i.IndexOf("=")).Trim(); - string value = i.Substring(i.IndexOf("=") + 1).Trim(); - - if (key.StartsWith("-")) - key = key.TrimStart('-'); - - if (value.Contains("#") && !value.StartsWith("#") && - !value.StartsWith("'#") && !value.StartsWith("\"#")) - - value = value.Substring(0, value.IndexOf("#")).Trim(); - - _Conf[key] = value; - } - - foreach (var i in _Conf) - ProcessProperty(i.Key, i.Value); - } - - return _Conf; - } - } - - public void LoadScripts() - { - if (Directory.Exists(ConfigFolder + "scripts-ps")) - foreach (string file in Directory.GetFiles(ConfigFolder + "scripts-ps", "*.ps1")) - App.RunTask(() => InvokePowerShellScript(file)); - } - - public void InvokePowerShellScript(string file) - { - PowerShell ps = new PowerShell(); - ps.Variables.Add(new KeyValuePair("core", Core)); - ps.Variables.Add(new KeyValuePair("window", MainForm.Instance)); - ps.Scripts.Add("Using namespace mpvnet; [Reflection.Assembly]::LoadWithPartialName('mpvnet')" + BR); - - string eventCode = @" - $eventJob = Register-ObjectEvent -InputObject $mp -EventName Event -Action { - foreach ($pair in $mp.EventHandlers) - { - if ($pair.Key -eq $args[0]) - { - if ($args.Length -gt 1) - { - $args2 = $args[1] - } - - Invoke-Command -ScriptBlock $pair.Value -ArgumentList $args2 - } - } - } - - $mp.RedirectStreams($eventJob) - "; - - string propertyChangedCode = @" - $propertyChangedJob = Register-ObjectEvent -InputObject $mp -EventName PropertyChanged -Action { - foreach ($pair in $mp.PropChangedHandlers) - { - if ($pair.Key -eq $args[0]) - { - if ($args.Length -gt 1) - { - $args2 = $args[1] - } - - Invoke-Command -ScriptBlock $pair.Value -ArgumentList $args2 - } - } - } - - $mp.RedirectStreams($propertyChangedJob) - "; - - ps.Scripts.Add(eventCode); - ps.Scripts.Add(propertyChangedCode); - ps.Scripts.Add(File.ReadAllText(file)); - ps.Module = System.IO.Path.GetFileName(file); - ps.Print = true; - - lock (PowerShell.References) - PowerShell.References.Add(ps); - - ps.Invoke(); - } - - void UpdateVideoSize(string w, string h) - { - Size size = new Size(GetPropertyInt(w), GetPropertyInt(h)); - - if (size.Width == 0 || size.Height == 0) - return; - - if (VideoRotate == 90 || VideoRotate == 270) - size = new Size(size.Height, size.Width); - - if (VideoSize != size) - { - VideoSize = size; - InvokeEvent(VideoSizeChanged, VideoSizeChangedAsync, size); - VideoSizeAutoResetEvent.Set(); - } - } - - public void MainEventLoop() - { - while (true) - mpv_wait_event(Handle, -1); - } - - public void EventLoop() - { - while (true) - { - IntPtr ptr = mpv_wait_event(NamedHandle, -1); - mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event)); - - try - { - switch (evt.event_id) - { - case mpv_event_id.MPV_EVENT_SHUTDOWN: - IsQuitNeeded = false; - Shutdown?.Invoke(); - WriteHistory(); - ShutdownAutoResetEvent.Set(); - return; - case mpv_event_id.MPV_EVENT_LOG_MESSAGE: - { - var data = (mpv_event_log_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_log_message)); - - if (data.log_level == mpv_log_level.MPV_LOG_LEVEL_INFO) - { - string prefix = ConvertFromUtf8(data.prefix); - - if (prefix == "bd") - ProcessBluRayLogMessage(ConvertFromUtf8(data.text)); - } - - if (LogMessage != null || LogMessageAsync != null) - { - string msg = $"[{ConvertFromUtf8(data.prefix)}] {ConvertFromUtf8(data.text)}"; - InvokeAsync(LogMessageAsync, data.log_level, msg); - LogMessage?.Invoke(data.log_level, msg); - } - } - break; - case mpv_event_id.MPV_EVENT_CLIENT_MESSAGE: - { - var data = (mpv_event_client_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_client_message)); - string[] args = ConvertFromUtf8Strings(data.args, data.num_args); - - if (UseNewMsgModel && args[0] != "mpv.net") - App.RunTask(() => Commands.Execute(args[0], args.Skip(1).ToArray())); - else if (args.Length > 1 && args[0] == "mpv.net") - App.RunTask(() => Commands.Execute(args[1], args.Skip(2).ToArray())); - - if (args.Length > 1 && args[0] == "osc-idlescreen") - { - if (args[1] == "no") - HideLogo(); - else if (args[1] == "yes" && PlaylistPos == -1) - ShowLogo(); - } - - InvokeAsync(ClientMessageAsync, args); - ClientMessage?.Invoke(args); - } - break; - case mpv_event_id.MPV_EVENT_VIDEO_RECONFIG: - UpdateVideoSize("dwidth", "dheight"); - InvokeEvent(VideoReconfig, VideoReconfigAsync); - break; - case mpv_event_id.MPV_EVENT_END_FILE: - { - var data = (mpv_event_end_file)Marshal.PtrToStructure(evt.data, typeof(mpv_event_end_file)); - var reason = (mpv_end_file_reason)data.reason; - InvokeAsync(EndFileAsync, reason); - EndFile?.Invoke(reason); - FileEnded = true; - } - break; - case mpv_event_id.MPV_EVENT_FILE_LOADED: - { - if (App.AutoPlay && Paused) - SetPropertyBool("pause", false); - - App.QuickBookmark = 0; - - HideLogo(); - - Duration = TimeSpan.FromSeconds(GetPropertyDouble("duration")); - - if (App.StartSize == "video") - WasInitialSizeSet = false; - - string path = GetPropertyString("path"); - - if (!VideoTypes.Contains(path.Ext()) || AudioTypes.Contains(path.Ext())) - { - UpdateVideoSize("width", "height"); - VideoSizeAutoResetEvent.Set(); - } - - App.RunTask(new Action(() => UpdateTracks())); - App.RunTask(new Action(() => WriteHistory())); - - InvokeEvent(FileLoaded, FileLoadedAsync); - } - break; - case mpv_event_id.MPV_EVENT_PROPERTY_CHANGE: - { - var data = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property)); - - if (data.format == mpv_format.MPV_FORMAT_FLAG) - { - lock (BoolPropChangeActions) - foreach (var pair in BoolPropChangeActions) - if (pair.Key == data.name) - { - bool value = Marshal.PtrToStructure(data.data) == 1; - - foreach (var action in pair.Value) - action.Invoke(value); - } - } - else if (data.format == mpv_format.MPV_FORMAT_STRING) - { - lock (StringPropChangeActions) - foreach (var pair in StringPropChangeActions) - if (pair.Key == data.name) - { - string value = ConvertFromUtf8(Marshal.PtrToStructure(data.data)); - - foreach (var action in pair.Value) - action.Invoke(value); - } - } - else if (data.format == mpv_format.MPV_FORMAT_INT64) - { - lock (IntPropChangeActions) - foreach (var pair in IntPropChangeActions) - if (pair.Key == data.name) - { - int value = Marshal.PtrToStructure(data.data); - - foreach (var action in pair.Value) - action.Invoke(value); - } - } - else if (data.format == mpv_format.MPV_FORMAT_NONE) - { - lock (PropChangeActions) - foreach (var pair in PropChangeActions) - if (pair.Key == data.name) - foreach (var action in pair.Value) - action.Invoke(); - } - else if (data.format == mpv_format.MPV_FORMAT_DOUBLE) - { - lock (DoublePropChangeActions) - foreach (var pair in DoublePropChangeActions) - if (pair.Key == data.name) - { - double value = Marshal.PtrToStructure(data.data); - - foreach (var action in pair.Value) - action.Invoke(value); - } - } - } - break; - case mpv_event_id.MPV_EVENT_GET_PROPERTY_REPLY: - InvokeEvent(GetPropertyReply, GetPropertyReplyAsync); - break; - case mpv_event_id.MPV_EVENT_SET_PROPERTY_REPLY: - InvokeEvent(SetPropertyReply, SetPropertyReplyAsync); - break; - case mpv_event_id.MPV_EVENT_COMMAND_REPLY: - InvokeEvent(CommandReply, CommandReplyAsync); - break; - case mpv_event_id.MPV_EVENT_START_FILE: - InvokeEvent(StartFile, StartFileAsync); - App.RunTask(() => LoadFolder()); - break; - case mpv_event_id.MPV_EVENT_AUDIO_RECONFIG: - InvokeEvent(AudioReconfig, AudioReconfigAsync); - break; - case mpv_event_id.MPV_EVENT_SEEK: - InvokeEvent(Seek, SeekAsync); - break; - case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART: - InvokeEvent(PlaybackRestart, PlaybackRestartAsync); - break; - } - } - catch (Exception ex) - { - App.ShowException(ex); - } - } - } - - void ProcessBluRayLogMessage(string msg) - { - lock (BluRayTitles) - { - if (msg.Contains(" 0 duration: ")) - BluRayTitles.Clear(); - - if (msg.Contains(" duration: ")) - { - int start = msg.IndexOf(" duration: ") + 11; - BluRayTitles.Add(new TimeSpan( - msg.Substring(start, 2).ToInt(), - msg.Substring(start + 3, 2).ToInt(), - msg.Substring(start + 6, 2).ToInt())); - } - } - } - - public void SetBluRayTitle(int id) - { - LoadFiles(new[] { @"bd://" + id }, false, false); - } - - void InvokeEvent(Action action, Action asyncAction) - { - InvokeAsync(asyncAction); - action?.Invoke(); - } - - void InvokeEvent(Action action, Action asyncAction, T t) - { - InvokeAsync(asyncAction, t); - action?.Invoke(t); - } - - void InvokeAsync(Action action) - { - if (action != null) - { - foreach (Action a in action.GetInvocationList()) - { - var a2 = a; - App.RunTask(a2); - } - } - } - - void InvokeAsync(Action action, T t) - { - if (action != null) - { - foreach (Action a in action.GetInvocationList()) - { - var a2 = a; - App.RunTask(() => a2.Invoke(t)); - } - } - } - - void InvokeAsync(Action action, T1 t1, T2 t2) - { - if (action != null) - { - foreach (Action a in action.GetInvocationList()) - { - var a2 = a; - App.RunTask(() => a2.Invoke(t1, t2)); - } - } - } - - public void Command(string command) - { - mpv_error err = mpv_command_string(Handle, command); - if (err < 0) - HandleError(err, "error executing command: " + command); - } - - public void CommandV(params string[] args) - { - int count = args.Length + 1; - IntPtr[] pointers = new IntPtr[count]; - IntPtr rootPtr = Marshal.AllocHGlobal(IntPtr.Size * count); - - for (int index = 0; index < args.Length; index++) - { - var bytes = GetUtf8Bytes(args[index]); - IntPtr ptr = Marshal.AllocHGlobal(bytes.Length); - Marshal.Copy(bytes, 0, ptr, bytes.Length); - pointers[index] = ptr; - } - - Marshal.Copy(pointers, 0, rootPtr, count); - mpv_error err = mpv_command(Handle, rootPtr); - - foreach (IntPtr ptr in pointers) - Marshal.FreeHGlobal(ptr); - - Marshal.FreeHGlobal(rootPtr); - if (err < 0) - HandleError(err, "error executing command: " + string.Join("\n", args)); - } - - public string Expand(string value) - { - if (value == null) - return ""; - - if (!value.Contains("${")) - return value; - - string[] args = { "expand-text", value }; - int count = args.Length + 1; - IntPtr[] pointers = new IntPtr[count]; - IntPtr rootPtr = Marshal.AllocHGlobal(IntPtr.Size * count); - - for (int index = 0; index < args.Length; index++) - { - var bytes = GetUtf8Bytes(args[index]); - IntPtr ptr = Marshal.AllocHGlobal(bytes.Length); - Marshal.Copy(bytes, 0, ptr, bytes.Length); - pointers[index] = ptr; - } - - Marshal.Copy(pointers, 0, rootPtr, count); - IntPtr resultNodePtr = Marshal.AllocHGlobal(16); - mpv_error err = mpv_command_ret(Handle, rootPtr, resultNodePtr); - - foreach (IntPtr ptr in pointers) - Marshal.FreeHGlobal(ptr); - - Marshal.FreeHGlobal(rootPtr); - - if (err < 0) - { - HandleError(err, "error executing command: " + string.Join("\n", args)); - Marshal.FreeHGlobal(resultNodePtr); - return "property expansion error"; - } - - mpv_node resultNode = Marshal.PtrToStructure(resultNodePtr); - string ret = ConvertFromUtf8(resultNode.str); - mpv_free_node_contents(resultNodePtr); - Marshal.FreeHGlobal(resultNodePtr); - return ret; - } - - public bool GetPropertyBool(string name) - { - mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), - mpv_format.MPV_FORMAT_FLAG, out IntPtr lpBuffer); - if (err < 0) - HandleError(err, "error getting property: " + name); - return lpBuffer.ToInt32() != 0; - } - - public void SetPropertyBool(string name, bool value) - { - long val = value ? 1 : 0; - mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_FLAG, ref val); - if (err < 0) - HandleError(err, $"error setting property: {name} = {value}"); - } - - public int GetPropertyInt(string name) - { - mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), - mpv_format.MPV_FORMAT_INT64, out IntPtr lpBuffer); - if (err < 0 && App.DebugMode) - HandleError(err, "error getting property: " + name); - return lpBuffer.ToInt32(); - } - - public void SetPropertyInt(string name, int value) - { - long val = value; - mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val); - if (err < 0) - HandleError(err, $"error setting property: {name} = {value}"); - } - - public void SetPropertyLong(string name, long value) - { - mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref value); - if (err < 0) - HandleError(err, $"error setting property: {name} = {value}"); - } - - public long GetPropertyLong(string name) - { - mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), - mpv_format.MPV_FORMAT_INT64, out IntPtr lpBuffer); - if (err < 0) - HandleError(err, "error getting property: " + name); - return lpBuffer.ToInt64(); - } - - public double GetPropertyDouble(string name, bool handleError = true) - { - mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), - mpv_format.MPV_FORMAT_DOUBLE, out double value); - if (err < 0 && handleError && App.DebugMode) - HandleError(err, "error getting property: " + name); - return value; - } - - public void SetPropertyDouble(string name, double value) - { - double val = value; - mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_DOUBLE, ref val); - if (err < 0) - HandleError(err, $"error setting property: {name} = {value}"); - } - - public string GetPropertyString(string name) - { - mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), - mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer); - - if (err == 0) - { - string ret = ConvertFromUtf8(lpBuffer); - mpv_free(lpBuffer); - return ret; - } - - if (err < 0 && App.DebugMode) - HandleError(err, "error getting property: " + name); - - return ""; - } - - public void SetPropertyString(string name, string value) - { - byte[] bytes = GetUtf8Bytes(value); - mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes); - if (err < 0) - HandleError(err, $"error setting property: {name} = {value}"); - } - - public string GetPropertyOsdString(string name) - { - mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), - mpv_format.MPV_FORMAT_OSD_STRING, out IntPtr lpBuffer); - - if (err == 0) - { - string ret = ConvertFromUtf8(lpBuffer); - mpv_free(lpBuffer); - return ret; - } - - if (err < 0) - HandleError(err, "error getting property: " + name); - - return ""; - } - - public void ObservePropertyInt(string name, Action action) - { - lock (IntPropChangeActions) - { - if (!IntPropChangeActions.ContainsKey(name)) - { - mpv_error err = mpv_observe_property(NamedHandle, 0, name, mpv_format.MPV_FORMAT_INT64); - - if (err < 0) - HandleError(err, "error observing property: " + name); - else - IntPropChangeActions[name] = new List>(); - } - - if (IntPropChangeActions.ContainsKey(name)) - IntPropChangeActions[name].Add(action); - } - } - - public void ObservePropertyDouble(string name, Action action) - { - lock (DoublePropChangeActions) - { - if (!DoublePropChangeActions.ContainsKey(name)) - { - mpv_error err = mpv_observe_property(NamedHandle, 0, name, mpv_format.MPV_FORMAT_DOUBLE); - - if (err < 0) - HandleError(err, "error observing property: " + name); - else - DoublePropChangeActions[name] = new List>(); - } - - if (DoublePropChangeActions.ContainsKey(name)) - DoublePropChangeActions[name].Add(action); - } - } - - public void ObservePropertyBool(string name, Action action) - { - lock (BoolPropChangeActions) - { - if (!BoolPropChangeActions.ContainsKey(name)) - { - mpv_error err = mpv_observe_property(NamedHandle, 0, name, mpv_format.MPV_FORMAT_FLAG); - - if (err < 0) - HandleError(err, "error observing property: " + name); - else - BoolPropChangeActions[name] = new List>(); - } - - if (BoolPropChangeActions.ContainsKey(name)) - BoolPropChangeActions[name].Add(action); - } - } - - public void ObservePropertyString(string name, Action action) - { - lock (StringPropChangeActions) - { - if (!StringPropChangeActions.ContainsKey(name)) - { - mpv_error err = mpv_observe_property(NamedHandle, 0, name, mpv_format.MPV_FORMAT_STRING); - - if (err < 0) - HandleError(err, "error observing property: " + name); - else - StringPropChangeActions[name] = new List>(); - } - - if (StringPropChangeActions.ContainsKey(name)) - StringPropChangeActions[name].Add(action); - } - } - - public void ObserveProperty(string name, Action action) - { - lock (PropChangeActions) - { - if (!PropChangeActions.ContainsKey(name)) - { - mpv_error err = mpv_observe_property(NamedHandle, 0, name, mpv_format.MPV_FORMAT_NONE); - - if (err < 0) - HandleError(err, "error observing property: " + name); - else - PropChangeActions[name] = new List(); - } - - if (PropChangeActions.ContainsKey(name)) - PropChangeActions[name].Add(action); - } - } - - public void HandleError(mpv_error err, string msg) - { - Terminal.WriteError(msg); - Terminal.WriteError(GetError(err)); - } - - public void ProcessCommandLine(bool preInit) - { - bool shuffle = false; - var args = Environment.GetCommandLineArgs().Skip(1); - - string[] preInitProperties = { "input-terminal", "terminal", "input-file", "config", - "config-dir", "input-conf", "load-scripts", "scripts", "player-operation-mode", - "idle", "log-file", "msg-color", "dump-stats", "msg-level", "really-quiet" }; - - foreach (string i in args) - { - string arg = i; - - if (arg.StartsWith("-") && arg.Length > 1) - { - if (!preInit) - { - if (arg == "--profile=help") - { - Console.WriteLine(mpvHelp.GetProfiles()); - continue; - } - else if (arg == "--vd=help" || arg == "--ad=help") - { - Console.WriteLine(mpvHelp.GetDecoders()); - continue; - } - else if (arg == "--audio-device=help") - { - Console.WriteLine(GetPropertyOsdString("audio-device-list")); - continue; - } - else if (arg == "--version") - { - Console.WriteLine(App.Version); - continue; - } - else if (arg == "--input-keylist") - { - Console.WriteLine(GetPropertyString("input-key-list").Replace(",", BR)); - continue; - } - else if (arg.StartsWith("--command=")) - { - Command(arg.Substring(10)); - continue; - } - } - - if (!arg.StartsWith("--")) - arg = "-" + arg; - - if (!arg.Contains("=")) - { - if (arg.Contains("--no-")) - { - arg = arg.Replace("--no-", "--"); - arg += "=no"; - } - else - arg += "=yes"; - } - - string left = arg.Substring(2, arg.IndexOf("=") - 2); - string right = arg.Substring(left.Length + 3); - - switch (left) - { - case "script": left = "scripts"; break; - case "audio-file": left = "audio-files"; break; - case "sub-file": left = "sub-files"; break; - case "external-file": left = "external-files"; break; - } - - if (preInit && preInitProperties.Contains(left)) - { - ProcessProperty(left, right); - - if (!App.ProcessProperty(left, right)) - SetPropertyString(left, right); - } - else if (!preInit && !preInitProperties.Contains(left)) - { - ProcessProperty(left, right); - - if (!App.ProcessProperty(left, right)) - { - SetPropertyString(left, right); - - if (left == "shuffle" && right == "yes") - shuffle = true; - } - } - } - } - - if (!preInit) - { - List files = new List(); - - foreach (string i in args) - if (!i.StartsWith("--") && (i == "-" || i.Contains("://") || - i.Contains(":\\") || i.StartsWith("\\\\") || File.Exists(i))) - - files.Add(i); - - LoadFiles(files.ToArray(), !App.Queue, Control.ModifierKeys.HasFlag(Keys.Control) || App.Queue); - - if (shuffle) - { - Command("playlist-shuffle"); - SetPropertyInt("playlist-pos", 0); - } - - if (files.Count == 0 || files[0].Contains("://")) - { - VideoSizeChanged?.Invoke(VideoSize); - VideoSizeAutoResetEvent.Set(); - } - } - } - - public DateTime LastLoad; - - public void LoadFiles(string[] files, bool loadFolder, bool append) - { - if (files is null || files.Length == 0) - return; - - if ((DateTime.Now - LastLoad).TotalMilliseconds < 1000) - append = true; - - LastLoad = DateTime.Now; - - for (int i = 0; i < files.Length; i++) - { - string file = files[i]; - - if (string.IsNullOrEmpty(file)) - continue; - - if (file.Contains("|")) - file = file.Substring(0, file.IndexOf("|")); - - file = ConvertFilePath(file); - - string ext = file.Ext(); - - switch (ext) - { - case "avs": LoadAviSynth(); break; - case "lnk": file = GetShortcutTarget(file); break; - } - - if (ext == "iso") - LoadISO(file); - else if(SubtitleTypes.Contains(ext)) - CommandV("sub-add", file); - else if (!IsMediaExtension(ext) && !file.Contains("://") && Directory.Exists(file) && - File.Exists(System.IO.Path.Combine(file, "BDMV\\index.bdmv"))) - { - Command("stop"); - Thread.Sleep(500); - SetPropertyString("bluray-device", file); - CommandV("loadfile", @"bd://"); - } - else - { - if (i == 0 && !append) - CommandV("loadfile", file); - else - CommandV("loadfile", file, "append"); - } - } - - if (string.IsNullOrEmpty(GetPropertyString("path"))) - SetPropertyInt("playlist-pos", 0); - } - - public string ConvertFilePath(string path) - { - if ((path.Contains(":/") && !path.Contains("://")) || (path.Contains(":\\") && path.Contains("/"))) - path = path.Replace("/", "\\"); - - if (!path.Contains(":") && !path.StartsWith("\\\\") && File.Exists(path)) - path = System.IO.Path.GetFullPath(path); - - return path; - } - - public void LoadISO(string path) - { - long gb = new FileInfo(path).Length / 1024 / 1024 / 1024; - - if (gb < 10) - { - System.Windows.MessageBoxResult result = - Msg.ShowQuestion("Click Yes for Blu-ray and No for DVD.", - System.Windows.MessageBoxButton.YesNoCancel); - - switch (result) - { - case System.Windows.MessageBoxResult.Yes: - Command("stop"); - Thread.Sleep(500); - SetPropertyString("bluray-device", path); - LoadFiles(new[] { @"bd://" }, false, false); - break; - case System.Windows.MessageBoxResult.No: - Command("stop"); - Thread.Sleep(500); - SetPropertyString("dvd-device", path); - LoadFiles(new[] { @"dvd://" }, false, false); - break; - } - } - else - { - Command("stop"); - Thread.Sleep(500); - SetPropertyString("bluray-device", path); - LoadFiles(new[] { @"bd://" }, false, false); - } - } - - public void LoadDiskFolder(string path) - { - Core.Command("stop"); - Thread.Sleep(500); - - if (Directory.Exists(path + "\\BDMV")) - { - Core.SetPropertyString("bluray-device", path); - Core.LoadFiles(new[] { @"bd://" }, false, false); - } - else - { - Core.SetPropertyString("dvd-device", path); - Core.LoadFiles(new[] { @"dvd://" }, false, false); - } - } - - static object LoadFolderLockObject = new object(); - - public void LoadFolder() - { - if (!App.AutoLoadFolder || Control.ModifierKeys.HasFlag(Keys.Shift)) - return; - - Thread.Sleep(1000); - - lock (LoadFolderLockObject) - { - string path = GetPropertyString("path"); - - if (!File.Exists(path) || GetPropertyInt("playlist-count") != 1) - return; - - string dir = Environment.CurrentDirectory; - - if (path.Contains(":/") && !path.Contains("://")) - path = path.Replace("/", "\\"); - - if (path.Contains("\\")) - dir = System.IO.Path.GetDirectoryName(path); - - List files = GetMediaFiles(Directory.GetFiles(dir)).ToList(); - files.Sort(new StringLogicalComparer()); - int index = files.IndexOf(path); - files.Remove(path); - - foreach (string i in files) - CommandV("loadfile", i, "append"); - - if (index > 0) - CommandV("playlist-move", "0", (index + 1).ToString()); - } - } - - IEnumerable GetMediaFiles(IEnumerable files) => files.Where(i => IsMediaExtension(i.Ext())); - - bool IsMediaExtension(string ext) - { - return VideoTypes.Contains(ext) || AudioTypes.Contains(ext) || ImageTypes.Contains(ext); - } - - bool WasAviSynthLoaded; - - void LoadAviSynth() - { - if (!WasAviSynthLoaded) - { - string dll = Environment.GetEnvironmentVariable("AviSynthDLL"); - - if (File.Exists(dll)) - Native.LoadLibrary(dll); - else - Native.LoadLibrary("AviSynth.dll"); - - WasAviSynthLoaded = true; - } - } - - string HistoryPath; - - void WriteHistory() - { - double totalMinutes = (DateTime.Now - HistoryTime).TotalMinutes; - - if (!string.IsNullOrEmpty(HistoryPath) && totalMinutes > 1 && - !HistoryDiscard() && File.Exists(ConfigFolder + "history.txt")) - { - string path = HistoryPath; - - if (path.Contains("://")) - path = GetPropertyString("media-title"); - - string txt = DateTime.Now.ToString().Substring(0, 16) + " " + - Convert.ToInt32(totalMinutes).ToString().PadLeft(3) + " " + path + "\r\n"; - - File.AppendAllText(ConfigFolder + "history.txt", txt); - } - - HistoryPath = Path; - HistoryTime = DateTime.Now; - } - - public bool HistoryDiscard() - { - if (App.HistoryFilter != null) - foreach (string filter in App.HistoryFilter) - if (HistoryPath.Contains(filter.Trim())) - return true; - return false; - } - - public void ShowLogo() - { - if (!App.ShowLogo || MainForm.Instance == null || Core.Handle == IntPtr.Zero) - return; - - bool december = DateTime.Now.Month == 12; - Rectangle cr = MainForm.Instance.ClientRectangle; - int len = Convert.ToInt32(cr.Height / (december ? 4.5 : 5)); - - if (len < 16 || cr.Height < 16) - return; - - using (Bitmap bmp = new Bitmap(len, len)) - { - using (Graphics gx = Graphics.FromImage(bmp)) - { - gx.InterpolationMode = InterpolationMode.HighQualityBicubic; - gx.Clear(Color.Black); - Rectangle rect = new Rectangle(0, 0, len, len); - Bitmap bmp2 = (december && App.ShowSantaLogo) ? Properties.Resources.mpvnet_santa : Properties.Resources.mpvnet; - gx.DrawImage(bmp2, rect); - BitmapData bd = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb); - int x = Convert.ToInt32((cr.Width - len) / (december ? 1.95 : 2)); - int y = Convert.ToInt32((cr.Height - len) / 2.0 * (december ? 0.85 : 0.9)); - CommandV("overlay-add", "0", $"{x}", $"{y}", "&" + bd.Scan0.ToInt64().ToString(), "0", "bgra", bd.Width.ToString(), bd.Height.ToString(), bd.Stride.ToString()); - bmp.UnlockBits(bd); - } - } - } - - void HideLogo() => Command("overlay-remove 0"); - - public bool IsImage => ImageTypes.Contains(Path.Ext()); - - public bool IsAudio => AudioTypes.Contains(Path.Ext()); - - string GetLanguage(string id) - { - foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures)) - if (ci.ThreeLetterISOLanguageName == id || Convert(ci.ThreeLetterISOLanguageName) == id) - return ci.EnglishName; - - return id; - - string Convert(string id2) - { - switch (id2) - { - case "bng": return "ben"; - case "ces": return "cze"; - case "deu": return "ger"; - case "ell": return "gre"; - case "eus": return "baq"; - case "fra": return "fre"; - case "hye": return "arm"; - case "isl": return "ice"; - case "kat": return "geo"; - case "mya": return "bur"; - case "nld": return "dut"; - case "sqi": return "alb"; - case "zho": return "chi"; - default: return id2; - } - } - } - - string GetNativeLanguage(string name) - { - foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures)) - if (ci.EnglishName == name) - return ci.NativeName; - - return name; - } - - public static string GetShortcutTarget(string path) - { - Type t = Type.GetTypeFromProgID("WScript.Shell"); - dynamic sh = Activator.CreateInstance(t); - return sh.CreateShortcut(path).TargetPath; - } - - public void RaiseScaleWindow(float value) => ScaleWindow(value); - - public void RaiseMoveWindow(string value) => MoveWindow(value); - - public void RaiseWindowScaleNET(float value) => WindowScaleNET(value); - - public void RaiseShowMenu() => ShowMenu(); - - public void UpdateTracks() - { - string path = GetPropertyString("path"); - - if (!path.ToLowerEx().StartsWithEx("bd://")) - lock (BluRayTitles) - BluRayTitles.Clear(); - - lock (MediaTracksLock) - { - if (App.MediaInfo && !path.Contains("://") && !path.Contains(@"\\.\pipe\") && File.Exists(path)) - MediaTracks = GetMediaInfoTracks(path); - else - MediaTracks = GetTracks(); - } - } - - public List GetChapters() { - List chapters = new List(); - int count = GetPropertyInt("chapter-list/count"); - - for (int x = 0; x < count; x++) - { - string title = GetPropertyString($"chapter-list/{x}/title"); - double time = GetPropertyDouble($"chapter-list/{x}/time"); - - if (string.IsNullOrEmpty(title) || - (title.Length == 12 && title.Contains(":") && title.Contains("."))) - - title = "Chapter " + (x + 1); - - chapters.Add(new Chapter() { Title = title, Time = time }); - } - - return chapters; - } - - public void UpdateExternalTracks() - { - int trackListTrackCount = GetPropertyInt("track-list/count"); - int editionCount = GetPropertyInt("edition-list/count"); - int count = MediaTracks.Where(i => i.Type != "g").Count(); - - lock (MediaTracksLock) - { - if (count != (trackListTrackCount + editionCount)) - { - MediaTracks = MediaTracks.Where(i => !i.External).ToList(); - MediaTracks.AddRange(GetTracks(false)); - } - } - } - - public List GetTracks(bool includeInternal = true, bool includeExternal = true) - { - List tracks = new List(); - - int trackCount = GetPropertyInt("track-list/count"); - - for (int i = 0; i < trackCount; i++) - { - bool external = GetPropertyBool($"track-list/{i}/external"); - - if ((external && !includeExternal) || (!external && !includeInternal)) - continue; - - string type = GetPropertyString($"track-list/{i}/type"); - string filename = GetPropertyString($"filename/no-ext"); - string title = GetPropertyString($"track-list/{i}/title").Replace(filename, ""); - - title = Regex.Replace(title, @"^[\._\-]", ""); - - if (type == "video") - { - string codec = GetPropertyString($"track-list/{i}/codec").ToUpperEx(); - if (codec == "MPEG2VIDEO") - codec = "MPEG2"; - else if (codec == "DVVIDEO") - codec = "DV"; - MediaTrack track = new MediaTrack(); - Add(track, codec); - Add(track, GetPropertyString($"track-list/{i}/demux-w") + "x" + GetPropertyString($"track-list/{i}/demux-h")); - Add(track, GetPropertyString($"track-list/{i}/demux-fps").Replace(".000000", "") + " FPS"); - Add(track, GetPropertyBool($"track-list/{i}/default") ? "Default" : null); - track.Text = "V: " + track.Text.Trim(' ', ','); - track.Type = "v"; - track.ID = GetPropertyInt($"track-list/{i}/id"); - tracks.Add(track); - } - else if (type == "audio") - { - string codec = GetPropertyString($"track-list/{i}/codec").ToUpperEx(); - if (codec.Contains("PCM")) - codec = "PCM"; - MediaTrack track = new MediaTrack(); - Add(track, GetLanguage(GetPropertyString($"track-list/{i}/lang"))); - Add(track, codec); - Add(track, GetPropertyInt($"track-list/{i}/audio-channels") + " ch"); - Add(track, GetPropertyInt($"track-list/{i}/demux-samplerate") / 1000 + " kHz"); - Add(track, GetPropertyBool($"track-list/{i}/forced") ? "Forced" : null); - Add(track, GetPropertyBool($"track-list/{i}/default") ? "Default" : null); - Add(track, GetPropertyBool($"track-list/{i}/external") ? "External" : null); - Add(track, title); - track.Text = "A: " + track.Text.Trim(' ', ','); - track.Type = "a"; - track.ID = GetPropertyInt($"track-list/{i}/id"); - track.External = external; - tracks.Add(track); - } - else if (type == "sub") - { - string codec = GetPropertyString($"track-list/{i}/codec").ToUpperEx(); - if (codec.Contains("PGS")) - codec = "PGS"; - else if (codec == "SUBRIP") - codec = "SRT"; - else if (codec == "WEBVTT") - codec = "VTT"; - else if (codec == "DVB_SUBTITLE") - codec = "DVB"; - else if (codec == "DVD_SUBTITLE") - codec = "VOB"; - MediaTrack track = new MediaTrack(); - Add(track, GetLanguage(GetPropertyString($"track-list/{i}/lang"))); - Add(track, codec); - Add(track, GetPropertyBool($"track-list/{i}/forced") ? "Forced" : null); - Add(track, GetPropertyBool($"track-list/{i}/default") ? "Default" : null); - Add(track, GetPropertyBool($"track-list/{i}/external") ? "External" : null); - Add(track, title); - track.Text = "S: " + track.Text.Trim(' ', ','); - track.Type = "s"; - track.ID = GetPropertyInt($"track-list/{i}/id"); - track.External = external; - tracks.Add(track); - } - } - - if (includeInternal) - { - int editionCount = GetPropertyInt("edition-list/count"); - - for (int i = 0; i < editionCount; i++) - { - string title = GetPropertyString($"edition-list/{i}/title"); - if (string.IsNullOrEmpty(title)) - title = "Edition " + i; - MediaTrack track = new MediaTrack(); - track.Text = "E: " + title; - track.Type = "e"; - track.ID = i; - tracks.Add(track); - } - } - - return tracks; - } - - public List GetMediaInfoTracks(string path) - { - List tracks = new List(); - - using (MediaInfo mi = new MediaInfo(path)) - { - MediaTrack track = new MediaTrack(); - Add(track, mi.GetGeneral("Format")); - Add(track, mi.GetGeneral("FileSize/String")); - Add(track, mi.GetGeneral("Duration/String")); - Add(track, mi.GetGeneral("OverallBitRate/String")); - track.Text = "G: " + track.Text.Trim(' ', ','); - track.Type = "g"; - tracks.Add(track); - - int videoCount = mi.GetCount(MediaInfoStreamKind.Video); - - for (int i = 0; i < videoCount; i++) - { - string fps = mi.GetVideo(i, "FrameRate"); - - if (float.TryParse(fps, NumberStyles.Float, CultureInfo.InvariantCulture, out float result)) - fps = result.ToString(CultureInfo.InvariantCulture); - - track = new MediaTrack(); - Add(track, mi.GetVideo(i, "Format")); - Add(track, mi.GetVideo(i, "Format_Profile")); - Add(track, mi.GetVideo(i, "Width") + "x" + mi.GetVideo(i, "Height")); - Add(track, mi.GetVideo(i, "BitRate/String")); - Add(track, fps + " FPS"); - Add(track, (videoCount > 1 && mi.GetVideo(i, "Default") == "Yes") ? "Default" : ""); - track.Text = "V: " + track.Text.Trim(' ', ','); - track.Type = "v"; - track.ID = i + 1; - tracks.Add(track); - } - - int audioCount = mi.GetCount(MediaInfoStreamKind.Audio); - - for (int i = 0; i < audioCount; i++) - { - string lang = mi.GetAudio(i, "Language/String"); - string nativeLang = GetNativeLanguage(lang); - string title = mi.GetAudio(i, "Title"); - string format = mi.GetAudio(i, "Format"); - - if (!string.IsNullOrEmpty(title)) - { - if (title.ContainsEx("DTS-HD MA")) - format = "DTS-MA"; - - if (title.ContainsEx("DTS-HD MA")) - title = title.Replace("DTS-HD MA", ""); - - if (title.ContainsEx("Blu-ray")) - title = title.Replace("Blu-ray", ""); - - if (title.ContainsEx("UHD ")) - title = title.Replace("UHD ", ""); - - if (title.ContainsEx("EAC")) - title = title.Replace("EAC", "E-AC"); - - if (title.ContainsEx("AC3")) - title = title.Replace("AC3", "AC-3"); - - if (title.ContainsEx(lang)) - title = title.Replace(lang, "").Trim(); - - if (title.ContainsEx(nativeLang)) - title = title.Replace(nativeLang, "").Trim(); - - if (title.ContainsEx("Surround")) - title = title.Replace("Surround", ""); - - if (title.ContainsEx("Dolby Digital")) - title = title.Replace("Dolby Digital", ""); - - if (title.ContainsEx("Stereo")) - title = title.Replace("Stereo", ""); - - if (title.StartsWithEx(format + " ")) - title = title.Replace(format + " ", ""); - - foreach (string i2 in new [] { "2.0", "5.1", "6.1", "7.1" }) - if (title.ContainsEx(i2)) - title = title.Replace(i2, "").Trim(); - - if (title.ContainsEx("@ ")) - title = title.Replace("@ ", ""); - - if (title.ContainsEx(" @")) - title = title.Replace(" @", ""); - - if (title.ContainsEx("()")) - title = title.Replace("()", ""); - - if (title.ContainsEx("[]")) - title = title.Replace("[]", ""); - - if (title.TrimEx() == format) - title = null; - - if (!string.IsNullOrEmpty(title)) - title = title.Trim(" _-".ToCharArray()); - } - - track = new MediaTrack(); - Add(track, lang); - Add(track, format); - Add(track, mi.GetAudio(i, "Format_Profile")); - Add(track, mi.GetAudio(i, "BitRate/String")); - Add(track, mi.GetAudio(i, "Channel(s)") + " ch"); - Add(track, mi.GetAudio(i, "SamplingRate/String")); - Add(track, mi.GetAudio(i, "Forced") == "Yes" ? "Forced" : ""); - Add(track, (audioCount > 1 && mi.GetAudio(i, "Default") == "Yes") ? "Default" : ""); - Add(track, title); - - if (track.Text.Contains("MPEG Audio, Layer 2")) - track.Text = track.Text.Replace("MPEG Audio, Layer 2", "MP2"); - - if (track.Text.Contains("MPEG Audio, Layer 3")) - track.Text = track.Text.Replace("MPEG Audio, Layer 2", "MP3"); - - track.Text = "A: " + track.Text.Trim(' ', ','); - track.Type = "a"; - track.ID = i + 1; - tracks.Add(track); - } - - int subCount = mi.GetCount(MediaInfoStreamKind.Text); - - for (int i = 0; i < subCount; i++) - { - string codec = mi.GetText(i, "Format").ToUpperEx(); - - if (codec == "UTF-8") - codec = "SRT"; - else if (codec == "WEBVTT") - codec = "VTT"; - else if (codec == "VOBSUB") - codec = "VOB"; - - string lang = mi.GetText(i, "Language/String"); - string nativeLang = GetNativeLanguage(lang); - string title = mi.GetText(i, "Title"); - bool forced = mi.GetText(i, "Forced") == "Yes"; - - if (!string.IsNullOrEmpty(title)) - { - if (title.ContainsEx("VobSub")) - title = title.Replace("VobSub", "VOB"); - - if (title.ContainsEx(codec)) - title = title.Replace(codec, ""); - - if (title.ContainsEx(lang.ToLowerEx())) - title = title.Replace(lang.ToLowerEx(), lang); - - if (title.ContainsEx(nativeLang.ToLowerEx())) - title = title.Replace(nativeLang.ToLowerEx(), nativeLang).Trim(); - - if (title.ContainsEx(lang)) - title = title.Replace(lang, ""); - - if (title.ContainsEx(nativeLang)) - title = title.Replace(nativeLang, "").Trim(); - - if (title.ContainsEx("full")) - title = title.Replace("full", "").Trim(); - - if (title.ContainsEx("Full")) - title = title.Replace("Full", "").Trim(); - - if (title.ContainsEx("Subtitles")) - title = title.Replace("Subtitles", "").Trim(); - - if (title.ContainsEx("forced")) - title = title.Replace("forced", "Forced").Trim(); - - if (forced && title.ContainsEx("Forced")) - title = title.Replace("Forced", "").Trim(); - - if (title.ContainsEx("()")) - title = title.Replace("()", ""); - - if (title.ContainsEx("[]")) - title = title.Replace("[]", ""); - - if (!string.IsNullOrEmpty(title)) - title = title.Trim(" _-".ToCharArray()); - } - - track = new MediaTrack(); - Add(track, lang); - Add(track, codec); - Add(track, mi.GetText(i, "Format_Profile")); - Add(track, forced ? "Forced" : ""); - Add(track, (subCount > 1 && mi.GetText(i, "Default") == "Yes") ? "Default" : ""); - Add(track, title); - track.Text = "S: " + track.Text.Trim(' ', ','); - track.Type = "s"; - track.ID = i + 1; - tracks.Add(track); - } - } - - int editionCount = GetPropertyInt("edition-list/count"); - - for (int i = 0; i < editionCount; i++) - { - string title = GetPropertyString($"edition-list/{i}/title"); - if (string.IsNullOrEmpty(title)) - title = "Edition " + i; - MediaTrack track = new MediaTrack(); - track.Text = "E: " + title; - track.Type = "e"; - track.ID = i; - tracks.Add(track); - } - - return tracks; - } - - void Add(MediaTrack track, object value) - { - string str = value.ToStringEx().Trim(); - - if (str != "" && !(track.Text != null && track.Text.Contains(str))) - track.Text += " " + str + ","; - } - - private string[] _ProfileNames; - - public string[] ProfileNames - { - get - { - if (_ProfileNames == null) - { - string[] ignore = { "builtin-pseudo-gui", "encoding", "libmpv", "pseudo-gui", "default" }; - string profileList = Core.GetPropertyString("profile-list"); - var json = profileList.FromJson>>(); - _ProfileNames = json.Select(i => i["name"].ToString()) - .Where(i => !ignore.Contains(i)).ToArray(); - } - - return _ProfileNames; - } - } - } -} diff --git a/src/Misc/PowerShell.cs b/src/Misc/PowerShell.cs deleted file mode 100644 index 4335460..0000000 --- a/src/Misc/PowerShell.cs +++ /dev/null @@ -1,243 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Management.Automation; -using System.Management.Automation.Runspaces; -using System.Threading; - -using static mpvnet.Global; - -namespace mpvnet -{ - public class PowerShell - { - public Runspace Runspace { get; set; } - public Pipeline Pipeline { get; set; } - public string Module { get; set; } - public bool Print { get; set; } - public List Scripts { get; } = new List(); - public List> Variables = new List>(); - public string[] Arguments { get; } - public event Action Event; - public event Action PropertyChanged; - public List> EventHandlers = new List>(); - public List> PropChangedHandlers = new List>(); - - public static List References { get; } = new List(); - - public object Invoke() => Invoke(null, null); - - public object Invoke(string variable, object obj) - { - try - { - Runspace = RunspaceFactory.CreateRunspace(); - Runspace.ApartmentState = ApartmentState.STA; - Runspace.Open(); - Pipeline = Runspace.CreatePipeline(); - - foreach (string script in Scripts) - Pipeline.Commands.AddScript(script); - - if (Arguments != null) - foreach (string param in Arguments) - foreach (Command command in Pipeline.Commands) - command.Parameters.Add(null, param); - - Runspace.SessionStateProxy.SetVariable("mp", this); - - foreach (var i in Variables) - Runspace.SessionStateProxy.SetVariable(i.Key, i.Value); - - if (!string.IsNullOrEmpty(variable)) - Runspace.SessionStateProxy.SetVariable(variable, obj); - - if (Print) - { - Pipeline.Output.DataReady += Output_DataReady; - Pipeline.Error.DataReady += Error_DataReady; - } - - return Pipeline.Invoke(); - } - catch (RuntimeException e) - { - string message = e.Message + BR + BR + e.ErrorRecord.ScriptStackTrace.Replace( - " , ", "") + BR + BR + Module + BR; - - throw new PowerShellException(message); - } - catch (Exception e) - { - throw e; - } - } - - public static string InvokeAndReturnString(string code, string varName, object varValue) - { - PowerShell ps = new PowerShell() { Print = false }; - ps.Scripts.Add(code); - string ret = string.Join(Environment.NewLine, (ps.Invoke(varName, varValue) - as IEnumerable).Select(item => item.ToString())).ToString(); - ps.Runspace.Dispose(); - return ret; - } - - public void Output_DataReady(object sender, EventArgs e) - { - var output = sender as PipelineReader; - - while (output.Count > 0) - Terminal.Write(output.Read(), Module); - } - - public void Error_DataReady(object sender, EventArgs e) - { - var output = sender as PipelineReader; - - while (output.Count > 0) - Terminal.WriteError(output.Read(), Module); - } - - public void RedirectStreams(PSEventJob job) - { - if (Print) - { - job.Output.DataAdded += Output_DataAdded; - job.Error.DataAdded += Error_DataAdded; - } - } - - public void CommandV(params string[] args) => Core.CommandV(args); - - public void Command(string command) => Core.Command(command); - - public bool GetPropertyBool(string name) => Core.GetPropertyBool(name); - - public void SetPropertyBool(string name, bool value) => Core.SetPropertyBool(name, value); - - public int GetPropertyInt(string name) => Core.GetPropertyInt(name); - - public void SetPropertyInt(string name, int value) => Core.SetPropertyInt(name, value); - - public double GetPropertyDouble(string name) => Core.GetPropertyDouble(name); - - public void SetPropertyDouble(string name, double value) => Core.SetPropertyDouble(name, value); - - public string GetPropertyString(string name) => Core.GetPropertyString(name); - - public void SetPropertyString(string name, string value) => Core.SetPropertyString(name, value); - - public void ObserveProperty(string name, string type, ScriptBlock sb) - { - PropChangedHandlers.Add(new KeyValuePair(name, sb)); - - switch (type) - { - case "bool": case "boolean": - Core.ObservePropertyBool(name, value => App.RunTask(() => PropertyChanged.Invoke(name, value))); - break; - - case "string": - Core.ObservePropertyString(name, value => App.RunTask(() => PropertyChanged.Invoke(name, value))); - break; - - case "int": case "integer": - Core.ObservePropertyInt(name, value => App.RunTask(() => PropertyChanged.Invoke(name, value))); - break; - - case "float": case "double": - Core.ObservePropertyDouble(name, value => App.RunTask(() => PropertyChanged.Invoke(name, value))); - break; - - case "nil": case "none": case "native": - Core.ObserveProperty(name, () => App.RunTask(() => PropertyChanged.Invoke(name, null))); - break; - - default: - App.ShowError("Invalid Type, valid types are: bool or boolean, string, int or integer, float or double, nil or none or native"); - break; - } - } - - public void RegisterEvent(string name, ScriptBlock sb) - { - EventHandlers.Add(new KeyValuePair(name, sb)); - - switch (name) - { - case "log-message": - Core.LogMessageAsync += (level, msg) => Event.Invoke("log-message", new object[] { level, msg }); - break; - - case "end-file": - Core.EndFileAsync += reason => Event.Invoke("end-file", new object[] { reason }); - break; - - case "client-message": - Core.ClientMessageAsync += args => Event.Invoke("client-message", args); - break; - - case "shutdown": - Core.Shutdown += () => Event.Invoke("shutdown", null); - break; - - case "get-property-reply": - Core.GetPropertyReplyAsync += () => Event.Invoke("get-property-reply", null); - break; - - case "set-property-reply": - Core.SetPropertyReplyAsync += () => Event.Invoke("set-property-reply", null); - break; - - case "command-reply": - Core.CommandReplyAsync += () => Event.Invoke("command-reply", null); - break; - - case "start-file": - Core.StartFileAsync += () => Event.Invoke("start-file", null); - break; - - case "file-loaded": - Core.FileLoadedAsync += () => Event.Invoke("file-loaded", null); - break; - - case "video-reconfig": - Core.VideoReconfigAsync += () => Event.Invoke("video-reconfig", null); - break; - - case "audio-reconfig": - Core.AudioReconfigAsync += () => Event.Invoke("audio-reconfig", null); - break; - - case "seek": - Core.SeekAsync += () => Event.Invoke("seek", null); - break; - - case "playback-restart": - Core.PlaybackRestartAsync += () => Event.Invoke("playback-restart", null); - break; - } - } - - void Output_DataAdded(object sender, DataAddedEventArgs e) - { - var output = sender as PSDataCollection; - Terminal.Write(output[e.Index], Module); - } - - void Error_DataAdded(object sender, DataAddedEventArgs e) - { - var error = sender as PSDataCollection; - Terminal.WriteError(error[e.Index], Module); - } - } - - public class PowerShellException : Exception - { - public PowerShellException(string message) : base(message) - { - } - } -} diff --git a/src/Misc/Program.cs b/src/Misc/Program.cs deleted file mode 100644 index b874c77..0000000 --- a/src/Misc/Program.cs +++ /dev/null @@ -1,100 +0,0 @@ - -using System; -using System.Windows.Forms; -using System.Linq; -using System.Collections.Generic; -using System.Threading; -using System.Diagnostics; - -namespace mpvnet -{ - static class Program - { - [STAThread] - static void Main() - { - try - { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - - if (App.IsTerminalAttached) - Native.AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/); - - string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray(); - - if (args.Length > 0 && args[0] == "--register-file-associations") - { - FileAssociation.Register(args[1], args.Skip(1).ToArray()); - return; - } - - App.Init(); - Mutex mutex = new Mutex(true, StringHelp.GetMD5Hash(App.ConfPath), out bool isFirst); - - if (Control.ModifierKeys.HasFlag(Keys.Shift)) - App.ProcessInstance = "multi"; - - if ((App.ProcessInstance == "single" || App.ProcessInstance == "queue") && !isFirst) - { - List args2 = new List(); - args2.Add(App.ProcessInstance); - - foreach (string arg in args) - { - if (!arg.StartsWith("--") && (arg == "-" || arg.Contains("://") || - arg.Contains(":\\") || arg.StartsWith("\\\\"))) - - args2.Add(arg); - else if (arg == "--queue") - args2[0] = "queue"; - else if (arg.StartsWith("--command=")) - { - args2[0] = "command"; - args2.Add(arg.Substring(10)); - } - } - - Process[] procs = Process.GetProcessesByName("mpvnet"); - - for (int i = 0; i < 20; i++) - { - foreach (Process proc in procs) - { - if (proc.MainWindowHandle != IntPtr.Zero) - { - Native.AllowSetForegroundWindow(proc.Id); - var data = new Native.COPYDATASTRUCT(); - data.lpData = string.Join("\n", args2.ToArray()); - data.cbData = data.lpData.Length * 2 + 1; - Native.SendMessage(proc.MainWindowHandle, 0x004A /*WM_COPYDATA*/, IntPtr.Zero, ref data); - mutex.Dispose(); - - if (App.IsTerminalAttached) - Native.FreeConsole(); - - return; - } - } - - Thread.Sleep(50); - } - - mutex.Dispose(); - return; - } - - Application.Run(new MainForm()); - - if (App.IsTerminalAttached) - Native.FreeConsole(); - - mutex.Dispose(); - } - catch (Exception ex) - { - Msg.ShowException(ex); - } - } - } -} diff --git a/src/Misc/Settings.cs b/src/Misc/Settings.cs deleted file mode 100644 index 17177f3..0000000 --- a/src/Misc/Settings.cs +++ /dev/null @@ -1,69 +0,0 @@ - -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 bool InputDefaultBindingsFixApplied; - public bool ShowMenuFixApplied; - public int Volume = 70; - public List RecentFiles = new List(); - public Point WindowLocation; - public Point WindowPosition; - public Size WindowSize; - public string ConfigEditorSearch = "Video:"; - public string Mute = "no"; - } - - class SettingsManager - { - public static string SettingsFile => Core.ConfigFolder + "settings.xml"; - - public static AppSettings Load() - { - if (!File.Exists(SettingsFile)) - return new AppSettings(); - - try - { - XmlSerializer serializer = new XmlSerializer(typeof(AppSettings)); - - using (FileStream fs = new FileStream(SettingsFile, FileMode.Open)) - return (AppSettings)serializer.Deserialize(fs); - } - catch (Exception ex) - { - Terminal.WriteError(ex.ToString()); - return new AppSettings(); - } - } - - public static void Save(object obj) - { - try - { - 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); - } - } - catch (Exception ex) - { - Terminal.WriteError(ex.ToString()); - } - } - } -} diff --git a/src/Misc/Terminal.cs b/src/Misc/Terminal.cs deleted file mode 100644 index 1063034..0000000 --- a/src/Misc/Terminal.cs +++ /dev/null @@ -1,50 +0,0 @@ - -using System; -using System.Diagnostics; - -namespace mpvnet -{ - public static class Terminal - { - static int Padding { get; } = 60; - - public static void WriteError(object obj, string module = "mpv.net") - { - Write(obj, module, ConsoleColor.DarkRed, false); - } - - public static void Write(object obj, string module = "mpv.net") - { - Write(obj, module, ConsoleColor.Black, true); - } - - public static void Write(object obj, string module, ConsoleColor color, bool useDefaultColor) - { - if (obj == null) - return; - - string value = obj.ToString(); - - if (!string.IsNullOrEmpty(module)) - module = "[" + module + "] "; - - if (useDefaultColor) - Console.ResetColor(); - else - Console.ForegroundColor = color; - - value = module + value; - - if (value.Length < Padding) - value = value.PadRight(Padding); - - if (color == ConsoleColor.Red || color == ConsoleColor.DarkRed) - Console.Error.WriteLine(value); - else - Console.WriteLine(value); - - Console.ResetColor(); - Trace.WriteLine(obj); - } - } -} diff --git a/src/Misc/Theme.cs b/src/Misc/Theme.cs deleted file mode 100644 index d9b578f..0000000 --- a/src/Misc/Theme.cs +++ /dev/null @@ -1,99 +0,0 @@ - -using System.Collections.Generic; -using System.Windows.Media; - -namespace mpvnet -{ - public class Theme - { - public string Name { get; set; } - public Dictionary Dictionary { get; } = new Dictionary(); - - public static List DefaultThemes { get; set; } - public static List CustomThemes { get; set; } - - public static Theme Current { get; set; } - - public Brush Background { get; set; } - public Brush Foreground { get; set; } - public Brush Foreground2 { get; set; } - public Brush Heading { get; set; } - public Brush MenuBackground { get; set; } - public Brush MenuHighlight { get; set; } - - public Brush GetBrush(string key) - { - return new SolidColorBrush((Color)ColorConverter.ConvertFromString(Dictionary[key])); - } - - public Color GetColor(string key) => (Color)ColorConverter.ConvertFromString(Dictionary[key]); - - public static void Init(string customContent, string defaultContent, string activeTheme) - { - Current = null; - - DefaultThemes = Load(defaultContent); - CustomThemes = Load(customContent); - - foreach (Theme theme in CustomThemes) - { - if (theme.Name == activeTheme) - { - bool isKeyMissing = false; - - foreach (string key in DefaultThemes[0].Dictionary.Keys) - { - if (!theme.Dictionary.ContainsKey(key)) - { - isKeyMissing = true; - Terminal.WriteError($"Theme '{activeTheme}' misses '{key}'"); - break; - } - } - - if (!isKeyMissing) - Current = theme; - - break; - } - } - - if (Current == null) - foreach (Theme theme in DefaultThemes) - if (theme.Name == activeTheme) - Current = theme; - - if (Current == null) - Current = DefaultThemes[0]; - - Current.Background = Current.GetBrush("background"); - Current.Foreground = Current.GetBrush("foreground"); - Current.Foreground2 = Current.GetBrush("foreground2"); - Current.Heading = Current.GetBrush("heading"); - Current.MenuBackground = Current.GetBrush("menu-background"); - Current.MenuHighlight = Current.GetBrush("menu-highlight"); - } - - static List Load(string content) - { - List list = new List(); - Theme theme = null; - - foreach (string currentLine in (content ?? "").Split(new [] { '\r', '\n' })) - { - string line = currentLine.Trim(); - - if (line.StartsWith("[") && line.EndsWith("]")) - list.Add(theme = new Theme() { Name = line.Substring(1, line.Length - 2).Trim() }); - - if (line.Contains("=") && theme != null) - { - string left = line.Substring(0, line.IndexOf("=")).Trim(); - theme.Dictionary[left] = line.Substring(line.IndexOf("=") + 1).Trim(); - } - } - - return list; - } - } -} diff --git a/src/MpvNet.Extension/ExampleExtension/ExampleExtension.cs b/src/MpvNet.Extension/ExampleExtension/ExampleExtension.cs new file mode 100644 index 0000000..4115b14 --- /dev/null +++ b/src/MpvNet.Extension/ExampleExtension/ExampleExtension.cs @@ -0,0 +1,24 @@ + +namespace MpvNet.Extension.ExampleExtension; + +public class Extension : IExtension +{ + public MpvClient Player { get; set; } + + public Extension() + { + Player = Global.Player.CreateNewPlayer("example"); + Player.ObservePropertyBool("fullscreen", FullscreenChange); + Player.FileLoaded += Player_FileLoaded; + } + + void Player_FileLoaded() + { + Terminal.Write("File loaded: " + Player.GetPropertyString("path")); + } + + void FullscreenChange(bool value) + { + Player.CommandV("show-text", "fullscreen: " + value); + } +} diff --git a/src/MpvNet.Extension/ExampleExtension/ExampleExtension.csproj b/src/MpvNet.Extension/ExampleExtension/ExampleExtension.csproj new file mode 100644 index 0000000..dd483ee --- /dev/null +++ b/src/MpvNet.Extension/ExampleExtension/ExampleExtension.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + false + C:\Users\frank\AppData\Roaming\mpv.net-experimental\extensions\ExampleExtension + + + + + False + + + + diff --git a/src/MpvNet.Extension/ExampleExtension/ExampleExtension.sln b/src/MpvNet.Extension/ExampleExtension/ExampleExtension.sln new file mode 100644 index 0000000..94bd734 --- /dev/null +++ b/src/MpvNet.Extension/ExampleExtension/ExampleExtension.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34018.315 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleExtension", "ExampleExtension.csproj", "{4D6623A0-E890-44E5-956F-D5A5A24A6619}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4D6623A0-E890-44E5-956F-D5A5A24A6619}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D6623A0-E890-44E5-956F-D5A5A24A6619}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D6623A0-E890-44E5-956F-D5A5A24A6619}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D6623A0-E890-44E5-956F-D5A5A24A6619}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {47E1F7E3-3833-4E05-841B-4683C1DEA133} + EndGlobalSection +EndGlobal diff --git a/src/MpvNet.Windows/.editorconfig b/src/MpvNet.Windows/.editorconfig new file mode 100644 index 0000000..2c285fe --- /dev/null +++ b/src/MpvNet.Windows/.editorconfig @@ -0,0 +1,25 @@ +[*.cs] + +# IDE0058: Expression value is never used +dotnet_diagnostic.IDE0058.severity = none + +# IDE0055: Fix formatting +dotnet_diagnostic.IDE0055.severity = none + +# IDE0022: Use block body for methods +dotnet_diagnostic.IDE0022.severity = none + +# IDE0040: Add accessibility modifiers +dotnet_diagnostic.IDE0040.severity = none + +# IDE0011: Add braces +dotnet_diagnostic.IDE0011.severity = none + +# IDE0010: Add missing cases +dotnet_diagnostic.IDE0010.severity = none + +# IDE0044: Add readonly modifier +dotnet_diagnostic.IDE0044.severity = silent + +# Member does not access instance data and can be marked as static +dotnet_diagnostic.CA1822.severity = none diff --git a/src/App.config b/src/MpvNet.Windows/App.config similarity index 51% rename from src/App.config rename to src/MpvNet.Windows/App.config index ccc7a5d..92d5ffd 100644 --- a/src/App.config +++ b/src/MpvNet.Windows/App.config @@ -2,7 +2,4 @@ - - - \ No newline at end of file diff --git a/src/MpvNet.Windows/Conf.cs b/src/MpvNet.Windows/Conf.cs new file mode 100644 index 0000000..87fde57 --- /dev/null +++ b/src/MpvNet.Windows/Conf.cs @@ -0,0 +1,134 @@ + +using MpvNet.ExtensionMethod; + +namespace MpvNet.Windows; + +public class Conf +{ + public static List LoadConf(string content) + { + List settingsList = new List(); + + foreach (ConfSection? section in ConfParser.Parse(content)) + { + Setting? baseSetting = null; + + if (section.HasName("option")) + { + OptionSetting optionSetting = new OptionSetting(); + baseSetting = optionSetting; + optionSetting.Default = section.GetValue("default"); + optionSetting.Value = optionSetting.Default; + + foreach (var it in section.GetValues("option")) + { + var opt = new OptionSettingOption(); + + if (it.Value.ContainsEx(" ")) + { + opt.Name = it.Value![..it.Value!.IndexOf(" ")]; + opt.Help = it.Value[it.Value.IndexOf(" ")..].Trim(); + } + else + opt.Name = it.Value; + + if (opt.Name == optionSetting.Default) + opt.Text = opt.Name + " (Default)"; + + opt.OptionSetting = optionSetting; + optionSetting.Options.Add(opt); + } + } + else + { + StringSetting stringSetting = new StringSetting(); + baseSetting = stringSetting; + stringSetting.Default = section.HasName("default") ? section.GetValue("default") : ""; + } + + baseSetting.Name = section.GetValue("name"); + baseSetting.File = section.GetValue("file"); + baseSetting.Directory = section.GetValue("directory"); + + if (section.HasName("help")) baseSetting.Help = section.GetValue("help"); + if (section.HasName("url")) baseSetting.URL = section.GetValue("url"); + if (section.HasName("width")) baseSetting.Width = Convert.ToInt32(section.GetValue("width")); + if (section.HasName("type")) baseSetting.Type = section.GetValue("type"); + + if (baseSetting.Help.ContainsEx("\\n")) + baseSetting.Help = baseSetting.Help?.Replace("\\n", "\n"); + + settingsList.Add(baseSetting); + } + + return settingsList; + } +} + +public class ConfItem +{ + public string Comment { get; set; } = ""; + public string File { get; set; } = ""; + public string LineComment { get; set; } = ""; + public string Name { get; set; } = ""; + public string Section { get; set; } = ""; + public string Value { get; set; } = ""; + + public bool IsSectionItem { get; set; } + public Setting? SettingBase { get; set; } +} + +public class ConfParser +{ + public static List Parse(string content) + { + string[] lines = content.Split(BR.ToCharArray(), StringSplitOptions.None); + var sections = new List(); + ConfSection? currentGroup = null; + + foreach (string it in lines) + { + string line = it.Trim(); + + if (line == "") + { + currentGroup = new ConfSection(); + sections.Add(currentGroup); + } + else if (line.Contains('=')) + { + string name = line[..line.IndexOf("=")].Trim(); + string value = line[(line.IndexOf("=") + 1)..].Trim(); + + currentGroup?.Items.Add(new StringPair(name, value)); + } + } + + return sections; + } +} + +public class ConfSection +{ + public List Items { get; set; } = new List(); + + public bool HasName(string name) + { + foreach (var i in Items) + if (i.Name == name) + return true; + + return false; + } + + public string? GetValue(string name) + { + foreach (var i in Items) + if (i.Name == name) + return i.Value; + + return null; + } + + public List GetValues(string name) => Items.Where(i => i.Name == name).ToList(); +} diff --git a/src/MpvNet.Windows/FileAssociation.cs b/src/MpvNet.Windows/FileAssociation.cs new file mode 100644 index 0000000..b285b45 --- /dev/null +++ b/src/MpvNet.Windows/FileAssociation.cs @@ -0,0 +1,68 @@ + +using Microsoft.Win32; + +using MpvNet.Windows.Help; + +namespace MpvNet.Windows; + +public static class FileAssociation +{ + public static void Register(string perceivedType, string[] extensions) + { + string exePath = Environment.ProcessPath!; + string exeFilename = Path.GetFileName(exePath); + string exeFilenameNoExt = Path.GetFileNameWithoutExtension(exePath); + + string[] protocols = { "ytdl", "rtsp", "srt", "srtp" }; + + if (perceivedType != "unreg") + { + foreach (string it in protocols) + { + RegistryHelp.SetValue($@"HKCR\{it}", $"{it.ToUpper()} Protocol", ""); + RegistryHelp.SetValue($@"HKCR\{it}\shell\open\command", "", $"\"{exePath}\" \"%1\""); + } + + RegistryHelp.SetValue(@"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" + exeFilename, "", exePath); + RegistryHelp.SetValue(@"HKCR\Applications\" + exeFilename, "FriendlyAppName", "mpv.net media player"); + RegistryHelp.SetValue(@"HKCR\Applications\" + exeFilename + @"\shell\open\command", "", $"\"{exePath}\" \"%1\""); + RegistryHelp.SetValue(@"HKCR\SystemFileAssociations\video\OpenWithList\" + exeFilename, "", ""); + RegistryHelp.SetValue(@"HKCR\SystemFileAssociations\audio\OpenWithList\" + exeFilename, "", ""); + RegistryHelp.SetValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net", @"SOFTWARE\Clients\Media\mpv.net\Capabilities"); + RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationDescription", "mpv.net media player"); + RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationName", "mpv.net"); + + foreach (string ext in extensions) + { + RegistryHelp.SetValue(@"HKCR\Applications\" + exeFilename + @"\SupportedTypes", "." + ext, ""); + RegistryHelp.SetValue(@"HKCR\" + "." + ext, "", exeFilenameNoExt + "." + ext); + RegistryHelp.SetValue(@"HKCR\" + "." + ext + @"\OpenWithProgIDs", exeFilenameNoExt + "." + ext, ""); + RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", perceivedType); + RegistryHelp.SetValue(@"HKCR\" + exeFilenameNoExt + "." + ext + @"\shell\open\command", "", $"\"{exePath}\" \"%1\""); + RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities\FileAssociations", "." + ext, exeFilenameNoExt + "." + ext); + } + } + else + { + foreach (string i in protocols) + RegistryHelp.RemoveKey($@"HKCR\{i}"); + + RegistryHelp.RemoveKey(@"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" + exeFilename); + RegistryHelp.RemoveKey(@"HKCR\Applications\" + exeFilename); + RegistryHelp.RemoveKey(@"HKLM\SOFTWARE\Clients\Media\mpv.net"); + RegistryHelp.RemoveKey(@"HKCR\SystemFileAssociations\video\OpenWithList\" + exeFilename); + RegistryHelp.RemoveKey(@"HKCR\SystemFileAssociations\audio\OpenWithList\" + exeFilename); + + RegistryHelp.RemoveValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net"); + + foreach (string id in Registry.ClassesRoot.GetSubKeyNames()) + { + if (id.StartsWith(exeFilenameNoExt + ".")) + Registry.ClassesRoot.DeleteSubKeyTree(id); + + RegistryHelp.RemoveValue($@"HKCR\Software\Classes\{id}\OpenWithProgIDs", exeFilenameNoExt + id); + RegistryHelp.RemoveValue($@"HKLM\Software\Classes\{id}\OpenWithProgIDs", exeFilenameNoExt + id); + } + } + } +} diff --git a/src/MpvNet.Windows/GlobalUsings.cs b/src/MpvNet.Windows/GlobalUsings.cs new file mode 100644 index 0000000..488e43f --- /dev/null +++ b/src/MpvNet.Windows/GlobalUsings.cs @@ -0,0 +1,8 @@ + +global using System; +global using System.Collections.Generic; +global using System.Diagnostics; +global using System.IO; +global using System.Linq; + +global using static MpvNet.Global; diff --git a/src/MpvNet.Windows/GuiCommand.cs b/src/MpvNet.Windows/GuiCommand.cs new file mode 100644 index 0000000..e7563c4 --- /dev/null +++ b/src/MpvNet.Windows/GuiCommand.cs @@ -0,0 +1,303 @@ + +using System.Text.RegularExpressions; +using System.Windows.Forms; +using System.Windows.Interop; +using System.Windows; +using System.Globalization; + +using MpvNet.ExtensionMethod; +using MpvNet.Help; +using MpvNet.Windows.WinForms; +using MpvNet.Windows.WPF.Views; +using MpvNet.Windows.WPF; +using MpvNet.Windows.WPF.MsgBox; +using MpvNet.Windows.UI; + +namespace MpvNet; + +public class GuiCommand +{ + Dictionary>>? _commands; + + public event Action? ScaleWindow; + public event Action? MoveWindow; + public event Action? WindowScaleMpv; + public event Action? WindowScaleNet; + public event Action? ShowMenu; + + public static GuiCommand Current { get; } = new(); + + public Dictionary>> Commands => _commands ??= new() + { + ["show-about"] = args => ShowDialog(typeof(AboutWindow)), + ["show-conf-editor"] = args => ShowDialog(typeof(ConfWindow)), + ["show-input-editor"] = args => ShowDialog(typeof(InputWindow)), + ["show-audio-devices"] = args => Msg.ShowInfo(Player.GetPropertyOsdString("audio-device-list")), + ["show-profiles"] = args => Msg.ShowInfo(Player.GetProfiles()), + ["load-sub"] = LoadSubtitle, + ["open-files"] = OpenFiles, + ["open-optical-media"] = Open_DVD_Or_BD_Folder, + ["load-audio"] = LoadAudio, + ["open-clipboard"] = OpenFromClipboard, + ["reg-file-assoc"] = RegisterFileAssociations, + ["scale-window"] = args => ScaleWindow?.Invoke(float.Parse(args[0], CultureInfo.InvariantCulture)), + ["show-media-info"] = ShowMediaInfo, + ["move-window"] = args => MoveWindow?.Invoke(args[0]), + ["window-scale"] = args => WindowScaleNet?.Invoke(float.Parse(args[0], CultureInfo.InvariantCulture)), + ["show-menu"] = args => ShowMenu?.Invoke(), + ["show-command-palette"] = args => ShowCommandPalette(), + + + // backward compatibility + ["show-info"] = args => ShowMediaInfo(new[] { "osd" }), // backward compatibility + ["playlist-random"] = args => PlaylistRandom(), // backward compatibility + ["quick-bookmark"] = args => QuickBookmark(), // backward compatibility + ["show-commands"] = args => ShowCommands(), // backward compatibility + ["show-history"] = args => ShowHistory(), // backward compatibility + ["show-playlist"] = args => ShowPlaylist(), // backward compatibility + }; + + public void ShowDialog(Type winType) + { + Window? win = Activator.CreateInstance(winType) as Window; + new WindowInteropHelper(win).Owner = MainForm.Instance!.Handle; + win?.ShowDialog(); + } + + public void LoadSubtitle(IList args) + { + using var dialog = new OpenFileDialog(); + string path = Player.GetPropertyString("path"); + + if (File.Exists(path)) + dialog.InitialDirectory = Path.GetDirectoryName(path); + + dialog.Multiselect = true; + + if (dialog.ShowDialog() == DialogResult.OK) + foreach (string filename in dialog.FileNames) + Player.CommandV("sub-add", filename); + } + + public void OpenFiles(IList args) + { + bool append = false; + + foreach (string arg in args) + if (arg == "append") + append = true; + + using var dialog = new OpenFileDialog() { Multiselect = true }; + + if (dialog.ShowDialog() == DialogResult.OK) + Player.LoadFiles(dialog.FileNames, true, append); + } + + public void Open_DVD_Or_BD_Folder(IList args) + { + var dialog = new FolderBrowserDialog(); + + if (dialog.ShowDialog() == DialogResult.OK) + Player.LoadDiskFolder(dialog.SelectedPath); + } + + public void OpenFromClipboard(IList args) + { + if (System.Windows.Forms.Clipboard.ContainsFileDropList()) + { + string[] files = System.Windows.Forms.Clipboard.GetFileDropList().Cast().ToArray(); + Player.LoadFiles(files, false, false); + } + else + { + string clipboard = System.Windows.Forms.Clipboard.GetText(); + List files = new List(); + + foreach (string i in clipboard.Split(BR.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) + if (i.Contains("://") || File.Exists(i)) + files.Add(i); + + if (files.Count == 0) + { + Terminal.WriteError("The clipboard does not contain a valid URL or file."); + return; + } + + Player.LoadFiles(files.ToArray(), false, false); + } + } + + public void LoadAudio(IList args) + { + using var dialog = new OpenFileDialog(); + string path = Player.GetPropertyString("path"); + + if (File.Exists(path)) + dialog.InitialDirectory = Path.GetDirectoryName(path); + + dialog.Multiselect = true; + + if (dialog.ShowDialog() == DialogResult.OK) + foreach (string i in dialog.FileNames) + Player.CommandV("audio-add", i); + } + + public void RegisterFileAssociations(IList args) + { + string perceivedType = args[0]; + string[] extensions = Array.Empty(); + + switch (perceivedType) + { + case "video": extensions = FileTypes.Video; break; + case "audio": extensions = FileTypes.Audio; break; + case "image": extensions = FileTypes.Image; break; + } + + try + { + using Process proc = new Process(); + proc.StartInfo.FileName = Environment.ProcessPath; + proc.StartInfo.Arguments = "--register-file-associations " + + perceivedType + " " + string.Join(" ", extensions); + proc.StartInfo.Verb = "runas"; + proc.StartInfo.UseShellExecute = true; + proc.Start(); + proc.WaitForExit(); + + if (proc.ExitCode == 0) + Msg.ShowInfo("File associations were successfully " + + (perceivedType == "unreg" ? "removed" : "created") + + ".\n\nFile Explorer icons will refresh after process restart."); + else + Msg.ShowError("Error creating file associations."); + } + catch { } + } + + public void ShowMediaInfo(IList args) + { + if (Player.PlaylistPos == -1) + return; + + bool full = args.Contains("full"); + bool raw = args.Contains("raw"); + bool editor = args.Contains("editor"); + bool osd = args.Contains("osd") || args == null || args.Count == 0; + + long fileSize = 0; + + string text = ""; + string path = Player.GetPropertyString("path"); + + if (File.Exists(path) && osd) + { + if (FileTypes.Audio.Contains(path.Ext())) + { + text = Player.GetPropertyOsdString("filtered-metadata"); + Player.CommandV("show-text", text, "5000"); + return; + } + else if (FileTypes.Image.Contains(path.Ext())) + { + fileSize = new FileInfo(path).Length; + + text = "Width: " + Player.GetPropertyInt("width") + "\n" + + "Height: " + Player.GetPropertyInt("height") + "\n" + + "Size: " + Convert.ToInt32(fileSize / 1024.0) + " KB\n" + + "Type: " + path.Ext().ToUpper(); + + Player.CommandV("show-text", text, "5000"); + return; + } + } + + if (path.Contains("://")) + { + if (path.Contains("://")) + path = Player.GetPropertyString("media-title"); + string videoFormat = Player.GetPropertyString("video-format").ToUpper(); + string audioCodec = Player.GetPropertyString("audio-codec-name").ToUpper(); + int width = Player.GetPropertyInt("video-params/w"); + int height = Player.GetPropertyInt("video-params/h"); + TimeSpan len = TimeSpan.FromSeconds(Player.GetPropertyDouble("duration")); + text = path.FileName() + "\n"; + text += FormatTime(len.TotalMinutes) + ":" + FormatTime(len.Seconds) + "\n"; + if (fileSize > 0) + text += Convert.ToInt32(fileSize / 1024.0 / 1024.0) + " MB\n"; + text += $"{width} x {height}\n"; + text += $"{videoFormat}\n{audioCodec}"; + Player.CommandV("show-text", text, "5000"); + return; + } + + if (App.MediaInfo && !osd && File.Exists(path) && !path.Contains(@"\\.\pipe\")) + using (MediaInfo mediaInfo = new MediaInfo(path)) + text = Regex.Replace(mediaInfo.GetSummary(full, raw), "Unique ID.+", ""); + else + { + Player.UpdateExternalTracks(); + text = "N: " + Player.GetPropertyString("filename") + BR; + lock (Player.MediaTracksLock) + foreach (MediaTrack track in Player.MediaTracks) + text += track.Text + BR; + } + + text = text.TrimEx(); + + if (editor) + ShowTextWithEditor("media-info", text); + else if (osd) + Command.ShowText(text.Replace("\r", ""), 5000, 16); + else + { + MessageBoxEx.SetFont("Consolas"); + Msg.ShowInfo(text); + MessageBoxEx.SetFont("Segoe UI"); + } + } + + public static string FormatTime(double value) => ((int)value).ToString("00"); + + public void ShowTextWithEditor(string name, string text) + { + string file = Path.Combine(Path.GetTempPath(), name + ".txt"); + App.TempFiles.Add(file); + File.WriteAllText(file, BR + text.Trim() + BR); + ProcessHelp.ShellExecute(file); + } + + public void ShowCommandPalette() + { + MainForm.Instance?.BeginInvoke(() => { + CommandPalette.Instance.SetItems(CommandPalette.GetItems()); + MainForm.Instance.ShowCommandPalette(); + CommandPalette.Instance.SelectFirst(); + }); + } + + // backward compatibility + public void PlaylistRandom() => + Msg.ShowInfo("This feature was moved to a user script,\nwhich can be found here:\n\n" + + "https://github.com/stax76/mpv-scripts/blob/main/misc.lua"); + + // backward compatibility + public void QuickBookmark() => + Msg.ShowInfo("This feature was moved to a user script,\nwhich can be found here:\n\n" + + "https://github.com/stax76/mpv-scripts/blob/main/misc.lua"); + + // backward compatibility + public void ShowCommands() => + Msg.ShowInfo("This feature was moved to a user script,\nwhich can be found here:\n\n" + + "https://github.com/stax76/mpv-scripts#command_palette"); + + // backward compatibility + public void ShowHistory() => + Msg.ShowInfo("This feature was moved to a user script,\nwhich can be found here:\n\n" + + "https://github.com/stax76/mpv-scripts/blob/main/history.lua"); + + // backward compatibility + public void ShowPlaylist() => + Msg.ShowInfo("This feature was moved to a user script,\nwhich can be found here:\n\n" + + "https://github.com/stax76/mpv-scripts#command_palette"); +} diff --git a/src/MpvNet.Windows/Help/RegistryHelp.cs b/src/MpvNet.Windows/Help/RegistryHelp.cs new file mode 100644 index 0000000..fc5b16d --- /dev/null +++ b/src/MpvNet.Windows/Help/RegistryHelp.cs @@ -0,0 +1,74 @@ + +using Microsoft.Win32; + +namespace MpvNet.Windows.Help; + +public static class RegistryHelp +{ + static string? _appKey; + + public static string? ProductName { get; set; } + + public static string AppKey { + get + { + if (ProductName == null) + throw new Exception("ProductName cannot be null."); + + return _appKey ??= @"HKCU\Software\" + ProductName; + } + } + + public static void SetInt(string name, object value) => SetValue(AppKey, name, value); + + public static void SetString(string name, string value) => SetValue(AppKey, name, value); + + public static void SetValue(string name, object value) + { + using RegistryKey regKey = GetRootKey(AppKey).CreateSubKey(AppKey[5..], RegistryKeyPermissionCheck.ReadWriteSubTree); + regKey.SetValue(name, value); + } + + public static void SetValue(string path, string name, object value) + { + using RegistryKey regKey = GetRootKey(path).CreateSubKey(path[5..], RegistryKeyPermissionCheck.ReadWriteSubTree); + regKey.SetValue(name, value); + } + + public static string GetString(string name, string defaultValue = "") => + GetValue(AppKey, name, defaultValue)?.ToString() ?? defaultValue; + + public static int GetInt(string name, int defaultValue = 0) => + GetValue(AppKey, name, defaultValue) is int i ? i : defaultValue; + + public static object? GetValue(string name) => GetValue(AppKey, name, null); + + public static object? GetValue(string path, string name, object? defaultValue = null) + { + using RegistryKey? regKey = GetRootKey(path).OpenSubKey(path[5..]); + return regKey?.GetValue(name, defaultValue); + } + + public static void RemoveKey(string path) + { + try { + GetRootKey(path).DeleteSubKeyTree(path[5..], false); + } catch { } + } + + public static void RemoveValue(string path, string name) + { + try { + using RegistryKey? regKey = GetRootKey(path).OpenSubKey(path[5..], true); + regKey?.DeleteValue(name, false); + } catch { } + } + + static RegistryKey GetRootKey(string path) => path[..4] switch + { + "HKLM" => Registry.LocalMachine, + "HKCU" => Registry.CurrentUser, + "HKCR" => Registry.ClassesRoot, + _ => throw new Exception(), + }; +} diff --git a/src/MpvNet.Windows/Misc.cs b/src/MpvNet.Windows/Misc.cs new file mode 100644 index 0000000..a49e896 --- /dev/null +++ b/src/MpvNet.Windows/Misc.cs @@ -0,0 +1,15 @@ +using MpvNet.ExtensionMethod; + +namespace MpvNet.Windows; + +public class Misc +{ + public static void CopyMpvnetCom() + { + string dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).AddSep() + + "Microsoft\\WindowsApps\\"; + + if (File.Exists(dir + "MpvNet.exe") && !File.Exists(dir + "MpvNet.com")) + File.Copy(Folder.Startup + "MpvNet.com", dir + "MpvNet.com"); + } +} diff --git a/src/MpvNet.Windows/MpvNet.Windows.csproj b/src/MpvNet.Windows/MpvNet.Windows.csproj new file mode 100644 index 0000000..1ffeec2 --- /dev/null +++ b/src/MpvNet.Windows/MpvNet.Windows.csproj @@ -0,0 +1,43 @@ + + + + WinExe + net6.0-windows + MpvNet.Windows + false + mpvnet + true + true + mpv-icon.ico + mpv.net + 7.0.0.0 + 7.0.0.0 + enable + + + + + + + + + + + + + MSBuild:Compile + Wpf + Designer + + + + + + + + + + + + + diff --git a/src/Native/StockIcon.cs b/src/MpvNet.Windows/Native/StockIcon.cs similarity index 99% rename from src/Native/StockIcon.cs rename to src/MpvNet.Windows/Native/StockIcon.cs index f7db5be..45d85e2 100644 --- a/src/Native/StockIcon.cs +++ b/src/MpvNet.Windows/Native/StockIcon.cs @@ -1,5 +1,4 @@  -using System; using System.Runtime.InteropServices; public class StockIcon diff --git a/src/Native/Taskbar.cs b/src/MpvNet.Windows/Native/Taskbar.cs similarity index 99% rename from src/Native/Taskbar.cs rename to src/MpvNet.Windows/Native/Taskbar.cs index d5fe8d1..630253e 100644 --- a/src/Native/Taskbar.cs +++ b/src/MpvNet.Windows/Native/Taskbar.cs @@ -1,5 +1,4 @@  -using System; using System.Runtime.InteropServices; public class Taskbar @@ -52,4 +51,4 @@ public enum TaskbarStates Normal = 0x2, Error = 0x4, Paused = 0x8 -} \ No newline at end of file +} diff --git a/src/MpvNet.Windows/Native/WinApi.cs b/src/MpvNet.Windows/Native/WinApi.cs new file mode 100644 index 0000000..5b3f222 --- /dev/null +++ b/src/MpvNet.Windows/Native/WinApi.cs @@ -0,0 +1,211 @@ + +using System.Drawing; +using System.Runtime.InteropServices; + +namespace MpvNet.Windows.Native; + +public static class WinApi +{ + public static Version WindowsTen1607 { get; } = new Version(10, 0, 14393); // Windows 10 1607 + + [DllImport("kernel32.dll")] + public static extern bool AttachConsole(int dwProcessId); + + [DllImport("kernel32.dll")] + public static extern bool FreeConsole(); + + [DllImport("kernel32.dll")] + public static extern IntPtr LoadLibrary(string path); + + [DllImport("user32.dll")] + public static extern uint ActivateKeyboardLayout(IntPtr hkl, uint flags); + + [DllImport("user32.dll")] + public static extern bool GetWindowRect(IntPtr hwnd, out Rect lpRect); + + [DllImport("user32.dll", CharSet = CharSet.Unicode)] + public static extern IntPtr FindWindowEx( + IntPtr parentHandle, IntPtr childAfter, string lclassName, string? windowTitle); + + [DllImport("user32.dll", CharSet = CharSet.Unicode)] + public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); + + [DllImport("user32.dll", CharSet = CharSet.Unicode)] + public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref CopyDataStruct lParam); + + [DllImport("user32.dll", CharSet = CharSet.Unicode)] + public static extern IntPtr PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); + + [DllImport("user32.dll", CharSet = CharSet.Unicode)] + public static extern int RegisterWindowMessage(string id); + + [DllImport("user32.dll")] + public static extern bool AllowSetForegroundWindow(int dwProcessId); + + [DllImport("user32.dll")] + public static extern void ReleaseCapture(); + + [DllImport("user32.dll")] + public static extern int GetDpiForWindow(IntPtr hwnd); + + [DllImport("user32.dll")] + public static extern bool AdjustWindowRect(ref Rect lpRect, uint dwStyle, bool bMenu); + + [DllImport("user32.dll")] + public static extern bool AdjustWindowRectExForDpi( + ref Rect lpRect, uint dwStyle, bool bMenu, uint dwExStyle, uint dpi); + + [DllImport("user32.dll")] + public static extern bool SetWindowPos( + IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags); + + [DllImport("user32.dll", EntryPoint = "GetWindowLong")] + static extern IntPtr GetWindowLong32(IntPtr hWnd, int nIndex); + + [DllImport("user32.dll")] + static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex); + + public static IntPtr GetWindowLong(IntPtr hWnd, int nIndex) + { + if (IntPtr.Size == 8) + return GetWindowLongPtr(hWnd, nIndex); + else + return GetWindowLong32(hWnd, nIndex); + } + + [DllImport("user32.dll", EntryPoint = "SetWindowLong")] + public static extern IntPtr SetWindowLong32(IntPtr hWnd, int nIndex, uint dwNewLong); + + [DllImport("user32.dll")] + public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, uint dwNewLong); + + public static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong) + { + if (IntPtr.Size == 8) + return SetWindowLongPtr(hWnd, nIndex, dwNewLong); + else + return SetWindowLong32(hWnd, nIndex, dwNewLong); + } + + [DllImport("gdi32.dll")] + public static extern int GetDeviceCaps(IntPtr hdc, int nIndex); + + [DllImport("dwmapi.dll")] + public static extern int DwmGetWindowAttribute( + IntPtr hwnd, uint dwAttribute, out Rect pvAttribute, uint cbAttribute); + + public static bool GetDwmWindowRect(IntPtr handle, out Rect rect) + { + const uint DWMWA_EXTENDED_FRAME_BOUNDS = 9; + + return 0 == DwmGetWindowAttribute(handle, DWMWA_EXTENDED_FRAME_BOUNDS, + out rect, (uint)Marshal.SizeOf()); + } + + public static Rectangle GetWorkingArea(IntPtr handle, Rectangle workingArea) + { + if (handle != IntPtr.Zero && GetDwmWindowRect(handle, out Rect dwmRect) && + GetWindowRect(handle, out Rect rect)) + { + int left = workingArea.Left; + int top = workingArea.Top; + int right = workingArea.Right; + int bottom = workingArea.Bottom; + + left += rect.Left - dwmRect.Left; + top -= rect.Top - dwmRect.Top; + right -= dwmRect.Right - rect.Right; + bottom -= dwmRect.Bottom - rect.Bottom; + + return new Rectangle(left, top, right - left, bottom - top); + } + + return workingArea; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Rect + { + public int Left; + public int Top; + public int Right; + public int Bottom; + + public Rect(Rectangle r) + { + Left = r.Left; + Top = r.Top; + Right = r.Right; + Bottom = r.Bottom; + } + + public Rect(int left, int top, int right, int bottom) + { + Left = left; + Top = top; + Right = right; + Bottom = bottom; + } + + public Rectangle ToRectangle() => Rectangle.FromLTRB(Left, Top, Right, Bottom); + public Size Size => new Size(Right - Left, Bottom - Top); + public int Width => Right - Left; + public int Height => Bottom - Top; + + public static Rect FromRectangle(Rectangle rect) + { + return new Rect(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height); + } + + public override string ToString() + { + return "{Left=" + Left + ",Top=" + Top + ",Right=" + Right + ",Bottom=" + Bottom + "}"; + } + } + + [StructLayout(LayoutKind.Sequential)] + public struct CopyDataStruct + { + public IntPtr dwData; + public int cbData; + [MarshalAs(UnmanagedType.LPTStr)] + public string lpData; + } + + public static int GetResizeBorder(int v) + { + switch (v) + { + case 1 /* WMSZ_LEFT */ : return 3; + case 3 /* WMSZ_TOP */ : return 2; + case 2 /* WMSZ_RIGHT */ : return 3; + case 6 /* WMSZ_BOTTOM */ : return 2; + case 4 /* WMSZ_TOPLEFT */ : return 1; + case 5 /* WMSZ_TOPRIGHT */ : return 1; + case 7 /* WMSZ_BOTTOMLEFT */ : return 3; + case 8 /* WMSZ_BOTTOMRIGHT */ : return 3; + default: return -1; + } + } + + public static void SubtractWindowBorders(IntPtr hwnd, ref Rect rc, int dpi) + { + Rect r = new Rect(0, 0, 0, 0); + AddWindowBorders(hwnd, ref r, dpi); + rc.Left -= r.Left; + rc.Top -= r.Top; + rc.Right -= r.Right; + rc.Bottom -= r.Bottom; + } + + public static void AddWindowBorders(IntPtr hwnd, ref Rect rc, int dpi) + { + uint windowStyle = (uint)GetWindowLong(hwnd, -16); // GWL_STYLE + uint windowStyleEx = (uint)GetWindowLong(hwnd, -20); // GWL_EXSTYLE + + if (Environment.OSVersion.Version >= WindowsTen1607) + AdjustWindowRectExForDpi(ref rc, windowStyle, false, windowStyleEx, (uint)dpi); + else + AdjustWindowRect(ref rc, windowStyle, false); + } +} diff --git a/src/Package/Images/LockScreenLogo.scale-200.png b/src/MpvNet.Windows/Package/Images/LockScreenLogo.scale-200.png similarity index 100% rename from src/Package/Images/LockScreenLogo.scale-200.png rename to src/MpvNet.Windows/Package/Images/LockScreenLogo.scale-200.png diff --git a/src/Package/Images/SplashScreen.scale-200.png b/src/MpvNet.Windows/Package/Images/SplashScreen.scale-200.png similarity index 100% rename from src/Package/Images/SplashScreen.scale-200.png rename to src/MpvNet.Windows/Package/Images/SplashScreen.scale-200.png diff --git a/src/Package/Images/Square150x150Logo.scale-200.png b/src/MpvNet.Windows/Package/Images/Square150x150Logo.scale-200.png similarity index 100% rename from src/Package/Images/Square150x150Logo.scale-200.png rename to src/MpvNet.Windows/Package/Images/Square150x150Logo.scale-200.png diff --git a/src/Package/Images/Square44x44Logo.scale-200.png b/src/MpvNet.Windows/Package/Images/Square44x44Logo.scale-200.png similarity index 100% rename from src/Package/Images/Square44x44Logo.scale-200.png rename to src/MpvNet.Windows/Package/Images/Square44x44Logo.scale-200.png diff --git a/src/Package/Images/Square44x44Logo.targetsize-24_altform-unplated.png b/src/MpvNet.Windows/Package/Images/Square44x44Logo.targetsize-24_altform-unplated.png similarity index 100% rename from src/Package/Images/Square44x44Logo.targetsize-24_altform-unplated.png rename to src/MpvNet.Windows/Package/Images/Square44x44Logo.targetsize-24_altform-unplated.png diff --git a/src/Package/Images/StoreLogo.png b/src/MpvNet.Windows/Package/Images/StoreLogo.png similarity index 100% rename from src/Package/Images/StoreLogo.png rename to src/MpvNet.Windows/Package/Images/StoreLogo.png diff --git a/src/Package/Images/Wide310x150Logo.scale-200.png b/src/MpvNet.Windows/Package/Images/Wide310x150Logo.scale-200.png similarity index 100% rename from src/Package/Images/Wide310x150Logo.scale-200.png rename to src/MpvNet.Windows/Package/Images/Wide310x150Logo.scale-200.png diff --git a/src/Package/Package.appxmanifest b/src/MpvNet.Windows/Package/Package.appxmanifest similarity index 98% rename from src/Package/Package.appxmanifest rename to src/MpvNet.Windows/Package/Package.appxmanifest index 2c1b3c0..c7c3f4c 100644 --- a/src/Package/Package.appxmanifest +++ b/src/MpvNet.Windows/Package/Package.appxmanifest @@ -11,7 +11,7 @@ + Version="6.0.3.0" /> mpv.net @@ -45,7 +45,7 @@ - + diff --git a/src/Package/mpv.net.package.wapproj b/src/MpvNet.Windows/Package/mpv.net.package.wapproj similarity index 100% rename from src/Package/mpv.net.package.wapproj rename to src/MpvNet.Windows/Package/mpv.net.package.wapproj diff --git a/src/MpvNet.Windows/Program.cs b/src/MpvNet.Windows/Program.cs new file mode 100644 index 0000000..6f5a5bf --- /dev/null +++ b/src/MpvNet.Windows/Program.cs @@ -0,0 +1,105 @@ + +using System.Windows.Forms; +using System.Threading; + +using MpvNet.Windows.Native; +using MpvNet.Help; +using MpvNet.Windows.UI; +using MpvNet.Windows.Help; + +namespace MpvNet.Windows; + +static class Program +{ + [STAThread] + static void Main() + { + try + { + RegistryHelp.ProductName = AppInfo.Product; + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + + AppDomain.CurrentDomain.UnhandledException += (sender, e) => Terminal.WriteError(e.ExceptionObject); + Application.ThreadException += (sender, e) => Terminal.WriteError(e.Exception); + + if (App.IsTerminalAttached) + WinApi.AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/); + + string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray(); + + if (args.Length > 0 && args[0] == "--register-file-associations") + { + FileAssociation.Register(args[1], args.Skip(1).ToArray()); + return; + } + + App.Init(); + Theme.Init(); + Mutex mutex = new Mutex(true, StringHelp.GetMD5Hash(App.ConfPath), out bool isFirst); + + if (Control.ModifierKeys.HasFlag(Keys.Shift)) + App.ProcessInstance = "multi"; + + if ((App.ProcessInstance == "single" || App.ProcessInstance == "queue") && !isFirst) + { + List args2 = new List { App.ProcessInstance }; + + foreach (string arg in args) + { + if (!arg.StartsWith("--") && (arg == "-" || arg.Contains("://") || + arg.Contains(":\\") || arg.StartsWith("\\\\"))) + + args2.Add(arg); + else if (arg == "--queue") + args2[0] = "queue"; + else if (arg.StartsWith("--command=")) + { + args2[0] = "command"; + args2.Add(arg[10..]); + } + } + + Process[] procs = Process.GetProcessesByName("mpvnet"); + + for (int i = 0; i < 20; i++) + { + foreach (Process proc in procs) + { + if (proc.MainWindowHandle != IntPtr.Zero) + { + WinApi.AllowSetForegroundWindow(proc.Id); + var data = new WinApi.CopyDataStruct(); + data.lpData = string.Join("\n", args2.ToArray()); + data.cbData = data.lpData.Length * 2 + 1; + WinApi.SendMessage(proc.MainWindowHandle, 0x004A /*WM_COPYDATA*/, IntPtr.Zero, ref data); + mutex.Dispose(); + + if (App.IsTerminalAttached) + WinApi.FreeConsole(); + + return; + } + } + + Thread.Sleep(50); + } + + mutex.Dispose(); + return; + } + + Application.Run(new WinForms.MainForm()); + + if (App.IsTerminalAttached) + WinApi.FreeConsole(); + + mutex.Dispose(); + } + catch (Exception ex) + { + Terminal.WriteError(ex); + } + } +} diff --git a/src/Properties/Resources.Designer.cs b/src/MpvNet.Windows/Properties/Resources.Designer.cs similarity index 69% rename from src/Properties/Resources.Designer.cs rename to src/MpvNet.Windows/Properties/Resources.Designer.cs index f427d33..8cfe430 100644 --- a/src/Properties/Resources.Designer.cs +++ b/src/MpvNet.Windows/Properties/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace mpvnet.Properties { +namespace MpvNet.Windows.Properties { using System; @@ -20,7 +20,7 @@ namespace mpvnet.Properties { // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [DebuggerNonUserCode()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -39,7 +39,7 @@ namespace mpvnet.Properties { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("mpvnet.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MpvNet.Windows.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; @@ -79,48 +79,7 @@ namespace mpvnet.Properties { return ResourceManager.GetString("editor_conf", resourceCulture); } } - - /// - /// Looks up a localized string similar to - ///# This file defines the key and mouse bindings and also the context menu of mpv.net. - /// - ///# A input and config editor can be found in the context menu under 'Settings'. - /// - ///# The mpv.conf defaults of mpv.net contain input-default-bindings=yes and - ///# input-builtin-bindings=no which disables the input defaults of mpv. - /// - ///# The input test mode can be started via command line: --input-test - /// - ///# The input key list can be printed with --input-keylist or - ///# shown from the context menu under: View > Show Keys - /// - ///# m [rest of string was truncated]";. - /// - internal static string input_conf { - get { - return ResourceManager.GetString("input_conf", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap mpvnet { - get { - object obj = ResourceManager.GetObject("mpvnet", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap mpvnet_santa { - get { - object obj = ResourceManager.GetObject("mpvnet_santa", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } + /// /// Looks up a localized string similar to diff --git a/src/Properties/Resources.resx b/src/MpvNet.Windows/Properties/Resources.resx similarity index 89% rename from src/Properties/Resources.resx rename to src/MpvNet.Windows/Properties/Resources.resx index 0d8d15f..262f734 100644 --- a/src/Properties/Resources.resx +++ b/src/MpvNet.Windows/Properties/Resources.resx @@ -121,15 +121,6 @@ ..\Resources\editor_conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - ..\Resources\input.conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - ..\Resources\mpvnet.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\mpvnet-santa.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\theme.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 diff --git a/src/Release.ps1 b/src/MpvNet.Windows/Release.ps1 similarity index 83% rename from src/Release.ps1 rename to src/MpvNet.Windows/Release.ps1 index 2dcd044..dd43b17 100644 --- a/src/Release.ps1 +++ b/src/MpvNet.Windows/Release.ps1 @@ -4,7 +4,7 @@ $exePath = $PSScriptRoot + '\bin\mpvnet.exe' $versionInfo = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath) $7z = 'C:\Program Files\7-Zip\7z.exe' -$targetDir = $tmpDir + "\mpv.net-$($versionInfo.FileVersion)-beta" +$targetDir = $tmpDir + "\mpvnet-$($versionInfo.FileVersion)-beta" Copy-Item $PSScriptRoot\bin $targetDir -Recurse -Exclude System.Management.Automation.xml $folders = 'Debug', 'Release', 'x64', 'x86', 'Arm' @@ -14,6 +14,8 @@ foreach ($folder in $folders) { } & $7z a -tzip -mx9 "$targetDir.zip" -r "$targetDir\*" -if ($LastExitCode) { throw $LastExitCode } + +if ($LastExitCode) + { throw $LastExitCode } Write-Host 'successfully finished' -ForegroundColor Green diff --git a/src/Resources/editor_conf.txt b/src/MpvNet.Windows/Resources/editor_conf.txt similarity index 86% rename from src/Resources/editor_conf.txt rename to src/MpvNet.Windows/Resources/editor_conf.txt index 51e7f74..a969366 100644 --- a/src/Resources/editor_conf.txt +++ b/src/MpvNet.Windows/Resources/editor_conf.txt @@ -2,61 +2,55 @@ name = process-instance file = mpvnet default = single -filter = General -help = Defines if more then one mpv.net process is allowed. (mpv.net specific option)\n\nMulti can alternatively be enabled by pressing the SHIFT key.\n\nWhenever the control key is pressed when files or URLs are opened, the playlist is not cleared but the files or URLs are appended to the playlist. This not only works on process startup but in all mpv.net features that open files and URLs. +directory = General +help = Defines if more then one mpv.net process is allowed. (mpv.net option)\n\nMulti can alternatively be enabled by pressing the SHIFT key. option = multi Create a new process everytime the shell starts mpv.net option = single Force a single process everytime the shell starts mpv.net option = queue Force a single process and add files to playlist name = recent-count file = mpvnet -filter = General -help = Amount of recent files to be remembered. Default: 15 (mpv.net specific option) +directory = General +help = Amount of recent files to be remembered. Default: 15 (mpv.net option) name = media-info file = mpvnet default = yes -filter = General -help = Usage of the media info library instead of mpv to access media information. (mpv.net specific option) +directory = General +help = Usage of the media info library instead of mpv to access media information. (mpv.net option) option = yes option = no -name = history-filter -file = mpvnet -filter = General -width = 500 -help = Semicolon separated list of paths to be excluded from the history log feature. - name = video-file-extensions file = mpvnet -filter = General +directory = General width = 500 -help = Video file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net specific option) +help = Video file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net option) name = audio-file-extensions file = mpvnet -filter = General +directory = General width = 500 -help = Audio file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net specific option) +help = Audio file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net option) name = image-file-extensions file = mpvnet -filter = General +directory = General width = 500 -help = Image file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net specific option) +help = Image file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net option) name = debug-mode file = mpvnet default = no -filter = General -help = Enable this only when a developer asks for it. (mpv.net specific option) +directory = General +help = Enable this only when a developer asks for it. (mpv.net option) option = yes option = no name = vo file = mpv default = gpu -filter = Video +directory = Video help = Video output drivers to be used.\n\nFor more information visit: url = https://mpv.io/manual/master/#video-output-drivers-vo option = gpu General purpose, customizable, GPU-accelerated video output driver. It supports extended scaling methods, dithering, color management, custom shaders, HDR, and more. @@ -66,7 +60,7 @@ option = direct3d Video output driver that uses the Direct3D interface. name = hwdec file = mpv default = no -filter = Video +directory = Video url = https://mpv.io/manual/master/#options-hwdec help = Specify the hardware video decoding API that should be used if possible. Whether hardware decoding is actually done depends on the video codec. If hardware decoding is not possible, mpv will fall back on software decoding.\n\nFor more information visit: option = no always use software decoding @@ -86,7 +80,7 @@ option = nvdec-copy copies video back to system RAM (Any platform CUDA is ava name = gpu-api file = mpv default = auto -filter = Video +directory = Video help = Controls which type of graphics APIs will be accepted. Auto uses d3d11, it should only be changed in case of problems, Vulkan is not recommended. option = auto Use any available API option = d3d11 Allow only gpu-context=d3d11 @@ -96,7 +90,7 @@ option = vulkan Allow only Vulkan name = gpu-context file = mpv default = auto -filter = Video +directory = Video option = auto auto-select option = d3d11 Win32, with native Direct3D 11 rendering. option = angle Direct3D11 through the OpenGL ES translation layer ANGLE. This supports almost everything the win backend does (if the ANGLE build is new enough). @@ -107,7 +101,7 @@ option = winvk VK_KHR_win32_surface name = video-sync file = mpv default = audio -filter = Video +directory = Video help = How the player synchronizes audio and video.\n\nFor more information visit: url = https://mpv.io/manual/master/#options-video-sync option = audio @@ -122,7 +116,7 @@ option = desync name = scale file = mpv default = bilinear -filter = Video +directory = Video help = The GPU renderer filter function to use when upscaling video. There are some more filters, but most are not as useful. For a complete list, pass help as value, e.g.: mpv --scale=help option = bilinear Bilinear hardware texture filtering (fastest, very low quality). option = spline36 Mid quality and speed. This is the default when using gpu-hq. @@ -135,7 +129,7 @@ option = oversample A version of nearest neighbour that (naively) oversam name = cscale file = mpv default = bilinear -filter = Video +directory = Video help = As scale, but for interpolating chroma information. If the image is not subsampled, this option is ignored entirely. option = bilinear Bilinear hardware texture filtering (fastest, very low quality). option = spline36 Mid quality and speed. This is the default when using gpu-hq. @@ -148,7 +142,7 @@ option = oversample A version of nearest neighbour that (naively) oversam name = dscale file = mpv default = -filter = Video +directory = Video help = Like scale, but apply these filters on downscaling instead. \nIf no option is selected, it will keep the same with the upscaler. option = bilinear Bilinear hardware texture filtering (fastest, very low quality). option = spline36 Mid quality and speed. This is the default when using gpu-hq. @@ -161,7 +155,7 @@ option = oversample A version of nearest neighbour that (naively) oversam name = dither-depth file = mpv default = no -filter = Video +directory = Video help = Set dither target depth to N. Note that the depth of the connected video display device cannot be detected. Often, LCD panels will do dithering on their own, which conflicts with this option and leads to ugly output. option = no Disable any dithering done by mpv. option = auto Automatic selection. If output bit depth cannot be detected, 8 bits per component are assumed. @@ -171,7 +165,7 @@ option = 10 Dither to 10 bit output. name = correct-downscaling file = mpv default = no -filter = Video +directory = Video help = When using convolution based filters, extend the filter size when downscaling. Increases quality, but reduces performance while downscaling.\n\nThis will perform slightly sub-optimally for anamorphic video (but still better than without it) since it will extend the size to match only the milder of the scale factors between the axes. option = yes option = no @@ -179,7 +173,7 @@ option = no name = sigmoid-upscaling file = mpv default = no -filter = Video +directory = Video help = When upscaling, use a sigmoidal color transform to avoid emphasizing ringing artifacts. This also implies linear-scaling. option = yes option = no @@ -187,7 +181,7 @@ option = no name = deband file = mpv default = no -filter = Video +directory = Video help = Enable the debanding algorithm. This greatly reduces the amount of visible banding, blocking and other quantization artifacts, at the expense of very slightly blurring some of the finest details. In practice, it's virtually always an improvement - the only reason to disable it would be for performance. option = yes option = no @@ -195,7 +189,7 @@ option = no name = d3d11va-zero-copy file = mpv default = no -filter = Video +directory = Video help = By default, when using hardware decoding with --gpu-api=d3d11, the video image will be copied (GPU-to-GPU) from the decoder surface to a shader resource. Set this option to avoid that copy by sampling directly from the decoder image. This may increase performance and reduce power usage, but can cause the image to be sampled incorrectly on the bottom and right edges due to padding, and may invoke driver bugs, since Direct3D 11 technically does not allow sampling from a decoder surface (though most drivers support it.) option = yes option = no @@ -203,7 +197,7 @@ option = no name = hdr-compute-peak file = mpv default = auto -filter = Video +directory = Video help = Compute the HDR peak and frame average brightness per-frame instead of relying on tagged metadata. These values are averaged over local regions as well as over several frames to prevent the value from jittering around too much. This option basically gives you dynamic, per-scene tone mapping. Requires compute shaders, which is a fairly recent OpenGL feature, and will probably also perform horribly on some drivers, so enable at your own risk. The special value auto (default) will enable HDR peak computation automatically if compute shaders and SSBOs are supported. option = auto option = yes @@ -212,34 +206,34 @@ option = no name = allow-delayed-peak-detect file = mpv default = yes -filter = Video +directory = Video help = When using --hdr-compute-peak, allow delaying the detected peak by a frame when beneficial for performance. In particular, this is required to avoid an unnecessary FBO indirection when no advanced rendering is required otherwise. Has no effect if there already is an indirect pass, such as when advanced scaling is enabled. (Only affects --vo=gpu-next, note that --vo=gpu always delays the peak.) option = yes option = no name = volume file = mpv -filter = Audio +directory = Audio help = Set the startup volume. 0 means silence, 100 means no volume reduction or amplification. Negative values can be passed for compatibility, but are treated as 0. Since mpv 0.18.1, this always controls the internal mixer (aka "softvol"). Default: 100 name = remember-volume file = mpvnet default = yes -filter = Audio -help = Save volume and mute on exit and restore it on start. (mpv.net specific option) +directory = Audio +help = Save volume and mute on exit and restore it on start. (mpv.net option) option = yes option = no name = alang file = mpv -filter = Audio +directory = Audio type = string help = Specify a priority list of audio languages to use. Different container formats employ different language codes. DVDs use ISO 639-1 two-letter language codes, Matroska, MPEG-TS and NUT use ISO 639-2 three-letter language codes, while OGM uses a free-form identifier. See also aid.\n\nExamples\n\nmpv dvd://1 alang=hu,en chooses the Hungarian language track on a DVD and falls back on English if Hungarian is not available.\n\nmpv alang=jpn example.mkv plays a Matroska file with Japanese audio. name = audio-file-auto file = mpv default = no -filter = Audio +directory = Audio help = Load additional audio files matching the video filename. The parameter specifies how external audio files are matched. option = no Don't automatically load external audio files. option = exact Load the media filename with audio file extension. @@ -248,21 +242,21 @@ option = all Load all audio files in the current and audio-file-paths directo name = audio-device file = mpv -filter = Audio +directory = Audio type = string url = https://mpv.io/manual/master/#options-audio-device -help = Use the given audio device. This consists of the audio output name, e.g. alsa, followed by /, followed by the audio output specific device name. The default value for this option is auto, which tries every audio output in preference order with the default device.\nAvailable devices can be found in the context menu under:\nView > Advanced > Show Audio Devices +help = Use the given audio device. This consists of the audio output name, e.g. alsa, followed by /, followed by the audio output specific device name. The default value for this option is auto, which tries every audio output in preference order with the default device. name = slang file = mpv -filter = Subtitle +directory = Subtitle type = string help = Specify a priority list of subtitle languages to use. Different container formats employ different language codes. DVDs use ISO 639-1 two letter language codes, Matroska uses ISO 639-2 three letter language codes while OGM uses a free-form identifier. See also sid. name = sub-auto file = mpv default = exact -filter = Subtitle +directory = Subtitle help = Load additional subtitle files matching the video filename. The parameter specifies how external subtitle files are matched. exact is enabled by default. option = no Don't automatically load external subtitle files. option = exact Load the media filename with subtitle file extension. @@ -271,37 +265,38 @@ option = all Load all subs in the current and sub-file-paths directories. name = sub-font file = mpv -filter = Subtitle +directory = Subtitle type = string help = Specify font to use for subtitles that do not themselves specify a particular font. The default is sans-serif. name = sub-font-size file = mpv -filter = Subtitle +directory = Subtitle help = Specify the sub font size. The unit is the size in scaled pixels at a window height of 720. The actual pixel size is scaled with the window height: if the window height is larger or smaller than 720, the actual size of the text increases or decreases as well. Default: 55 name = sub-color file = mpv type = color -filter = Subtitle -help = Specify the color used for unstyled text subtitles.\n\nThe color is specified in the form r/g/b, where each color component is specified as number in the range 0.0 to 1.0. It's also possible to specify the transparency by using r/g/b/a, where the alpha value 0 means fully transparent, and 1.0 means opaque. If the alpha component is not given, the color is 100% opaque.\n\nPassing a single number to the option sets the sub to gray, and the form gray/a lets you specify alpha additionally.\n\nExamples\n\n1.0/0.0/0.0 set sub to opaque red\n1.0/0.0/0.0/0.75 set sub to opaque red with 75% alpha\n0.5/0.75 set sub to 50% gray with 75% alpha\n\nAlternatively, the color can be specified as a RGB hex triplet in the form #RRGGBB, where each 2-digit group expresses a color value in the range 0 (00) to 255 (FF). For example, #FF0000 is red. This is similar to web colors. Alpha is given with #AARRGGBB.\n\nExamples\n\n#FF0000 set sub to opaque red\n#C0808080 set sub to 50% gray with 75% alpha +directory = Subtitle +url = https://mpv.io/manual/master/#options-sub-color +help = Specify the color used for unstyled text subtitles.\n\nA usage description and examples can be found in the manual at: name = sub-border-color file = mpv type = color -filter = Subtitle +directory = Subtitle help = See sub-color. Color used for the sub font border. Ignored when sub-back-color is specified (or more exactly: when that option is not set to completely transparent). name = sub-back-color file = mpv type = color -filter = Subtitle +directory = Subtitle help = See sub-color. Color used for sub text background. You can use sub-shadow-offset to change its size relative to the text. name = fullscreen file = mpv default = no -filter = Screen +directory = Screen help = Start the player in fullscreen mode. option = yes option = no @@ -309,72 +304,72 @@ option = no name = border file = mpv default = yes -filter = Screen +directory = Screen help = Show window with decoration (titlebar, border). option = yes option = no name = screen file = mpv -filter = Screen +directory = Screen help = <0-32> In multi-monitor configurations (i.e. a single desktop that spans across multiple displays), this option tells mpv which screen to display the video on. name = osd-playing-msg file = mpv width = 300 -filter = Screen +directory = Screen type = string help = Show a message on OSD when playback starts. The string is expanded for properties, e.g. osd-playing-msg='file: ${filename}' will show the message file: followed by a space and the currently played filename. For more information visit: url = https://mpv.io/manual/master/#property-expansion name = osd-font-size file = mpv -filter = Screen +directory = Screen help = Specify the OSD font size. See sub-font-size for details. Default: 55 name = osd-duration file = mpv -filter = Screen +directory = Screen help = Set the duration of the OSD messages in ms. Default: 1000 name = osd-scale-by-window file = mpv default = yes -filter = Screen +directory = Screen help = Whether to scale the OSD with the window size. If this is disabled, osd-font-size and other OSD options that use scaled pixels are always in actual pixels. The effect is that changing the window size won't change the OSD font size. option = yes option = no name = autofit file = mpv -filter = Screen +directory = Screen help = Initial window height in percent. Default: 60 name = autofit-image file = mpvnet -filter = Screen +directory = Screen help = Initial window height in percent for image files. Default: 80 name = autofit-audio file = mpvnet -filter = Screen +directory = Screen help = Initial window height in percent for audio files. Default: 70 name = autofit-smaller file = mpv -filter = Screen +directory = Screen help = Minimum window height in percent. Default: 10 name = autofit-larger file = mpv -filter = Screen +directory = Screen help = Maximum window height in percent. Default: 80 name = start-size file = mpvnet default = height-session -filter = Screen -help = Setting to remember the window size. (mpv.net specific option) +directory = Screen +help = Setting to remember the window size. (mpv.net option) option = width-session Window width is remembered in the current session option = width-always Window width is always remembered option = height-session Window height is remembered in the current session @@ -386,33 +381,33 @@ option = always Window size is always remembered name = keepaspect-window file = mpv default = yes -filter = Screen +directory = Screen help = keepaspect-window will lock the window size to the video aspect. Default: yes option = yes option = no name = minimum-aspect-ratio file = mpvnet -filter = Screen -help = Minimum aspect ratio of the window. Useful to force a wider window and therefore a larger OSC. (mpv.net specific option) +directory = Screen +help = Minimum aspect ratio of the window. Useful to force a wider window and therefore a larger OSC. (mpv.net option) name = minimum-aspect-ratio-audio file = mpvnet -filter = Screen +directory = Screen help = Same as minimum-aspect-ratio but used for audio files. name = remember-window-position file = mpvnet default = no -filter = Screen -help = Save the window position on exit. (mpv.net specific option) +directory = Screen +help = Save the window position on exit. (mpv.net option) option = yes option = no name = snap-window file = mpv default = no -filter = Screen +directory = Screen help = Snap the player window to screen edges. option = yes option = no @@ -420,20 +415,20 @@ option = no name = window-maximized file = mpv default = no -filter = Screen +directory = Screen help = Start with a maximized window. option = yes option = no name = start-threshold file = mpvnet -filter = Screen -help = Threshold in milliseconds to wait for libmpv returning the video resolution before the window is shown, otherwise default dimensions are used as defined by autofit and start-size. Default: 1500 (mpv.net specific option) +directory = Screen +help = Threshold in milliseconds to wait for libmpv returning the video resolution before the window is shown, otherwise default dimensions are used as defined by autofit and start-size. Default: 1500 (mpv.net option) name = taskbar-progress file = mpv default = yes -filter = Playback +directory = Playback help = Show progress in taskbar. option = yes option = no @@ -441,7 +436,7 @@ option = no name = keep-open file = mpv default = no -filter = Playback +directory = Playback option = yes If the current file ends, go to the next file, keep the last file open. option = no If the current file ends, go to the next file. If idle is set to no, the player exits after the last file. option = always Playback will never automatically advance to the next file. @@ -449,7 +444,7 @@ option = always Playback will never automatically advance to the next file. name = keep-open-pause file = mpv default = yes -filter = Playback +directory = Playback help = If set to no, instead of pausing when keep-open is active, just stop at end of file and continue playing forward when you seek backwards until end where it stops again. option = yes option = no @@ -457,43 +452,35 @@ option = no name = idle file = mpv default = yes -filter = Playback +directory = Playback help = If set to no and keep-open is also set to no, the player exits after the last file ends. option = yes option = no option = once -name = auto-play -file = mpvnet -default = no -filter = Playback -help = Sets pause=no on file load. (mpv.net specific option) -option = yes -option = no - name = loop-file file = mpv -filter = Playback +directory = Playback help = Loop a single file N times. inf means forever, no means normal playback.\n\nThe difference to loop-playlist is that this doesn't loop the playlist, just the file itself. If the playlist contains only a single file, the difference between the two option is that this option performs a seek on loop, instead of reloading the file. loop is an alias for this option. name = save-position-on-quit file = mpv default = no -filter = Playback +directory = Playback help = Always save the current playback position on quit. When this file is played again later, the player will seek to the old playback position on start. This does not happen if playback of a file is stopped in any other way than quitting. For example, going to the next file in the playlist will not save the position, and start playback at beginning the next time the file is played.\n\nThis behavior is disabled by default, but is always available when quitting the player with Shift+Q. option = yes option = no name = watch-later-options file = mpv -filter = Playback +directory = Playback help = The options that are saved in "watch later" files if they have been changed since when mpv started. These values will be restored the next time the files are played. This is a string list option. For more information visit: url = https://mpv.io/manual/master/#options-watch-later-options name = hr-seek file = mpv default = absolute -filter = Playback +directory = Playback help = Select when to use precise seeks that are not limited to keyframes. Such seeks require decoding video from the previous keyframe up to the target position and so can take some time depending on decoding performance. For some video formats, precise seeks are disabled. This option selects the default choice to use for seeks; it is possible to explicitly override that default in the definition of key bindings and in input commands. option = yes Use precise seeks whenever possible. option = no Never use precise seeks. @@ -503,38 +490,38 @@ option = always Same as yes (for compatibility). name = track-auto-selection file = mpv default = yes -filter = Playback +directory = Playback help = Enable the default track auto-selection. Enabling this will make the player select streams according to aid, alang, and others. If it is disabled, no tracks are selected. In addition, the player will not exit if no tracks are selected, and wait instead (this wait mode is similar to pausing, but the pause option is not set).\n\nThis is useful with lavfi-complex: you can start playback in this mode, and then set select tracks at runtime by setting the filter graph. Note that if lavfi-complex is set before playback is started, the referenced tracks are always selected. option = yes option = no name = loop-playlist file = mpv -filter = Playback +directory = Playback help = Loops playback N times. A value of 1 plays it one time (default), 2 two times, etc. inf means forever. no is the same as 1 and disables looping. If several files are specified on command line, the entire playlist is looped. The force mode is like inf, but does not skip playlist entries which have been marked as failing. This means the player might waste CPU time trying to loop a file that doesn't exist. But it might be useful for playing webradios under very bad network conditions. name = auto-load-folder file = mpvnet default = yes -filter = Playback -help = For single files automatically load the entire directory into the playlist. Can be suppressed via shift key. (mpv.net specific option) +directory = Playback +help = For single files automatically load the entire directory into the playlist. (mpv.net option) option = yes option = no name = input-ar-delay file = mpv -filter = Input +directory = Input help = Delay in milliseconds before we start to autorepeat a key (0 to disable). name = input-ar-rate file = mpv -filter = Input +directory = Input help = Number of key presses to generate per second on autorepeat. name = dark-mode file = mpvnet default = always -filter = UI +directory = UI help = Changes between a light and dark theme.\nmpv.net must be restarted after a change.\nmpv.net specific option. option = always option = system Available on Windows 10 or higher @@ -542,43 +529,27 @@ option = never name = dark-theme file = mpvnet -filter = UI -url = https://github.com/mpvnet-player/mpv.net/blob/master/docs/Manual.md#color-theme +directory = UI +url = https://github.com/mpvnet-player/mpvnet/blob/master/docs/manual.md#color-theme help = Color theme used in dark mode.\nmpv.net must be restarted after a change.\nmpv.net specific option. Default: dark name = light-theme file = mpvnet -filter = UI -url = https://github.com/mpvnet-player/mpv.net/blob/master/docs/Manual.md#color-theme +directory = UI +url = https://github.com/mpvnet-player/mpvnet/blob/master/docs/manual.md#color-theme help = Color theme used in light mode.\nmpv.net must be restarted after a change.\nmpv.net specific option. Default: light -name = show-logo -file = mpvnet -default = yes -filter = UI -help = Draws the blue mpv.net logo ontop of the native OSC logo. -option = yes -option = no - -name = show-santa-logo -file = mpvnet -default = yes -filter = UI -help = Draws the blue mpv.net logo with a santa hat in december, the option is called greenandgrumpy in mpv. -option = yes -option = no - name = screenshot-directory file = mpv width = 500 type = folder -filter = Screenshot +directory = Video/Screenshot help = Store screenshots in this directory. This path is joined with the filename generated by screenshot-template. If the template filename is already absolute, the directory is ignored.\n\nIf the directory does not exist, it is created on the first screenshot. If it is not a directory, an error is generated when trying to write a screenshot. name = screenshot-format file = mpv default = jpg -filter = Screenshot +directory = Video/Screenshot help = Set the image file type used for saving screenshots. option = jpg option = png @@ -586,7 +557,7 @@ option = png name = screenshot-tag-colorspace file = mpv default = no -filter = Screenshot +directory = Video/Screenshot help = Tag screenshots with the appropriate colorspace. Note that not all formats are supported. option = yes option = no @@ -594,7 +565,7 @@ option = no name = screenshot-high-bit-depth file = mpv default = yes -filter = Screenshot +directory = Video/Screenshot help = If possible, write screenshots with a bit depth similar to the source video. This is interesting in particular for PNG, as this sometimes triggers writing 16 bit PNGs with huge file sizes. This will also include an unused alpha channel in the resulting files if 16 bit is used. option = yes option = no @@ -602,37 +573,37 @@ option = no name = screenshot-jpeg-source-chroma file = mpv default = yes -filter = Screenshot +directory = Video/Screenshot help = Write JPEG files with the same chroma subsampling as the video. If disabled, the libjpeg default is used. option = yes option = no name = screenshot-template file = mpv -filter = Screenshot +directory = Video/Screenshot type = string help = Specify the filename template used to save screenshots. The template specifies the filename without file extension, and can contain format specifiers, which will be substituted when taking a screenshot. By default, the template is mpv-shot%n, which results in filenames like mpv-shot0012.png for example.\n\nFind the full documentation here: url = https://mpv.io/manual/master/#options-screenshot-template name = screenshot-jpeg-quality file = mpv -filter = Screenshot +directory = Video/Screenshot help = <0-100> Set the JPEG quality level. Higher means better quality. The default is 90. name = screenshot-png-compression file = mpv -filter = Screenshot +directory = Video/Screenshot help = <0-9> Set the PNG compression level. Higher means better compression. This will affect the file size of the written screenshot file and the time it takes to write a screenshot. Too high compression might occupy enough CPU time to interrupt playback. The default is 7. name = screenshot-png-filter file = mpv -filter = Screenshot +directory = Video/Screenshot help = <0-5> Set the filter applied prior to PNG compression. 0 is none, 1 is 'sub', 2 is 'up', 3 is 'average', 4 is 'Paeth', and 5 is 'mixed'. This affects the level of compression that can be achieved. For most images, 'mixed' achieves the best compression ratio, hence it is the default. name = cache file = mpv default = auto -filter = Cache +directory = Cache help = Decide whether to use network cache settings. url = https://mpv.io/manual/master/#options-cache option = yes @@ -641,6 +612,6 @@ option = auto name = demuxer-max-bytes file = mpv -filter = Demuxer +directory = Demuxer help = Controls how much the demuxer is allowed to buffer ahead.\nSuffixes such as KiB and MiB are supported. url = https://mpv.io/manual/master/#options-demuxer-max-bytes diff --git a/src/Resources/theme.txt b/src/MpvNet.Windows/Resources/theme.txt similarity index 100% rename from src/Resources/theme.txt rename to src/MpvNet.Windows/Resources/theme.txt diff --git a/src/MpvNet.Windows/Settings.cs b/src/MpvNet.Windows/Settings.cs new file mode 100644 index 0000000..e6c4d68 --- /dev/null +++ b/src/MpvNet.Windows/Settings.cs @@ -0,0 +1,61 @@ + +using System.Windows; + +namespace MpvNet.Windows; + +public abstract class Setting +{ + public string? Default { get; set; } + public string? File { get; set; } + public string? Directory { get; set; } + public string? Help { get; set; } + public string? Name { get; set; } + public string? StartValue { get; set; } + public string? Type { get; set; } + public string? URL { get; set; } + public string? Value { get; set; } + + public int Width { get; set; } + + public ConfItem? ConfItem { get; set; } +} + +public class StringSetting : Setting +{ +} + +public class OptionSetting : Setting +{ + public List Options { get; } = new List(); +} + +public class OptionSettingOption +{ + string? _text; + + public string? Name { get; set; } + public string? Help { get; set; } + + public OptionSetting? OptionSetting { get; set; } + + public string? Text + { + get => string.IsNullOrEmpty(_text) ? Name : _text; + set => _text = value; + } + + public bool Checked + { + get => OptionSetting?.Value == Name; + set + { + if (value) + OptionSetting!.Value = Name; + } + } + + public Visibility Visibility + { + get => string.IsNullOrEmpty(Help) ? Visibility.Collapsed : Visibility.Visible; + } +} diff --git a/src/MpvNet.Windows/StringPair.cs b/src/MpvNet.Windows/StringPair.cs new file mode 100644 index 0000000..51989a7 --- /dev/null +++ b/src/MpvNet.Windows/StringPair.cs @@ -0,0 +1,13 @@ +namespace MpvNet.Windows; + +public class StringPair +{ + public string Name { get; set; } + public string Value { get; set; } + + public StringPair(string name, string value) + { + Name = name; + Value = value; + } +} diff --git a/src/MpvNet.Windows/UI/CommandPalette.cs b/src/MpvNet.Windows/UI/CommandPalette.cs new file mode 100644 index 0000000..cd4a3d4 --- /dev/null +++ b/src/MpvNet.Windows/UI/CommandPalette.cs @@ -0,0 +1,22 @@ + +using MpvNet.Windows.WPF.Controls; + +namespace MpvNet.Windows.UI; + +public class CommandPalette +{ + public static CommandPaletteControl Instance { get; } = new CommandPaletteControl(); + + public static IEnumerable GetItems() + { + return InputHelp.GetBindingsFromContent(App.InputConf.GetContent()) + .Where(i => i.Command != "") + .Select(i => new CommandPaletteItem() + { + Text = i.Path, + SecondaryText = i.Input, + Action = () => Core.Command(i.Command), + Binding = i + }); + } +} diff --git a/src/MpvNet.Windows/UI/CommandPaletteItem.cs b/src/MpvNet.Windows/UI/CommandPaletteItem.cs new file mode 100644 index 0000000..f157ee5 --- /dev/null +++ b/src/MpvNet.Windows/UI/CommandPaletteItem.cs @@ -0,0 +1,25 @@ + +namespace MpvNet.Windows.UI; + +public class CommandPaletteItem +{ + public CommandPaletteItem() { } + + public CommandPaletteItem(string text, Action action) + { + Text = text; + Action = action; + } + + public CommandPaletteItem(string text, string secondaryText, Action action) + { + Text = text; + Action = action; + SecondaryText = secondaryText; + } + + public string Text { get; set; } = ""; + public string SecondaryText { get; set; } = ""; + public Action? Action { get; set; } + public Binding? Binding { get; set; } +} diff --git a/src/MpvNet.Windows/UI/GlobalHotkey.cs b/src/MpvNet.Windows/UI/GlobalHotkey.cs new file mode 100644 index 0000000..09e2efe --- /dev/null +++ b/src/MpvNet.Windows/UI/GlobalHotkey.cs @@ -0,0 +1,183 @@ + +using System.ComponentModel; +using System.Runtime.InteropServices; + +using MpvNet.ExtensionMethod; + +namespace MpvNet.Windows.UI; + +class GlobalHotkey +{ + public static Dictionary? Commands { get; set; } + static int ID; + static IntPtr HWND; + + public static void RegisterGlobalHotkeys(IntPtr hwnd) + { + HWND = hwnd; + string path = Player.ConfigFolder + "global-input.conf"; + + if (!File.Exists(path)) + return; + + foreach (string i in File.ReadAllLines(path)) + { + string line = i.Trim(); + + if (line.StartsWith("#") || !line.Contains(' ')) + continue; + + ProcessGlobalHotkeyLine(line); + } + } + + static void ProcessGlobalHotkeyLine(string line) + { + string key = line[..line.IndexOf(" ")]; + string command = line[(line.IndexOf(" ") + 1)..]; + string[] parts = key.Split('+'); + KeyModifiers mod = KeyModifiers.None; + int vk; + + for (int i = 0; i < parts.Length - 1; i++) + { + string umod = parts[i].ToUpper(); + + if (umod == "ALT") mod |= KeyModifiers.Alt; + if (umod == "CTRL") mod |= KeyModifiers.Ctrl; + if (umod == "SHIFT") mod |= KeyModifiers.Shift; + if (umod == "WIN") mod |= KeyModifiers.Win; + } + + key = parts[^1]; + + if (key.Length == 1) + { + short result = VkKeyScanEx(key[0], GetKeyboardLayout(0)); + + int hi = result >> 8; + int lo = result & 0xFF; + + vk = lo; + + if ((hi & 1) == 1) mod |= KeyModifiers.Shift; + if ((hi & 2) == 2) mod |= KeyModifiers.Ctrl; + if ((hi & 4) == 4) mod |= KeyModifiers.Alt; + } + else + vk = Mpv_to_VK(key); + + Commands ??= new Dictionary(); + + if (vk > 0) + { + Commands[ID] = command.Trim(); + bool success = RegisterHotKey(HWND, ID++, mod, vk); + + if (!success) + Terminal.WriteError(line + ": " + new Win32Exception().Message + "\n", "global-input.conf"); + } + } + + public static void Execute(int id) + { + if (Commands!.ContainsKey(id)) + Player.Command(Commands[id]); + } + + static int Mpv_to_VK(string value) + { + return value.ToUpperEx() switch + { + "NEXT" => 0xB0,// VK_MEDIA_NEXT_TRACK + "PREV" => 0xB1,// VK_MEDIA_PREV_TRACK + "STOP" => 0xB2,// VK_MEDIA_STOP + "PLAYPAUSE" => 0xB3,// VK_MEDIA_PLAY_PAUSE + "SLEEP" => 0x5F,// VK_SLEEP + "RIGHT" => 0x27,// VK_RIGHT + "UP" => 0x26,// VK_UP + "LEFT" => 0x25,// VK_LEFT + "DOWN" => 0x28,// VK_DOWN + "PGUP" => 0x21,// VK_PRIOR + "PGDWN" => 0x22,// VK_NEXT + "PAUSE" => 0x13,// VK_PAUSE + "PRINT" => 0x2A,// VK_PRINT + "HOME" => 0x24,// VK_HOME + "INS" => 0x2D,// VK_INSERT + "KP_INS" => 0x2D,// VK_INSERT + "DEL" => 0x2E,// VK_DELETE + "KP_DEL" => 0x2E,// VK_DELETE + "END" => 0x23,// VK_END + "F1" => 0x70,// VK_F1 + "F2" => 0x71,// VK_F2 + "F3" => 0x72,// VK_F3 + "F4" => 0x73,// VK_F4 + "F5" => 0x74,// VK_F5 + "F6" => 0x75,// VK_F6 + "F7" => 0x76,// VK_F7 + "F8" => 0x77,// VK_F8 + "F9" => 0x78,// VK_F9 + "F10" => 0x79,// VK_F10 + "F11" => 0x7A,// VK_F11 + "F12" => 0x7B,// VK_F12 + "F13" => 0x7C,// VK_F13 + "F14" => 0x7D,// VK_F14 + "F15" => 0x7E,// VK_F15 + "F16" => 0x7F,// VK_F16 + "F17" => 0x80,// VK_F17 + "F18" => 0x81,// VK_F18 + "F19" => 0x82,// VK_F19 + "F20" => 0x83,// VK_F20 + "F21" => 0x84,// VK_F21 + "F22" => 0x85,// VK_F22 + "F23" => 0x86,// VK_F23 + "F24" => 0x87,// VK_F24 + "ENTER" => 0x0D,// VK_RETURN + "KP_ENTER" => 0x0D,// VK_RETURN + "TAB" => 0x09,// VK_TAB + "MENU" => 0x5D,// VK_APPS + "CANCEL" => 0x03,// VK_CANCEL + "BS" => 0x08,// VK_BACK + "KP_DEC" => 0x6E,// VK_DECIMAL + "ESC" => 0x1B,// VK_ESCAPE + "KP0" => 0x60,// VK_NUMPAD0 + "KP1" => 0x61,// VK_NUMPAD1 + "KP2" => 0x62,// VK_NUMPAD2 + "KP3" => 0x63,// VK_NUMPAD3 + "KP4" => 0x64,// VK_NUMPAD4 + "KP5" => 0x65,// VK_NUMPAD5 + "KP6" => 0x66,// VK_NUMPAD6 + "KP7" => 0x67,// VK_NUMPAD7 + "KP8" => 0x68,// VK_NUMPAD8 + "KP9" => 0x69,// VK_NUMPAD9 + "FAVORITES" => 0xAB,// VK_BROWSER_FAVORITES + "SEARCH" => 0xAA,// VK_BROWSER_SEARCH + "MAIL" => 0xB4,// VK_LAUNCH_MAIL + "VOLUME_UP" => 0xAF,// VK_VOLUME_UP + "VOLUME_DOWN" => 0xAE,// VK_VOLUME_DOWN + "MUTE" => 0xAD,// VK_VOLUME_MUTE + "SPACE" => 0x20,// VK_SPACE + "IDEOGRAPHIC_SPACE" => 0x20,// VK_SPACE + _ => 0, + }; + } + + [DllImport("user32.dll", CharSet = CharSet.Unicode)] + static extern short VkKeyScanEx(char ch, IntPtr dwhkl); + + [DllImport("user32.dll")] + static extern IntPtr GetKeyboardLayout(uint idThread); + + [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, int vk); + + [Flags] + enum KeyModifiers + { + None = 0, + Alt = 1, + Ctrl = 2, + Shift = 4, + Win = 8 + } +} diff --git a/src/MpvNet.Windows/UI/Theme.cs b/src/MpvNet.Windows/UI/Theme.cs new file mode 100644 index 0000000..97f42df --- /dev/null +++ b/src/MpvNet.Windows/UI/Theme.cs @@ -0,0 +1,141 @@ + +using System.Windows; +using System.Windows.Media; + +using Microsoft.Win32; + +namespace MpvNet.Windows.UI; + +public class Theme +{ + public string? Name { get; set; } + public Dictionary Dictionary { get; } = new Dictionary(); + + public static List? DefaultThemes { get; set; } + public static List? CustomThemes { get; set; } + + public static Theme? Current { get; set; } + + public Brush? Background { get; set; } + public Brush? Foreground { get; set; } + public Brush? Foreground2 { get; set; } + public Brush? Heading { get; set; } + public Brush? MenuBackground { get; set; } + public Brush? MenuHighlight { get; set; } + + public Brush GetBrush(string key) + { + return new SolidColorBrush((Color)ColorConverter.ConvertFromString(Dictionary[key])); + } + + public Color GetColor(string key) => (Color)ColorConverter.ConvertFromString(Dictionary[key]); + + public static void Init() + { + string? themeContent = null; + + if (File.Exists(Player.ConfigFolder + "theme.conf")) + themeContent = File.ReadAllText(Player.ConfigFolder + "theme.conf"); + + Init(themeContent, Properties.Resources.theme, DarkMode ? App.DarkTheme : App.LightTheme); + } + + public static void Init(string? customContent, string defaultContent, string activeTheme) + { + Current = null; + + DefaultThemes = Load(defaultContent); + CustomThemes = Load(customContent); + + foreach (Theme theme in CustomThemes) + { + if (theme.Name == activeTheme) + { + bool isKeyMissing = false; + + foreach (string key in DefaultThemes[0].Dictionary.Keys) + { + if (!theme.Dictionary.ContainsKey(key)) + { + isKeyMissing = true; + Terminal.WriteError($"Theme '{activeTheme}' misses '{key}'"); + break; + } + } + + if (!isKeyMissing) + Current = theme; + + break; + } + } + + if (Current == null) + foreach (Theme theme in DefaultThemes) + if (theme.Name == activeTheme) + Current = theme; + + if (Current == null) + Current = DefaultThemes[0]; + + Current.Background = Current.GetBrush("background"); + Current.Foreground = Current.GetBrush("foreground"); + Current.Foreground2 = Current.GetBrush("foreground2"); + Current.Heading = Current.GetBrush("heading"); + Current.MenuBackground = Current.GetBrush("menu-background"); + Current.MenuHighlight = Current.GetBrush("menu-highlight"); + } + + static List Load(string? content) + { + List list = new List(); + Theme? theme = null; + + foreach (string currentLine in (content ?? "").Split(new[] { '\r', '\n' })) + { + string line = currentLine.Trim(); + + if (line.StartsWith("[") && line.EndsWith("]")) + list.Add(theme = new Theme() { Name = line.Substring(1, line.Length - 2).Trim() }); + + if (line.Contains('=') && theme != null) + { + string left = line[..line.IndexOf("=")].Trim(); + theme.Dictionary[left] = line[(line.IndexOf("=") + 1)..].Trim(); + } + } + + return list; + } + + public static void UpdateWpfColors() + { + var dic = Application.Current.Resources; + + dic.Remove("BorderColor"); + dic.Add("BorderColor", Current!.GetColor("menu-highlight")); + + dic.Remove("RegionColor"); + dic.Add("RegionColor", Current.GetColor("menu-background")); + + dic.Remove("SecondaryRegionColor"); + dic.Add("SecondaryRegionColor", Current.GetColor("menu-highlight")); + + dic.Remove("PrimaryTextColor"); + dic.Add("PrimaryTextColor", Current.GetColor("menu-foreground")); + + dic.Remove("HighlightColor"); + dic.Add("HighlightColor", Current.GetColor("highlight")); + } + + static bool DarkModeSystem + { + get + { + string key = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; + return (int)(Registry.GetValue(key, "AppsUseLightTheme", 1) ?? 1) == 0; + } + } + + public static bool DarkMode => App.DarkMode == "system" && DarkModeSystem || App.DarkMode == "always"; +} diff --git a/src/MpvNet.Windows/UI/TreeNode.cs b/src/MpvNet.Windows/UI/TreeNode.cs new file mode 100644 index 0000000..7eb1b83 --- /dev/null +++ b/src/MpvNet.Windows/UI/TreeNode.cs @@ -0,0 +1,11 @@ + +namespace MpvNet.Windows.UI; + +public class TreeNode +{ + readonly List _children = new List(); + + public IList Children => _children; + + public string Name { get; set; } = ""; +} diff --git a/src/MpvNet.Windows/WPF/BindingProxy.cs b/src/MpvNet.Windows/WPF/BindingProxy.cs new file mode 100644 index 0000000..4cd313a --- /dev/null +++ b/src/MpvNet.Windows/WPF/BindingProxy.cs @@ -0,0 +1,20 @@ + +using System.Windows; + +namespace MpvNet.Windows.WPF; + +public class BindingProxy : Freezable +{ + protected override Freezable CreateInstanceCore() => new BindingProxy(); + + public object Data + { + get { return GetValue(DataProperty); } + set { SetValue(DataProperty, value); } + } + + // Using a DependencyProperty as the backing store for Data. + // This enables animation, styling, binding, etc... + public static readonly DependencyProperty DataProperty = + DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null)); +} diff --git a/src/MpvNet.Windows/WPF/ConfWindow.xaml b/src/MpvNet.Windows/WPF/ConfWindow.xaml new file mode 100644 index 0000000..451f01f --- /dev/null +++ b/src/MpvNet.Windows/WPF/ConfWindow.xaml @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs b/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs new file mode 100644 index 0000000..95aa219 --- /dev/null +++ b/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs @@ -0,0 +1,482 @@ + +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Threading; + +using CommunityToolkit.Mvvm.Input; + +using MpvNet.Help; +using MpvNet.Windows.UI; +using MpvNet.Windows.WPF.Controls; +using MpvNet.Windows.WPF.ViewModels; + +namespace MpvNet.Windows.WPF; + +public partial class ConfWindow : Window, INotifyPropertyChanged +{ + List Settings = Conf.LoadConf(Properties.Resources.editor_conf.TrimEnd()); + List ConfItems = new List(); + public ObservableCollection FilterStrings { get; } = new(); + string InitialContent; + string ThemeConf = GetThemeConf(); + string? _searchText; + List? _nodes; + public event PropertyChangedEventHandler? PropertyChanged; + + public ConfWindow() + { + InitializeComponent(); + DataContext = this; + LoadConf(Player.ConfPath); + LoadConf(App.ConfPath); + LoadSettings(); + InitialContent = GetCompareString(); + + if (string.IsNullOrEmpty(App.Settings.ConfigEditorSearch)) + SearchControl.Text = "General:"; + else + SearchControl.Text = App.Settings.ConfigEditorSearch; + + foreach (var node in Nodes) + SelectNodeFromSearchText(node); + + foreach (var node in Nodes) + ExpandNode(node); + } + + public Theme? Theme => Theme.Current; + + public string SearchText + { + get => _searchText ?? ""; + set + { + _searchText = value; + SearchTextChanged(); + OnPropertyChanged(); + } + } + + public List Nodes + { + get + { + if (_nodes == null) + { + var rootNode = new TreeNode(); + + foreach (Setting setting in Settings) + AddNode(rootNode.Children, setting.Directory!); + + _nodes = new NodeViewModel(rootNode).Children; + } + + return _nodes; + } + } + + public static TreeNode? AddNode(IList nodes, string path) + { + string[] parts = path.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries); + + for (int x = 0; x < parts.Length; x++) + { + bool found = false; + + foreach (var node in nodes) + { + if (x < parts.Length - 1) + { + if (node.Name == parts[x]) + { + found = true; + nodes = node.Children; + } + } + else if (x == parts.Length - 1 && node.Name == parts[x]) + { + found = true; + } + } + + if (!found) + { + if (x == parts.Length - 1) + { + var item = new TreeNode() { Name = parts[x] }; + nodes?.Add(item); + return item; + } + } + } + + return null; + } + + void LoadSettings() + { + foreach (Setting setting in Settings) + { + setting.StartValue = setting.Value; + + if (!FilterStrings.Contains(setting.Directory!)) + FilterStrings.Add(setting.Directory!); + + foreach (ConfItem confItem in ConfItems) + { + if (setting.Name == confItem.Name && confItem.Section == "" && !confItem.IsSectionItem) + { + setting.Value = confItem.Value.Trim('\'', '"'); + setting.StartValue = setting.Value; + setting.ConfItem = confItem; + confItem.SettingBase = setting; + } + } + + switch (setting) + { + case StringSetting s: + MainStackPanel.Children.Add(new StringSettingControl(s) { Visibility = Visibility.Collapsed }); + break; + case OptionSetting s: + MainStackPanel.Children.Add(new OptionSettingControl(s) { Visibility = Visibility.Collapsed }); + break; + } + } + } + + static string GetThemeConf() => Theme.DarkMode + App.DarkTheme + App.LightTheme; + + protected override void OnClosed(EventArgs e) + { + base.OnClosed(e); + App.Settings.ConfigEditorSearch = SearchControl.Text; + + if (InitialContent == GetCompareString()) + return; + + File.WriteAllText(Player.ConfPath, GetContent("mpv")); + File.WriteAllText(App.ConfPath, GetContent("mpvnet")); + + foreach (Setting it in Settings) + { + if (it.Value != it.StartValue) + { + if (it.File == "mpv") + { + Player.ProcessProperty(it.Name, it.Value); + Player.SetPropertyString(it.Name!, it.Value!); + } + else if (it.File == "mpvnet") + App.ProcessProperty(it.Name ?? "", it.Value ?? "", true); + } + } + + Theme.Init(); + Theme.UpdateWpfColors(); + + if (ThemeConf != GetThemeConf()) + MessageBox.Show("Changed theme settings require mpv.net being restarted.", "Info"); + } + + bool _shown; + + protected override void OnContentRendered(EventArgs e) + { + base.OnContentRendered(e); + + if (_shown) + return; + + _shown = true; + + Application.Current.Dispatcher.BeginInvoke(() => { + SearchControl.SearchTextBox.SelectAll(); + }, + DispatcherPriority.Background); + } + + string GetCompareString() + { + return string.Join("", Settings.Select(item => item.Name + item.Value).ToArray()); + } + + void LoadConf(string file) + { + if (!File.Exists(file)) + return; + + string comment = ""; + string section = ""; + + bool isSectionItem = false; + + foreach (string currentLine in File.ReadAllLines(file)) + { + string line = currentLine.Trim(); + + if (line == "") + { + comment += "\r\n"; + } + else if (line.StartsWith("#")) + { + comment += line.Trim() + "\r\n"; + } + else if (line.StartsWith("[") && line.Contains("]")) + { + if (!isSectionItem && comment != "" && comment != "\r\n") + ConfItems.Add(new ConfItem() { + Comment = comment, File = Path.GetFileNameWithoutExtension(file)}); + + section = line.Substring(0, line.IndexOf("]") + 1); + comment = ""; + isSectionItem = true; + } + else if (line.Contains("=")) + { + ConfItem item = new ConfItem(); + item.File = Path.GetFileNameWithoutExtension(file); + item.IsSectionItem = isSectionItem; + item.Comment = comment; + comment = ""; + item.Section = section; + section = ""; + + if (line.Contains("#") && !line.Contains("'") && !line.Contains("\"")) + { + item.LineComment = line.Substring(line.IndexOf("#")).Trim(); + line = line.Substring(0, line.IndexOf("#")).Trim(); + } + + int pos = line.IndexOf("="); + string left = line.Substring(0, pos).Trim().ToLower(); + string right = line.Substring(pos + 1).Trim(); + + if (left == "fs") + left = "fullscreen"; + + if (left == "loop") + left = "loop-file"; + + item.Name = left; + item.Value = right; + ConfItems.Add(item); + } + } + } + + string GetContent(string filename) + { + StringBuilder sb = new StringBuilder(); + List namesWritten = new List(); + + foreach (ConfItem item in ConfItems) + { + if (filename != item.File || item.Section != "" || item.IsSectionItem) + continue; + + if (item.Comment != "") + sb.Append(item.Comment); + + if (item.SettingBase == null) + { + if (item.Name != "") + { + sb.Append(item.Name + " = " + item.Value); + + if (item.LineComment != "") + sb.Append(" " + item.LineComment); + + sb.AppendLine(); + namesWritten.Add(item.Name); + } + } + else if ((item.SettingBase.Value ?? "") != item.SettingBase.Default) + { + string? value; + + if (item.SettingBase.Type == "string" || + item.SettingBase.Type == "folder" || + item.SettingBase.Type == "color") + + value = "'" + item.SettingBase.Value + "'"; + else + value = item.SettingBase.Value; + + sb.Append(item.Name + " = " + value); + + if (item.LineComment != "") + sb.Append(" " + item.LineComment); + + sb.AppendLine(); + namesWritten.Add(item.Name); + } + } + + if (!sb.ToString().Contains("# Editor")) + sb.AppendLine("# Editor"); + + foreach (Setting setting in Settings) + { + if (filename != setting.File || namesWritten.Contains(setting.Name!)) + continue; + + if ((setting.Value ?? "") != setting.Default) + { + string? value; + + if (setting.Type == "string" || + setting.Type == "folder" || + setting.Type == "color") + + value = "'" + setting.Value + "'"; + else + value = setting.Value; + + sb.AppendLine(setting.Name + " = " + value); + } + } + + foreach (ConfItem item in ConfItems) + { + if (filename != item.File || (item.Section == "" && !item.IsSectionItem)) + continue; + + if (item.Section != "") + { + if (!sb.ToString().EndsWith("\r\n\r\n")) + sb.AppendLine(); + + sb.AppendLine(item.Section); + } + + if (item.Comment != "") + sb.Append(item.Comment); + + sb.Append(item.Name + " = " + item.Value); + + if (item.LineComment != "") + sb.Append(" " + item.LineComment); + + sb.AppendLine(); + namesWritten.Add(item.Name); + } + + return "\r\n" + sb.ToString().Trim() + "\r\n"; + } + + void SearchTextChanged() + { + string activeFilter = ""; + + foreach (string i in FilterStrings) + if (SearchText == i + ":") + activeFilter = i; + + if (activeFilter == "") + { + foreach (UIElement i in MainStackPanel.Children) + if ((i as ISettingControl)!.Contains(SearchText) && SearchText.Length > 1) + i.Visibility = Visibility.Visible; + else + i.Visibility = Visibility.Collapsed; + + foreach (var node in Nodes) + UnselectNode(node); + } + else + foreach (UIElement i in MainStackPanel.Children) + if ((i as ISettingControl)!.Setting.Directory == activeFilter) + i.Visibility = Visibility.Visible; + else + i.Visibility = Visibility.Collapsed; + + MainScrollViewer.ScrollToTop(); + } + + void ConfWindow1_Loaded(object sender, RoutedEventArgs e) + { + SearchControl.SearchTextBox.SelectAll(); + Keyboard.Focus(SearchControl.SearchTextBox); + + foreach (var i in MainStackPanel.Children.OfType()) + i.Update(); + } + + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + + if (e.Key == Key.Escape) + Close(); + + if (e.Key == Key.F3 || e.Key == Key.F6 || (e.Key == Key.F && Keyboard.IsKeyDown(Key.LeftCtrl))) + { + Keyboard.Focus(SearchControl.SearchTextBox); + SearchControl.SearchTextBox.SelectAll(); + } + } + + protected void OnPropertyChanged([CallerMemberName] string? name = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + + void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) + { + var node = TreeView.SelectedItem as NodeViewModel; + + if (node == null) + return; + + Application.Current.Dispatcher.BeginInvoke(() => { + SearchText = node!.Path + ":"; + }, + DispatcherPriority.Background); + } + + void SelectNodeFromSearchText(NodeViewModel node) + { + if (node.Path + ":" == SearchControl.Text) + { + node.IsSelected = true; + return; + } + + foreach (var it in node.Children) + SelectNodeFromSearchText(it); + } + + void UnselectNode(NodeViewModel node) + { + if (node.IsSelected) + node.IsSelected = false; + + foreach (var it in node.Children) + SelectNodeFromSearchText(it); + } + + void ExpandNode(NodeViewModel node) + { + node.IsExpanded = true; + + foreach (var it in node.Children) + SelectNodeFromSearchText(it); + } + + [RelayCommand] void ShowMpvNetSpecificSettings() => SearchControl.Text = "mpv.net"; + + [RelayCommand] void PreviewMpvConfFile() => Msg.ShowInfo(GetContent("mpv")); + + [RelayCommand] void PreviewMpvNetConfFile() => Msg.ShowInfo(GetContent("mpvnet")); + + [RelayCommand] void ShowMpvManual() => ProcessHelp.ShellExecute("https://mpv.io/manual/master/"); + + [RelayCommand] void ShowMpvNetManual() => ProcessHelp.ShellExecute("https://github.com/mpvnet-player/mpv.net/blob/master/docs/manual.md"); +} diff --git a/src/WPF/CommandPaletteControl.xaml b/src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml similarity index 97% rename from src/WPF/CommandPaletteControl.xaml rename to src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml index c67b348..e989a8d 100644 --- a/src/WPF/CommandPaletteControl.xaml +++ b/src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml @@ -1,10 +1,10 @@  - - Items { get; } = new ObservableCollection(); + + public CommandPaletteControl() + { + InitializeComponent(); + DataContext = this; + CollectionViewSource = new CollectionViewSource() { Source = Items }; + CollectionView = CollectionViewSource.View; + CollectionView.Filter = new Predicate(item => Filter((CommandPaletteItem)item)); + MainListView.ItemsSource = CollectionView; + + SearchControl.SearchTextBox.PreviewKeyDown += SearchTextBox_PreviewKeyDown; + SearchControl.SearchTextBox.TextChanged += SearchTextBox_TextChanged; + SearchControl.HideClearButton = true; + + if (Environment.OSVersion.Version < new Version(10, 0)) + MainBorder.CornerRadius = new CornerRadius(0); + } + + void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e) + { + CollectionView.Refresh(); + SelectFirst(); + } + + void SearchTextBox_PreviewKeyDown(object sender, KeyEventArgs e) + { + switch (e.Key) + { + case Key.Up: + { + int index = MainListView.SelectedIndex; + index -= 1; + + if (index < 0) + index = 0; + + MainListView.SelectedIndex = index; + MainListView.ScrollIntoView(MainListView.SelectedItem); + } + break; + case Key.Down: + { + int index = MainListView.SelectedIndex; + + if (++index > MainListView.Items.Count - 1) + index = MainListView.Items.Count - 1; + + MainListView.SelectedIndex = index; + MainListView.ScrollIntoView(MainListView.SelectedItem); + } + break; + } + } + + void MainListView_SizeChanged(object sender, SizeChangedEventArgs e) => AdjustHeight(); + + void MainListView_MouseUp(object sender, MouseButtonEventArgs e) => ExecuteInternal(); + + [RelayCommand] + void Escape(object param) => MainForm.Instance?.HideCommandPalette(); + + [RelayCommand] + void Execute() => ExecuteInternal(); + + void OnLoaded(object sender, RoutedEventArgs e) => Keyboard.Focus(SearchControl.SearchTextBox); + + public Theme Theme => Theme.Current!; + + bool Filter(CommandPaletteItem item) + { + string filter = SearchControl.SearchTextBox.Text.ToLower(); + + if (item.Binding != null) + { + // TODO: CommandItem.Alias + //if (item.CommandItem.Alias.ContainsEx(filter)) + // return true; + + if (filter.Length == 1) + return item.Binding.Input.ToLower() + .Replace("ctrl+", "") + .Replace("shift+", "") + .Replace("alt+", "") == filter.ToLower(); + + if (item.Binding.Command.ToLower().Contains(filter)) + return true; + } + + if (filter == "" || item.Text.ToLower().Contains(filter) || + item.SecondaryText.ToLower().Contains(filter)) + + return true; + + return false; + } + + public void SelectFirst() + { + if (MainListView.Items.Count > 0) + { + MainListView.SelectedIndex = 0; + MainListView.ScrollIntoView(MainListView.SelectedItem); + } + } + + void ExecuteInternal() + { + if (MainListView.SelectedItem != null) + { + CommandPaletteItem? item = MainListView.SelectedItem as CommandPaletteItem; + MainForm.Instance?.HideCommandPalette(); + item?.Action?.Invoke(); + //MainForm.Instance.Voodoo(); //TODO: Voodoo + } + } + + public void SetItems(IEnumerable items) + { + Items.Clear(); + + foreach (var i in items) + Items.Add(i); + } + + public void AdjustHeight() + { + double actualHeight = SearchControl.ActualHeight + MainListView.ActualHeight + 5 + 16; + int dpi = MainForm.GetDpi(MainForm.Instance!.Handle); + MainForm.Instance.CommandPaletteHost.Height = (int)(actualHeight / 96.0 * dpi); + } +} diff --git a/src/MpvNet.Windows/WPF/Controls/HyperlinkEx.cs b/src/MpvNet.Windows/WPF/Controls/HyperlinkEx.cs new file mode 100644 index 0000000..df6ce2a --- /dev/null +++ b/src/MpvNet.Windows/WPF/Controls/HyperlinkEx.cs @@ -0,0 +1,27 @@ + +using System.Windows.Documents; +using System.Windows.Navigation; + +using MpvNet.Help; + +// TODO: change namespace to MpvNet.Windows.WPF.Controls +namespace MpvNet.Windows.WPF; + +public class HyperlinkEx : Hyperlink +{ + void HyperLinkEx_RequestNavigate(object sender, RequestNavigateEventArgs e) + { + ProcessHelp.ShellExecute(e.Uri.AbsoluteUri); + } + + public void SetURL(string? url) + { + if (string.IsNullOrEmpty(url)) + return; + + NavigateUri = new Uri(url); + RequestNavigate += HyperLinkEx_RequestNavigate; + Inlines.Clear(); + Inlines.Add(url); + } +} diff --git a/src/WPF/OptionSettingControl.xaml b/src/MpvNet.Windows/WPF/Controls/OptionSettingControl.xaml similarity index 95% rename from src/WPF/OptionSettingControl.xaml rename to src/MpvNet.Windows/WPF/Controls/OptionSettingControl.xaml index c57373f..310d958 100644 --- a/src/WPF/OptionSettingControl.xaml +++ b/src/MpvNet.Windows/WPF/Controls/OptionSettingControl.xaml @@ -1,10 +1,11 @@  Theme.Current; + + public Setting Setting => OptionSetting; + + public bool Contains(string searchString) => ContainsInternal(searchString.ToLower()); + + public bool ContainsInternal(string search) + { + if (TitleTextBox.Text.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) > -1) + return true; + + if (HelpTextBox.Text.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) > -1) + return true; + + foreach (var i in OptionSetting.Options) + { + if (i.Text?.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) > -1) + return true; + + if (i.Help?.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) > -1) + return true; + + if (i.Name?.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) > -1) + return true; + } + + return false; + } +} diff --git a/src/WPF/SearchTextBoxUserControl.xaml b/src/MpvNet.Windows/WPF/Controls/SearchControl.xaml similarity index 82% rename from src/WPF/SearchTextBoxUserControl.xaml rename to src/MpvNet.Windows/WPF/Controls/SearchControl.xaml index 15f933f..5da5b14 100644 --- a/src/WPF/SearchTextBoxUserControl.xaml +++ b/src/MpvNet.Windows/WPF/Controls/SearchControl.xaml @@ -1,18 +1,16 @@  - +