-
This commit is contained in:
46
CSScriptAddon/CSScriptAddon.vb
Normal file
46
CSScriptAddon/CSScriptAddon.vb
Normal file
@@ -0,0 +1,46 @@
|
||||
' mpv.net
|
||||
' Copyright(C) 2017 stax76
|
||||
'
|
||||
' This program Is free software: you can redistribute it And/Or modify
|
||||
' it under the terms of the GNU General Public License as published by
|
||||
' the Free Software Foundation, either version 3 of the License, Or
|
||||
' (at your option) any later version.
|
||||
'
|
||||
' This program Is distributed in the hope that it will be useful,
|
||||
' but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
' MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
' GNU General Public License for more details.
|
||||
'
|
||||
' You should have received a copy of the GNU General Public License
|
||||
' along with this program. If Not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Imports System.ComponentModel.Composition
|
||||
Imports System.IO
|
||||
|
||||
Imports vbnet
|
||||
Imports mpvnet
|
||||
Imports vbnet.UI.MainModule
|
||||
|
||||
Imports CSScriptLibrary
|
||||
|
||||
<Export(GetType(IAddon))>
|
||||
Public Class CSScriptAddon
|
||||
Implements IAddon
|
||||
|
||||
Sub New()
|
||||
Dim scriptDir = Folder.AppDataRoaming + "mpv\scripts"
|
||||
If Not Directory.Exists(scriptDir) Then Return
|
||||
Dim csxFiles = Directory.GetFiles(scriptDir, "*.cs")
|
||||
If csxFiles.Count = 0 Then Return
|
||||
CSScriptLibrary.CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom
|
||||
CSScriptLibrary.CSScript.Evaluator.ReferenceDomainAssemblies()
|
||||
|
||||
For Each i In csxFiles
|
||||
Try
|
||||
CSScriptLibrary.CSScript.Evaluator.LoadCode(File.ReadAllText(i))
|
||||
Catch ex As Exception
|
||||
MsgException(ex)
|
||||
End Try
|
||||
Next
|
||||
End Sub
|
||||
End Class
|
||||
124
CSScriptAddon/CSScriptAddon.vbproj
Normal file
124
CSScriptAddon/CSScriptAddon.vbproj
Normal file
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{71808A87-8B1C-4DF8-957C-D79C3B164CCA}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>CSScriptAddon</RootNamespace>
|
||||
<AssemblyName>CSScriptAddon</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>Windows</MyType>
|
||||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<OutputPath>..\mpvnet\bin\Debug\Addons\CSScript\</OutputPath>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<NoWarn>42105,42106,42107,42353,42354,42355</NoWarn>
|
||||
<WarningsAsErrors>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036</WarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<NoWarn>42105,42106,42107,42353,42354,42355</NoWarn>
|
||||
<WarningsAsErrors>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036</WarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionExplicit>On</OptionExplicit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionCompare>Binary</OptionCompare>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionStrict>On</OptionStrict>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="CSScriptLibrary, Version=3.27.5.0, Culture=neutral, PublicKeyToken=70fcc3d18c749033, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\CSScriptLibrary.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mpvnet, Version=0.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\mpvnet\bin\Debug\mpvnet.exe</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.Composition" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="vbnet">
|
||||
<HintPath>..\vbnet\bin\Debug\vbnet.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Import Include="Microsoft.VisualBasic" />
|
||||
<Import Include="System" />
|
||||
<Import Include="System.Collections" />
|
||||
<Import Include="System.Collections.Generic" />
|
||||
<Import Include="System.Data" />
|
||||
<Import Include="System.Diagnostics" />
|
||||
<Import Include="System.Linq" />
|
||||
<Import Include="System.Xml.Linq" />
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CSScriptAddon.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="CSScriptLibrary.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
</Project>
|
||||
BIN
CSScriptAddon/CSScriptLibrary.dll
Normal file
BIN
CSScriptAddon/CSScriptLibrary.dll
Normal file
Binary file not shown.
13
CSScriptAddon/My Project/Application.Designer.vb
generated
Normal file
13
CSScriptAddon/My Project/Application.Designer.vb
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
10
CSScriptAddon/My Project/Application.myapp
Normal file
10
CSScriptAddon/My Project/Application.myapp
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<MySubMain>false</MySubMain>
|
||||
<SingleInstance>false</SingleInstance>
|
||||
<ShutdownMode>0</ShutdownMode>
|
||||
<EnableVisualStyles>true</EnableVisualStyles>
|
||||
<AuthenticationMode>0</AuthenticationMode>
|
||||
<ApplicationType>1</ApplicationType>
|
||||
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
|
||||
</MyApplicationData>
|
||||
35
CSScriptAddon/My Project/AssemblyInfo.vb
Normal file
35
CSScriptAddon/My Project/AssemblyInfo.vb
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
||||
|
||||
<Assembly: AssemblyTitle("PowerShellAddon")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("")>
|
||||
<Assembly: AssemblyProduct("PowerShellAddon")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2017")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
'The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
<Assembly: Guid("4a748201-3948-497d-b156-7d172a332bd6")>
|
||||
|
||||
' 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")>
|
||||
63
CSScriptAddon/My Project/Resources.Designer.vb
generated
Normal file
63
CSScriptAddon/My Project/Resources.Designer.vb
generated
Normal file
@@ -0,0 +1,63 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
'''<summary>
|
||||
''' A strongly-typed resource class, for looking up localized strings, etc.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Returns the cached ResourceManager instance used by this class.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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("CSScriptAddon.Resources", GetType(Resources).Assembly)
|
||||
resourceMan = temp
|
||||
End If
|
||||
Return resourceMan
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Overrides the current thread's CurrentUICulture property for all
|
||||
''' resource lookups using this strongly typed resource class.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
117
CSScriptAddon/My Project/Resources.resx
Normal file
117
CSScriptAddon/My Project/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
73
CSScriptAddon/My Project/Settings.Designer.vb
generated
Normal file
73
CSScriptAddon/My Project/Settings.Designer.vb
generated
Normal file
@@ -0,0 +1,73 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.3.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
Friend ReadOnly Property Settings() As Global.CSScriptAddon.My.MySettings
|
||||
Get
|
||||
Return Global.CSScriptAddon.My.MySettings.Default
|
||||
End Get
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
7
CSScriptAddon/My Project/Settings.settings
Normal file
7
CSScriptAddon/My Project/Settings.settings
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
@@ -68,7 +68,7 @@ namespace Rating
|
||||
{
|
||||
int rating;
|
||||
|
||||
if (args?.Length < 2 || args[0] != "Rating" || ! int.TryParse(args[1], out rating))
|
||||
if (args?.Length != 2 || args[0] != "rate-file" || ! int.TryParse(args[1], out rating))
|
||||
return;
|
||||
|
||||
Dic[mpv.GetStringProp("path")] = rating;
|
||||
|
||||
32
mpv.net.sln
32
mpv.net.sln
@@ -4,9 +4,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
VisualStudioVersion = 15.0.26730.8
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpv.net", "mpvnet\mpv.net.csproj", "{1751F378-8EDF-4B62-BE6D-304C7C287089}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{55C88710-539D-4402-84C8-31694841C731} = {55C88710-539D-4402-84C8-31694841C731}
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA} = {71808A87-8B1C-4DF8-957C-D79C3B164CCA}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rating", "RatingAddon\Rating.csproj", "{55C88710-539D-4402-84C8-31694841C731}"
|
||||
EndProject
|
||||
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "vbnet", "vbnet\vbnet.vbproj", "{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}"
|
||||
EndProject
|
||||
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "CSScriptAddon", "CSScriptAddon\CSScriptAddon.vbproj", "{71808A87-8B1C-4DF8-957C-D79C3B164CCA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -41,6 +49,30 @@ 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
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Release|x64.Build.0 = Release|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}.Release|x86.Build.0 = Release|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|x64.Build.0 = Release|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{71808A87-8B1C-4DF8-957C-D79C3B164CCA}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -23,6 +23,8 @@ using System.ComponentModel.Composition.Hosting;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using static vbnet.UI.MainModule;
|
||||
|
||||
// MEF (Managed Extension Framework)
|
||||
|
||||
namespace mpvnet
|
||||
@@ -35,6 +37,8 @@ namespace mpvnet
|
||||
private readonly CompositionContainer CompositionContainer;
|
||||
|
||||
public Addon()
|
||||
{
|
||||
try
|
||||
{
|
||||
AggregateCatalog catalog = new AggregateCatalog();
|
||||
|
||||
@@ -56,6 +60,11 @@ namespace mpvnet
|
||||
CompositionContainer.ComposeParts(this);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MsgException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IAddon
|
||||
|
||||
103
mpvnet/Command.cs
Normal file
103
mpvnet/Command.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
*mpv.net
|
||||
*Copyright(C) 2017 stax76
|
||||
*
|
||||
*This program is free software: you can redistribute it and/or modify
|
||||
*it under the terms of the GNU General Public License as published by
|
||||
*the Free Software Foundation, either version 3 of the License, or
|
||||
*(at your option) any later version.
|
||||
*
|
||||
*This program is distributed in the hope that it will be useful,
|
||||
*but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
*GNU General Public License for more details.
|
||||
*
|
||||
*You should have received a copy of the GNU General Public License
|
||||
*along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using vbnet;
|
||||
|
||||
namespace mpvnet
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Action<string[]> Action { get; set; }
|
||||
|
||||
private static List<Command> commands;
|
||||
|
||||
public static List<Command> Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
if (commands == null)
|
||||
{
|
||||
commands = new List<Command>();
|
||||
var type = typeof(Command);
|
||||
var methods = type.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
|
||||
|
||||
foreach (var i in methods)
|
||||
{
|
||||
var parameters = i.GetParameters();
|
||||
|
||||
if (parameters == null || parameters.Length != 1 || parameters[0].ParameterType != typeof(string[]))
|
||||
continue;
|
||||
|
||||
var cmd = new Command() { Name = i.Name.Replace("_","-"), Action = (Action<string[]>)i.CreateDelegate(typeof(Action<string[]>)) };
|
||||
commands.Add(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
|
||||
public static void open_files(string[] args)
|
||||
{
|
||||
MainForm.Instance.Invoke(new Action(() => {
|
||||
using (var d = new OpenFileDialog())
|
||||
{
|
||||
d.Multiselect = true;
|
||||
d.Filter = Misc.GetFilter(Misc.FileTypes);
|
||||
|
||||
if (d.ShowDialog() == DialogResult.OK)
|
||||
mpv.LoadFiles(d.FileNames);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static void open_config_folder(string[] args)
|
||||
{
|
||||
ProcessHelp.Start(Folder.AppDataRoaming + "mpv");
|
||||
}
|
||||
|
||||
public static void show_keys(string[] args)
|
||||
{
|
||||
ProcessHelp.Start(OS.GetTextEditor(), '"' + mpv.InputConfPath + '"');
|
||||
}
|
||||
|
||||
public static void show_prefs(string[] args)
|
||||
{
|
||||
string filepath = Folder.AppDataRoaming + "mpv\\mpv.conf";
|
||||
|
||||
if (!File.Exists(filepath))
|
||||
{
|
||||
var dirPath = Folder.AppDataRoaming + "mpv\\";
|
||||
|
||||
if (!Directory.Exists(dirPath))
|
||||
Directory.CreateDirectory(dirPath);
|
||||
|
||||
File.WriteAllText(filepath, "# https://mpv.io/manual/master/#configuration-files");
|
||||
}
|
||||
|
||||
ProcessHelp.Start(OS.GetTextEditor(), '"' + filepath + '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
33
mpvnet/Extensions.cs
Normal file
33
mpvnet/Extensions.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mpvnet
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static string Join(this IEnumerable<string> instance, string delimiter, bool removeEmpty = false)
|
||||
{
|
||||
if (instance == null)
|
||||
return null;
|
||||
|
||||
bool containsEmpty = false;
|
||||
|
||||
foreach (var i in instance)
|
||||
{
|
||||
if (string.IsNullOrEmpty(i))
|
||||
{
|
||||
containsEmpty = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (containsEmpty && removeEmpty)
|
||||
instance = instance.Where(arg => !string.IsNullOrEmpty(arg));
|
||||
|
||||
return string.Join(delimiter, instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
6
mpvnet/MainForm.Designer.cs
generated
6
mpvnet/MainForm.Designer.cs
generated
@@ -42,11 +42,13 @@
|
||||
// MainForm
|
||||
//
|
||||
this.AllowDrop = true;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(19F, 37F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(20F, 48F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.Black;
|
||||
this.ClientSize = new System.Drawing.Size(1517, 951);
|
||||
this.ClientSize = new System.Drawing.Size(1553, 1000);
|
||||
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "MainForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "mpv.net";
|
||||
|
||||
@@ -19,11 +19,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using vbnet;
|
||||
using vbnet.UI;
|
||||
using static vbnet.UI.MainModule;
|
||||
|
||||
namespace mpvnet
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
@@ -33,8 +38,9 @@ namespace mpvnet
|
||||
|
||||
private Point LastCursorPosChanged;
|
||||
private int LastCursorChangedTickCount;
|
||||
private bool IsCloseRequired = true;
|
||||
|
||||
public ContextMenuEx CM;
|
||||
public ContextMenuStripEx CMS;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
@@ -50,10 +56,11 @@ namespace mpvnet
|
||||
mpv.VideoSizeChanged += Mpv_VideoSizeChanged;
|
||||
mpv.PlaybackRestart += Mpv_PlaybackRestart;
|
||||
|
||||
CM = new ContextMenuEx();
|
||||
ContextMenu = CM;
|
||||
CM.Popup += CM_Popup;
|
||||
ContextMenu.MenuItems.Add("About mpv.net", About);
|
||||
ToolStripManager.Renderer = new ToolStripRendererEx(ToolStripRenderModeEx.SystemDefault);
|
||||
CMS = new ContextMenuStripEx(components);
|
||||
CMS.Opened += CMS_Opened;
|
||||
ContextMenuStrip = CMS;
|
||||
BuildMenu();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -61,9 +68,60 @@ namespace mpvnet
|
||||
}
|
||||
}
|
||||
|
||||
public void BuildMenu()
|
||||
{
|
||||
if (!File.Exists(mpv.InputConfPath))
|
||||
{
|
||||
var dirPath = Folder.AppDataRoaming + "mpv\\";
|
||||
|
||||
if (!Directory.Exists(dirPath))
|
||||
Directory.CreateDirectory(dirPath);
|
||||
|
||||
File.WriteAllText(mpv.InputConfPath, Properties.Resources.input_conf);
|
||||
}
|
||||
|
||||
foreach (var i in File.ReadAllText(mpv.InputConfPath).SplitLinesNoEmpty())
|
||||
{
|
||||
if (!i.Contains("#menu:"))
|
||||
continue;
|
||||
|
||||
var left = i.Left("#menu:").Trim();
|
||||
|
||||
if (left.StartsWith("#"))
|
||||
continue;
|
||||
|
||||
var cmd = left.Right(" ").Trim();
|
||||
var menu = i.Right("#menu:").Trim();
|
||||
var key = menu.Left(";").Trim();
|
||||
var path = menu.Right(";").Trim();
|
||||
|
||||
if (path == "" || cmd == "")
|
||||
continue;
|
||||
|
||||
var menuItem = CMS.Add(path, () => {
|
||||
try
|
||||
{
|
||||
mpv.CommandString(cmd);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MsgException(e);
|
||||
}
|
||||
});
|
||||
|
||||
if (menuItem != null)
|
||||
menuItem.ShortcutKeyDisplayString = key.Replace("_","") + " ";
|
||||
}
|
||||
}
|
||||
|
||||
private void CMS_Opened(object sender, EventArgs e)
|
||||
{
|
||||
CursorHelp.Show();
|
||||
}
|
||||
|
||||
private void Mpv_PlaybackRestart()
|
||||
{
|
||||
BeginInvoke(new Action(() => Text = mpv.GetStringProp("filename") + " - mpv.net"));
|
||||
BeginInvoke(new Action(() => Text = mpv.GetStringProp("filename") + " - mpv.net " + Application.ProductVersion));
|
||||
}
|
||||
|
||||
private void CM_Popup(object sender, EventArgs e)
|
||||
@@ -78,10 +136,10 @@ namespace mpvnet
|
||||
|
||||
void HandleException(Exception e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "mpv.net Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MsgException(e);
|
||||
}
|
||||
|
||||
private void About(object sender, EventArgs e)
|
||||
private void About()
|
||||
{
|
||||
mpv.Command("show-text", Application.ProductName + " v" + Application.ProductVersion.ToString() +
|
||||
"\nCopyright (c) 2017 stax76\nGPL License", "5000");
|
||||
@@ -92,7 +150,11 @@ namespace mpvnet
|
||||
BeginInvoke(new Action(() => SetFormPosSize()));
|
||||
}
|
||||
|
||||
private void Mpv_AfterShutdown() => Invoke(new Action(() => Close()));
|
||||
private void Mpv_AfterShutdown()
|
||||
{
|
||||
if (IsCloseRequired)
|
||||
Invoke(new Action(() => Close()));
|
||||
}
|
||||
|
||||
public bool IsFullscreen
|
||||
{
|
||||
@@ -189,20 +251,7 @@ namespace mpvnet
|
||||
base.OnDragDrop(e);
|
||||
|
||||
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||
{
|
||||
int count = mpv.GetIntProp("playlist-count");
|
||||
string[] files = e.Data.GetData(DataFormats.FileDrop) as String[];
|
||||
|
||||
foreach (string file in files)
|
||||
mpv.Command("loadfile", file, "append");
|
||||
|
||||
mpv.SetIntProp("playlist-pos", count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
mpv.Command("playlist-remove", "0");
|
||||
|
||||
mpv.LoadFolder();
|
||||
}
|
||||
mpv.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as String[]);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
@@ -234,6 +283,7 @@ namespace mpvnet
|
||||
protected override void OnFormClosed(FormClosedEventArgs e)
|
||||
{
|
||||
base.OnFormClosed(e);
|
||||
IsCloseRequired = false;
|
||||
mpv.Command("quit");
|
||||
}
|
||||
|
||||
@@ -251,7 +301,7 @@ namespace mpvnet
|
||||
}
|
||||
else if (Environment.TickCount - LastCursorChangedTickCount > 1500 &&
|
||||
!IsMouseInOSC() && ClientRectangle.Contains(PointToClient(MousePosition)) &&
|
||||
Form.ActiveForm == this && !CM.Visible)
|
||||
Form.ActiveForm == this && !CMS.Visible)
|
||||
{
|
||||
CursorHelp.Hide();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,16 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace mpvnet
|
||||
{
|
||||
public class Misc
|
||||
{
|
||||
public static readonly string[] FileTypes = "264 265 3gp aac ac3 avc avi avs bmp divx dts dtshd dtshr dtsma eac3 evo flac flv h264 h265 hevc hvc jpg jpeg m2t m2ts m2v m4a m4v mka mkv mlp mov mp2 mp3 mp4 mpa mpeg mpg mpv mts ogg ogm opus pcm png pva raw rmvb thd thd+ac3 true-hd truehd ts vdr vob vpy w64 wav webm wmv y4m".Split(' ');
|
||||
|
||||
public static string GetFilter(IEnumerable<string> values)
|
||||
{
|
||||
return "*." + values.Join(";*.") + "|*." + values.Join(";*.") + "|All Files|*.*";
|
||||
}
|
||||
}
|
||||
|
||||
public class StringLogicalComparer : IComparer, IComparer<string>
|
||||
{
|
||||
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.1.0.0")]
|
||||
[assembly: AssemblyVersion("0.2.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.2.0.0")]
|
||||
|
||||
21
mpvnet/Properties/Resources.Designer.cs
generated
21
mpvnet/Properties/Resources.Designer.cs
generated
@@ -59,5 +59,26 @@ namespace mpvnet.Properties {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to
|
||||
///#key command key caption menu path/caption
|
||||
///
|
||||
///o script-message mpv.net open-files #menu: O; Open Files
|
||||
///
|
||||
///Space pause #menu: Space ; Play/Pause
|
||||
///s stop #menu: S ; Stop
|
||||
///
|
||||
///F11 playlist-prev #menu: F11 ; Navigate | Previous
|
||||
///F12 playlist-next #menu: F12 ; Navigate | Next
|
||||
///
|
||||
///Ctrl++ add video-zoom 0.1 #menu: Ctrl++ ; Pan && Scan | Increase Size
|
||||
///Ctrl+- add video-zoom -0.1 #menu: Ct [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string input_conf {
|
||||
get {
|
||||
return ResourceManager.GetString("input_conf", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
@@ -60,6 +60,7 @@
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
@@ -68,9 +69,10 @@
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
@@ -85,9 +87,10 @@
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
@@ -109,9 +112,13 @@
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="input_conf" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\input_conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||
</data>
|
||||
</root>
|
||||
49
mpvnet/Resources/input_conf.txt
Normal file
49
mpvnet/Resources/input_conf.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
#key command key caption menu path/caption
|
||||
|
||||
o script-message mpv.net open-files #menu: O; Open Files
|
||||
|
||||
Space pause #menu: Space ; Play/Pause
|
||||
s stop #menu: S ; Stop
|
||||
|
||||
F11 playlist-prev #menu: F11 ; Navigate | Previous
|
||||
F12 playlist-next #menu: F12 ; Navigate | Next
|
||||
|
||||
Ctrl++ add video-zoom 0.1 #menu: Ctrl++ ; Pan && Scan | Increase Size
|
||||
Ctrl+- add video-zoom -0.1 #menu: Ctrl+- ; Pan && Scan | Decrease Size
|
||||
|
||||
Enter cycle fullscreen #menu: Enter ; Cycle Fullscreen
|
||||
KP7 cycle audio #menu: Numpad 7 ; Cycle Audio
|
||||
KP8 cycle sub #menu: Numpad 8 ; Cycle Subtitle
|
||||
|
||||
+ add volume 5 #menu: + ; Volume | Up
|
||||
- add volume -5 #menu: - ; Volume | Down
|
||||
Axis_Up add volume 5 # wheel up
|
||||
Axis_Down add volume -5 # wheel down
|
||||
_ _ #menu: _ ; Volume | -
|
||||
m mute #menu: M ; Volume | Mute
|
||||
|
||||
Alt++ add audio-delay 0.1 #menu: Alt++ ; Audio | Delay +0.1
|
||||
Alt+- add audio-delay -0.1 #menu: Alt+- ; Audio | Delay -0.1
|
||||
|
||||
Right seek 10 #menu: Right ; Seek | 10 sec forward
|
||||
Left seek -10 #menu: Left ; Seek | 10 sec backward
|
||||
_ _ #menu: _ ; Seek | -
|
||||
Up seek 60 #menu: Up ; Seek | 1 min forward
|
||||
Down seek -60 #menu: Down ; Seek | 1 min backward
|
||||
_ _ #menu: _ ; Seek | -
|
||||
Ctrl+Right seek 300 #menu: Ctrl+Right ; Seek | 5 min forward
|
||||
Ctrl+Left seek -300 #menu: Ctrl+Left ; Seek | 5 min backward
|
||||
|
||||
KP0 script-message rate-file 0 #menu: Numpad 0 ; Addons | Rating | 0stars
|
||||
KP1 script-message rate-file 1 #menu: Numpad 1 ; Addons | Rating | 1stars
|
||||
KP2 script-message rate-file 2 #menu: Numpad 2 ; Addons | Rating | 2stars
|
||||
KP3 script-message rate-file 3 #menu: Numpad 3 ; Addons | Rating | 3stars
|
||||
KP4 script-message rate-file 4 #menu: Numpad 4 ; Addons | Rating | 4stars
|
||||
KP5 script-message rate-file 5 #menu: Numpad 5 ; Addons | Rating | 5stars
|
||||
|
||||
p script-message mpv.net show-prefs #menu: P ; Preferences
|
||||
k script-message mpv.net show-keys #menu: K ; Keys
|
||||
|
||||
F8 script-message mpv.net open-config-folder #menu: _ ; Tools | Config Folder
|
||||
Esc quit #menu: Escape ; Exit
|
||||
@@ -16,31 +16,641 @@
|
||||
*along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
using Microsoft.VisualBasic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace mpvnet
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static class ExtensionMethods
|
||||
// public static string Multiply(this string instance, int multiplier)
|
||||
// {
|
||||
// StringBuilder sb = new StringBuilder(multiplier * instance.Length);
|
||||
|
||||
// for (var i = 0; i <= multiplier - 1; i++)
|
||||
// {
|
||||
// sb.Append(instance);
|
||||
// }
|
||||
|
||||
// return sb.ToString();
|
||||
// }
|
||||
|
||||
// public static bool IsValidFileName(string instance)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(instance))
|
||||
// return false;
|
||||
|
||||
// string chars = "\"*/:<>?\\|";
|
||||
|
||||
// foreach (var i in instance)
|
||||
// {
|
||||
// if (chars.Contains(i.ToString()))
|
||||
// return false;
|
||||
|
||||
// if (Convert.ToInt32(i) < 32)
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string FileName(string instance)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(instance))
|
||||
// return "";
|
||||
// dynamic index = instance.LastIndexOf(Path.DirectorySeparatorChar);
|
||||
// if (index > -1)
|
||||
// return instance.Substring(index + 1);
|
||||
// return instance;
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string Upper(string instance)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(instance))
|
||||
// return "";
|
||||
// return instance.ToUpperInvariant;
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string Lower(string instance)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(instance))
|
||||
// return "";
|
||||
// return instance.ToLowerInvariant;
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string ChangeExt(string instance, string value)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(instance))
|
||||
// return "";
|
||||
// if (string.IsNullOrEmpty(value))
|
||||
// return instance;
|
||||
// if (!value.StartsWith("."))
|
||||
// value = "." + value;
|
||||
// return instance.DirAndBase + value.ToLower;
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string Escape(string instance)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(instance))
|
||||
// return "";
|
||||
|
||||
// dynamic chars = " ()".ToCharArray;
|
||||
|
||||
// foreach (void i_loopVariable in chars)
|
||||
// {
|
||||
// i = i_loopVariable;
|
||||
// if (instance.Contains(i))
|
||||
// return "\"" + instance + "\"";
|
||||
// }
|
||||
|
||||
// return instance;
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string Parent(string instance)
|
||||
// {
|
||||
// return DirPath.GetParent(instance);
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string ExistingParent(string instance)
|
||||
// {
|
||||
// dynamic ret = instance.Parent;
|
||||
// if (!Directory.Exists(ret))
|
||||
// ret = ret.Parent;
|
||||
// else
|
||||
// return ret;
|
||||
// if (!Directory.Exists(ret))
|
||||
// ret = ret.Parent;
|
||||
// else
|
||||
// return ret;
|
||||
// if (!Directory.Exists(ret))
|
||||
// ret = ret.Parent;
|
||||
// else
|
||||
// return ret;
|
||||
// if (!Directory.Exists(ret))
|
||||
// ret = ret.Parent;
|
||||
// else
|
||||
// return ret;
|
||||
// if (!Directory.Exists(ret))
|
||||
// ret = ret.Parent;
|
||||
// else
|
||||
// return ret;
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
public static string ExtFull(this string filepath)
|
||||
{
|
||||
public static string Ext(this string instance)
|
||||
return Ext(filepath, true);
|
||||
}
|
||||
|
||||
public static string Ext(this string filepath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(instance))
|
||||
return Ext(filepath, false);
|
||||
}
|
||||
|
||||
public static string Ext(this string filepath, bool dot)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filepath))
|
||||
return "";
|
||||
|
||||
string ext = Path.GetExtension(instance);
|
||||
var chars = filepath.ToCharArray();
|
||||
|
||||
if (ext == "")
|
||||
return "";
|
||||
|
||||
return ext.ToLowerInvariant().Substring(1);
|
||||
}
|
||||
|
||||
public static string ExtFull(this string instance)
|
||||
for (var x = filepath.Length - 1; x >= 0; x += -1)
|
||||
{
|
||||
if (string.IsNullOrEmpty(instance))
|
||||
if (chars[x] == Path.DirectorySeparatorChar)
|
||||
return "";
|
||||
|
||||
return Path.GetExtension(instance).ToLowerInvariant();
|
||||
}
|
||||
if (chars[x] == '.')
|
||||
return filepath.Substring(x + (dot ? 0 : 1)).ToLower();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
// [Extension()]
|
||||
// public static string Base(string instance)
|
||||
// {
|
||||
// return FilePath.GetBase(instance);
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string Dir(string instance)
|
||||
// {
|
||||
// return FilePath.GetDir(instance);
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string DirName(string instance)
|
||||
// {
|
||||
// return DirPath.GetName(instance);
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string DirAndBase(string instance)
|
||||
// {
|
||||
// return FilePath.GetDirAndBase(instance);
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static bool ContainsAll(string instance, IEnumerable<string> all)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(instance))
|
||||
// return all.All(arg => instance.Contains(arg));
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static bool ContainsAny(string instance, IEnumerable<string> any)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(instance))
|
||||
// return any.Any(arg => instance.Contains(arg));
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string ToTitleCase(string value)
|
||||
// {
|
||||
// //TextInfo.ToTitleCase won't work on all upper strings
|
||||
// return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value.ToLower);
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static bool IsInt(string value)
|
||||
// {
|
||||
// return int.TryParse(value, null);
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static int ToInt(string value, int defaultValue = 0)
|
||||
// {
|
||||
// if (!int.TryParse(value, null))
|
||||
// return defaultValue;
|
||||
// return Convert.ToInt32(value);
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static bool IsSingle(string value)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(value))
|
||||
// {
|
||||
// if (value.Contains(","))
|
||||
// value = value.Replace(",", ".");
|
||||
|
||||
// return float.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, null);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static float ToSingle(string value, float defaultValue = 0)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(value))
|
||||
// {
|
||||
// if (value.Contains(","))
|
||||
// value = value.Replace(",", ".");
|
||||
|
||||
// float ret = 0;
|
||||
|
||||
// if (float.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, ret))
|
||||
// {
|
||||
// return ret;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return defaultValue;
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static bool IsDouble(string value)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(value))
|
||||
// {
|
||||
// if (value.Contains(","))
|
||||
// value = value.Replace(",", ".");
|
||||
|
||||
// return double.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, null);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static double ToDouble(string value, float defaultValue = 0)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(value))
|
||||
// {
|
||||
// if (value.Contains(","))
|
||||
// value = value.Replace(",", ".");
|
||||
|
||||
// double ret = 0;
|
||||
|
||||
// if (double.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, ret))
|
||||
// {
|
||||
// return ret;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return defaultValue;
|
||||
// }
|
||||
|
||||
public static string Left(this string value, int index)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value) || index < 0)
|
||||
return "";
|
||||
|
||||
if (index > value.Length)
|
||||
return value;
|
||||
|
||||
return value.Substring(0, index);
|
||||
}
|
||||
|
||||
public static string Left(this string value, string start)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(start))
|
||||
return "";
|
||||
|
||||
if (!value.Contains(start))
|
||||
return "";
|
||||
|
||||
return value.Substring(0, value.IndexOf(start));
|
||||
}
|
||||
|
||||
public static string LeftLast(this string value, string start)
|
||||
{
|
||||
if (!value.Contains(start))
|
||||
return "";
|
||||
|
||||
return value.Substring(0, value.LastIndexOf(start));
|
||||
}
|
||||
|
||||
public static string Right(this string value, string start)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(start))
|
||||
return "";
|
||||
|
||||
if (!value.Contains(start))
|
||||
return "";
|
||||
|
||||
return value.Substring(value.IndexOf(start) + start.Length);
|
||||
}
|
||||
|
||||
public static string RightLast(this string value, string start)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(start))
|
||||
return "";
|
||||
|
||||
if (!value.Contains(start))
|
||||
return "";
|
||||
|
||||
return value.Substring(value.LastIndexOf(start) + start.Length);
|
||||
}
|
||||
|
||||
// [Extension()]
|
||||
// public static bool EqualIgnoreCase(string a, string b)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b))
|
||||
// return false;
|
||||
// return string.Compare(a, b, StringComparison.OrdinalIgnoreCase) == 0;
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string Shorten(string value, int maxLength)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(value) || value.Length <= maxLength)
|
||||
// {
|
||||
// return value;
|
||||
// }
|
||||
|
||||
// return value.Substring(0, maxLength);
|
||||
// }
|
||||
|
||||
public static string[] SplitNoEmpty(this string value, params string[] delimiters)
|
||||
{
|
||||
return value.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
public static string[] SplitKeepEmpty(this string value, params string[] delimiters)
|
||||
{
|
||||
return value.Split(delimiters, StringSplitOptions.None);
|
||||
}
|
||||
|
||||
public static string[] SplitNoEmptyAndWhiteSpace(this string value, params string[] delimiters)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return null;
|
||||
|
||||
var a = SplitNoEmpty(value, delimiters);
|
||||
|
||||
for (var i = 0; i <= a.Length - 1; i++)
|
||||
a[i] = a[i].Trim();
|
||||
|
||||
var l = a.ToList();
|
||||
|
||||
while (l.Contains(""))
|
||||
l.Remove("");
|
||||
|
||||
return l.ToArray();
|
||||
}
|
||||
|
||||
public static string[] SplitLinesNoEmpty(this string value)
|
||||
{
|
||||
return SplitNoEmpty(value, Environment.NewLine);
|
||||
}
|
||||
|
||||
// [Extension()]
|
||||
// public static string RemoveChars(string value, string chars)
|
||||
// {
|
||||
// dynamic ret = value;
|
||||
|
||||
// foreach (void i_loopVariable in value)
|
||||
// {
|
||||
// i = i_loopVariable;
|
||||
// if (chars.IndexOf(i) >= 0)
|
||||
// {
|
||||
// ret = ret.Replace(i, "");
|
||||
// }
|
||||
// }
|
||||
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string DeleteRight(string value, int count)
|
||||
// {
|
||||
// return Strings.Left(value, value.Length - count);
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static string ReplaceUnicode(string value)
|
||||
// {
|
||||
// if (value.Contains(Convert.ToChar(0x2212)))
|
||||
// {
|
||||
// value = value.Replace(Convert.ToChar(0x2212), '-');
|
||||
// }
|
||||
|
||||
// return value;
|
||||
// }
|
||||
|
||||
// [Extension()]
|
||||
// public static void ToClipboard(string value)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(value))
|
||||
// {
|
||||
// Clipboard.SetText(value);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Clipboard.Clear();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
public class DirPath : PathBase
|
||||
{
|
||||
|
||||
// public static string TrimTrailingSeparator(string path)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(path))
|
||||
// return "";
|
||||
|
||||
// if (path.EndsWith(Separator) && !(path.Length <= 3))
|
||||
// {
|
||||
// return path.TrimEnd(Separator);
|
||||
// }
|
||||
|
||||
// return path;
|
||||
// }
|
||||
|
||||
// public static string FixSeperator(string path)
|
||||
// {
|
||||
// if (path.Contains("\\") && Separator != "\\")
|
||||
// {
|
||||
// path = path.Replace("\\", Separator);
|
||||
// }
|
||||
|
||||
// if (path.Contains("/") && Separator != "/")
|
||||
// {
|
||||
// path = path.Replace("/", Separator);
|
||||
// }
|
||||
|
||||
// return path;
|
||||
// }
|
||||
|
||||
// public static string GetParent(string path)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(path))
|
||||
// return "";
|
||||
// dynamic temp = TrimTrailingSeparator(path);
|
||||
// if (temp.Contains(Separator))
|
||||
// path = temp.LeftLast(Separator) + Separator;
|
||||
// return path;
|
||||
// }
|
||||
|
||||
// public static string GetName(string path)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(path))
|
||||
// return "";
|
||||
// path = TrimTrailingSeparator(path);
|
||||
// return path.RightLast(Separator);
|
||||
// }
|
||||
|
||||
// public static bool IsFixedDrive(string path)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(path))
|
||||
// return new DriveInfo(path).DriveType == DriveType.Fixed;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public class FilePath : PathBase
|
||||
{
|
||||
|
||||
|
||||
// private string Value;
|
||||
// public FilePath(string path)
|
||||
// {
|
||||
// Value = path;
|
||||
// }
|
||||
|
||||
// public static string GetDir(string path)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(path))
|
||||
// return "";
|
||||
// if (path.Contains("\\"))
|
||||
// path = path.LeftLast("\\") + "\\";
|
||||
// return path;
|
||||
// }
|
||||
|
||||
// public static string GetDirAndBase(string path)
|
||||
// {
|
||||
// return GetDir(path) + GetBase(path);
|
||||
// }
|
||||
|
||||
// public static string GetName(string path)
|
||||
// {
|
||||
// if ((path != null))
|
||||
// {
|
||||
// dynamic index = path.LastIndexOf(IO.Path.DirectorySeparatorChar);
|
||||
|
||||
// if (index > -1)
|
||||
// {
|
||||
// return path.Substring(index + 1);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return path;
|
||||
// }
|
||||
|
||||
// public static string GetDirNoSep(string path)
|
||||
// {
|
||||
// path = GetDir(path);
|
||||
// if (path.EndsWith(Separator))
|
||||
// path = TrimSep(path);
|
||||
// return path;
|
||||
// }
|
||||
|
||||
// public static string GetBase(string path)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(path))
|
||||
// return "";
|
||||
// dynamic ret = path;
|
||||
// if (ret.Contains(Separator))
|
||||
// ret = ret.RightLast(Separator);
|
||||
// if (ret.Contains("."))
|
||||
// ret = ret.LeftLast(".");
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
// public static string TrimSep(string path)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(path))
|
||||
// return "";
|
||||
|
||||
// if (path.EndsWith(Separator) && !path.EndsWith(":" + Separator))
|
||||
// {
|
||||
// return path.TrimEnd(Separator);
|
||||
// }
|
||||
|
||||
// return path;
|
||||
// }
|
||||
|
||||
// public static string GetDirNameOnly(string path)
|
||||
// {
|
||||
// return FilePath.GetDirNoSep(path).RightLast("\\");
|
||||
// }
|
||||
}
|
||||
|
||||
public class PathBase
|
||||
{
|
||||
//public static char Separator {
|
||||
// get { return Path.DirectorySeparatorChar; }
|
||||
//}
|
||||
|
||||
// public static bool IsSameBase(string a, string b)
|
||||
// {
|
||||
// return FilePath.GetBase(a).EqualIgnoreCase(FilePath.GetBase(b));
|
||||
// }
|
||||
|
||||
// public static bool IsSameDir(string a, string b)
|
||||
// {
|
||||
// return FilePath.GetDir(a).EqualIgnoreCase(FilePath.GetDir(b));
|
||||
// }
|
||||
|
||||
// public static bool IsValidFileSystemName(string name)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(name))
|
||||
// return false;
|
||||
// dynamic chars = "\"*/:<>?\\|^".ToCharArray;
|
||||
|
||||
// foreach (void i_loopVariable in name.ToCharArray)
|
||||
// {
|
||||
// i = i_loopVariable;
|
||||
// if (chars.Contains(i))
|
||||
// return false;
|
||||
// if (Convert.ToInt32(i) < 32)
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// public static string RemoveIllegalCharsFromName(string name)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(name))
|
||||
// return "";
|
||||
|
||||
// dynamic chars = "\"*/:<>?\\|^".ToCharArray;
|
||||
|
||||
// foreach (void i_loopVariable in name.ToCharArray)
|
||||
// {
|
||||
// i = i_loopVariable;
|
||||
// if (chars.Contains(i))
|
||||
// {
|
||||
// name = name.Replace(i, "_");
|
||||
// }
|
||||
// }
|
||||
|
||||
// for (x = 1; x <= 31; x++)
|
||||
// {
|
||||
// if (name.Contains(Convert.ToChar(x)))
|
||||
// {
|
||||
// name = name.Replace(Convert.ToChar(x), '_');
|
||||
// }
|
||||
// }
|
||||
|
||||
// return name;
|
||||
}
|
||||
}
|
||||
25
mpvnet/UI.cs
25
mpvnet/UI.cs
@@ -51,29 +51,4 @@ namespace mpvnet
|
||||
Math.Abs(screenPos.Y - Control.MousePosition.Y) > 10;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MsgBox
|
||||
{
|
||||
public static void MsgInfo(string text)
|
||||
{
|
||||
MessageBox.Show(text, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
|
||||
public class ContextMenuEx : ContextMenu
|
||||
{
|
||||
public bool Visible { get ; set; }
|
||||
|
||||
protected override void OnCollapse(EventArgs e)
|
||||
{
|
||||
base.OnCollapse(e);
|
||||
Visible = false;
|
||||
}
|
||||
|
||||
protected override void OnPopup(EventArgs e)
|
||||
{
|
||||
base.OnPopup(e);
|
||||
Visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,13 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
using static mpvnet.libmpv;
|
||||
using static mpvnet.Native;
|
||||
using System.Drawing;
|
||||
|
||||
using vbnet;
|
||||
using static vbnet.UI.MainModule;
|
||||
|
||||
namespace mpvnet
|
||||
{
|
||||
@@ -47,6 +50,8 @@ namespace mpvnet
|
||||
public static Addon Addon;
|
||||
public static List<Action<bool>> BoolPropChangeActions = new List<Action<bool>>();
|
||||
public static Size VideoSize;
|
||||
public static string InputConfPath = Folder.AppDataRoaming + "mpv\\input.conf";
|
||||
public static StringPairList BindingList = new StringPairList();
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
@@ -54,7 +59,6 @@ namespace mpvnet
|
||||
MpvHandle = mpv_create();
|
||||
SetIntProp("input-ar-delay", 500);
|
||||
SetIntProp("input-ar-rate", 20);
|
||||
SetIntProp("osd-duration", 3000);
|
||||
SetIntProp("volume", 50);
|
||||
SetStringProp("hwdec", "auto");
|
||||
SetStringProp("input-default-bindings", "yes");
|
||||
@@ -110,7 +114,14 @@ namespace mpvnet
|
||||
if (ClientMessage != null)
|
||||
{
|
||||
var client_messageData = (mpv_event_client_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_client_message));
|
||||
ClientMessage?.Invoke(NativeUtf8StrArray2ManagedStrArray(client_messageData.args, client_messageData.num_args));
|
||||
var args = NativeUtf8StrArray2ManagedStrArray(client_messageData.args, client_messageData.num_args);
|
||||
|
||||
if (args != null && args.Length > 1 && args[0] == "mpv.net")
|
||||
foreach (var i in mpvnet.Command.Commands)
|
||||
if (args[1] == i.Name)
|
||||
i.Action(args.Skip(2).ToArray());
|
||||
|
||||
ClientMessage?.Invoke(args);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -151,7 +162,7 @@ namespace mpvnet
|
||||
int err = mpv_command_string(MpvHandle, command);
|
||||
|
||||
if (err < 0)
|
||||
throw new Exception($"{(mpv_error)err}");
|
||||
throw new Exception($"{(mpv_error)err}" + BR2 + command);
|
||||
}
|
||||
|
||||
public static void SetStringProp(string name, string value, bool throwException = true)
|
||||
@@ -242,6 +253,21 @@ namespace mpvnet
|
||||
LoadFolder();
|
||||
}
|
||||
|
||||
public static void LoadFiles(string[] files)
|
||||
{
|
||||
int count = mpv.GetIntProp("playlist-count");
|
||||
|
||||
foreach (string file in files)
|
||||
mpv.Command("loadfile", file, "append");
|
||||
|
||||
mpv.SetIntProp("playlist-pos", count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
mpv.Command("playlist-remove", "0");
|
||||
|
||||
mpv.LoadFolder();
|
||||
}
|
||||
|
||||
public static void LoadFolder()
|
||||
{
|
||||
if (GetIntProp("playlist-count") == 1)
|
||||
|
||||
@@ -104,6 +104,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Addon.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="StringExtensions.cs" />
|
||||
<Compile Include="libmpv.cs" />
|
||||
<Compile Include="MainForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
@@ -113,11 +115,11 @@
|
||||
</Compile>
|
||||
<Compile Include="Misc.cs" />
|
||||
<Compile Include="mpv.cs" />
|
||||
<Compile Include="Command.cs" />
|
||||
<Compile Include="Native.cs" />
|
||||
<Compile Include="NativeHelp.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="StringExtensions.cs" />
|
||||
<Compile Include="UI.cs" />
|
||||
<EmbeddedResource Include="MainForm.resx">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
@@ -148,7 +150,16 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="mpv.ico" />
|
||||
<Content Include="screenshot.jpg" />
|
||||
<None Include="Resources\input_conf.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\vbnet\vbnet.vbproj">
|
||||
<Project>{af1b21c5-28fc-4d47-ad0b-54f6a38391a6}</Project>
|
||||
<Name>vbnet</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
BIN
mpvnet/screenshot.jpg
Normal file
BIN
mpvnet/screenshot.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 497 KiB |
790
vbnet/Extensions.vb
Normal file
790
vbnet/Extensions.vb
Normal file
@@ -0,0 +1,790 @@
|
||||
Imports System.Drawing.Drawing2D
|
||||
Imports System.Globalization
|
||||
Imports System.IO
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.CompilerServices
|
||||
Imports System.Security.Cryptography
|
||||
Imports System.Text
|
||||
Imports Microsoft.Win32
|
||||
Imports VB6 = Microsoft.VisualBasic
|
||||
|
||||
Imports vbnet.UI
|
||||
|
||||
Module StringExtensions
|
||||
<Extension>
|
||||
Public Function Multiply(instance As String, multiplier As Integer) As String
|
||||
Dim sb As New StringBuilder(multiplier * instance.Length)
|
||||
|
||||
For i = 0 To multiplier - 1
|
||||
sb.Append(instance)
|
||||
Next
|
||||
|
||||
Return sb.ToString()
|
||||
End Function
|
||||
|
||||
<Extension>
|
||||
Function IsValidFileName(instance As String) As Boolean
|
||||
If instance = "" Then Return False
|
||||
Dim chars = """*/:<>?\|"
|
||||
|
||||
For Each i In instance
|
||||
If chars.Contains(i) Then Return False
|
||||
If Convert.ToInt32(i) < 32 Then Return False
|
||||
Next
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
<Extension>
|
||||
Function IsANSICompatible(instance As String) As Boolean
|
||||
If instance = "" Then Return True
|
||||
Dim bytes = Encoding.Convert(Encoding.Unicode, Encoding.Default, Encoding.Unicode.GetBytes(instance))
|
||||
Return instance = Encoding.Unicode.GetString(Encoding.Convert(Encoding.Default, Encoding.Unicode, bytes))
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function FileName(instance As String) As String
|
||||
If instance = "" Then Return ""
|
||||
Dim index = instance.LastIndexOf(Path.DirectorySeparatorChar)
|
||||
If index > -1 Then Return instance.Substring(index + 1)
|
||||
Return instance
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Upper(instance As String) As String
|
||||
If instance = "" Then Return ""
|
||||
Return instance.ToUpperInvariant
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Lower(instance As String) As String
|
||||
If instance = "" Then Return ""
|
||||
Return instance.ToLowerInvariant
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ChangeExt(instance As String, value As String) As String
|
||||
If instance = "" Then Return ""
|
||||
If value = "" Then Return instance
|
||||
If Not value.StartsWith(".") Then value = "." + value
|
||||
Return instance.DirAndBase + value.ToLower
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Escape(instance As String) As String
|
||||
If instance = "" Then Return ""
|
||||
|
||||
Dim chars = " ()".ToCharArray
|
||||
|
||||
For Each i In chars
|
||||
If instance.Contains(i) Then Return """" + instance + """"
|
||||
Next
|
||||
|
||||
Return instance
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Parent(instance As String) As String
|
||||
Return DirPath.GetParent(instance)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ExistingParent(instance As String) As String
|
||||
Dim ret = instance.Parent
|
||||
If Not Directory.Exists(ret) Then ret = ret.Parent Else Return ret
|
||||
If Not Directory.Exists(ret) Then ret = ret.Parent Else Return ret
|
||||
If Not Directory.Exists(ret) Then ret = ret.Parent Else Return ret
|
||||
If Not Directory.Exists(ret) Then ret = ret.Parent Else Return ret
|
||||
If Not Directory.Exists(ret) Then ret = ret.Parent Else Return ret
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Ext(instance As String) As String
|
||||
Return FilePath.GetExt(instance)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ExtFull(instance As String) As String
|
||||
Return FilePath.GetExtFull(instance)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Base(instance As String) As String
|
||||
Return FilePath.GetBase(instance)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Dir(instance As String) As String
|
||||
Return FilePath.GetDir(instance)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function DirName(instance As String) As String
|
||||
Return DirPath.GetName(instance)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function DirAndBase(instance As String) As String
|
||||
Return FilePath.GetDirAndBase(instance)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ContainsAll(instance As String, all As IEnumerable(Of String)) As Boolean
|
||||
If instance <> "" Then Return all.All(Function(arg) instance.Contains(arg))
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ContainsAny(instance As String, any As IEnumerable(Of String)) As Boolean
|
||||
If instance <> "" Then Return any.Any(Function(arg) instance.Contains(arg))
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function EqualsAny(instance As String, ParamArray values As String()) As Boolean
|
||||
If instance = "" OrElse values.NothingOrEmpty Then Return False
|
||||
Return values.Contains(instance)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function FixDir(instance As String) As String
|
||||
If instance = "" Then Return ""
|
||||
|
||||
While instance.EndsWith(DirPath.Separator + DirPath.Separator)
|
||||
instance = instance.Substring(0, instance.Length - 1)
|
||||
End While
|
||||
|
||||
If instance.EndsWith(DirPath.Separator) Then Return instance
|
||||
Return instance + DirPath.Separator
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function FixBreak(value As String) As String
|
||||
value = value.Replace(VB6.ChrW(13) + VB6.ChrW(10), VB6.ChrW(10))
|
||||
value = value.Replace(VB6.ChrW(13), VB6.ChrW(10))
|
||||
Return value.Replace(VB6.ChrW(10), VB6.ChrW(13) + VB6.ChrW(10))
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ContainsUnicode(value As String) As Boolean
|
||||
If value = "" Then Return False
|
||||
|
||||
For Each i In value
|
||||
If Convert.ToInt32(i) > 255 Then Return True
|
||||
Next
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ToTitleCase(value As String) As String
|
||||
'TextInfo.ToTitleCase won't work on all upper strings
|
||||
Return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value.ToLower)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function IsInt(value As String) As Boolean
|
||||
Return Integer.TryParse(value, Nothing)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ToInt(value As String, Optional defaultValue As Integer = 0) As Integer
|
||||
If Not Integer.TryParse(value, Nothing) Then Return defaultValue
|
||||
Return CInt(value)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function IsSingle(value As String) As Boolean
|
||||
If value <> "" Then
|
||||
If value.Contains(",") Then value = value.Replace(",", ".")
|
||||
|
||||
Return Single.TryParse(value,
|
||||
NumberStyles.Float Or NumberStyles.AllowThousands,
|
||||
CultureInfo.InvariantCulture,
|
||||
Nothing)
|
||||
End If
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ToSingle(value As String, Optional defaultValue As Single = 0) As Single
|
||||
If value <> "" Then
|
||||
If value.Contains(",") Then value = value.Replace(",", ".")
|
||||
|
||||
Dim ret As Single
|
||||
|
||||
If Single.TryParse(value,
|
||||
NumberStyles.Float Or NumberStyles.AllowThousands,
|
||||
CultureInfo.InvariantCulture,
|
||||
ret) Then
|
||||
Return ret
|
||||
End If
|
||||
End If
|
||||
|
||||
Return defaultValue
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function IsDouble(value As String) As Boolean
|
||||
If value <> "" Then
|
||||
If value.Contains(",") Then value = value.Replace(",", ".")
|
||||
|
||||
Return Double.TryParse(value,
|
||||
NumberStyles.Float Or NumberStyles.AllowThousands,
|
||||
CultureInfo.InvariantCulture,
|
||||
Nothing)
|
||||
End If
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ToDouble(value As String, Optional defaultValue As Single = 0) As Double
|
||||
If value <> "" Then
|
||||
If value.Contains(",") Then value = value.Replace(",", ".")
|
||||
|
||||
Dim ret As Double
|
||||
|
||||
If Double.TryParse(value,
|
||||
NumberStyles.Float Or NumberStyles.AllowThousands,
|
||||
CultureInfo.InvariantCulture,
|
||||
ret) Then
|
||||
Return ret
|
||||
End If
|
||||
End If
|
||||
|
||||
Return defaultValue
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function FormatColumn(value As String, delimiter As String) As String
|
||||
If value = "" Then Return ""
|
||||
Dim lines = value.SplitKeepEmpty(BR)
|
||||
Dim leftSides As New List(Of String)
|
||||
|
||||
For Each i In lines
|
||||
Dim pos = i.IndexOf(delimiter)
|
||||
|
||||
If pos > 0 Then
|
||||
leftSides.Add(i.Substring(0, pos).Trim)
|
||||
Else
|
||||
leftSides.Add(i)
|
||||
End If
|
||||
Next
|
||||
|
||||
Dim highest = Aggregate i In leftSides Into Max(i.Length)
|
||||
Dim ret As New List(Of String)
|
||||
|
||||
For i = 0 To lines.Length - 1
|
||||
Dim line = lines(i)
|
||||
|
||||
If line.Contains(delimiter) Then
|
||||
ret.Add(leftSides(i).PadRight(highest) + " " + delimiter + " " + line.Substring(line.IndexOf(delimiter) + 1).Trim)
|
||||
Else
|
||||
ret.Add(leftSides(i))
|
||||
End If
|
||||
Next
|
||||
|
||||
Return ret.Join(BR)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Sub WriteANSIFile(instance As String, path As String)
|
||||
WriteFile(instance, path, Encoding.Default)
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Sub WriteUTF8File(instance As String, path As String)
|
||||
WriteFile(instance, path, Encoding.UTF8)
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Sub WriteFile(value As String, path As String, encoding As Encoding)
|
||||
Try
|
||||
File.WriteAllText(path, value, encoding)
|
||||
Catch ex As Exception
|
||||
MsgException(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Function Left(value As String, index As Integer) As String
|
||||
If value = "" OrElse index < 0 Then Return ""
|
||||
If index > value.Length Then Return value
|
||||
Return value.Substring(0, index)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Left(value As String, start As String) As String
|
||||
If value = "" OrElse start = "" Then Return ""
|
||||
If Not value.Contains(start) Then Return ""
|
||||
Return value.Substring(0, value.IndexOf(start))
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function LeftLast(value As String, start As String) As String
|
||||
If Not value.Contains(start) Then Return ""
|
||||
Return value.Substring(0, value.LastIndexOf(start))
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Right(value As String, start As String) As String
|
||||
If value = "" OrElse start = "" Then Return ""
|
||||
If Not value.Contains(start) Then Return ""
|
||||
Return value.Substring(value.IndexOf(start) + start.Length)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function RightLast(value As String, start As String) As String
|
||||
If value = "" OrElse start = "" Then Return ""
|
||||
If Not value.Contains(start) Then Return ""
|
||||
Return value.Substring(value.LastIndexOf(start) + start.Length)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function EqualIgnoreCase(a As String, b As String) As Boolean
|
||||
If a = "" OrElse b = "" Then Return False
|
||||
Return String.Compare(a, b, StringComparison.OrdinalIgnoreCase) = 0
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Shorten(value As String, maxLength As Integer) As String
|
||||
If value = "" OrElse value.Length <= maxLength Then
|
||||
Return value
|
||||
End If
|
||||
|
||||
Return value.Substring(0, maxLength)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function SplitNoEmpty(value As String, ParamArray delimiters As String()) As String()
|
||||
Return value.Split(delimiters, StringSplitOptions.RemoveEmptyEntries)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function SplitKeepEmpty(value As String, ParamArray delimiters As String()) As String()
|
||||
Return value.Split(delimiters, StringSplitOptions.None)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function SplitNoEmptyAndWhiteSpace(value As String, ParamArray delimiters As String()) As String()
|
||||
If value = "" Then Return {}
|
||||
|
||||
Dim a = SplitNoEmpty(value, delimiters)
|
||||
|
||||
For i = 0 To a.Length - 1
|
||||
a(i) = a(i).Trim
|
||||
Next
|
||||
|
||||
Dim l = a.ToList
|
||||
|
||||
While l.Contains("")
|
||||
l.Remove("")
|
||||
End While
|
||||
|
||||
Return l.ToArray
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function SplitLinesNoEmpty(value As String) As String()
|
||||
Return SplitNoEmpty(value, Environment.NewLine)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function RemoveChars(value As String, chars As String) As String
|
||||
Dim ret = value
|
||||
|
||||
For Each i In value
|
||||
If chars.IndexOf(i) >= 0 Then
|
||||
ret = ret.Replace(i, "")
|
||||
End If
|
||||
Next
|
||||
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function DeleteRight(value As String, count As Integer) As String
|
||||
Return Left(value, value.Length - count)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ReplaceUnicode(value As String) As String
|
||||
If value.Contains(Convert.ToChar(&H2212)) Then
|
||||
value = value.Replace(Convert.ToChar(&H2212), "-"c)
|
||||
End If
|
||||
|
||||
Return value
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function SHA512Hash(value As String) As String
|
||||
Dim crypt = SHA512CryptoServiceProvider.Create()
|
||||
Dim hash = crypt.ComputeHash(ASCIIEncoding.ASCII.GetBytes(value))
|
||||
Dim sb As New StringBuilder()
|
||||
|
||||
For Each i In hash
|
||||
sb.Append(i.ToString("x2"))
|
||||
Next
|
||||
|
||||
Return sb.ToString()
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Sub ToClipboard(value As String)
|
||||
If value <> "" Then
|
||||
Clipboard.SetText(value)
|
||||
Else
|
||||
Clipboard.Clear()
|
||||
End If
|
||||
End Sub
|
||||
End Module
|
||||
|
||||
Module MiscExtensions
|
||||
<Extension()>
|
||||
Function ToInvariantString(instance As Double, format As String) As String
|
||||
Dim ret = instance.ToString(format, CultureInfo.InvariantCulture)
|
||||
|
||||
If (ret.Contains(".") OrElse ret.Contains(",")) AndAlso ret.EndsWith("0") Then
|
||||
ret = ret.TrimEnd("0"c)
|
||||
End If
|
||||
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ToInvariantString(instance As IConvertible) As String
|
||||
If Not instance Is Nothing Then Return instance.ToString(CultureInfo.InvariantCulture)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ContainsAny(Of T)(instance As IEnumerable(Of T), ParamArray values As T()) As Boolean
|
||||
Return instance.Where(Function(arg) values.Contains(arg)).Count > 0
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Sort(Of T)(instance As IEnumerable(Of T)) As IEnumerable(Of T)
|
||||
Dim ret = instance.ToArray
|
||||
Array.Sort(Of T)(ret)
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function Join(instance As IEnumerable(Of String),
|
||||
delimiter As String,
|
||||
Optional removeEmpty As Boolean = False) As String
|
||||
|
||||
If instance Is Nothing Then Return Nothing
|
||||
Dim containsEmpty As Boolean
|
||||
|
||||
For Each item In instance
|
||||
If item = "" Then
|
||||
containsEmpty = True
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If containsEmpty AndAlso removeEmpty Then instance = instance.Where(Function(arg) arg <> "")
|
||||
Return String.Join(delimiter, instance)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function GetAttribute(Of T)(mi As MemberInfo) As T
|
||||
Dim attributes = mi.GetCustomAttributes(True)
|
||||
|
||||
If Not attributes.NothingOrEmpty Then
|
||||
If attributes.Length = 1 Then
|
||||
If TypeOf attributes(0) Is T Then
|
||||
Return DirectCast(attributes(0), T)
|
||||
End If
|
||||
Else
|
||||
For Each i In attributes
|
||||
If TypeOf i Is T Then
|
||||
Return DirectCast(i, T)
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function IsDigit(c As Char) As Boolean
|
||||
Return Char.IsDigit(c)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function EnsureRange(value As Integer, min As Integer, max As Integer) As Integer
|
||||
If value < min Then
|
||||
value = min
|
||||
ElseIf value > max Then
|
||||
value = max
|
||||
End If
|
||||
|
||||
Return value
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function NeutralCulture(ci As CultureInfo) As CultureInfo
|
||||
If ci.IsNeutralCulture Then Return ci Else Return ci.Parent
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function NothingOrEmpty(strings As IEnumerable(Of String)) As Boolean
|
||||
If strings Is Nothing OrElse strings.Count = 0 Then Return True
|
||||
|
||||
For Each i In strings
|
||||
If i = "" Then Return True
|
||||
Next
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function NothingOrEmpty(objects As IEnumerable(Of Object)) As Boolean
|
||||
If objects Is Nothing OrElse objects.Count = 0 Then Return True
|
||||
|
||||
For Each i In objects
|
||||
If i Is Nothing Then Return True
|
||||
Next
|
||||
End Function
|
||||
End Module
|
||||
|
||||
Module RegistryKeyExtensions
|
||||
Private Function GetValue(Of T)(rootKey As RegistryKey, key As String, name As String) As T
|
||||
Using k = rootKey.OpenSubKey(key)
|
||||
If Not k Is Nothing Then
|
||||
Dim r = k.GetValue(name)
|
||||
|
||||
If Not r Is Nothing Then
|
||||
Try
|
||||
Return CType(r, T)
|
||||
Catch ex As Exception
|
||||
End Try
|
||||
End If
|
||||
End If
|
||||
End Using
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function GetString(rootKey As RegistryKey, subKey As String, name As String) As String
|
||||
Return GetValue(Of String)(rootKey, subKey, name)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function GetInt(rootKey As RegistryKey, subKey As String, name As String) As Integer
|
||||
Return GetValue(Of Integer)(rootKey, subKey, name)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function GetBoolean(rootKey As RegistryKey, subKey As String, name As String) As Boolean
|
||||
Return GetValue(Of Boolean)(rootKey, subKey, name)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function GetValueNames(rootKey As RegistryKey, subKeyName As String) As IEnumerable(Of String)
|
||||
Using k = rootKey.OpenSubKey(subKeyName)
|
||||
If Not k Is Nothing Then
|
||||
Return k.GetValueNames
|
||||
End If
|
||||
End Using
|
||||
|
||||
Return {}
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Sub GetSubKeys(rootKey As RegistryKey, keys As List(Of RegistryKey))
|
||||
If Not rootKey Is Nothing Then
|
||||
keys.Add(rootKey)
|
||||
|
||||
For Each i In rootKey.GetSubKeyNames
|
||||
GetSubKeys(rootKey.OpenSubKey(i), keys)
|
||||
Next
|
||||
End If
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Sub Write(rootKey As RegistryKey, subKey As String, valueName As String, valueValue As Object)
|
||||
Dim k = rootKey.OpenSubKey(subKey, True)
|
||||
|
||||
If k Is Nothing Then
|
||||
k = rootKey.CreateSubKey(subKey, RegistryKeyPermissionCheck.ReadWriteSubTree)
|
||||
End If
|
||||
|
||||
k.SetValue(valueName, valueValue)
|
||||
k.Close()
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Sub DeleteValue(rootKey As RegistryKey, key As String, valueName As String)
|
||||
Using k = rootKey.OpenSubKey(key, True)
|
||||
If Not k Is Nothing Then
|
||||
k.DeleteValue(valueName, False)
|
||||
End If
|
||||
End Using
|
||||
End Sub
|
||||
End Module
|
||||
|
||||
Module ControlExtension
|
||||
<Extension()>
|
||||
Sub ScaleClientSize(instance As Control, width As Single, height As Single)
|
||||
instance.ClientSize = New Size(CInt(instance.Font.Height * width), CInt(instance.Font.Height * height))
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Sub SetFontStyle(instance As Control, style As FontStyle)
|
||||
instance.Font = New Font(instance.Font.FontFamily, instance.Font.Size, style)
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Sub AddClickAction(instance As Control, action As Action)
|
||||
AddHandler instance.Click, Sub() action()
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Function ClientMousePos(instance As Control) As Point
|
||||
Return instance.PointToClient(Control.MousePosition)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function GetMaxTextSpace(instance As Control, ParamArray values As String()) As String
|
||||
Dim ret As String
|
||||
|
||||
For x = 4 To 2 Step -1
|
||||
ret = values.Join("".PadRight(x))
|
||||
Dim testWidth = TextRenderer.MeasureText(ret, instance.Font).Width
|
||||
If testWidth < instance.Width - 2 OrElse x = 2 Then Return ret
|
||||
Next
|
||||
|
||||
Return ret
|
||||
End Function
|
||||
End Module
|
||||
|
||||
Module UIExtensions
|
||||
<Extension()>
|
||||
Sub ClearAndDisplose(instance As ToolStripItemCollection)
|
||||
For Each i In instance.OfType(Of IDisposable).ToArray
|
||||
i.Dispose()
|
||||
Next
|
||||
|
||||
instance.Clear()
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Function ResizeToSmallIconSize(img As Image) As Image
|
||||
If Not img Is Nothing AndAlso img.Size <> SystemInformation.SmallIconSize Then
|
||||
Dim s = SystemInformation.SmallIconSize
|
||||
Dim r As New Bitmap(s.Width, s.Height)
|
||||
|
||||
Using g = Graphics.FromImage(DirectCast(r, Image))
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality
|
||||
g.DrawImage(img, 0, 0, s.Width, s.Height)
|
||||
End Using
|
||||
|
||||
Return r
|
||||
End If
|
||||
|
||||
Return img
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function ResizeImage(image As Image, ByVal height As Integer) As Image
|
||||
Dim percentHeight = height / image.Height
|
||||
Dim ret = New Bitmap(CInt(image.Width * percentHeight), CInt(height))
|
||||
|
||||
Using g = Graphics.FromImage(ret)
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic
|
||||
g.DrawImage(image, 0, 0, ret.Width, ret.Height)
|
||||
End Using
|
||||
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Sub SetSelectedPath(d As FolderBrowserDialog, path As String)
|
||||
If Not Directory.Exists(path) Then path = path.ExistingParent
|
||||
If Directory.Exists(path) Then d.SelectedPath = path
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Sub SetInitDir(d As FileDialog, ParamArray paths As String())
|
||||
For Each i In paths
|
||||
If Not Directory.Exists(i) Then i = i.ExistingParent
|
||||
|
||||
If Directory.Exists(i) Then
|
||||
d.InitialDirectory = i
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Sub SetFilter(d As FileDialog, values As IEnumerable(Of String))
|
||||
d.Filter = GetFilter(values)
|
||||
End Sub
|
||||
|
||||
Function GetFilter(values As IEnumerable(Of String)) As String
|
||||
Return "*." + values.Join(";*.") + "|*." + values.Join(";*.") + "|All Files|*.*"
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Sub SendMessageCue(tb As TextBox, value As String, hideWhenFocused As Boolean)
|
||||
Dim wParam = If(hideWhenFocused, 0, 1)
|
||||
Native.SendMessage(tb.Handle, Native.EM_SETCUEBANNER, wParam, value)
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Sub SendMessageCue(c As ComboBox, value As String)
|
||||
Native.SendMessage(c.Handle, Native.CB_SETCUEBANNER, 1, value)
|
||||
End Sub
|
||||
|
||||
Function GetPropertyValue(obj As String, propertyName As String) As Object
|
||||
obj.GetType.GetProperty(propertyName).GetValue(obj)
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Sub RemoveSelection(dgv As DataGridView)
|
||||
For Each i As DataGridViewRow In dgv.SelectedRows
|
||||
dgv.Rows.Remove(i)
|
||||
Next
|
||||
|
||||
If dgv.SelectedRows.Count = 0 AndAlso dgv.RowCount > 0 Then
|
||||
dgv.Rows(dgv.RowCount - 1).Selected = True
|
||||
End If
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Function CanMoveUp(dgv As DataGridView) As Boolean
|
||||
Return dgv.SelectedRows.Count > 0 AndAlso dgv.SelectedRows(0).Index > 0
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Function CanMoveDown(dgv As DataGridView) As Boolean
|
||||
Return dgv.SelectedRows.Count > 0 AndAlso dgv.SelectedRows(0).Index < dgv.RowCount - 1
|
||||
End Function
|
||||
|
||||
<Extension()>
|
||||
Sub MoveSelectionUp(dgv As DataGridView)
|
||||
If CanMoveUp(dgv) Then
|
||||
Dim bs = DirectCast(dgv.DataSource, BindingSource)
|
||||
Dim pos = bs.Position
|
||||
bs.RaiseListChangedEvents = False
|
||||
Dim current = bs.Current
|
||||
bs.Remove(current)
|
||||
pos -= 1
|
||||
bs.Insert(pos, current)
|
||||
bs.Position = pos
|
||||
bs.RaiseListChangedEvents = True
|
||||
bs.ResetBindings(False)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
<Extension()>
|
||||
Sub MoveSelectionDown(dgv As DataGridView)
|
||||
If CanMoveDown(dgv) Then
|
||||
Dim bs = DirectCast(dgv.DataSource, BindingSource)
|
||||
Dim pos = bs.Position
|
||||
bs.RaiseListChangedEvents = False
|
||||
Dim current = bs.Current
|
||||
bs.Remove(current)
|
||||
pos += 1
|
||||
bs.Insert(pos, current)
|
||||
bs.Position = pos
|
||||
bs.RaiseListChangedEvents = True
|
||||
bs.ResetBindings(False)
|
||||
End If
|
||||
End Sub
|
||||
End Module
|
||||
141
vbnet/HSLColor.vb
Normal file
141
vbnet/HSLColor.vb
Normal file
@@ -0,0 +1,141 @@
|
||||
Public Structure HSLColor
|
||||
Public Sub New(color As Color)
|
||||
SetRGB(color.R, color.G, color.B)
|
||||
End Sub
|
||||
|
||||
Public Sub New(h As Integer, s As Integer, l As Integer)
|
||||
Hue = h
|
||||
Saturation = s
|
||||
Luminosity = l
|
||||
End Sub
|
||||
|
||||
Private HueValue As Double
|
||||
|
||||
Property Hue As Integer
|
||||
Get
|
||||
Return CInt(HueValue * 240)
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
HueValue = CheckRange(value / 240)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private SaturationValue As Double
|
||||
|
||||
Property Saturation As Integer
|
||||
Get
|
||||
Return CInt(SaturationValue * 240)
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
SaturationValue = CheckRange(value / 240)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private LuminosityValue As Double
|
||||
|
||||
Property Luminosity As Integer
|
||||
Get
|
||||
Return CInt(LuminosityValue * 240)
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
LuminosityValue = CheckRange(value / 240)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private Function CheckRange(value As Double) As Double
|
||||
If value < 0 Then
|
||||
value = 0
|
||||
ElseIf value > 1 Then
|
||||
value = 1
|
||||
End If
|
||||
|
||||
Return value
|
||||
End Function
|
||||
|
||||
Function ToColorAddLuminosity(luminosity As Integer) As Color
|
||||
Me.Luminosity += luminosity
|
||||
Return ToColor()
|
||||
End Function
|
||||
|
||||
Function ToColorSetLuminosity(luminosity As Integer) As Color
|
||||
Me.Luminosity = luminosity
|
||||
Return ToColor()
|
||||
End Function
|
||||
|
||||
Function ToColor() As Color
|
||||
Dim r, g, b As Double
|
||||
|
||||
If LuminosityValue <> 0 Then
|
||||
If SaturationValue = 0 Then
|
||||
b = LuminosityValue
|
||||
g = LuminosityValue
|
||||
r = LuminosityValue
|
||||
Else
|
||||
Dim temp2 = GetTemp2(Me)
|
||||
Dim temp1 = 2.0 * LuminosityValue - temp2
|
||||
|
||||
r = GetColorComponent(temp1, temp2, HueValue + 1.0 / 3.0)
|
||||
g = GetColorComponent(temp1, temp2, HueValue)
|
||||
b = GetColorComponent(temp1, temp2, HueValue - 1.0 / 3.0)
|
||||
End If
|
||||
End If
|
||||
|
||||
Return Color.FromArgb(CInt(255 * r), CInt(255 * g), CInt(255 * b))
|
||||
End Function
|
||||
|
||||
Private Shared Function GetColorComponent(temp1 As Double,
|
||||
temp2 As Double,
|
||||
temp3 As Double) As Double
|
||||
temp3 = MoveIntoRange(temp3)
|
||||
|
||||
If temp3 < 1 / 6 Then
|
||||
Return temp1 + (temp2 - temp1) * 6.0 * temp3
|
||||
ElseIf temp3 < 0.5 Then
|
||||
Return temp2
|
||||
ElseIf temp3 < 2 / 3 Then
|
||||
Return temp1 + ((temp2 - temp1) * ((2 / 3) - temp3) * 6)
|
||||
Else
|
||||
Return temp1
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Shared Function MoveIntoRange(temp3 As Double) As Double
|
||||
If temp3 < 0 Then
|
||||
temp3 += 1
|
||||
ElseIf temp3 > 1 Then
|
||||
temp3 -= 1
|
||||
End If
|
||||
|
||||
Return temp3
|
||||
End Function
|
||||
|
||||
Private Shared Function GetTemp2(hslColor As HSLColor) As Double
|
||||
Dim temp2 As Double
|
||||
|
||||
If hslColor.LuminosityValue < 0.5 Then
|
||||
temp2 = hslColor.LuminosityValue * (1.0 + hslColor.SaturationValue)
|
||||
Else
|
||||
temp2 = hslColor.LuminosityValue + hslColor.SaturationValue - (hslColor.LuminosityValue * hslColor.SaturationValue)
|
||||
End If
|
||||
|
||||
Return temp2
|
||||
End Function
|
||||
|
||||
Public Shared Function Convert(c As Color) As HSLColor
|
||||
Dim r As New HSLColor()
|
||||
|
||||
r.HueValue = c.GetHue() / 360.0
|
||||
r.LuminosityValue = c.GetBrightness()
|
||||
r.SaturationValue = c.GetSaturation()
|
||||
|
||||
Return r
|
||||
End Function
|
||||
|
||||
Public Sub SetRGB(red As Integer, green As Integer, blue As Integer)
|
||||
Dim hc = HSLColor.Convert(Color.FromArgb(red, green, blue))
|
||||
|
||||
HueValue = hc.HueValue
|
||||
SaturationValue = hc.SaturationValue
|
||||
LuminosityValue = hc.LuminosityValue
|
||||
End Sub
|
||||
End Structure
|
||||
133
vbnet/MainModule.vb
Normal file
133
vbnet/MainModule.vb
Normal file
@@ -0,0 +1,133 @@
|
||||
Namespace UI
|
||||
Public Module MainModule
|
||||
Public ReadOnly BR As String = Environment.NewLine
|
||||
Public ReadOnly BR2 As String = Environment.NewLine + Environment.NewLine
|
||||
|
||||
Sub MsgInfo(text As String, Optional content As String = Nothing)
|
||||
Msg(text, content, MsgIcon.Info, TaskDialogButtons.Ok)
|
||||
End Sub
|
||||
|
||||
Sub MsgError(text As String, Optional content As String = Nothing)
|
||||
If text = "" Then text = content
|
||||
If text = "" Then Exit Sub
|
||||
|
||||
Using td As New TaskDialog(Of String)
|
||||
td.AllowCancel = False
|
||||
|
||||
If content = "" Then
|
||||
If text.Length < 80 Then
|
||||
td.MainInstruction = text
|
||||
Else
|
||||
td.Content = text
|
||||
End If
|
||||
Else
|
||||
td.MainInstruction = text
|
||||
td.Content = content
|
||||
End If
|
||||
|
||||
td.MainIcon = TaskDialogIcon.Error
|
||||
td.Footer = "[copymsg: Copy Message]"
|
||||
td.Show()
|
||||
End Using
|
||||
End Sub
|
||||
|
||||
Sub MsgWarn(text As String, Optional content As String = Nothing)
|
||||
Msg(text, content, MsgIcon.Warning, TaskDialogButtons.Ok)
|
||||
End Sub
|
||||
|
||||
Function MsgOK(text As String) As Boolean
|
||||
Return Msg(text, Nothing, MsgIcon.Question, TaskDialogButtons.OkCancel) = DialogResult.OK
|
||||
End Function
|
||||
|
||||
Function MsgQuestion(text As String,
|
||||
Optional buttons As TaskDialogButtons = TaskDialogButtons.OkCancel) As DialogResult
|
||||
Return Msg(text, Nothing, MsgIcon.Question, buttons)
|
||||
End Function
|
||||
|
||||
Function MsgQuestion(heading As String,
|
||||
content As String,
|
||||
Optional buttons As TaskDialogButtons = TaskDialogButtons.OkCancel) As DialogResult
|
||||
Return Msg(heading, content, MsgIcon.Question, buttons)
|
||||
End Function
|
||||
|
||||
Function Msg(mainInstruction As String,
|
||||
content As String,
|
||||
icon As MsgIcon,
|
||||
buttons As TaskDialogButtons,
|
||||
Optional defaultButton As DialogResult = DialogResult.None) As DialogResult
|
||||
|
||||
Try
|
||||
If mainInstruction Is Nothing Then mainInstruction = ""
|
||||
|
||||
Using td As New TaskDialog(Of DialogResult)
|
||||
td.AllowCancel = False
|
||||
td.DefaultButton = defaultButton
|
||||
|
||||
If content Is Nothing Then
|
||||
If mainInstruction.Length < 80 Then
|
||||
td.MainInstruction = mainInstruction
|
||||
Else
|
||||
td.Content = mainInstruction
|
||||
End If
|
||||
Else
|
||||
td.MainInstruction = mainInstruction
|
||||
td.Content = content
|
||||
End If
|
||||
|
||||
Select Case icon
|
||||
Case MsgIcon.Error
|
||||
td.MainIcon = TaskDialogIcon.Error
|
||||
Case MsgIcon.Warning
|
||||
td.MainIcon = TaskDialogIcon.Warning
|
||||
Case MsgIcon.Info
|
||||
td.MainIcon = TaskDialogIcon.Info
|
||||
End Select
|
||||
|
||||
If buttons = TaskDialogButtons.OkCancel Then
|
||||
td.AddButton("OK", DialogResult.OK)
|
||||
td.AddButton("Cancel", DialogResult.Cancel) 'don't use system language
|
||||
Else
|
||||
td.CommonButtons = buttons
|
||||
End If
|
||||
|
||||
Return td.Show()
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
MsgBox(mainInstruction + content, MessageBoxIcon.Error)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Sub MsgException(e As Exception, Optional msg As String = Nothing, Optional timeout As Integer = 0)
|
||||
Try
|
||||
Using td As New TaskDialog(Of String)
|
||||
If msg = "" Then
|
||||
td.MainInstruction = e.GetType.Name + $" ({Application.ProductVersion})"
|
||||
Else
|
||||
td.MainInstruction = msg
|
||||
End If
|
||||
|
||||
td.Timeout = timeout
|
||||
td.Content = e.Message
|
||||
td.MainIcon = TaskDialogIcon.Error
|
||||
td.ExpandedInformation = e.ToString
|
||||
td.Footer = "[copymsg: Copy Message]"
|
||||
td.Show()
|
||||
End Using
|
||||
Catch
|
||||
MsgBox(e.GetType.Name + BR2 + e.Message + BR2 + e.ToString, MessageBoxIcon.Error)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Sub MsgBox(text As String, icon As MessageBoxIcon)
|
||||
MessageBox.Show(text, Application.ProductName, MessageBoxButtons.OK, icon)
|
||||
End Sub
|
||||
End Module
|
||||
|
||||
Public Enum MsgIcon
|
||||
None = MessageBoxIcon.None
|
||||
Info = MessageBoxIcon.Information
|
||||
[Error] = MessageBoxIcon.Error
|
||||
Warning = MessageBoxIcon.Warning
|
||||
Question = MessageBoxIcon.Question
|
||||
End Enum
|
||||
End Namespace
|
||||
403
vbnet/Menu.vb
Normal file
403
vbnet/Menu.vb
Normal file
@@ -0,0 +1,403 @@
|
||||
Imports System.ComponentModel
|
||||
|
||||
Namespace UI
|
||||
Public Class MenuItemEx
|
||||
Inherits ToolStripMenuItem
|
||||
|
||||
Shared Property UseTooltips As Boolean
|
||||
|
||||
Sub New()
|
||||
End Sub
|
||||
|
||||
Sub New(text As String)
|
||||
MyBase.New(text)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function GetPreferredSize(constrainingSize As Size) As Size
|
||||
Dim ret = MyBase.GetPreferredSize(constrainingSize)
|
||||
ret.Height = CInt(Font.Height * 1.4)
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
Sub SetImage(symbol As Symbol)
|
||||
SetImage(symbol, Me)
|
||||
End Sub
|
||||
|
||||
Shared Async Sub SetImage(symbol As Symbol, mi As ToolStripMenuItem)
|
||||
If symbol = Symbol.None Then
|
||||
mi.Image = Nothing
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim img = Await ImageHelp.GetSymbolImageAsync(symbol)
|
||||
|
||||
Try
|
||||
If Not mi.IsDisposed Then
|
||||
mi.ImageScaling = ToolStripItemImageScaling.None
|
||||
mi.Image = img
|
||||
End If
|
||||
Catch
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Function ShouldSerializeHelpText() As Boolean
|
||||
Return HelpValue <> ""
|
||||
End Function
|
||||
|
||||
Private HelpValue As String
|
||||
|
||||
Property Help() As String
|
||||
Get
|
||||
Return HelpValue
|
||||
End Get
|
||||
Set(Value As String)
|
||||
HelpValue = Value
|
||||
|
||||
If UseTooltips Then
|
||||
If HelpValue <> "" Then
|
||||
If HelpValue.Length < 80 Then
|
||||
ToolTipText = HelpValue.TrimEnd("."c)
|
||||
Else
|
||||
ToolTipText = "Right-click for help"
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
|
||||
If e.Button = MouseButtons.Right AndAlso Help <> "" Then
|
||||
CloseAll(Me)
|
||||
ShowHelp(Text, Help)
|
||||
End If
|
||||
|
||||
MyBase.OnMouseDown(e)
|
||||
End Sub
|
||||
|
||||
Sub ShowHelp(title As String, content As String)
|
||||
If title <> "" Then title = title.TrimEnd("."c, ":"c)
|
||||
MsgInfo(title, content)
|
||||
End Sub
|
||||
|
||||
Sub CloseAll(item As Object)
|
||||
If TypeOf item Is ToolStripItem Then
|
||||
Dim d = DirectCast(item, ToolStripItem)
|
||||
CloseAll(d.Owner)
|
||||
End If
|
||||
|
||||
If TypeOf item Is ToolStripDropDown Then
|
||||
Dim d = DirectCast(item, ToolStripDropDown)
|
||||
d.Close()
|
||||
CloseAll(d.OwnerItem)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnClick(e As EventArgs)
|
||||
Application.DoEvents()
|
||||
MyBase.OnClick(e)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class ActionMenuItem
|
||||
Inherits MenuItemEx
|
||||
|
||||
Private Action As Action
|
||||
|
||||
Property EnabledFunc As Func(Of Boolean)
|
||||
Property VisibleFunc As Func(Of Boolean)
|
||||
|
||||
Property Form As Form
|
||||
|
||||
Sub New()
|
||||
End Sub
|
||||
|
||||
Sub New(text As String, a As Action)
|
||||
Me.New(text, a, Nothing)
|
||||
End Sub
|
||||
|
||||
Sub New(text As String,
|
||||
action As Action,
|
||||
Optional tooltip As String = Nothing,
|
||||
Optional enabled As Boolean = True)
|
||||
|
||||
Me.Text = text
|
||||
Me.Action = action
|
||||
Me.Help = tooltip
|
||||
Me.Enabled = enabled
|
||||
End Sub
|
||||
|
||||
Private ShortcutValue As Keys
|
||||
|
||||
Property Shortcut As Keys
|
||||
Get
|
||||
Return ShortcutValue
|
||||
End Get
|
||||
Set(value As Keys)
|
||||
ShortcutValue = value
|
||||
ShortcutKeyDisplayString = KeysHelp.GetKeyString(value) + " "
|
||||
AddHandler Form.KeyDown, AddressOf KeyDown
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Sub KeyDown(sender As Object, e As KeyEventArgs)
|
||||
If Enabled AndAlso e.KeyData = Shortcut AndAlso
|
||||
If(EnabledFunc Is Nothing, True, EnabledFunc.Invoke) AndAlso
|
||||
If(VisibleFunc Is Nothing, True, VisibleFunc.Invoke) Then
|
||||
|
||||
PerformClick()
|
||||
e.Handled = True
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Opening(sender As Object, e As CancelEventArgs)
|
||||
If Not EnabledFunc Is Nothing Then Enabled = EnabledFunc.Invoke
|
||||
If Not VisibleFunc Is Nothing Then Visible = VisibleFunc.Invoke
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnClick(e As EventArgs)
|
||||
Application.DoEvents()
|
||||
If Not Action Is Nothing Then Action()
|
||||
MyBase.OnClick(e)
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Dispose(disposing As Boolean)
|
||||
MyBase.Dispose(disposing)
|
||||
If Not Form Is Nothing Then RemoveHandler Form.KeyDown, AddressOf KeyDown
|
||||
Action = Nothing
|
||||
EnabledFunc = Nothing
|
||||
VisibleFunc = Nothing
|
||||
Form = Nothing
|
||||
End Sub
|
||||
|
||||
Shared Function Add(Of T)(items As ToolStripItemCollection,
|
||||
path As String,
|
||||
action As Action(Of T),
|
||||
value As T,
|
||||
Optional help As String = Nothing) As ActionMenuItem
|
||||
|
||||
Return Add(items, path, Sub() action(value), help)
|
||||
End Function
|
||||
|
||||
Shared Function Add(items As ToolStripItemCollection,
|
||||
path As String) As ActionMenuItem
|
||||
|
||||
Return Add(items, path, Nothing)
|
||||
End Function
|
||||
|
||||
Shared Function Add(items As ToolStripItemCollection,
|
||||
path As String,
|
||||
action As Action) As ActionMenuItem
|
||||
|
||||
Return Add(items, path, action, Symbol.None, Nothing)
|
||||
End Function
|
||||
|
||||
Shared Function Add(items As ToolStripItemCollection,
|
||||
path As String,
|
||||
action As Action,
|
||||
tip As String) As ActionMenuItem
|
||||
|
||||
Return Add(items, path, action, Symbol.None, tip)
|
||||
End Function
|
||||
|
||||
Shared Function Add(items As ToolStripItemCollection,
|
||||
path As String,
|
||||
action As Action,
|
||||
symbol As Symbol,
|
||||
Optional tip As String = Nothing) As ActionMenuItem
|
||||
|
||||
Dim a = path.SplitNoEmpty(" | ")
|
||||
Dim l = items
|
||||
|
||||
For x = 0 To a.Length - 1
|
||||
Dim found = False
|
||||
|
||||
For Each i In l.OfType(Of ToolStripMenuItem)()
|
||||
If x < a.Length - 1 Then
|
||||
If i.Text = a(x) Then
|
||||
found = True
|
||||
l = i.DropDownItems
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
If Not found Then
|
||||
If x = a.Length - 1 Then
|
||||
If a(x) = "-" Then
|
||||
l.Add(New ToolStripSeparator)
|
||||
Else
|
||||
Dim item As New ActionMenuItem(a(x), action, tip)
|
||||
item.SetImage(symbol)
|
||||
l.Add(item)
|
||||
l = item.DropDownItems
|
||||
Return item
|
||||
End If
|
||||
Else
|
||||
Dim item As New ActionMenuItem()
|
||||
item.Text = a(x)
|
||||
l.Add(item)
|
||||
l = item.DropDownItems
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Public Class ContextMenuStripEx
|
||||
Inherits ContextMenuStrip
|
||||
|
||||
Private FormValue As Form
|
||||
|
||||
Sub New()
|
||||
End Sub
|
||||
|
||||
Sub New(container As IContainer)
|
||||
MyBase.New(container)
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnOpening(e As CancelEventArgs)
|
||||
MyBase.OnOpening(e)
|
||||
MenuHelp.SetRenderer(Me)
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnHandleCreated(e As EventArgs)
|
||||
MyBase.OnHandleCreated(e)
|
||||
Font = New Font("Segoe UI", 9)
|
||||
End Sub
|
||||
|
||||
<DefaultValue(GetType(Form), Nothing)>
|
||||
Property Form As Form
|
||||
Get
|
||||
Return FormValue
|
||||
End Get
|
||||
Set(value As Form)
|
||||
AddHandler value.Disposed, Sub() Dispose()
|
||||
FormValue = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Function Add(path As String) As ActionMenuItem
|
||||
Return Add(path, Nothing)
|
||||
End Function
|
||||
|
||||
Function Add(path As String,
|
||||
action As Action) As ActionMenuItem
|
||||
|
||||
Return Add(path, action, Nothing)
|
||||
End Function
|
||||
|
||||
Function Add(path As String,
|
||||
action As Action,
|
||||
help As String) As ActionMenuItem
|
||||
|
||||
Return Add(path, action, help, True)
|
||||
End Function
|
||||
|
||||
Function Add(path As String,
|
||||
action As Action,
|
||||
help As String,
|
||||
enabled As Boolean) As ActionMenuItem
|
||||
|
||||
Dim ret = ActionMenuItem.Add(Items, path, action)
|
||||
If ret Is Nothing Then Exit Function
|
||||
|
||||
ret.Form = Form
|
||||
ret.Help = help
|
||||
ret.Enabled = enabled
|
||||
|
||||
AddHandler Opening, AddressOf ret.Opening
|
||||
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
Function Add(path As String,
|
||||
action As Action,
|
||||
shortcut As Keys,
|
||||
enabledFunc As Func(Of Boolean),
|
||||
Optional help As String = Nothing) As ActionMenuItem
|
||||
|
||||
Dim ret = ActionMenuItem.Add(Items, path, action)
|
||||
|
||||
ret.Form = Form
|
||||
ret.Shortcut = shortcut
|
||||
ret.EnabledFunc = enabledFunc
|
||||
ret.Help = help
|
||||
|
||||
AddHandler Opening, AddressOf ret.Opening
|
||||
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
Function GetTips() As StringPairList
|
||||
Dim ret As New StringPairList
|
||||
|
||||
For Each i In GetItems.OfType(Of ActionMenuItem)()
|
||||
If i.Help <> "" Then
|
||||
Dim pair As New StringPair
|
||||
|
||||
If i.Text.EndsWith("...") Then
|
||||
pair.Name = i.Text.TrimEnd("."c)
|
||||
Else
|
||||
pair.Name = i.Text
|
||||
End If
|
||||
|
||||
pair.Value = i.Help
|
||||
ret.Add(pair)
|
||||
End If
|
||||
Next
|
||||
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
Function GetKeys() As StringPairList
|
||||
Dim ret As New StringPairList
|
||||
|
||||
For Each i In GetItems.OfType(Of ActionMenuItem)()
|
||||
If i.ShortcutKeyDisplayString <> "" Then
|
||||
Dim sp As New StringPair
|
||||
|
||||
If i.Text.EndsWith("...") Then
|
||||
sp.Name = i.Text.TrimEnd("."c)
|
||||
Else
|
||||
sp.Name = i.Text
|
||||
End If
|
||||
|
||||
sp.Value = i.ShortcutKeyDisplayString
|
||||
ret.Add(sp)
|
||||
End If
|
||||
Next
|
||||
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
Function GetItems() As List(Of ToolStripItem)
|
||||
Dim ret As New List(Of ToolStripItem)
|
||||
AddItemsRecursive(Items, ret)
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
Shared Sub AddItemsRecursive(searchList As ToolStripItemCollection, returnList As List(Of ToolStripItem))
|
||||
For Each i As ToolStripItem In searchList
|
||||
returnList.Add(i)
|
||||
|
||||
If TypeOf i Is ToolStripDropDownItem Then
|
||||
AddItemsRecursive(DirectCast(i, ToolStripDropDownItem).DropDownItems, returnList)
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class MenuHelp
|
||||
Shared Sub SetRenderer(ms As ToolStrip)
|
||||
ms.Renderer = New ToolStripRendererEx(ToolStripRenderModeEx.SystemAuto)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Enum ToolStripRenderModeEx
|
||||
SystemAuto
|
||||
SystemDefault
|
||||
Win7Auto
|
||||
Win7Default
|
||||
Win10Auto
|
||||
Win10Default
|
||||
End Enum
|
||||
End Namespace
|
||||
465
vbnet/Misc.vb
Normal file
465
vbnet/Misc.vb
Normal file
@@ -0,0 +1,465 @@
|
||||
Imports System.ComponentModel
|
||||
Imports System.IO
|
||||
Imports System.Runtime.InteropServices
|
||||
Imports System.Security.Permissions
|
||||
Imports System.Text
|
||||
|
||||
Imports vbnet.UI
|
||||
|
||||
Public Class OSVersion
|
||||
Shared Property Windows7 As Single = 6.1
|
||||
Shared Property Windows8 As Single = 6.2
|
||||
Shared Property Windows10 As Single = 10.0
|
||||
|
||||
Shared ReadOnly Property Current As Single
|
||||
Get
|
||||
Return CSng(Environment.OSVersion.Version.Major + Environment.OSVersion.Version.Minor / 10)
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
|
||||
Public Class ProcessHelp
|
||||
Shared Sub Start(cmd As String, Optional args As String = Nothing)
|
||||
Try
|
||||
Process.Start(cmd, args)
|
||||
Catch ex As Exception
|
||||
If cmd Like "http*://*" Then
|
||||
MsgError("Failed to open URL with browser." + BR2 + cmd, ex.Message)
|
||||
ElseIf File.Exists(cmd) Then
|
||||
MsgError("Failed to launch file." + BR2 + cmd, ex.Message)
|
||||
ElseIf Directory.Exists(cmd) Then
|
||||
MsgError("Failed to launch directory." + BR2 + cmd, ex.Message)
|
||||
Else
|
||||
MsgException(ex, "Failed to execute command:" + BR2 + cmd + BR2 + "Arguments:" + BR2 + args)
|
||||
End If
|
||||
End Try
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class KeysHelp
|
||||
Private Shared Converter As TypeConverter = TypeDescriptor.GetConverter(GetType(Keys))
|
||||
Private Shared KeysTexts As Dictionary(Of Keys, String)
|
||||
|
||||
Shared Sub New()
|
||||
KeysTexts = New Dictionary(Of Keys, String)
|
||||
KeysTexts(Keys.Add) = "+ (Numpad)"
|
||||
KeysTexts(Keys.Back) = "Back"
|
||||
KeysTexts(Keys.Decimal) = "Decimal"
|
||||
KeysTexts(Keys.Delete) = "Delete"
|
||||
KeysTexts(Keys.Divide) = "Divide"
|
||||
KeysTexts(Keys.Down) = "Down"
|
||||
KeysTexts(Keys.End) = "End"
|
||||
KeysTexts(Keys.Enter) = "Enter"
|
||||
KeysTexts(Keys.Escape) = "Escape"
|
||||
KeysTexts(Keys.Home) = "Home"
|
||||
KeysTexts(Keys.Insert) = "Insert"
|
||||
KeysTexts(Keys.Left) = "Left"
|
||||
KeysTexts(Keys.Multiply) = "Multiply"
|
||||
KeysTexts(Keys.Next) = "Page Down"
|
||||
KeysTexts(Keys.Prior) = "Page Up"
|
||||
KeysTexts(Keys.Right) = "Right"
|
||||
KeysTexts(Keys.Space) = "Space"
|
||||
KeysTexts(Keys.Subtract) = "- (Numpad)"
|
||||
KeysTexts(Keys.Up) = "Up"
|
||||
KeysTexts(Keys.Control) = "Control"
|
||||
KeysTexts(Keys.Alt) = "Alt"
|
||||
KeysTexts(Keys.Shift) = "Shift"
|
||||
|
||||
KeysTexts(Keys.D0) = "0"
|
||||
KeysTexts(Keys.D1) = "1"
|
||||
KeysTexts(Keys.D2) = "2"
|
||||
KeysTexts(Keys.D3) = "3"
|
||||
KeysTexts(Keys.D4) = "4"
|
||||
KeysTexts(Keys.D5) = "5"
|
||||
KeysTexts(Keys.D6) = "6"
|
||||
KeysTexts(Keys.D7) = "7"
|
||||
KeysTexts(Keys.D8) = "8"
|
||||
KeysTexts(Keys.D9) = "9"
|
||||
|
||||
KeysTexts(Keys.NumPad0) = "0 (Numpad)"
|
||||
KeysTexts(Keys.NumPad1) = "1 (Numpad)"
|
||||
KeysTexts(Keys.NumPad2) = "2 (Numpad)"
|
||||
KeysTexts(Keys.NumPad3) = "3 (Numpad)"
|
||||
KeysTexts(Keys.NumPad4) = "4 (Numpad)"
|
||||
KeysTexts(Keys.NumPad5) = "5 (Numpad)"
|
||||
KeysTexts(Keys.NumPad6) = "6 (Numpad)"
|
||||
KeysTexts(Keys.NumPad7) = "7 (Numpad)"
|
||||
KeysTexts(Keys.NumPad8) = "8 (Numpad)"
|
||||
KeysTexts(Keys.NumPad9) = "9 (Numpad)"
|
||||
End Sub
|
||||
|
||||
Shared Function GetKeyString(k As Keys) As String
|
||||
If k = Keys.None Then Return ""
|
||||
|
||||
Dim s = ""
|
||||
|
||||
If (k And Keys.Control) = Keys.Control Then
|
||||
k = k Xor Keys.Control
|
||||
s += "Ctrl+"
|
||||
End If
|
||||
|
||||
If (k And Keys.Alt) = Keys.Alt Then
|
||||
k = k Xor Keys.Alt
|
||||
s += "Alt+"
|
||||
End If
|
||||
|
||||
If (k And Keys.Shift) = Keys.Shift Then
|
||||
k = k Xor Keys.Shift
|
||||
s += "Shift+"
|
||||
End If
|
||||
|
||||
If KeysTexts.ContainsKey(k) Then
|
||||
s += KeysTexts(k)
|
||||
Else
|
||||
Dim value = MapVirtualKey(CInt(k), 2) 'MAPVK_VK_TO_CHAR
|
||||
|
||||
If value = 0 OrElse (value And 1 << 31) = 1 << 31 Then
|
||||
s += k.ToString
|
||||
Else
|
||||
s += Convert.ToChar(value)
|
||||
End If
|
||||
End If
|
||||
|
||||
Return s
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Function MapVirtualKey(wCode As Integer, wMapType As Integer) As Integer
|
||||
End Function
|
||||
End Class
|
||||
|
||||
<Serializable>
|
||||
Public Class StringPair
|
||||
Implements IComparable(Of StringPair)
|
||||
|
||||
Property Name As String
|
||||
Property Value As String
|
||||
|
||||
Sub New()
|
||||
End Sub
|
||||
|
||||
Sub New(name As String, text As String)
|
||||
Me.Name = name
|
||||
Me.Value = text
|
||||
End Sub
|
||||
|
||||
Function CompareTo(other As StringPair) As Integer Implements System.IComparable(Of StringPair).CompareTo
|
||||
Return Name.CompareTo(other.Name)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
<Serializable()>
|
||||
Public Class StringPairList
|
||||
Inherits List(Of StringPair)
|
||||
|
||||
Sub New()
|
||||
End Sub
|
||||
|
||||
Sub New(list As IEnumerable(Of StringPair))
|
||||
AddRange(list)
|
||||
End Sub
|
||||
|
||||
Overloads Sub Add(name As String, text As String)
|
||||
Add(New StringPair(name, text))
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class Folder
|
||||
|
||||
#Region "System"
|
||||
|
||||
Shared ReadOnly Property Desktop() As String
|
||||
Get
|
||||
Return Environment.GetFolderPath(Environment.SpecialFolder.Desktop).FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared ReadOnly Property Startup() As String
|
||||
Get
|
||||
Return Application.StartupPath.FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared ReadOnly Property Current() As String
|
||||
Get
|
||||
Return Environment.CurrentDirectory.FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared ReadOnly Property Temp() As String
|
||||
Get
|
||||
Return Path.GetTempPath.FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared ReadOnly Property System() As String
|
||||
Get
|
||||
Return Environment.SystemDirectory.FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared ReadOnly Property Programs() As String
|
||||
Get
|
||||
Return GetFolderPath(Environment.SpecialFolder.ProgramFiles).FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared ReadOnly Property Home() As String
|
||||
Get
|
||||
Return GetFolderPath(Environment.SpecialFolder.UserProfile).FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared ReadOnly Property AppDataCommon() As String
|
||||
Get
|
||||
Return GetFolderPath(Environment.SpecialFolder.CommonApplicationData).FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared ReadOnly Property AppDataLocal() As String
|
||||
Get
|
||||
Return GetFolderPath(Environment.SpecialFolder.LocalApplicationData).FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared ReadOnly Property AppDataRoaming() As String
|
||||
Get
|
||||
Return GetFolderPath(Environment.SpecialFolder.ApplicationData).FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared ReadOnly Property Windows() As String
|
||||
Get
|
||||
Return GetFolderPath(Environment.SpecialFolder.Windows).FixDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "StaxRip"
|
||||
|
||||
Shared ReadOnly Property Apps As String
|
||||
Get
|
||||
Return Folder.Startup + "Apps\"
|
||||
End Get
|
||||
End Property
|
||||
|
||||
#End Region
|
||||
|
||||
<DllImport("shfolder.dll", CharSet:=CharSet.Unicode)>
|
||||
Private Shared Function SHGetFolderPath(hwndOwner As IntPtr, nFolder As Integer, hToken As IntPtr, dwFlags As Integer, lpszPath As StringBuilder) As Integer
|
||||
End Function
|
||||
|
||||
Private Shared Function GetFolderPath(folder As Environment.SpecialFolder) As String
|
||||
Dim sb As New StringBuilder(260)
|
||||
SHGetFolderPath(IntPtr.Zero, CInt(folder), IntPtr.Zero, 0, sb)
|
||||
Dim ret = sb.ToString.FixDir '.NET fails on 'D:'
|
||||
Call New FileIOPermission(FileIOPermissionAccess.PathDiscovery, ret).Demand()
|
||||
Return ret
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Public Class PathBase
|
||||
Shared ReadOnly Property Separator() As Char
|
||||
Get
|
||||
Return Path.DirectorySeparatorChar
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Shared Function IsSameBase(a As String, b As String) As Boolean
|
||||
Return FilePath.GetBase(a).EqualIgnoreCase(FilePath.GetBase(b))
|
||||
End Function
|
||||
|
||||
Shared Function IsSameDir(a As String, b As String) As Boolean
|
||||
Return FilePath.GetDir(a).EqualIgnoreCase(FilePath.GetDir(b))
|
||||
End Function
|
||||
|
||||
Shared Function IsValidFileSystemName(name As String) As Boolean
|
||||
If name = "" Then Return False
|
||||
Dim chars = """*/:<>?\|^".ToCharArray
|
||||
|
||||
For Each i In name.ToCharArray
|
||||
If chars.Contains(i) Then Return False
|
||||
If Convert.ToInt32(i) < 32 Then Return False
|
||||
Next
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Shared Function RemoveIllegalCharsFromName(name As String) As String
|
||||
If name = "" Then Return ""
|
||||
|
||||
Dim chars = """*/:<>?\|^".ToCharArray
|
||||
|
||||
For Each i In name.ToCharArray
|
||||
If chars.Contains(i) Then
|
||||
name = name.Replace(i, "_")
|
||||
End If
|
||||
Next
|
||||
|
||||
For x = 1 To 31
|
||||
If name.Contains(Convert.ToChar(x)) Then
|
||||
name = name.Replace(Convert.ToChar(x), "_"c)
|
||||
End If
|
||||
Next
|
||||
|
||||
Return name
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Public Class DirPath
|
||||
Inherits PathBase
|
||||
|
||||
Shared Function TrimTrailingSeparator(path As String) As String
|
||||
If path = "" Then Return ""
|
||||
|
||||
If path.EndsWith(Separator) AndAlso Not path.Length <= 3 Then
|
||||
Return path.TrimEnd(Separator)
|
||||
End If
|
||||
|
||||
Return path
|
||||
End Function
|
||||
|
||||
Shared Function FixSeperator(path As String) As String
|
||||
If path.Contains("\") AndAlso Separator <> "\" Then
|
||||
path = path.Replace("\", Separator)
|
||||
End If
|
||||
|
||||
If path.Contains("/") AndAlso Separator <> "/" Then
|
||||
path = path.Replace("/", Separator)
|
||||
End If
|
||||
|
||||
Return path
|
||||
End Function
|
||||
|
||||
Shared Function GetParent(path As String) As String
|
||||
If path = "" Then Return ""
|
||||
Dim temp = TrimTrailingSeparator(path)
|
||||
If temp.Contains(Separator) Then path = temp.LeftLast(Separator) + Separator
|
||||
Return path
|
||||
End Function
|
||||
|
||||
Shared Function GetName(path As String) As String
|
||||
If path = "" Then Return ""
|
||||
path = TrimTrailingSeparator(path)
|
||||
Return path.RightLast(Separator)
|
||||
End Function
|
||||
|
||||
Shared Function IsInSysDir(path As String) As Boolean
|
||||
If path = "" Then Return False
|
||||
If Not path.EndsWith("\") Then path += "\"
|
||||
Return path.ToUpper.Contains(Folder.Programs.ToUpper)
|
||||
End Function
|
||||
|
||||
Shared Function IsFixedDrive(path As String) As Boolean
|
||||
Try
|
||||
If path <> "" Then Return New DriveInfo(path).DriveType = DriveType.Fixed
|
||||
Catch ex As Exception
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Public Class FilePath
|
||||
Inherits PathBase
|
||||
|
||||
Private Value As String
|
||||
|
||||
Sub New(path As String)
|
||||
Value = path
|
||||
End Sub
|
||||
|
||||
Shared Function GetDir(path As String) As String
|
||||
If path = "" Then Return ""
|
||||
If path.Contains("\") Then path = path.LeftLast("\") + "\"
|
||||
Return path
|
||||
End Function
|
||||
|
||||
Shared Function GetDirAndBase(path As String) As String
|
||||
Return GetDir(path) + GetBase(path)
|
||||
End Function
|
||||
|
||||
Shared Function GetName(path As String) As String
|
||||
If Not path Is Nothing Then
|
||||
Dim index = path.LastIndexOf(IO.Path.DirectorySeparatorChar)
|
||||
|
||||
If index > -1 Then
|
||||
Return path.Substring(index + 1)
|
||||
End If
|
||||
End If
|
||||
|
||||
Return path
|
||||
End Function
|
||||
|
||||
Shared Function GetExtFull(filepath As String) As String
|
||||
Return GetExt(filepath, True)
|
||||
End Function
|
||||
|
||||
Shared Function GetExt(filepath As String) As String
|
||||
Return GetExt(filepath, False)
|
||||
End Function
|
||||
|
||||
Shared Function GetExt(filepath As String, dot As Boolean) As String
|
||||
If filepath = "" Then Return ""
|
||||
Dim chars = filepath.ToCharArray
|
||||
|
||||
For x = filepath.Length - 1 To 0 Step -1
|
||||
If chars(x) = Separator Then Return ""
|
||||
If chars(x) = "."c Then Return filepath.Substring(x + If(dot, 0, 1)).ToLower
|
||||
Next
|
||||
|
||||
Return ""
|
||||
End Function
|
||||
|
||||
Shared Function GetDirNoSep(path As String) As String
|
||||
path = GetDir(path)
|
||||
If path.EndsWith(Separator) Then path = TrimSep(path)
|
||||
Return path
|
||||
End Function
|
||||
|
||||
Shared Function GetBase(path As String) As String
|
||||
If path = "" Then Return ""
|
||||
Dim ret = path
|
||||
If ret.Contains(Separator) Then ret = ret.RightLast(Separator)
|
||||
If ret.Contains(".") Then ret = ret.LeftLast(".")
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
Shared Function TrimSep(path As String) As String
|
||||
If path = "" Then Return ""
|
||||
|
||||
If path.EndsWith(Separator) AndAlso Not path.EndsWith(":" + Separator) Then
|
||||
Return path.TrimEnd(Separator)
|
||||
End If
|
||||
|
||||
Return path
|
||||
End Function
|
||||
|
||||
Shared Function GetDirNameOnly(path As String) As String
|
||||
Return FilePath.GetDirNoSep(path).RightLast("\")
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Public Class OS
|
||||
Shared Function GetTextEditor() As String
|
||||
Dim ret = GetAssociatedApplication(".txt")
|
||||
If ret <> "" Then Return ret
|
||||
Return "notepad.exe"
|
||||
End Function
|
||||
|
||||
Shared Function GetAssociatedApplication(ext As String) As String
|
||||
Dim c = 0UI
|
||||
|
||||
'ASSOCF_VERIFY, ASSOCSTR_EXECUTABLE
|
||||
If 1 = Native.AssocQueryString(&H40, 2, ext, Nothing, Nothing, c) Then
|
||||
If c > 0 Then
|
||||
Dim sb As New StringBuilder(CInt(c))
|
||||
|
||||
'ASSOCF_VERIFY, ASSOCSTR_EXECUTABLE
|
||||
If 0 = Native.AssocQueryString(&H40, 2, ext, Nothing, sb, c) Then
|
||||
Dim ret = sb.ToString
|
||||
If File.Exists(ret) Then Return ret
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End Function
|
||||
End Class
|
||||
13
vbnet/My Project/Application.Designer.vb
generated
Normal file
13
vbnet/My Project/Application.Designer.vb
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
10
vbnet/My Project/Application.myapp
Normal file
10
vbnet/My Project/Application.myapp
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<MySubMain>false</MySubMain>
|
||||
<SingleInstance>false</SingleInstance>
|
||||
<ShutdownMode>0</ShutdownMode>
|
||||
<EnableVisualStyles>true</EnableVisualStyles>
|
||||
<AuthenticationMode>0</AuthenticationMode>
|
||||
<ApplicationType>1</ApplicationType>
|
||||
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
|
||||
</MyApplicationData>
|
||||
35
vbnet/My Project/AssemblyInfo.vb
Normal file
35
vbnet/My Project/AssemblyInfo.vb
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
||||
|
||||
<Assembly: AssemblyTitle("vbnet")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("")>
|
||||
<Assembly: AssemblyProduct("vbnet")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2017")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
'The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
<Assembly: Guid("82111131-50ca-475d-afda-bafda7e5bf69")>
|
||||
|
||||
' 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")>
|
||||
63
vbnet/My Project/Resources.Designer.vb
generated
Normal file
63
vbnet/My Project/Resources.Designer.vb
generated
Normal file
@@ -0,0 +1,63 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
'''<summary>
|
||||
''' A strongly-typed resource class, for looking up localized strings, etc.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Returns the cached ResourceManager instance used by this class.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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("vbnet.Resources", GetType(Resources).Assembly)
|
||||
resourceMan = temp
|
||||
End If
|
||||
Return resourceMan
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Overrides the current thread's CurrentUICulture property for all
|
||||
''' resource lookups using this strongly typed resource class.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
117
vbnet/My Project/Resources.resx
Normal file
117
vbnet/My Project/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
73
vbnet/My Project/Settings.Designer.vb
generated
Normal file
73
vbnet/My Project/Settings.Designer.vb
generated
Normal file
@@ -0,0 +1,73 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.3.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
Friend ReadOnly Property Settings() As Global.vbnet.My.MySettings
|
||||
Get
|
||||
Return Global.vbnet.My.MySettings.Default
|
||||
End Get
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
7
vbnet/My Project/Settings.settings
Normal file
7
vbnet/My Project/Settings.settings
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
278
vbnet/Native.vb
Normal file
278
vbnet/Native.vb
Normal file
@@ -0,0 +1,278 @@
|
||||
Imports System.Runtime.InteropServices
|
||||
Imports System.Text
|
||||
|
||||
Public Class Native
|
||||
Public Delegate Function CallbackHandler(handle As IntPtr, parameter As Integer) As Boolean
|
||||
|
||||
<DllImport("gdi32.dll")>
|
||||
Public Shared Function ExcludeClipRect(hdc As IntPtr, nLeftRect As Integer, nTopRect As Integer, nRightRect As Integer, nBottomRect As Integer) As Integer
|
||||
End Function
|
||||
|
||||
#Region "Constants"
|
||||
|
||||
Friend Const EM_SETCUEBANNER As Integer = &H1501
|
||||
Friend Const CB_SETCUEBANNER As Integer = &H1703
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "Function"
|
||||
|
||||
#Region "user32.dll"
|
||||
<DllImport("user32.dll", SetLastError:=True)>
|
||||
Shared Function SetWindowPos(hWnd As IntPtr,
|
||||
hWndInsertAfter As IntPtr,
|
||||
X As Integer,
|
||||
Y As Integer,
|
||||
cx As Integer,
|
||||
cy As Integer,
|
||||
uFlags As UInteger) As Boolean
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Function GetWindowLong(hWnd As IntPtr, nIndex As Integer) As Integer
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function RegisterWindowMessage(id As String) As Integer
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Function RegisterHotKey(hWnd As IntPtr, id As Integer, fsModifiers As Integer, vk As Integer) As Boolean
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Function MapVirtualKey(wCode As Integer, wMapType As Integer) As Integer
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Function UnregisterHotKey(hWnd As IntPtr, id As Integer) As Boolean
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Function GetForegroundWindow() As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll", SetLastError:=True)>
|
||||
Shared Function GetWindowThreadProcessId(hwnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Function SetForegroundWindow(handle As IntPtr) As Boolean
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function GetWindowModuleFileName(hwnd As IntPtr,
|
||||
lpszFileName As StringBuilder,
|
||||
cchFileNameMax As UInteger) As UInteger
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Function SendMessage(handle As IntPtr,
|
||||
message As Int32,
|
||||
wParam As IntPtr,
|
||||
lParam As IntPtr) As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function SendMessage(hWnd As IntPtr,
|
||||
Msg As Int32,
|
||||
wParam As IntPtr,
|
||||
lParam As String) As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function SendMessage(hWnd As IntPtr,
|
||||
Msg As Int32,
|
||||
wParam As Integer,
|
||||
lParam As Integer) As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function SendMessage(hWnd As IntPtr,
|
||||
Msg As Int32,
|
||||
wParam As Integer,
|
||||
lParam As String) As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function SendMessage(hWnd As IntPtr,
|
||||
Msg As Int32,
|
||||
ByRef wParam As IntPtr,
|
||||
lParam As StringBuilder) As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Function SendMessageTimeout(windowHandle As IntPtr,
|
||||
msg As Integer,
|
||||
wParam As IntPtr,
|
||||
lParam As IntPtr,
|
||||
flags As Integer,
|
||||
timeout As Integer,
|
||||
ByRef result As IntPtr) As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function PostMessage(hwnd As IntPtr,
|
||||
wMsg As Integer,
|
||||
wParam As IntPtr,
|
||||
lParam As IntPtr) As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Sub ReleaseCapture()
|
||||
End Sub
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Public Shared Function GetWindowRect(hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Public Shared Function GetWindowDC(hWnd As IntPtr) As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Public Shared Function ReleaseDC(hWnd As IntPtr, hDC As IntPtr) As Integer
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "kernel32.dll"
|
||||
|
||||
<DllImport("kernel32.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function LoadLibrary(path As String) As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("kernel32.dll", SetLastError:=True)>
|
||||
Shared Function FreeLibrary(hModule As IntPtr) As Boolean
|
||||
End Function
|
||||
|
||||
<DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
|
||||
Shared Function FormatMessage(dwFlags As Integer,
|
||||
lpSource As IntPtr,
|
||||
dwMessageId As Integer,
|
||||
dwLanguageId As Integer,
|
||||
ByRef lpBuffer As String,
|
||||
nSize As Integer,
|
||||
Arguments As IntPtr) As Integer
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
<DllImport("uxtheme.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function SetWindowTheme(hWnd As IntPtr,
|
||||
pszSubAppName As String,
|
||||
pszSubIdList As String) As Integer
|
||||
End Function
|
||||
|
||||
<DllImport("Shlwapi.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
|
||||
Shared Function AssocQueryString(
|
||||
flags As UInteger,
|
||||
str As UInteger,
|
||||
pszAssoc As String,
|
||||
pszExtra As String,
|
||||
pszOut As StringBuilder,
|
||||
ByRef pcchOut As UInteger) As UInteger
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "Structures"
|
||||
|
||||
Public Structure RECT
|
||||
Public Left As Integer
|
||||
Public Top As Integer
|
||||
Public Right As Integer
|
||||
Public Bottom As Integer
|
||||
|
||||
Sub New(r As Rectangle)
|
||||
Left = r.Left
|
||||
Top = r.Top
|
||||
Right = r.Right
|
||||
Bottom = r.Bottom
|
||||
End Sub
|
||||
|
||||
Public Sub New(left As Integer, top As Integer, right As Integer, bottom As Integer)
|
||||
Me.Left = left
|
||||
Me.Top = top
|
||||
Me.Right = right
|
||||
Me.Bottom = bottom
|
||||
End Sub
|
||||
|
||||
Function ToRectangle() As Rectangle
|
||||
Return Rectangle.FromLTRB(Left, Top, Right, Bottom)
|
||||
End Function
|
||||
End Structure
|
||||
|
||||
Public Structure SHFILEINFO
|
||||
Public hIcon As IntPtr
|
||||
Public iIcon As Integer
|
||||
Public dwAttributes As Integer
|
||||
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)>
|
||||
Public szDisplayName As String
|
||||
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)>
|
||||
Public szTypeName As String
|
||||
End Structure
|
||||
|
||||
Public Structure NMHDR
|
||||
Public hwndFrom As Integer
|
||||
Public idFrom As Integer
|
||||
Public code As Integer
|
||||
End Structure
|
||||
|
||||
Public Structure NCCALCSIZE_PARAMS
|
||||
Public rgrc0, rgrc1, rgrc2 As RECT
|
||||
Public lppos As IntPtr
|
||||
End Structure
|
||||
|
||||
#End Region
|
||||
|
||||
End Class
|
||||
|
||||
Public Class Taskbar
|
||||
Private Taskbar As ITaskbarList3 = DirectCast(New TaskBarCommunication(), ITaskbarList3)
|
||||
|
||||
Property Handle As IntPtr
|
||||
|
||||
Public Sub New(handle As IntPtr)
|
||||
Me.Handle = handle
|
||||
End Sub
|
||||
|
||||
<ComImportAttribute>
|
||||
<InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)>
|
||||
<GuidAttribute("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")>
|
||||
Private Interface ITaskbarList3
|
||||
'ITaskbarList
|
||||
<PreserveSig> Sub HrInit()
|
||||
<PreserveSig> Sub AddTab(hwnd As IntPtr)
|
||||
<PreserveSig> Sub DeleteTab(hwnd As IntPtr)
|
||||
<PreserveSig> Sub ActivateTab(hwnd As IntPtr)
|
||||
<PreserveSig> Sub SetActiveAlt(hwnd As IntPtr)
|
||||
'ITaskbarList2
|
||||
<PreserveSig> Sub MarkFullscreenWindow(hwnd As IntPtr, <MarshalAs(UnmanagedType.Bool)> fFullscreen As Boolean)
|
||||
'ITaskbarList3
|
||||
<PreserveSig> Sub SetProgressValue(hwnd As IntPtr, ullCompleted As UInt64, ullTotal As UInt64)
|
||||
<PreserveSig> Sub SetProgressState(hwnd As IntPtr, state As TaskbarStates)
|
||||
End Interface
|
||||
|
||||
<ComImportAttribute>
|
||||
<ClassInterfaceAttribute(ClassInterfaceType.None)>
|
||||
<GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")>
|
||||
Private Class TaskBarCommunication
|
||||
End Class
|
||||
|
||||
Public Sub SetState(taskbarState As TaskbarStates)
|
||||
Taskbar.SetProgressState(Handle, taskbarState)
|
||||
End Sub
|
||||
|
||||
Public Sub SetValue(progressValue As Double, progressMax As Double)
|
||||
Taskbar.SetProgressValue(Handle, CULng(Math.Truncate(progressValue)), CULng(Math.Truncate(progressMax)))
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Enum TaskbarStates
|
||||
NoProgress = 0
|
||||
Indeterminate = &H1
|
||||
Normal = &H2
|
||||
[Error] = &H4
|
||||
Paused = &H8
|
||||
End Enum
|
||||
551
vbnet/TaskDialog.vb
Normal file
551
vbnet/TaskDialog.vb
Normal file
@@ -0,0 +1,551 @@
|
||||
Imports System.Runtime.InteropServices
|
||||
Imports System.Text
|
||||
Imports System.Text.RegularExpressions
|
||||
|
||||
Namespace UI
|
||||
Public Delegate Function PFTASKDIALOGCALLBACK(hwnd As IntPtr,
|
||||
msg As UInteger,
|
||||
wParam As IntPtr,
|
||||
lParam As IntPtr,
|
||||
lpRefData As IntPtr) As Integer
|
||||
Public Class TaskDialog(Of T)
|
||||
Inherits TaskDialog
|
||||
Implements IDisposable
|
||||
|
||||
Private IdValueDic As New Dictionary(Of Integer, T)
|
||||
Private IdTextDic As New Dictionary(Of Integer, String)
|
||||
Private CommandLinkShieldList As New List(Of Integer)
|
||||
Private ButtonArray As IntPtr, RadioButtonArray As IntPtr
|
||||
Private Buttons As New List(Of TASKDIALOG_BUTTON)
|
||||
Private RadioButtons As New List(Of TASKDIALOG_BUTTON)
|
||||
|
||||
Private Config As TASKDIALOGCONFIG
|
||||
|
||||
Sub New()
|
||||
Config = New TASKDIALOGCONFIG()
|
||||
|
||||
Config.cbSize = CUInt(Marshal.SizeOf(Config))
|
||||
Config.hwndParent = GetHandle()
|
||||
Config.hInstance = IntPtr.Zero
|
||||
Config.dwFlags = Flags.TDF_ALLOW_DIALOG_CANCELLATION
|
||||
Config.dwCommonButtons = TaskDialogButtons.None
|
||||
Config.MainIcon = New TASKDIALOGCONFIG_ICON_UNION(0)
|
||||
Config.FooterIcon = New TASKDIALOGCONFIG_ICON_UNION(0)
|
||||
Config.cxWidth = 0
|
||||
|
||||
Config.cButtons = 0
|
||||
Config.cRadioButtons = 0
|
||||
Config.pButtons = IntPtr.Zero
|
||||
Config.pRadioButtons = IntPtr.Zero
|
||||
Config.nDefaultButton = 0
|
||||
Config.nDefaultRadioButton = 0
|
||||
|
||||
Config.pszWindowTitle = Application.ProductName
|
||||
Config.pszMainInstruction = ""
|
||||
Config.pszContent = ""
|
||||
Config.pszVerificationText = Nothing
|
||||
Config.pszExpandedInformation = Nothing
|
||||
Config.pszExpandedControlText = Nothing
|
||||
Config.pszCollapsedControlText = Nothing
|
||||
Config.pszFooter = Nothing
|
||||
|
||||
Config.pfCallback = New PFTASKDIALOGCALLBACK(AddressOf DialogProc)
|
||||
End Sub
|
||||
|
||||
Function GetHandle() As IntPtr
|
||||
Dim r As New StringBuilder(260)
|
||||
Dim h = GetForegroundWindow()
|
||||
GetWindowModuleFileName(h, r, 260)
|
||||
If r.ToString.Replace(".vshost", "").Base = Application.ExecutablePath.Base Then Return h
|
||||
End Function
|
||||
|
||||
#Region "Constants"
|
||||
Const TDE_CONTENT As Integer = 0
|
||||
Const TDE_EXPANDED_INFORMATION As Integer = 1
|
||||
Const TDE_FOOTER As Integer = 2
|
||||
Const TDE_MAIN_INSTRUCTION As Integer = 3
|
||||
|
||||
Const TDN_CREATED As Integer = 0
|
||||
Const TDN_NAVIGATED As Integer = 1
|
||||
Const TDN_BUTTON_CLICKED As Integer = 2
|
||||
Const TDN_HYPERLINK_CLICKED As Integer = 3
|
||||
Const TDN_TIMER As Integer = 4
|
||||
Const TDN_DESTROYED As Integer = 5
|
||||
Const TDN_RADIO_BUTTON_CLICKED As Integer = 6
|
||||
Const TDN_DIALOG_CONSTRUCTED As Integer = 7
|
||||
Const TDN_VERIFICATION_CLICKED As Integer = 8
|
||||
Const TDN_HELP As Integer = 9
|
||||
Const TDN_EXPANDO_BUTTON_CLICKED As Integer = 10
|
||||
|
||||
Const TDM_NAVIGATE_PAGE As Integer = &H400 + 101
|
||||
Const TDM_CLICK_BUTTON As Integer = &H400 + 102 'wParam = Button ID
|
||||
Const TDM_SET_MARQUEE_PROGRESS_BAR As Integer = &H400 + 103 'wParam = 0 (nonMarque) wParam != 0 (Marquee)
|
||||
Const TDM_SET_PROGRESS_BAR_STATE As Integer = &H400 + 104 'wParam = new progress state
|
||||
Const TDM_SET_PROGRESS_BAR_RANGE As Integer = &H400 + 105 'lParam = MAKELPARAM(nMinRange, nMaxRange)
|
||||
Const TDM_SET_PROGRESS_BAR_POS As Integer = &H400 + 106 'wParam = new position
|
||||
Const TDM_SET_PROGRESS_BAR_MARQUEE As Integer = &H400 + 107 'wParam = 0 (stop marquee), wParam != 0 (start marquee), lparam = speed (milliseconds between repaints)
|
||||
Const TDM_SET_ELEMENT_TEXT As Integer = &H400 + 108 'wParam = element (TASKDIALOG_ELEMENTS), lParam = new element text (LPCWSTR)
|
||||
Const TDM_CLICK_RADIO_BUTTON As Integer = &H400 + 110 'wParam = Radio Button ID
|
||||
Const TDM_ENABLE_BUTTON As Integer = &H400 + 111 'lParam = 0 (disable), lParam != 0 (enable), wParam = Button ID
|
||||
Const TDM_ENABLE_RADIO_BUTTON As Integer = &H400 + 112 'lParam = 0 (disable), lParam != 0 (enable), wParam = Radio Button ID
|
||||
Const TDM_CLICK_VERIFICATION As Integer = &H400 + 113 'wParam = 0 (unchecked), 1 (checked), lParam = 1 (set key focus)
|
||||
Const TDM_UPDATE_ELEMENT_TEXT As Integer = &H400 + 114 'wParam = element (TASKDIALOG_ELEMENTS), lParam = new element text (LPCWSTR)
|
||||
Const TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE As Integer = &H400 + 115 'wParam = Button ID, lParam = 0 (elevation not required), lParam != 0 (elevation required)
|
||||
Const TDM_UPDATE_ICON As Integer = &H400 + 116 'wParam = icon element (TASKDIALOG_ICON_ELEMENTS), lParam = new icon (hIcon if TDF_USE_HICON_* was set, PCWSTR otherwise)
|
||||
#End Region
|
||||
|
||||
#Region "Properties"
|
||||
|
||||
Private AllowCancelValue As Boolean
|
||||
|
||||
WriteOnly Property AllowCancel() As Boolean
|
||||
Set(Value As Boolean)
|
||||
If Value Then
|
||||
Config.dwFlags = Config.dwFlags Or Flags.TDF_ALLOW_DIALOG_CANCELLATION
|
||||
ElseIf (Config.dwFlags And Flags.TDF_ALLOW_DIALOG_CANCELLATION) = Flags.TDF_ALLOW_DIALOG_CANCELLATION Then
|
||||
Config.dwFlags = Config.dwFlags Xor Flags.TDF_ALLOW_DIALOG_CANCELLATION
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property MainInstruction() As String
|
||||
Get
|
||||
Return Config.pszMainInstruction
|
||||
End Get
|
||||
Set(Value As String)
|
||||
Config.pszMainInstruction = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property Content() As String
|
||||
Get
|
||||
Return Config.pszContent
|
||||
End Get
|
||||
Set(Value As String)
|
||||
Config.pszContent = ExpandWikiMarkup(Value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property ExpandedInformation() As String
|
||||
Get
|
||||
Return Config.pszExpandedInformation
|
||||
End Get
|
||||
Set(Value As String)
|
||||
Config.pszExpandedInformation = ExpandWikiMarkup(Value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property VerificationText() As String
|
||||
Get
|
||||
Return Config.pszVerificationText
|
||||
End Get
|
||||
Set(Value As String)
|
||||
Config.pszVerificationText = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property DefaultButton() As DialogResult
|
||||
Get
|
||||
Return CType(Config.nDefaultButton, DialogResult)
|
||||
End Get
|
||||
Set(Value As DialogResult)
|
||||
Config.nDefaultButton = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property Footer() As String
|
||||
Get
|
||||
Return Config.pszFooter
|
||||
End Get
|
||||
Set(Value As String)
|
||||
Config.pszFooter = ExpandWikiMarkup(Value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
WriteOnly Property MainIcon() As TaskDialogIcon
|
||||
Set(Value As TaskDialogIcon)
|
||||
Config.MainIcon = New TASKDIALOGCONFIG_ICON_UNION(Value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private SelectedIDValue As Integer = -1
|
||||
|
||||
Property SelectedID As Integer
|
||||
Get
|
||||
Return SelectedIDValue
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
For Each i In IdValueDic
|
||||
If i.Key = value Then SelectedIDValue = value
|
||||
Next
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private SelectedValueValue As T
|
||||
|
||||
Property SelectedValue() As T
|
||||
Get
|
||||
If IdValueDic.ContainsKey(SelectedID) Then Return IdValueDic(SelectedID)
|
||||
Return SelectedValueValue
|
||||
End Get
|
||||
Set(value As T)
|
||||
SelectedValueValue = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private SelectedTextValue As String
|
||||
|
||||
Property SelectedText() As String
|
||||
Get
|
||||
If IdTextDic.ContainsKey(SelectedID) Then Return IdTextDic(SelectedID)
|
||||
Return SelectedTextValue
|
||||
End Get
|
||||
Set(value As String)
|
||||
SelectedTextValue = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property CheckBoxChecked() As Boolean
|
||||
Get
|
||||
Return (Config.dwFlags And Flags.TDF_VERIFICATION_FLAG_CHECKED) = Flags.TDF_VERIFICATION_FLAG_CHECKED
|
||||
End Get
|
||||
Set(value As Boolean)
|
||||
If value Then
|
||||
Config.dwFlags = Config.dwFlags Or Flags.TDF_VERIFICATION_FLAG_CHECKED
|
||||
ElseIf CheckBoxChecked Then
|
||||
Config.dwFlags = Config.dwFlags Xor Flags.TDF_VERIFICATION_FLAG_CHECKED
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private CommonButtonsValue As TaskDialogButtons
|
||||
|
||||
Property CommonButtons() As TaskDialogButtons
|
||||
Get
|
||||
Return Config.dwCommonButtons
|
||||
End Get
|
||||
Set(Value As TaskDialogButtons)
|
||||
Config.dwCommonButtons = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private TimeoutValue As Integer
|
||||
|
||||
Property Timeout As Integer
|
||||
Get
|
||||
Return CInt(TimeoutValue / 1000)
|
||||
End Get
|
||||
Set(Value As Integer)
|
||||
TimeoutValue = Value * 1000
|
||||
|
||||
If Value > 0 Then
|
||||
Config.dwFlags = Config.dwFlags Or Flags.TDF_CALLBACK_TIMER
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
#End Region
|
||||
|
||||
#Region "Methods"
|
||||
|
||||
Sub AddButton(text As String, value As T)
|
||||
Dim id = 1000 + IdValueDic.Count + 1
|
||||
IdValueDic(id) = value
|
||||
Buttons.Add(New TASKDIALOG_BUTTON(id, text))
|
||||
End Sub
|
||||
|
||||
Function ExpandWikiMarkup(value As String) As String
|
||||
If value.Contains("[") Then
|
||||
Dim re As New Regex("\[(\w+?:.*?) (.+?)\]")
|
||||
Dim m = re.Match(value)
|
||||
|
||||
If m.Success Then
|
||||
Config.dwFlags = Config.dwFlags Or Flags.TDF_ENABLE_HYPERLINKS
|
||||
value = re.Replace(value, "<a href=""$1"">$2</a>")
|
||||
End If
|
||||
End If
|
||||
|
||||
Return value
|
||||
End Function
|
||||
|
||||
Sub AddCommandLink(text As String, value As T)
|
||||
Dim id = 1000 + IdValueDic.Count + 1
|
||||
IdValueDic(id) = value
|
||||
IdTextDic(id) = text
|
||||
Buttons.Add(New TASKDIALOG_BUTTON(id, text))
|
||||
Config.dwFlags = Config.dwFlags Or Flags.TDF_USE_COMMAND_LINKS
|
||||
End Sub
|
||||
|
||||
Sub AddCommandLink(text As String,
|
||||
description As String,
|
||||
value As T,
|
||||
Optional setShield As Boolean = False)
|
||||
|
||||
Dim id = 1000 + IdValueDic.Count + 1
|
||||
IdValueDic(id) = value
|
||||
If setShield Then CommandLinkShieldList.Add(id)
|
||||
If description <> "" Then text = text + BR + description
|
||||
Buttons.Add(New TASKDIALOG_BUTTON(id, text))
|
||||
Config.dwFlags = Config.dwFlags Or Flags.TDF_USE_COMMAND_LINKS
|
||||
End Sub
|
||||
|
||||
Sub AddRadioButton(text As String, value As T)
|
||||
Dim id = 1000 + IdValueDic.Count + 1
|
||||
IdValueDic(id) = value
|
||||
RadioButtons.Add(New TASKDIALOG_BUTTON(id, text))
|
||||
End Sub
|
||||
|
||||
Function Show() As T
|
||||
MarshalDialogControlStructs()
|
||||
Dim isChecked As Boolean
|
||||
Dim hr = TaskDialogIndirect(Config, Nothing, Nothing, isChecked)
|
||||
CheckBoxChecked = isChecked
|
||||
If hr < 0 Then Marshal.ThrowExceptionForHR(hr)
|
||||
If TypeOf SelectedValue Is DialogResult Then SelectedValue = DirectCast(CObj(SelectedID), T)
|
||||
Return SelectedValue
|
||||
End Function
|
||||
|
||||
Private ExitTickCount As Integer
|
||||
|
||||
Private Function DialogProc(hwnd As IntPtr,
|
||||
msg As UInteger,
|
||||
wParam As IntPtr,
|
||||
lParam As IntPtr,
|
||||
lpRefData As IntPtr) As Integer
|
||||
Select Case msg
|
||||
Case TDN_BUTTON_CLICKED, TDN_RADIO_BUTTON_CLICKED
|
||||
If TypeOf SelectedValue Is DialogResult Then
|
||||
SelectedIDValue = wParam.ToInt32
|
||||
Else
|
||||
SelectedID = wParam.ToInt32
|
||||
End If
|
||||
Case TDN_TIMER
|
||||
If ExitTickCount = 0 Then
|
||||
ExitTickCount = Environment.TickCount + Timeout * 1000
|
||||
End If
|
||||
|
||||
If Environment.TickCount > ExitTickCount Then
|
||||
SendMessage(hwnd, TDM_CLICK_BUTTON, DialogResult.OK, 0)
|
||||
End If
|
||||
Case TDN_HYPERLINK_CLICKED
|
||||
Dim url = Marshal.PtrToStringUni(lParam)
|
||||
|
||||
If url.StartsWith("mailto:") OrElse url Like "http*://*" Then
|
||||
ProcessHelp.Start(url)
|
||||
ElseIf url = "copymsg:" Then
|
||||
Clipboard.SetText(MainInstruction + BR2 + Content + BR2 + ExpandedInformation)
|
||||
MsgBox("Message was copied to clipboard.", MessageBoxIcon.Information)
|
||||
End If
|
||||
Case TDN_CREATED
|
||||
For Each i In CommandLinkShieldList
|
||||
SendMessage(hwnd, TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE, i, 1)
|
||||
Next
|
||||
End Select
|
||||
|
||||
Return 0
|
||||
End Function
|
||||
|
||||
Private Sub MarshalDialogControlStructs()
|
||||
If Not Buttons Is Nothing AndAlso Buttons.Count > 0 Then
|
||||
ButtonArray = AllocateAndMarshalButtons(Buttons)
|
||||
Config.pButtons = ButtonArray
|
||||
Config.cButtons = CUInt(Buttons.Count)
|
||||
End If
|
||||
|
||||
If Not RadioButtons Is Nothing AndAlso RadioButtons.Count > 0 Then
|
||||
RadioButtonArray = AllocateAndMarshalButtons(RadioButtons)
|
||||
Config.pRadioButtons = RadioButtonArray
|
||||
Config.cRadioButtons = CUInt(RadioButtons.Count)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Shared Function AllocateAndMarshalButtons(structs As List(Of TASKDIALOG_BUTTON)) As IntPtr
|
||||
Dim initialPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(TASKDIALOG_BUTTON)) * structs.Count)
|
||||
Dim currentPtr = initialPtr
|
||||
|
||||
For Each button In structs
|
||||
Marshal.StructureToPtr(button, currentPtr, False)
|
||||
currentPtr = CType((currentPtr.ToInt64 + Marshal.SizeOf(button)), IntPtr)
|
||||
Next
|
||||
|
||||
Return initialPtr
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "IDispose Pattern"
|
||||
|
||||
Private disposed As Boolean
|
||||
|
||||
Sub Dispose() Implements IDisposable.Dispose
|
||||
Dispose(True)
|
||||
GC.SuppressFinalize(Me)
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Finalize()
|
||||
Try
|
||||
Dispose(False)
|
||||
Finally
|
||||
MyBase.Finalize()
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Protected Sub Dispose(disposing As Boolean)
|
||||
If Not disposed Then
|
||||
disposed = True
|
||||
|
||||
If ButtonArray <> IntPtr.Zero Then
|
||||
Marshal.FreeHGlobal(ButtonArray)
|
||||
ButtonArray = IntPtr.Zero
|
||||
End If
|
||||
|
||||
If RadioButtonArray <> IntPtr.Zero Then
|
||||
Marshal.FreeHGlobal(RadioButtonArray)
|
||||
RadioButtonArray = IntPtr.Zero
|
||||
End If
|
||||
|
||||
If disposing Then
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
End Class
|
||||
|
||||
Public Class TaskDialog
|
||||
<DllImport("comctl32", CharSet:=CharSet.Unicode, SetLastError:=True)>
|
||||
Shared Function TaskDialogIndirect(<[In]()> pTaskConfig As TASKDIALOGCONFIG,
|
||||
<Out()> ByRef pnButton As Integer,
|
||||
<Out()> ByRef pnRadioButton As Integer,
|
||||
<MarshalAs(UnmanagedType.Bool)> <Out()> ByRef pVerificationFlagChecked As Boolean) As Integer
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll")>
|
||||
Shared Function GetForegroundWindow() As IntPtr
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function GetWindowModuleFileName(hwnd As IntPtr,
|
||||
lpszFileName As StringBuilder,
|
||||
cchFileNameMax As UInteger) As UInteger
|
||||
End Function
|
||||
|
||||
<DllImport("user32.dll", CharSet:=CharSet.Unicode)>
|
||||
Shared Function SendMessage(hWnd As IntPtr,
|
||||
Msg As Int32,
|
||||
wParam As Integer,
|
||||
lParam As Integer) As IntPtr
|
||||
End Function
|
||||
|
||||
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode, Pack:=4)>
|
||||
Public Class TASKDIALOGCONFIG
|
||||
Public cbSize As UInteger
|
||||
Public hwndParent As IntPtr
|
||||
Public hInstance As IntPtr
|
||||
Public dwFlags As Flags
|
||||
Public dwCommonButtons As TaskDialogButtons
|
||||
<MarshalAs(UnmanagedType.LPWStr)>
|
||||
Public pszWindowTitle As String
|
||||
Public MainIcon As TASKDIALOGCONFIG_ICON_UNION
|
||||
<MarshalAs(UnmanagedType.LPWStr)>
|
||||
Public pszMainInstruction As String
|
||||
<MarshalAs(UnmanagedType.LPWStr)>
|
||||
Public pszContent As String
|
||||
Public cButtons As UInteger
|
||||
Public pButtons As IntPtr
|
||||
Public nDefaultButton As Integer
|
||||
Public cRadioButtons As UInteger
|
||||
Public pRadioButtons As IntPtr
|
||||
Public nDefaultRadioButton As Integer
|
||||
<MarshalAs(UnmanagedType.LPWStr)>
|
||||
Public pszVerificationText As String
|
||||
<MarshalAs(UnmanagedType.LPWStr)>
|
||||
Public pszExpandedInformation As String
|
||||
<MarshalAs(UnmanagedType.LPWStr)>
|
||||
Public pszExpandedControlText As String
|
||||
<MarshalAs(UnmanagedType.LPWStr)>
|
||||
Public pszCollapsedControlText As String
|
||||
Public FooterIcon As TASKDIALOGCONFIG_ICON_UNION
|
||||
<MarshalAs(UnmanagedType.LPWStr)>
|
||||
Public pszFooter As String
|
||||
Public pfCallback As PFTASKDIALOGCALLBACK
|
||||
Public lpCallbackData As IntPtr
|
||||
Public cxWidth As UInteger
|
||||
End Class
|
||||
|
||||
'TASKDIALOG_FLAGS
|
||||
Public Enum Flags
|
||||
NONE = 0
|
||||
TDF_ENABLE_HYPERLINKS = &H1
|
||||
TDF_USE_HICON_MAIN = &H2
|
||||
TDF_USE_HICON_FOOTER = &H4
|
||||
TDF_ALLOW_DIALOG_CANCELLATION = &H8
|
||||
TDF_USE_COMMAND_LINKS = &H10
|
||||
TDF_USE_COMMAND_LINKS_NO_ICON = &H20
|
||||
TDF_EXPAND_FOOTER_AREA = &H40
|
||||
TDF_EXPANDED_BY_DEFAULT = &H80
|
||||
TDF_VERIFICATION_FLAG_CHECKED = &H100
|
||||
TDF_SHOW_PROGRESS_BAR = &H200
|
||||
TDF_SHOW_MARQUEE_PROGRESS_BAR = &H400
|
||||
TDF_CALLBACK_TIMER = &H800
|
||||
TDF_POSITION_RELATIVE_TO_WINDOW = &H1000
|
||||
TDF_RTL_LAYOUT = &H2000
|
||||
TDF_NO_DEFAULT_RADIO_BUTTON = &H4000
|
||||
End Enum
|
||||
|
||||
<StructLayout(LayoutKind.Explicit, CharSet:=CharSet.Unicode)>
|
||||
Public Structure TASKDIALOGCONFIG_ICON_UNION
|
||||
Sub New(i As Integer)
|
||||
spacer = IntPtr.Zero
|
||||
pszIcon = 0
|
||||
hMainIcon = i
|
||||
End Sub
|
||||
|
||||
<FieldOffset(0)>
|
||||
Public hMainIcon As Integer
|
||||
<FieldOffset(0)>
|
||||
Public pszIcon As Integer
|
||||
<FieldOffset(0)>
|
||||
Public spacer As IntPtr
|
||||
End Structure
|
||||
|
||||
<StructLayout(LayoutKind.Sequential,
|
||||
CharSet:=CharSet.Unicode, Pack:=4)>
|
||||
Public Structure TASKDIALOG_BUTTON
|
||||
Sub New(n As Integer, txt As String)
|
||||
nButtonID = n
|
||||
pszButtonText = txt
|
||||
End Sub
|
||||
|
||||
Public nButtonID As Integer
|
||||
<MarshalAs(UnmanagedType.LPWStr)>
|
||||
Public pszButtonText As String
|
||||
End Structure
|
||||
End Class
|
||||
|
||||
Public Enum TaskDialogButtons
|
||||
None = &H0
|
||||
Ok = &H1
|
||||
Yes = &H2
|
||||
No = &H4
|
||||
Cancel = &H8
|
||||
Retry = &H10
|
||||
RetryCancel = Retry Or Cancel
|
||||
Close = &H20
|
||||
OkCancel = Ok Or Cancel
|
||||
YesNo = Yes Or No
|
||||
YesNoCancel = YesNo Or Cancel
|
||||
End Enum
|
||||
|
||||
Public Enum TaskDialogIcon
|
||||
Warning = 65535 'TD_WARNING_ICON
|
||||
[Error] = 65534 'TD_ERROR_ICON
|
||||
Info = 65533 'TD_INFORMATION_ICON
|
||||
Shield = 65532 'TD_SHIELD_ICON
|
||||
SecurityShieldBlue = 65531
|
||||
SecurityWarning = 65530
|
||||
SecurityError = 65529
|
||||
SecuritySuccess = 65528
|
||||
SecurityShieldGray = 65527
|
||||
End Enum
|
||||
End Namespace
|
||||
311
vbnet/ToolStripRendererEx.vb
Normal file
311
vbnet/ToolStripRendererEx.vb
Normal file
@@ -0,0 +1,311 @@
|
||||
Imports System.Drawing.Drawing2D
|
||||
Imports System.Drawing.Text
|
||||
Imports Microsoft.Win32
|
||||
|
||||
Namespace UI
|
||||
Public Class ToolStripRendererEx
|
||||
Inherits ToolStripSystemRenderer
|
||||
|
||||
Shared RenderMode As ToolStripRenderModeEx
|
||||
|
||||
Shared Property ColorChecked As Color
|
||||
Shared Property ColorBorder As Color
|
||||
Shared Property ColorTop As Color
|
||||
Shared Property ColorBottom As Color
|
||||
Shared Property ColorBackground As Color
|
||||
|
||||
Shared Property ColorToolStrip1 As Color
|
||||
Shared Property ColorToolStrip2 As Color
|
||||
Shared Property ColorToolStrip3 As Color
|
||||
Shared Property ColorToolStrip4 As Color
|
||||
|
||||
Private TextOffset As Integer
|
||||
|
||||
Sub New(mode As ToolStripRenderModeEx)
|
||||
RenderMode = mode
|
||||
InitColors(mode)
|
||||
End Sub
|
||||
|
||||
Shared Function IsAutoRenderMode() As Boolean
|
||||
Return _
|
||||
RenderMode = ToolStripRenderModeEx.SystemAuto OrElse
|
||||
RenderMode = ToolStripRenderModeEx.Win7Auto OrElse
|
||||
RenderMode = ToolStripRenderModeEx.Win10Auto
|
||||
End Function
|
||||
|
||||
Shared Sub InitColors(renderMode As ToolStripRenderModeEx)
|
||||
If ToolStripRendererEx.IsAutoRenderMode Then
|
||||
Dim argb = CInt(Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM", "ColorizationColor", 0))
|
||||
If argb = 0 Then argb = Color.LightBlue.ToArgb
|
||||
InitColors(Color.FromArgb(argb))
|
||||
Else
|
||||
ColorBorder = Color.FromArgb(&HFF83ABDC)
|
||||
ColorTop = Color.FromArgb(&HFFE7F0FB)
|
||||
ColorBottom = Color.FromArgb(&HFFCCE1FB)
|
||||
ColorBackground = SystemColors.Control
|
||||
|
||||
ColorToolStrip1 = Color.FromArgb(&HFFFDFEFF)
|
||||
ColorToolStrip2 = Color.FromArgb(&HFFE6F0FA)
|
||||
ColorToolStrip3 = Color.FromArgb(&HFFDCE6F4)
|
||||
ColorToolStrip4 = Color.FromArgb(&HFFDDE9F7)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Shared Sub InitColors(c As Color)
|
||||
ColorBorder = HSLColor.Convert(c).ToColorSetLuminosity(100)
|
||||
ColorChecked = HSLColor.Convert(c).ToColorSetLuminosity(200)
|
||||
ColorBottom = HSLColor.Convert(c).ToColorSetLuminosity(220)
|
||||
ColorBackground = HSLColor.Convert(c).ToColorSetLuminosity(230)
|
||||
ColorTop = HSLColor.Convert(c).ToColorSetLuminosity(240)
|
||||
|
||||
ColorToolStrip1 = ControlPaint.LightLight(ControlPaint.LightLight(ControlPaint.Light(ColorBorder, 1)))
|
||||
ColorToolStrip2 = ControlPaint.LightLight(ControlPaint.LightLight(ControlPaint.Light(ColorBorder, 0.7)))
|
||||
ColorToolStrip3 = ControlPaint.LightLight(ControlPaint.LightLight(ControlPaint.Light(ColorBorder, 0.1)))
|
||||
ColorToolStrip4 = ControlPaint.LightLight(ControlPaint.LightLight(ControlPaint.Light(ColorBorder, 0.4)))
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnRenderToolStripBorder(e As ToolStripRenderEventArgs)
|
||||
ControlPaint.DrawBorder(e.Graphics, e.AffectedBounds, Color.FromArgb(160, 175, 195), ButtonBorderStyle.Solid)
|
||||
End Sub
|
||||
|
||||
Protected Overloads Overrides Sub OnRenderItemText(e As ToolStripItemTextRenderEventArgs)
|
||||
e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias
|
||||
|
||||
If TypeOf e.Item Is ToolStripMenuItem AndAlso Not TypeOf e.Item.Owner Is MenuStrip Then
|
||||
Dim r = e.TextRectangle
|
||||
|
||||
Dim dropDown = TryCast(e.ToolStrip, ToolStripDropDownMenu)
|
||||
|
||||
If dropDown Is Nothing OrElse dropDown.ShowImageMargin OrElse dropDown.ShowCheckMargin Then
|
||||
TextOffset = CInt(e.Item.Height * 1.1)
|
||||
Else
|
||||
TextOffset = CInt(e.Item.Height * 0.2)
|
||||
End If
|
||||
|
||||
e.TextRectangle = New Rectangle(TextOffset, CInt((e.Item.Height - r.Height) / 2), r.Width, r.Height)
|
||||
End If
|
||||
|
||||
MyBase.OnRenderItemText(e)
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnRenderToolStripBackground(e As ToolStripRenderEventArgs)
|
||||
If Not TypeOf e.ToolStrip Is ToolStripDropDownMenu AndAlso
|
||||
Not e.ToolStrip.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow Then
|
||||
|
||||
Dim r As New Rectangle(-1, -1, e.AffectedBounds.Width, e.AffectedBounds.Height)
|
||||
|
||||
If IsFlat() Then
|
||||
Using b As New SolidBrush(ColorToolStrip2)
|
||||
e.Graphics.FillRectangle(b, r)
|
||||
End Using
|
||||
Else
|
||||
Dim cb As New ColorBlend()
|
||||
cb.Colors = {ColorToolStrip1, ColorToolStrip2, ColorToolStrip3, ColorToolStrip4}
|
||||
cb.Positions = {0.0F, 0.5F, 0.5F, 1.0F}
|
||||
|
||||
Using b As New LinearGradientBrush(r, ColorToolStrip1, ColorToolStrip4, 90)
|
||||
b.InterpolationColors = cb
|
||||
e.Graphics.FillRectangle(b, r)
|
||||
End Using
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnRenderMenuItemBackground(e As ToolStripItemRenderEventArgs)
|
||||
e.Item.ForeColor = Color.Black
|
||||
|
||||
Dim left = 22
|
||||
Dim r = New Rectangle(Point.Empty, e.Item.Size)
|
||||
Dim g = e.Graphics
|
||||
|
||||
If Not TypeOf e.Item.Owner Is MenuStrip Then
|
||||
g.Clear(ColorBackground)
|
||||
End If
|
||||
|
||||
If e.Item.Selected AndAlso e.Item.Enabled Then
|
||||
If TypeOf e.Item.Owner Is MenuStrip Then
|
||||
DrawButton(e)
|
||||
Else
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias
|
||||
|
||||
Dim r2 = New Rectangle(r.X + 2, r.Y, r.Width - 4, r.Height - 1)
|
||||
|
||||
If IsFlat() Then
|
||||
Using pen As New Pen(ColorBorder)
|
||||
g.DrawRectangle(pen, r2)
|
||||
End Using
|
||||
|
||||
r2.Inflate(-1, -1)
|
||||
|
||||
Using b As New SolidBrush(ColorBottom)
|
||||
g.FillRectangle(b, r2)
|
||||
End Using
|
||||
Else
|
||||
Using path = CreateRoundRectangle(r2, 3)
|
||||
Using b As New LinearGradientBrush(r2,
|
||||
ControlPaint.LightLight(ControlPaint.LightLight(ColorTop)),
|
||||
ControlPaint.LightLight(ControlPaint.LightLight(ColorBottom)),
|
||||
90.0F)
|
||||
g.FillPath(b, path)
|
||||
End Using
|
||||
|
||||
Using p As New Pen(ColorBorder)
|
||||
g.DrawPath(p, path)
|
||||
End Using
|
||||
End Using
|
||||
|
||||
r2.Inflate(-1, -1)
|
||||
|
||||
Using path = CreateRoundRectangle(r2, 3)
|
||||
Using b As New LinearGradientBrush(r2, ColorTop, ColorBottom, 90.0F)
|
||||
g.FillPath(b, path)
|
||||
End Using
|
||||
End Using
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub DrawButton(e As ToolStripItemRenderEventArgs)
|
||||
Dim g = e.Graphics
|
||||
Dim r = New Rectangle(Point.Empty, e.Item.Size)
|
||||
Dim r2 = New Rectangle(r.X, r.Y, r.Width - 1, r.Height - 1)
|
||||
|
||||
If IsFlat() Then
|
||||
Using pen As New Pen(ColorBorder)
|
||||
g.DrawRectangle(pen, r2)
|
||||
End Using
|
||||
|
||||
r2.Inflate(-1, -1)
|
||||
|
||||
Dim tsb = TryCast(e.Item, ToolStripButton)
|
||||
|
||||
If Not tsb Is Nothing AndAlso tsb.Checked Then
|
||||
Using brush As New SolidBrush(ColorChecked)
|
||||
g.FillRectangle(brush, r2)
|
||||
End Using
|
||||
Else
|
||||
Using brush As New SolidBrush(ColorBottom)
|
||||
g.FillRectangle(brush, r2)
|
||||
End Using
|
||||
End If
|
||||
Else
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias
|
||||
|
||||
Dim c1 = HSLColor.Convert(ColorToolStrip1).ToColorAddLuminosity(15)
|
||||
Dim c2 = HSLColor.Convert(ColorToolStrip2).ToColorAddLuminosity(15)
|
||||
Dim c3 = HSLColor.Convert(ColorToolStrip3).ToColorAddLuminosity(15)
|
||||
Dim c4 = HSLColor.Convert(ColorToolStrip4).ToColorAddLuminosity(15)
|
||||
|
||||
Dim cb As New ColorBlend()
|
||||
|
||||
cb.Colors = {c1, c2, c3, c4}
|
||||
cb.Positions = {0.0F, 0.5F, 0.5F, 1.0F}
|
||||
|
||||
Using path = CreateRoundRectangle(r2, 3)
|
||||
Using b As New LinearGradientBrush(r2, c1, c4, 90)
|
||||
b.InterpolationColors = cb
|
||||
g.FillPath(b, path)
|
||||
End Using
|
||||
|
||||
Using p As New Pen(ColorBorder)
|
||||
g.DrawPath(p, path)
|
||||
End Using
|
||||
End Using
|
||||
|
||||
r2.Inflate(-1, -1)
|
||||
|
||||
c1 = HSLColor.Convert(ColorToolStrip1).ToColorAddLuminosity(5)
|
||||
c2 = HSLColor.Convert(ColorToolStrip2).ToColorAddLuminosity(5)
|
||||
c3 = HSLColor.Convert(ColorToolStrip3).ToColorAddLuminosity(-10)
|
||||
c4 = HSLColor.Convert(ColorToolStrip4).ToColorAddLuminosity(-10)
|
||||
|
||||
cb.Colors = {c1, c2, c3, c4}
|
||||
cb.Positions = {0.0F, 0.5F, 0.5F, 1.0F}
|
||||
|
||||
Using b As New LinearGradientBrush(r2, c1, c4, 90)
|
||||
b.InterpolationColors = cb
|
||||
|
||||
Using path = CreateRoundRectangle(r2, 3)
|
||||
g.FillPath(b, path)
|
||||
End Using
|
||||
End Using
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnRenderDropDownButtonBackground(e As ToolStripItemRenderEventArgs)
|
||||
If e.Item.Selected Then DrawButton(e)
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnRenderButtonBackground(e As ToolStripItemRenderEventArgs)
|
||||
Dim button = DirectCast(e.Item, ToolStripButton)
|
||||
If e.Item.Selected OrElse button.Checked Then DrawButton(e)
|
||||
End Sub
|
||||
|
||||
Protected Overloads Overrides Sub OnRenderArrow(e As ToolStripArrowRenderEventArgs)
|
||||
Dim value = If(e.Direction = ArrowDirection.Down, &H36, &H34)
|
||||
Dim s = Convert.ToChar(value).ToString
|
||||
Dim font = New Font("Marlett", e.Item.Font.Size - 2)
|
||||
Dim size = e.Graphics.MeasureString(s, font)
|
||||
Dim x = CInt(e.Item.Width - size.Width)
|
||||
Dim y = CInt((e.Item.Height - size.Height) / 2) + 1
|
||||
e.Graphics.DrawString(s, font, Brushes.Black, x, y)
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnRenderItemCheck(e As ToolStripItemImageRenderEventArgs)
|
||||
Dim x = CInt(e.ImageRectangle.Height * 0.2)
|
||||
e.Graphics.DrawImage(e.Image, New Point(x, x))
|
||||
End Sub
|
||||
|
||||
Protected Overloads Overrides Sub OnRenderSeparator(e As ToolStripSeparatorRenderEventArgs)
|
||||
If e.Item.IsOnDropDown Then
|
||||
e.Graphics.Clear(ColorBackground)
|
||||
Dim right = e.Item.Width - CInt(TextOffset / 5)
|
||||
Dim top = e.Item.Height \ 2
|
||||
top -= 1
|
||||
Dim b = e.Item.Bounds
|
||||
|
||||
Using p As New Pen(Color.Gray)
|
||||
e.Graphics.DrawLine(p, New Point(TextOffset, top), New Point(right, top))
|
||||
End Using
|
||||
ElseIf e.Vertical Then
|
||||
Dim b = e.Item.Bounds
|
||||
|
||||
Using p As New Pen(SystemColors.ControlDarkDark)
|
||||
e.Graphics.DrawLine(p, CInt(b.Width / 2), CInt(b.Height * 0.15), CInt(b.Width / 2), CInt(b.Height * 0.85))
|
||||
End Using
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Shared Function CreateRoundRectangle(r As Rectangle, radius As Integer) As GraphicsPath
|
||||
Dim path As New GraphicsPath()
|
||||
|
||||
Dim l = r.Left
|
||||
Dim t = r.Top
|
||||
Dim w = r.Width
|
||||
Dim h = r.Height
|
||||
Dim d = radius << 1
|
||||
|
||||
path.AddArc(l, t, d, d, 180, 90)
|
||||
path.AddLine(l + radius, t, l + w - radius, t)
|
||||
path.AddArc(l + w - d, t, d, d, 270, 90)
|
||||
path.AddLine(l + w, t + radius, l + w, t + h - radius)
|
||||
path.AddArc(l + w - d, t + h - d, d, d, 0, 90)
|
||||
path.AddLine(l + w - radius, t + h, l + radius, t + h)
|
||||
path.AddArc(l, t + h - d, d, d, 90, 90)
|
||||
path.AddLine(l, t + h - radius, l, t + radius)
|
||||
path.CloseFigure()
|
||||
|
||||
Return path
|
||||
End Function
|
||||
|
||||
Shared Function IsFlat() As Boolean
|
||||
If RenderMode = ToolStripRenderModeEx.Win10Default Then Return True
|
||||
If RenderMode = ToolStripRenderModeEx.Win10Auto Then Return True
|
||||
|
||||
If (RenderMode = ToolStripRenderModeEx.SystemDefault OrElse
|
||||
RenderMode = ToolStripRenderModeEx.SystemAuto) AndAlso
|
||||
OSVersion.Current >= OSVersion.Windows8 Then Return True
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
2108
vbnet/UI.vb
Normal file
2108
vbnet/UI.vb
Normal file
File diff suppressed because it is too large
Load Diff
122
vbnet/vbnet.vbproj
Normal file
122
vbnet/vbnet.vbproj
Normal file
@@ -0,0 +1,122 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{AF1B21C5-28FC-4D47-AD0B-54F6A38391A6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>vbnet</RootNamespace>
|
||||
<AssemblyName>vbnet</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>Windows</MyType>
|
||||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<NoWarn>42030,42104,42105,42106,42107,42108,42109,42353,42354,42355</NoWarn>
|
||||
<WarningsAsErrors>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036</WarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<NoWarn>42030,42104,42105,42106,42107,42108,42109,42353,42354,42355</NoWarn>
|
||||
<WarningsAsErrors>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036</WarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionExplicit>On</OptionExplicit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionCompare>Binary</OptionCompare>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionStrict>On</OptionStrict>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Import Include="Microsoft.VisualBasic" />
|
||||
<Import Include="System" />
|
||||
<Import Include="System.Collections" />
|
||||
<Import Include="System.Collections.Generic" />
|
||||
<Import Include="System.Data" />
|
||||
<Import Include="System.Diagnostics" />
|
||||
<Import Include="System.Drawing" />
|
||||
<Import Include="System.Linq" />
|
||||
<Import Include="System.Windows.Forms" />
|
||||
<Import Include="System.Xml.Linq" />
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extensions.vb" />
|
||||
<Compile Include="HSLColor.vb" />
|
||||
<Compile Include="MainModule.vb" />
|
||||
<Compile Include="Menu.vb">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Misc.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="Native.vb" />
|
||||
<Compile Include="TaskDialog.vb" />
|
||||
<Compile Include="ToolStripRendererEx.vb" />
|
||||
<Compile Include="UI.vb" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user