From 8430842679f929f949c58c73e3cc58d70d3bc1fa Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sat, 27 Jul 2019 01:17:25 +0200 Subject: [PATCH] misc --- Changelog.md | 10 +- README.md | 11 +- .../CSScriptExtension/CSScriptExtension.vb | 40 ----- .../CSScriptExtension.vbproj | 144 ------------------ .../My Project/Application.Designer.vb | 13 -- .../My Project/Application.myapp | 10 -- .../My Project/AssemblyInfo.vb | 35 ----- .../My Project/Resources.Designer.vb | 63 -------- .../My Project/Resources.resx | 117 -------------- .../My Project/Settings.Designer.vb | 73 --------- .../My Project/Settings.settings | 7 - .../CSScriptLibrary.dll | Bin .../Properties/AssemblyInfo.cs | 36 +++++ .../ScriptingExtension/ScriptingExtension.cs | 47 ++++++ .../ScriptingExtension.csproj | 80 ++++++++++ .../ScriptingExtension/ScriptingExtension.sln | 31 ++++ extensions/ScriptingExtension/script.cs | 40 +++++ mpv.net.sln | 24 +-- mpv.net/Misc/Command.cs | 2 +- mpv.net/Misc/Misc.cs | 19 ++- mpv.net/Misc/Program.cs | 4 +- mpv.net/WinForms/MainForm.cs | 5 +- mpv.net/mpv/mp.cs | 14 +- 23 files changed, 283 insertions(+), 542 deletions(-) delete mode 100644 extensions/CSScriptExtension/CSScriptExtension.vb delete mode 100644 extensions/CSScriptExtension/CSScriptExtension.vbproj delete mode 100644 extensions/CSScriptExtension/My Project/Application.Designer.vb delete mode 100644 extensions/CSScriptExtension/My Project/Application.myapp delete mode 100644 extensions/CSScriptExtension/My Project/AssemblyInfo.vb delete mode 100644 extensions/CSScriptExtension/My Project/Resources.Designer.vb delete mode 100644 extensions/CSScriptExtension/My Project/Resources.resx delete mode 100644 extensions/CSScriptExtension/My Project/Settings.Designer.vb delete mode 100644 extensions/CSScriptExtension/My Project/Settings.settings rename extensions/{CSScriptExtension => ScriptingExtension}/CSScriptLibrary.dll (100%) create mode 100644 extensions/ScriptingExtension/Properties/AssemblyInfo.cs create mode 100644 extensions/ScriptingExtension/ScriptingExtension.cs create mode 100644 extensions/ScriptingExtension/ScriptingExtension.csproj create mode 100644 extensions/ScriptingExtension/ScriptingExtension.sln create mode 100644 extensions/ScriptingExtension/script.cs diff --git a/Changelog.md b/Changelog.md index 4792d2c..e845205 100644 --- a/Changelog.md +++ b/Changelog.md @@ -17,8 +17,14 @@ to fail if it was waiting for a drive to wakeup - a new JavaScript was included to show the playlist with a smaller font size, the script is located at startup/scripts -- terminal support added via mpvnet.com, reading input keys from stdin - is not supported +- terminal support added via mpvnet.com, this brings mpv.net to a new level :-) +- script engine performence and error handling was improved +- the [scripting wiki page](https://github.com/stax76/mpv.net/wiki/Scripting) was improved +- the C# scripting host extension was converted from VB to C# because it's not + only used for hosting but I also use it now to code and debug script code +- there was a copy paste bug in the file association feature resulting in keys + from mpv being overwritten instead of using mpv.net keys. Thanks to floppyD! +- there was a exception fixed that happened opening rar files ### 4.7.7 diff --git a/README.md b/README.md index 8fae51d..0c7e497 100644 --- a/README.md +++ b/README.md @@ -136,18 +136,15 @@ input.conf defines mpv's key and mouse bindings and mpv.net uses comments to def ### Settings -mpv.net is able to share the settings with mpv. +When mpv.net finds no config folder on startup it will ask for a location. -If a directory named portable_config next to the mpvnet.exe exists, -all config will be loaded from this directory only. +If a folder named portable_config next to the mpvnet.exe exists, +all config will be loaded from this folder only. ```Text \portable_config\ ``` -On first start if no portable config folder exists mpv.net asks -which folder should be used as config folder. - mpv specific settings are stored in the file mpv.conf, if no mpv.conf file exists mpv.net generates it with the following defaults: @@ -163,6 +160,8 @@ input.conf file, if it's missing mpv.net generates it with the following default mpv.net supports almost all mpv settings and features, [limitations are listed in the wiki](https://github.com/stax76/mpv.net/wiki/Limitations). +The config folder can be opened from the context menu. + ### Scripting [Scripting wiki page](https://github.com/stax76/mpv.net/wiki/Scripting) diff --git a/extensions/CSScriptExtension/CSScriptExtension.vb b/extensions/CSScriptExtension/CSScriptExtension.vb deleted file mode 100644 index ec91cab..0000000 --- a/extensions/CSScriptExtension/CSScriptExtension.vb +++ /dev/null @@ -1,40 +0,0 @@ -'this extension implements the C# scripting feature of mpv.net, -'it is based on CS-Script: https://www.cs-script.net/ - -' the assembly/dll name of extensions must end with 'Extension' - -Imports System.ComponentModel.Composition -Imports System.IO -Imports System.Windows.Forms - -Imports mpvnet - -Imports CSScriptLibrary - - -Public Class CSScriptExtension - Implements IExtension - - Sub New() - Dim scriptFiles As New List(Of String) - - If Directory.Exists(mp.ConfigFolder + "scripts") Then - scriptFiles.AddRange(Directory.GetFiles(mp.ConfigFolder + "scripts", "*.cs")) - End If - - If Directory.Exists(Application.StartupPath + "\scripts") Then - scriptFiles.AddRange(Directory.GetFiles(Application.StartupPath + "\scripts", "*.cs")) - End If - - If scriptFiles.Count = 0 Then Return - CSScriptLibrary.CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom - - For Each i In scriptFiles - Try - CSScriptLibrary.CSScript.Evaluator.LoadCode(File.ReadAllText(i)) - Catch ex As Exception - Msg.ShowException(ex) - End Try - Next - End Sub -End Class \ No newline at end of file diff --git a/extensions/CSScriptExtension/CSScriptExtension.vbproj b/extensions/CSScriptExtension/CSScriptExtension.vbproj deleted file mode 100644 index 1dffdb7..0000000 --- a/extensions/CSScriptExtension/CSScriptExtension.vbproj +++ /dev/null @@ -1,144 +0,0 @@ - - - - - Debug - AnyCPU - {71808A87-8B1C-4DF8-957C-D79C3B164CCA} - Library - CSScriptExtension - CSScriptExtension - 512 - Windows - v4.7.2 - - - - On - - - Binary - - - On - - - On - - - true - true - true - ..\..\mpv.net\bin\x86\Extensions\CSScriptExtension\ - 42105,42106,42107,42353,42354,42355 - full - x86 - 41999,42016,42017,42018,42019,42020,42021,42022,42032,42036 - MinimumRecommendedRules.ruleset - - - true - ..\..\mpv.net\bin\x86\Extensions\CSScriptExtension\ - true - 42105,42106,42107,42353,42354,42355 - pdbonly - x86 - 41999,42016,42017,42018,42019,42020,42021,42022,42032,42036 - MinimumRecommendedRules.ruleset - - - true - true - true - ..\..\mpv.net\bin\x64\Extensions\CSScriptExtension\ - 42105,42106,42107,42353,42354,42355 - full - x64 - 41999,42016,42017,42018,42019,42020,42021,42022,42032,42036 - MinimumRecommendedRules.ruleset - - - true - ..\..\mpv.net\bin\x64\Extensions\CSScriptExtension\ - true - 42105,42106,42107,42353,42354,42355 - pdbonly - x64 - 41999,42016,42017,42018,42019,42020,42021,42022,42032,42036 - MinimumRecommendedRules.ruleset - - - - False - .\CSScriptLibrary.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - True - Application.myapp - - - True - True - Resources.resx - - - True - Settings.settings - True - - - - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources - Designer - - - - - MyApplicationCodeGenerator - Application.Designer.vb - - - SettingsSingleFileGenerator - My - Settings.Designer.vb - - - - - - - - {1751f378-8edf-4b62-be6d-304c7c287089} - mpv.net - False - - - - \ No newline at end of file diff --git a/extensions/CSScriptExtension/My Project/Application.Designer.vb b/extensions/CSScriptExtension/My Project/Application.Designer.vb deleted file mode 100644 index 88dd01c..0000000 --- a/extensions/CSScriptExtension/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/extensions/CSScriptExtension/My Project/Application.myapp b/extensions/CSScriptExtension/My Project/Application.myapp deleted file mode 100644 index 758895d..0000000 --- a/extensions/CSScriptExtension/My Project/Application.myapp +++ /dev/null @@ -1,10 +0,0 @@ - - - false - false - 0 - true - 0 - 1 - true - diff --git a/extensions/CSScriptExtension/My Project/AssemblyInfo.vb b/extensions/CSScriptExtension/My Project/AssemblyInfo.vb deleted file mode 100644 index 36c2ec7..0000000 --- a/extensions/CSScriptExtension/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports 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. - -' Review the values of the assembly attributes - - - - - - - - - - -'The following GUID is for the ID of the typelib if this project is exposed to COM - - -' 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: -' - - - diff --git a/extensions/CSScriptExtension/My Project/Resources.Designer.vb b/extensions/CSScriptExtension/My Project/Resources.Designer.vb deleted file mode 100644 index 48b0033..0000000 --- a/extensions/CSScriptExtension/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'This class was auto-generated by the StronglyTypedResourceBuilder - 'class via a tool like ResGen or Visual Studio. - 'To add or remove a member, edit your .ResX file then rerun ResGen - 'with the /str option, or rebuild your VS project. - ''' - ''' A strongly-typed resource class, for looking up localized strings, etc. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Returns the cached ResourceManager instance used by this class. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("CSScriptExtension.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Overrides the current thread's CurrentUICulture property for all - ''' resource lookups using this strongly typed resource class. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/extensions/CSScriptExtension/My Project/Resources.resx b/extensions/CSScriptExtension/My Project/Resources.resx deleted file mode 100644 index af7dbeb..0000000 --- a/extensions/CSScriptExtension/My Project/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/extensions/CSScriptExtension/My Project/Settings.Designer.vb b/extensions/CSScriptExtension/My Project/Settings.Designer.vb deleted file mode 100644 index 202298f..0000000 --- a/extensions/CSScriptExtension/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "My.Settings Auto-Save Functionality" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.CSScriptExtension.My.MySettings - Get - Return Global.CSScriptExtension.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/extensions/CSScriptExtension/My Project/Settings.settings b/extensions/CSScriptExtension/My Project/Settings.settings deleted file mode 100644 index 85b890b..0000000 --- a/extensions/CSScriptExtension/My Project/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/extensions/CSScriptExtension/CSScriptLibrary.dll b/extensions/ScriptingExtension/CSScriptLibrary.dll similarity index 100% rename from extensions/CSScriptExtension/CSScriptLibrary.dll rename to extensions/ScriptingExtension/CSScriptLibrary.dll diff --git a/extensions/ScriptingExtension/Properties/AssemblyInfo.cs b/extensions/ScriptingExtension/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b338c1e --- /dev/null +++ b/extensions/ScriptingExtension/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +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("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("RatingExtension")] +[assembly: AssemblyCopyright("Copyright © 2017-2019 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/extensions/ScriptingExtension/ScriptingExtension.cs b/extensions/ScriptingExtension/ScriptingExtension.cs new file mode 100644 index 0000000..8cbd582 --- /dev/null +++ b/extensions/ScriptingExtension/ScriptingExtension.cs @@ -0,0 +1,47 @@ +//'This extension implements the C# scripting feature of mpv.net which +// is based on CS-Script (https://www.cs-script.net). + +// Furthermore the extension is used to code and debug scripts +// because writing script code without debugger is not an option :-) + +using System; +using System.ComponentModel.Composition; +using System.Collections.Generic; +using System.IO; +using System.Windows.Forms; + +using mpvnet; +using CSScriptLibrary; + +namespace ScriptingExtension // the file name of extensions must end with 'Extension' +{ + [Export(typeof(IExtension))] + public class ScriptingExtension : IExtension + { + Script Script; + + public ScriptingExtension() + { + //Script = new Script(); + List scriptFiles = new List(); + + if (Directory.Exists(mp.ConfigFolder + "scripts")) + scriptFiles.AddRange(Directory.GetFiles(mp.ConfigFolder + "scripts", "*.cs")); + + if (Directory.Exists(Application.StartupPath + "\\scripts")) + scriptFiles.AddRange(Directory.GetFiles(Application.StartupPath + "\\scripts", "*.cs")); + + if (scriptFiles.Count == 0) return; + CSScriptLibrary.CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom; + + foreach (var i in scriptFiles) + { + try { + CSScriptLibrary.CSScript.Evaluator.LoadCode(File.ReadAllText(i)); + } catch (Exception e) { + Msg.ShowException(e); + } + } + } + } +} \ No newline at end of file diff --git a/extensions/ScriptingExtension/ScriptingExtension.csproj b/extensions/ScriptingExtension/ScriptingExtension.csproj new file mode 100644 index 0000000..c329e92 --- /dev/null +++ b/extensions/ScriptingExtension/ScriptingExtension.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {94255EF2-C823-4D82-9017-0E993CC0F5A1} + Library + Properties + ScriptingExtension + ScriptingExtension + v4.7.2 + 512 + + + + true + ..\..\mpv.net\bin\x86\Extensions\ScriptingExtension\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + + + ..\..\mpv.net\bin\x86\Extensions\ScriptingExtension\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + + + true + ..\..\mpv.net\bin\x64\Extensions\ScriptingExtension\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + + + ..\..\mpv.net\bin\x64\Extensions\ScriptingExtension\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + + + + .\CSScriptLibrary.dll + + + + + + + + + + + + + + + + + + + + {1751f378-8edf-4b62-be6d-304c7c287089} + mpv.net + False + + + + \ No newline at end of file diff --git a/extensions/ScriptingExtension/ScriptingExtension.sln b/extensions/ScriptingExtension/ScriptingExtension.sln new file mode 100644 index 0000000..f3fb348 --- /dev/null +++ b/extensions/ScriptingExtension/ScriptingExtension.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29123.88 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptingExtension", "ScriptingExtension.csproj", "{55C88710-539D-4402-84C8-31694841C731}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {55C88710-539D-4402-84C8-31694841C731}.Debug|x64.ActiveCfg = Debug|x64 + {55C88710-539D-4402-84C8-31694841C731}.Debug|x64.Build.0 = Debug|x64 + {55C88710-539D-4402-84C8-31694841C731}.Debug|x86.ActiveCfg = Debug|x86 + {55C88710-539D-4402-84C8-31694841C731}.Debug|x86.Build.0 = Debug|x86 + {55C88710-539D-4402-84C8-31694841C731}.Release|x64.ActiveCfg = Release|x64 + {55C88710-539D-4402-84C8-31694841C731}.Release|x64.Build.0 = Release|x64 + {55C88710-539D-4402-84C8-31694841C731}.Release|x86.ActiveCfg = Release|x86 + {55C88710-539D-4402-84C8-31694841C731}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C8A53BF6-B00A-4215-B9D7-801ADB9C8F60} + EndGlobalSection +EndGlobal diff --git a/extensions/ScriptingExtension/script.cs b/extensions/ScriptingExtension/script.cs new file mode 100644 index 0000000..bd50592 --- /dev/null +++ b/extensions/ScriptingExtension/script.cs @@ -0,0 +1,40 @@ +using System; +using System.Windows.Forms; + +using mpvnet; + +class Script +{ + MainForm Form; + + bool WasPlaying; + bool WasPaused; + + public Script() + { + Form = MainForm.Instance; + Form.Resize += Form_Resize; + } + + private void Form_Resize(object sender, EventArgs e) + { + if (Form.WindowState == FormWindowState.Minimized) + { + WasPlaying = mp.get_property_string("pause") == "no"; + + if (WasPlaying) + { + mp.command("set pause yes"); + WasPaused = true; + } + } + else + { + if (WasPaused) + { + mp.command("set pause no"); + WasPaused = false; + } + } + } +} \ No newline at end of file diff --git a/mpv.net.sln b/mpv.net.sln index e334927..f87dffb 100644 --- a/mpv.net.sln +++ b/mpv.net.sln @@ -5,10 +5,10 @@ VisualStudioVersion = 16.0.28729.10 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpv.net", "mpv.net\mpv.net.csproj", "{1751F378-8EDF-4B62-BE6D-304C7C287089}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "CSScriptExtension", "extensions\CSScriptExtension\CSScriptExtension.vbproj", "{71808A87-8B1C-4DF8-957C-D79C3B164CCA}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RatingExtension", "extensions\RatingExtension\RatingExtension.csproj", "{55C88710-539D-4402-84C8-31694841C731}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptingExtension", "extensions\ScriptingExtension\ScriptingExtension.csproj", "{94255EF2-C823-4D82-9017-0E993CC0F5A1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,16 +29,6 @@ Global {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x64.Build.0 = Release|x64 {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x86.ActiveCfg = Release|x86 {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x86.Build.0 = Release|x86 - {71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|Any CPU.ActiveCfg = Debug|x86 - {71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|x64.ActiveCfg = Debug|x64 - {71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|x64.Build.0 = Debug|x64 - {71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|x86.ActiveCfg = Debug|x86 - {71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|x86.Build.0 = Debug|x86 - {71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|Any CPU.ActiveCfg = Release|x86 - {71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|x64.ActiveCfg = Release|x64 - {71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|x64.Build.0 = Release|x64 - {71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|x86.ActiveCfg = Release|x86 - {71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|x86.Build.0 = Release|x86 {55C88710-539D-4402-84C8-31694841C731}.Debug|Any CPU.ActiveCfg = Debug|x86 {55C88710-539D-4402-84C8-31694841C731}.Debug|x64.ActiveCfg = Debug|x64 {55C88710-539D-4402-84C8-31694841C731}.Debug|x64.Build.0 = Debug|x64 @@ -49,6 +39,16 @@ Global {55C88710-539D-4402-84C8-31694841C731}.Release|x64.Build.0 = Release|x64 {55C88710-539D-4402-84C8-31694841C731}.Release|x86.ActiveCfg = Release|x86 {55C88710-539D-4402-84C8-31694841C731}.Release|x86.Build.0 = Release|x86 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|Any CPU.ActiveCfg = Debug|x86 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x64.ActiveCfg = Debug|x64 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x64.Build.0 = Debug|x64 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x86.ActiveCfg = Debug|x86 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x86.Build.0 = Debug|x86 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|Any CPU.ActiveCfg = Release|x86 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x64.ActiveCfg = Release|x64 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x64.Build.0 = Release|x64 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x86.ActiveCfg = Release|x86 + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/mpv.net/Misc/Command.cs b/mpv.net/Misc/Command.cs index 3f3172a..640bd81 100644 --- a/mpv.net/Misc/Command.cs +++ b/mpv.net/Misc/Command.cs @@ -137,7 +137,7 @@ namespace mpvnet string videoFormat = mp.get_property_string("video-format").ToUpper(); string audioCodec = mp.get_property_string("audio-codec-name").ToUpper(); - text = Path.GetFileName(path) + "\n" + + text = PathHelp.GetFileName(path) + "\n" + FormatTime(position.TotalMinutes) + ":" + FormatTime(position.Seconds) + " / " + FormatTime(duration2.TotalMinutes) + ":" + diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index 73c3689..0101b7f 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -34,7 +34,7 @@ namespace mpvnet public static bool RememberHeight { get; set; } = true; public static bool RememberPosition { get; set; } public static bool DebugMode { get; set; } - public static bool IsTerminalHosted { get; } = Environment.GetEnvironmentVariable("_started_from_console") == "yes"; + public static bool IsStartedFromTerminal { get; } = Environment.GetEnvironmentVariable("_started_from_console") == "yes"; public static int StartThreshold { get; set; } = 1500; @@ -181,8 +181,8 @@ namespace mpvnet RegHelp.SetObject(@"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename, null, ExePath); RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}", "FriendlyAppName", "mpv.net media player"); RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}\\shell\\open\\command", null, $"\"{ExePath}\" \"%1\""); - RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv\Capabilities", "ApplicationDescription", "mpv.net media player"); - RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv\Capabilities", "ApplicationName", "mpv.net"); + RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationDescription", "mpv.net media player"); + RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationName", "mpv.net"); RegHelp.SetObject($"HKCR\\SystemFileAssociations\\video\\OpenWithList\\{ExeFilename}", null, ""); RegHelp.SetObject($"HKCR\\SystemFileAssociations\\audio\\OpenWithList\\{ExeFilename}", null, ""); @@ -409,4 +409,17 @@ namespace mpvnet Math.Abs(screenPos.Y - Control.MousePosition.Y) > 10; } } + + public class PathHelp + { + public static string GetFileName(string path) + { + if (string.IsNullOrEmpty(path)) return ""; + int index = path.LastIndexOf('\\'); + if (index > -1) return path.Substring(index + 1); + index = path.LastIndexOf('/'); + if (index > -1) return path.Substring(index + 1); + return path; + } + } } \ No newline at end of file diff --git a/mpv.net/Misc/Program.cs b/mpv.net/Misc/Program.cs index c95d4e7..3877f93 100644 --- a/mpv.net/Misc/Program.cs +++ b/mpv.net/Misc/Program.cs @@ -64,9 +64,9 @@ namespace mpvnet return; } - if (App.IsTerminalHosted) Native.AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/); + if (App.IsStartedFromTerminal) Native.AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/); Application.Run(new MainForm()); - if (App.IsTerminalHosted) Native.FreeConsole(); + if (App.IsStartedFromTerminal) Native.FreeConsole(); mutex.Dispose(); } catch (Exception ex) diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 70bc552..9e7a037 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Diagnostics; +using System.Threading.Tasks; namespace mpvnet { @@ -366,7 +367,7 @@ namespace mpvnet string path = mp.get_property_string("path"); BeginInvoke(new Action(() => { if (File.Exists(path) || path.Contains("://")) - Text = Path.GetFileName(path) + " - mpv.net " + Application.ProductVersion; + Text = PathHelp.GetFileName(path) + " - mpv.net " + Application.ProductVersion; else Text = "mpv.net " + Application.ProductVersion; })); @@ -533,6 +534,8 @@ namespace mpvnet CheckClipboardForURL(); Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y); WasShown = true; + Task.Run(() => { mp.LoadScripts(); }); + Task.Run(() => { mp.Extension = new Extension(); }); } protected override void OnActivated(EventArgs e) diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 4408c11..b7eeaf1 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -90,7 +90,7 @@ namespace mpvnet LoadLibrary("mpv-1.dll"); Handle = mpv_create(); - if (App.IsTerminalHosted) + if (App.IsStartedFromTerminal) { set_property_string("terminal", "yes"); set_property_string("msg-level", "osd/libass=fatal"); @@ -105,8 +105,6 @@ namespace mpvnet mpv_initialize(Handle); ShowLogo(); ProcessCommandLine(); - Task.Run(() => { LoadScripts(); }); - Task.Run(() => { Extension = new Extension(); }); Task.Run(() => { EventLoop(); }); } @@ -500,16 +498,6 @@ namespace mpvnet return val; } - public static bool get_property_bool(string name, bool throwOnException = false) - { - int err = mpv_get_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_FLAG, out IntPtr lpBuffer); - - if (err < 0 && throwOnException) - throw new Exception($"{name}: {(mpv_error)err}"); - else - return lpBuffer.ToInt32() == 1; - } - public static void set_property_int(string name, int value, bool throwOnException = false) { Int64 val = value;