Skip to content

Commit

Permalink
Version 1.2
Browse files Browse the repository at this point in the history
Version 1.2
  • Loading branch information
ElektroStudios committed Jun 5, 2019
1 parent 71702cf commit 4ebc80b
Show file tree
Hide file tree
Showing 18 changed files with 455 additions and 648 deletions.
129 changes: 129 additions & 0 deletions src/DevCase/CultureUtil.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
' This source-code is freely distributed as part of "DevCase for .NET Framework".
'
' Maybe you would like to consider to buy this powerful set of libraries to support me.
' You can do loads of things with my apis for a big amount of diverse thematics.
'
' Here is a link to the purchase page:
' https://codecanyon.net/item/elektrokit-class-library-for-net/19260282
'
' Thank you.

#Region " Option Statements "

Option Strict On
Option Explicit On
Option Infer Off

#End Region

#Region " Imports "

Imports System.Collections.ObjectModel
Imports System.Globalization
Imports System.Runtime.InteropServices
Imports System.Security

Imports DevCase.Interop.Unmanaged.Win32
Imports DevCase.Interop.Unmanaged.Win32.Enums

#End Region

#Region " Culture Util "

Namespace DevCase.Core.Application.Tools

Friend NotInheritable Class CultureUtil

#Region " Public Methods "

''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Sets the preferred UI languages for the current process.
''' <para></para>
''' To retrieve the preferred UI languages for the current process,
''' call <see cref="GetProcessPreferredUILanguages()"/> function.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' Dim langNames As String() = {"en-US", "es-ES", "it-IT", "de-DE", "fr-FR"}
''' Dim successfulLangs As Integer = SetProcessPreferredUILanguages(langNames)
''' Console.WriteLine($"{NameOf(successfulLangs)}: {successfulLangs}")
'''
''' Dim currentPreferredLangs As ReadOnlyCollection(Of CultureInfo) = GetProcessPreferredUILanguages()
''' Console.WriteLine($"{NameOf(currentPreferredLangs)}: {String.Join(", ", currentPreferredLangs.Select(Function(ci) ci.Name))}")
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
''' <param name="langNames">
''' The name of the languages, in the format languagecode2-country/regioncode2 (eg. "en-US")
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' Returns the amount of languages that were successfully set.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Function SetProcessPreferredUILanguages(ParamArray langNames As String()) As Integer

If (langNames Is Nothing) Then
Throw New ArgumentNullException(paramName:=NameOf(langNames))
End If

Dim languages As String = String.Join(ControlChars.NullChar, langNames)
Dim numLangs As UInteger
Dim result As Boolean = NativeMethods.SetProcessPreferredUILanguages(MuiLanguageMode.Name, languages, numLangs)
If Not (result) Then
Return 0
End If

Return CType(numLangs, Integer)

End Function

''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Sets the preferred UI languages for the current process.
''' <para></para>
''' To retrieve the preferred UI languages for the current process,
''' call <see cref="GetProcessPreferredUILanguages()"/> function.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' Dim cultures As CultureInfo() = {
''' CultureInfo.CreateSpecificCulture("en-US"),
''' CultureInfo.CreateSpecificCulture("es-ES"),
''' CultureInfo.CreateSpecificCulture("it-IT"),
''' CultureInfo.CreateSpecificCulture("de-DE"),
''' CultureInfo.CreateSpecificCulture("fr-FR")
''' }
'''
''' Dim successfulLangs As Integer = SetProcessPreferredUILanguages(cultures)
''' Console.WriteLine($"{NameOf(successfulLangs)}: {successfulLangs}")
'''
''' Dim currentPreferredLangs As ReadOnlyCollection(Of CultureInfo) = GetProcessPreferredUILanguages()
''' Console.WriteLine($"{NameOf(currentPreferredLangs)}: {String.Join(", ", currentPreferredLangs.Select(Function(ci) ci.Name))}")
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
''' <param name="cultures">
''' An array of <see cref="CultureInfo"/> representing each language.
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' Returns the amount of languages that were successfully set.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Function SetProcessPreferredUILanguages(ParamArray cultures As CultureInfo()) As Integer
Return SetProcessPreferredUILanguages(cultures.Select(Function(ci) ci.Name).ToArray())
End Function

#End Region

End Class

End Namespace

#End Region
4 changes: 2 additions & 2 deletions src/DevCase/Extensions/ControlExtensions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Namespace DevCase.Core.Extensions
''' </summary>
''' ----------------------------------------------------------------------------------------------------
<HideModuleName>
Public Module ControlExtensions
Friend Module ControlExtensions

#Region " Public Extension Methods "

Expand Down Expand Up @@ -188,7 +188,7 @@ Namespace DevCase.Core.Extensions
ctrl.BackColor = NumericUpDown.DefaultBackColor
ctrl.ForeColor = NumericUpDown.DefaultForeColor

ElseIf ctrl.GetType() = GetType(panel) Then
ElseIf ctrl.GetType() = GetType(Panel) Then
ctrl.BackColor = Panel.DefaultBackColor
ctrl.ForeColor = Panel.DefaultForeColor

Expand Down
2 changes: 1 addition & 1 deletion src/DevCase/Extensions/FormExtensions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Namespace DevCase.Core.Extensions
''' </summary>
''' ----------------------------------------------------------------------------------------------------
<HideModuleName>
Public Module FormExtensions
Friend Module FormExtensions

#Region " Public Extension Methods "

Expand Down
2 changes: 1 addition & 1 deletion src/DevCase/Extensions/PropertyGridExtensions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Namespace DevCase.Core.Extensions
''' </summary>
''' ----------------------------------------------------------------------------------------------------
<HideModuleName>
Public Module PropertyGridExtensions
Friend Module PropertyGridExtensions

#Region " Public Extension Methods "

Expand Down
51 changes: 39 additions & 12 deletions src/DevCase/FileSizeConverter.vb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ Option Infer Off
Imports System.ComponentModel
Imports System.ComponentModel.Design.Serialization
Imports System.Globalization

Imports System.Runtime.InteropServices
Imports System.Text
Imports DevCase.Core.IO
Imports DevCase.Interop.Unmanaged.Win32

#End Region

Expand All @@ -44,8 +46,9 @@ Namespace DevCase.Core.Design

''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Provides a type converter to convert from a file size specified in bytes,
''' to a rounded file size string using the most approximated unit of size.
''' Provides a type converter to converts a numeric value
''' into a string that represents the number expressed as a size value in bytes,
''' kilobytes, megabytes, gigabytes, petabytes or exabytes, depending on the size.
''' <para></para>
''' Conversion examples:
''' <para></para>
Expand All @@ -60,13 +63,23 @@ Namespace DevCase.Core.Design
''' ----------------------------------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' &lt;TypeConverter(GetType(FileSizeConverter))&gt;
''' &lt;Browsable(True)&gt;
''' Public ReadOnly Property FileSize As Long = 2048 ' Bytes
''' Public Class Form1
'''
''' Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
''' Me.PropertyGrid1.SelectedObject = New TestClass
''' End Sub
'''
''' End Class
'''
''' Public Class TestClass
'''
''' &lt;TypeConverter(GetType(FileSizeConverter))&gt;
''' Public ReadOnly Property FileSize1 As Long = 1024 ' Bytes
'''
''' &lt;TypeConverter(GetType(FileSizeConverter))&gt;
''' &lt;Browsable(True)&gt;
''' Public ReadOnly Property FileSize As New Filesize(2048, SizeUnits.Byte)
''' &lt;TypeConverter(GetType(FileSizeConverter))&gt;
''' Public ReadOnly Property FileSize2 As New Filesize(1024, SizeUnits.Byte)
'''
''' End Class
''' </code>
''' </example>
''' ----------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -169,11 +182,25 @@ Namespace DevCase.Core.Design
End If

If (destinationType Is GetType(String)) Then
If (TypeOf value Is Filesize) Then
Return DirectCast(value, Filesize).ToString()
'If (TypeOf value Is DevCase.Core.IO.Filesize) Then ' Return 'Filesize' string format.
' Return DirectCast(value, DevCase.Core.IO.Filesize).ToString()
'Else
Dim sb As New StringBuilder(16)
Dim longValue As ULong
If ULong.TryParse(value.ToString(), longValue) Then ' Return native string format.
Dim result As IntPtr = NativeMethods.StrFormatByteSize64A(longValue, sb, CUInt(sb.Capacity))
Dim win32Err As Integer = Marshal.GetLastWin32Error()

If (result <> IntPtr.Zero) Then
Return sb.ToString()
Else
Return New Win32Exception(win32Err).Message
End If
Else ' Return original value.
Return value
End If

Return New Filesize(CType(value, Double), SizeUnits.Byte).ToString()
'End If
End If

Return MyBase.ConvertTo(context, culture, value, destinationType)
Expand Down
Loading

0 comments on commit 4ebc80b

Please sign in to comment.