This commit is contained in:
NaBian committed 2020-07-14 23:09:13 +08:00
1 parent 25a6117ee1
commit d4e32272a2
19 files changed
+349 -148

No files matched your search

@@ -0,0 +1,33 @@
using System;
namespace HandyControl.Data
{
public class GrowlInfo
{
public string Message { get; set; }
public bool ShowDateTime { get; set; } = true;
public int WaitTime { get; set; } = 6;
public string CancelStr { get; set; } = Properties.Langs.Lang.Cancel;
public string ConfirmStr { get; set; } = Properties.Langs.Lang.Confirm;
public Func<bool, bool> ActionBeforeClose { get; set; }
public bool StaysOpen { get; set; }
public bool IsCustom { get; set; }
public InfoType Type { get; set; }
public string IconKey { get; set; }
public string IconBrushKey { get; set; }
public bool ShowCloseButton { get; set; } = true;
public string Token { get; set; }
}
}
@@ -0,0 +1,158 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using HandyControl.Tools.Interop;
namespace HandyControl.Data
{
internal sealed class ImageCodecInfo
{
private string _dllName;
public Guid Clsid { get; set; }
public Guid FormatID { get; set; }
public string CodecName { get; set; }
public string DllName
{
[SuppressMessage("Microsoft.Security", "CA2103:ReviewImperativeSecurity")]
get
{
if (_dllName != null)
{
new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.PathDiscovery, _dllName).Demand();
}
return _dllName;
}
[SuppressMessage("Microsoft.Security", "CA2103:ReviewImperativeSecurity")]
set
{
if (value != null)
{
new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.PathDiscovery, value).Demand();
}
_dllName = value;
}
}
public string FormatDescription { get; set; }
public string FilenameExtension { get; set; }
public string MimeType { get; set; }
public ImageCodecFlags Flags { get; set; }
public int Version { get; set; }
public byte[][] SignaturePatterns { get; set; }
public byte[][] SignatureMasks { get; set; }
public static ImageCodecInfo[] GetImageDecoders()
{
ImageCodecInfo[] imageCodecs;
var status = InteropMethods.Gdip.GdipGetImageDecodersSize(out var numDecoders, out var size);
if (status != InteropMethods.Gdip.Ok)
{
throw InteropMethods.Gdip.StatusException(status);
}
var memory = Marshal.AllocHGlobal(size);
try
{
status = InteropMethods.Gdip.GdipGetImageDecoders(numDecoders, size, memory);
if (status != InteropMethods.Gdip.Ok)
{
throw InteropMethods.Gdip.StatusException(status);
}
imageCodecs = ConvertFromMemory(memory, numDecoders);
}
finally
{
Marshal.FreeHGlobal(memory);
}
return imageCodecs;
}
public static ImageCodecInfo[] GetImageEncoders()
{
ImageCodecInfo[] imageCodecs;
var status = InteropMethods.Gdip.GdipGetImageEncodersSize(out var numEncoders, out var size);
if (status != InteropMethods.Gdip.Ok)
{
throw InteropMethods.Gdip.StatusException(status);
}
var memory = Marshal.AllocHGlobal(size);
try
{
status = InteropMethods.Gdip.GdipGetImageEncoders(numEncoders, size, memory);
if (status != InteropMethods.Gdip.Ok)
{
throw InteropMethods.Gdip.StatusException(status);
}
imageCodecs = ConvertFromMemory(memory, numEncoders);
}
finally
{
Marshal.FreeHGlobal(memory);
}
return imageCodecs;
}
public static ImageCodecInfo[] ConvertFromMemory(IntPtr memoryStart, int numCodecs)
{
var codecs = new ImageCodecInfo[numCodecs];
int index;
for (index = 0; index < numCodecs; index++)
{
var curcodec = (IntPtr)((long)memoryStart + Marshal.SizeOf(typeof(InteropValues.ImageCodecInfoPrivate)) * index);
var codecp = new InteropValues.ImageCodecInfoPrivate();
InteropMethods.PtrToStructure(curcodec, codecp);
codecs[index] = new ImageCodecInfo
{
Clsid = codecp.Clsid,
FormatID = codecp.FormatID,
CodecName = Marshal.PtrToStringUni(codecp.CodecName),
DllName = Marshal.PtrToStringUni(codecp.DllName),
FormatDescription = Marshal.PtrToStringUni(codecp.FormatDescription),
FilenameExtension = Marshal.PtrToStringUni(codecp.FilenameExtension),
MimeType = Marshal.PtrToStringUni(codecp.MimeType),
Flags = (ImageCodecFlags) codecp.Flags,
Version = codecp.Version,
SignaturePatterns = new byte[codecp.SigCount][],
SignatureMasks = new byte[codecp.SigCount][]
};
for (var j = 0; j < codecp.SigCount; j++)
{
codecs[index].SignaturePatterns[j] = new byte[codecp.SigSize];
codecs[index].SignatureMasks[j] = new byte[codecp.SigSize];
Marshal.Copy((IntPtr)((long)codecp.SigMask + j * codecp.SigSize), codecs[index].SignatureMasks[j], 0, codecp.SigSize);
Marshal.Copy((IntPtr)((long)codecp.SigPattern + j * codecp.SigSize), codecs[index].SignaturePatterns[j], 0, codecp.SigSize);
}
}
return codecs;
}
}
}
@@ -0,0 +1,21 @@
using System.Windows;
namespace HandyControl.Data
{
public class MessageBoxInfo
{
public string Message { get; set; }
public string Caption { get; set; }
public MessageBoxButton Button { get; set; } = MessageBoxButton.OK;
public string IconKey { get; set; }
public string IconBrushKey { get; set; }
public MessageBoxResult DefaultResult { get; set; } = MessageBoxResult.None;
public string StyleKey { get; set; }
}
}
@@ -0,0 +1,79 @@
// reference from https://github.com/sourcechord/FluentWPF/blob/master/FluentWPF/Utility/VersionInfo.cs
// LICENSE: https://github.com/sourcechord/FluentWPF/blob/master/LICENSE
using System;
namespace HandyControl.Data
{
public readonly struct SystemVersionInfo
{
public static SystemVersionInfo Windows10 => new SystemVersionInfo(10, 0, 10240);
public static SystemVersionInfo Windows10_1809 => new SystemVersionInfo(10, 0, 17763);
public static SystemVersionInfo Windows10_1903 => new SystemVersionInfo(10, 0, 18362);
public SystemVersionInfo(int major, int minor, int build)
{
Major = major;
Minor = minor;
Build = build;
}
public int Major { get; }
public int Minor { get; }
public int Build { get; }
public bool Equals(SystemVersionInfo other) => Major == other.Major && Minor == other.Minor && Build == other.Build;
public override bool Equals(object obj) => obj is SystemVersionInfo other && Equals(other);
public override int GetHashCode() => Major.GetHashCode() ^ Minor.GetHashCode() ^ Build.GetHashCode();
public static bool operator ==(SystemVersionInfo left, SystemVersionInfo right) => left.Equals(right);
public static bool operator !=(SystemVersionInfo left, SystemVersionInfo right) => !(left == right);
public int CompareTo(SystemVersionInfo other)
{
if (Major != other.Major)
{
return Major.CompareTo(other.Major);
}
if (Minor != other.Minor)
{
return Minor.CompareTo(other.Minor);
}
if (Build != other.Build)
{
return Build.CompareTo(other.Build);
}
return 0;
}
public int CompareTo(object obj)
{
if (!(obj is SystemVersionInfo other))
{
throw new ArgumentException();
}
return CompareTo(other);
}
public static bool operator <(SystemVersionInfo left, SystemVersionInfo right) => left.CompareTo(right) < 0;
public static bool operator <=(SystemVersionInfo left, SystemVersionInfo right) => left.CompareTo(right) <= 0;
public static bool operator >(SystemVersionInfo left, SystemVersionInfo right) => left.CompareTo(right) > 0;
public static bool operator >=(SystemVersionInfo left, SystemVersionInfo right) => left.CompareTo(right) >= 0;
public override string ToString() => $"{Major}.{Minor}.{Build}";
}
}