mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-28 23:19:53 +08:00
add OpenSourceLibrary
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
namespace System
|
||||
{
|
||||
internal static class MouseHook
|
||||
{
|
||||
delegate int HookProc(int nCode, int wParam, IntPtr lParam);
|
||||
|
||||
static int _mouseHookHandle;
|
||||
static HookProc? _mouseDelegate;
|
||||
|
||||
static event MouseUpEventHandler? MouseUp;
|
||||
|
||||
public static event MouseUpEventHandler OnMouseUp
|
||||
{
|
||||
add
|
||||
{
|
||||
Subscribe();
|
||||
MouseUp += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
MouseUp -= value;
|
||||
Unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
static void Unsubscribe()
|
||||
{
|
||||
if (_mouseHookHandle != 0)
|
||||
{
|
||||
int result = UnhookWindowsHookEx(_mouseHookHandle);
|
||||
_mouseHookHandle = 0;
|
||||
_mouseDelegate = null;
|
||||
if (result == 0)
|
||||
{
|
||||
int errorCode = Marshal.GetLastWin32Error();
|
||||
throw new Win32Exception(errorCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Subscribe()
|
||||
{
|
||||
if (_mouseHookHandle == 0)
|
||||
{
|
||||
var currentProcessMainModuleName = Process.GetCurrentProcess().MainModule?.ModuleName;
|
||||
if (string.IsNullOrWhiteSpace(currentProcessMainModuleName)) throw new ArgumentNullException(nameof(currentProcessMainModuleName));
|
||||
_mouseDelegate = MouseHookProc;
|
||||
_mouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL,
|
||||
_mouseDelegate,
|
||||
GetModuleHandle(currentProcessMainModuleName),
|
||||
0);
|
||||
if (_mouseHookHandle == 0)
|
||||
{
|
||||
int errorCode = Marshal.GetLastWin32Error();
|
||||
throw new Win32Exception(errorCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
|
||||
{
|
||||
if (nCode >= 0)
|
||||
{
|
||||
var mouseHookStructObj = Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
|
||||
if (mouseHookStructObj == null) throw new ArgumentNullException(nameof(mouseHookStructObj));
|
||||
var mouseHookStruct = (MSLLHOOKSTRUCT)mouseHookStructObj;
|
||||
if (wParam == WM_LBUTTONUP)
|
||||
{
|
||||
if (MouseUp != null)
|
||||
{
|
||||
MouseUp.Invoke(null, new Point(mouseHookStruct.pt.X, mouseHookStruct.pt.Y));
|
||||
}
|
||||
}
|
||||
}
|
||||
return CallNextHookEx(_mouseHookHandle, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
const int WH_MOUSE_LL = 14;
|
||||
const int WM_LBUTTONUP = 0x0202;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct MSLLHOOKSTRUCT
|
||||
{
|
||||
public PointInt32 pt;
|
||||
public uint mouseData;
|
||||
public uint flags;
|
||||
public uint time;
|
||||
public IntPtr dwExtraInfo;
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern IntPtr GetModuleHandle(string name);
|
||||
|
||||
[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto,
|
||||
CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
||||
static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId);
|
||||
|
||||
[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto,
|
||||
CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
||||
static extern int UnhookWindowsHookEx(int idHook);
|
||||
|
||||
[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto,
|
||||
CallingConvention = CallingConvention.StdCall)]
|
||||
static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr LoadCursor(IntPtr hInstance, uint lpCursorName);
|
||||
|
||||
[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto)]
|
||||
public static extern bool SetSystemCursor(IntPtr hcur, uint id);
|
||||
|
||||
public const uint OCR_NORMAL = 32512;
|
||||
public const uint OCR_IBEAM = 32513;
|
||||
public const uint OCR_CROSS = 32515;
|
||||
public const uint OCR_HAND = 32649;
|
||||
|
||||
[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto)]
|
||||
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam,
|
||||
IntPtr pvParam, uint fWinIni);
|
||||
|
||||
public enum SystemParametersDesktopInfo : uint
|
||||
{
|
||||
SPIF_SENDWININICHANGE = 2,
|
||||
SPI_SETDESKWALLPAPER = 20,
|
||||
SPI_SETDESKPATTERN = 21,
|
||||
SPI_SETWORKAREA = 47,
|
||||
SPI_GETWORKAREA = 48,
|
||||
SPI_GETFONTSMOOTHING = 74,
|
||||
SPI_SETFONTSMOOTHING = 75,
|
||||
SPI_SETCURSORS = 87,
|
||||
SPI_GETDESKWALLPAPER = 115,
|
||||
SPI_GETFLATMENU = 4130,
|
||||
SPI_SETFLATMENU = 4131,
|
||||
SPI_GETDROPSHADOW = 4132,
|
||||
SPI_SETDROPSHADOW = 4133,
|
||||
SPI_GETCLEARTYPE = 4168,
|
||||
SPI_SETCLEARTYPE = 4169,
|
||||
SPI_GETFONTSMOOTHINGTYPE = 8202,
|
||||
SPI_SETFONTSMOOTHINGTYPE = 8203,
|
||||
SPI_GETFONTSMOOTHINGCONTRAST = 8204,
|
||||
SPI_SETFONTSMOOTHINGCONTRAST = 8205,
|
||||
SPI_GETFONTSMOOTHINGORIENTATION = 8210,
|
||||
SPI_SETFONTSMOOTHINGORIENTATION = 8211
|
||||
}
|
||||
[Flags]
|
||||
public enum SystemParamtersInfoFlags : uint
|
||||
{
|
||||
None = 0,
|
||||
SPIF_UPDATEINIFILE = 1,
|
||||
SPIF_SENDCHANGE = 2,
|
||||
SPIF_SENDWININICHANGE = 2
|
||||
}
|
||||
|
||||
[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto, EntryPoint = "GetCursorPos")]
|
||||
public static extern bool GetCursorPos(out PointInt32 pt);
|
||||
|
||||
[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto, EntryPoint = "WindowFromPoint")]
|
||||
public static extern IntPtr WindowFromPoint(PointInt32 pt);
|
||||
}
|
||||
|
||||
internal delegate void MouseUpEventHandler(object? sender, Point p);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
internal static class NativeMethods
|
||||
{
|
||||
[DllImport("Avrt.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern IntPtr AvSetMmThreadCharacteristics(string taskName, ref uint taskIndex);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
[Serializable]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct PointInt32
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
|
||||
public PointInt32(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal class RECT
|
||||
{
|
||||
public int left;
|
||||
public int top;
|
||||
public int width;
|
||||
public int height;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace System
|
||||
{
|
||||
internal static class User32Window
|
||||
{
|
||||
public const string LibraryName = "user32.dll";
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Auto, EntryPoint = "FlashWindow")]
|
||||
static extern void FlashWindow(IntPtr hwnd, bool bInvert);
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Auto, EntryPoint = "FlashWindowEx")]
|
||||
static extern void FlashWindowEx(ref FLASHWINFO pwfi);
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Auto)]
|
||||
public static extern bool ShowWindow(IntPtr hWnd, short State);
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Auto)]
|
||||
internal static extern IntPtr GetOpenClipboardWindow();
|
||||
|
||||
[DllImport(LibraryName, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
internal static extern int GetWindowTextLength(IntPtr hWnd);
|
||||
|
||||
public enum Cmd_SHOWWINDOWS : short
|
||||
{
|
||||
/// <summary>
|
||||
/// Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when
|
||||
/// minimizing windows from a different thread.
|
||||
/// </summary>
|
||||
SW_FORCEMINIMIZE = 11,
|
||||
|
||||
/// <summary>
|
||||
/// Hides the window and activates another window.
|
||||
/// </summary>
|
||||
SW_HIDE = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Maximizes the specified window.
|
||||
/// </summary>
|
||||
SW_MAXIMIZE = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Minimizes the specified window and activates the next top-level window in the Z order.
|
||||
/// </summary>
|
||||
SW_MINIMIZE = 6,
|
||||
|
||||
/// <summary>
|
||||
/// Activates and displays the window. If the window is minimized or maximized, the system restores it to its original
|
||||
/// size and position. An application should specify this flag when restoring a minimized window.
|
||||
/// </summary>
|
||||
SW_RESTORE = 9,
|
||||
|
||||
/// <summary>
|
||||
/// Activates the window and displays it in its current size and position.
|
||||
/// </summary>
|
||||
SW_SHOW = 5,
|
||||
|
||||
/// <summary>
|
||||
/// Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess
|
||||
/// function by the program that started the application.
|
||||
/// </summary>
|
||||
SW_SHOWDEFAULT = 10,
|
||||
|
||||
/// <summary>
|
||||
/// Activates the window and displays it as a maximized window.
|
||||
/// </summary>
|
||||
SW_SHOWMAXIMIZED = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Activates the window and displays it as a minimized window.
|
||||
/// </summary>
|
||||
SW_SHOWMINIMIZED = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not
|
||||
/// activated.
|
||||
/// </summary>
|
||||
SW_SHOWMINNOACTIVE = 7,
|
||||
|
||||
/// <summary>
|
||||
/// Displays the window in its current size and position. This value is similar to SW_SHOW, except that the window is
|
||||
/// not activated.
|
||||
/// </summary>
|
||||
SW_SHOWNA = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except that the
|
||||
/// window is not activated.
|
||||
/// </summary>
|
||||
SW_SHOWNOACTIVATE = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Activates and displays a window. If the window is minimized or maximized, the system restores it to its original
|
||||
/// size and position. An application should specify this flag when displaying the window for the first time.
|
||||
/// </summary>
|
||||
SW_SHOWNORMAL = 1
|
||||
};
|
||||
|
||||
internal struct FLASHWINFO
|
||||
{
|
||||
#pragma warning disable 649
|
||||
|
||||
/// <summary>
|
||||
/// 该结构的字节大小
|
||||
/// </summary>
|
||||
public uint cbSize;
|
||||
|
||||
/// <summary>
|
||||
/// 要闪烁的窗口的句柄,该窗口可以是打开的或最小化的
|
||||
/// </summary>
|
||||
public IntPtr hwnd;
|
||||
|
||||
/// <summary>
|
||||
/// 闪烁的状态
|
||||
/// </summary>
|
||||
public uint dwFlags;
|
||||
|
||||
/// <summary>
|
||||
/// 闪烁窗口的次数
|
||||
/// </summary>
|
||||
public uint uCount;
|
||||
|
||||
/// <summary>
|
||||
/// 窗口闪烁的频度,毫秒为单位;若该值为0,则为默认图标的闪烁频度
|
||||
/// </summary>
|
||||
public uint dwTimeout;
|
||||
|
||||
#pragma warning restore 649
|
||||
}
|
||||
|
||||
public const uint FLASHW_TRAY = 2;
|
||||
public const uint FLASHW_TIMERNOFG = 12;
|
||||
|
||||
//获取窗口标题
|
||||
[DllImport(LibraryName, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static extern int GetWindowText(
|
||||
IntPtr hWnd,//窗口句柄
|
||||
StringBuilder lpString,//标题
|
||||
int nMaxCount //最大值
|
||||
);
|
||||
|
||||
//获取类的名字
|
||||
[DllImport(LibraryName, CharSet = CharSet.Unicode)]
|
||||
public static extern int GetClassName(
|
||||
IntPtr hWnd,//句柄
|
||||
StringBuilder lpString, //类名
|
||||
int nMaxCount //最大值
|
||||
);
|
||||
|
||||
//获取句柄所属进程pid
|
||||
[DllImport(LibraryName, CharSet = CharSet.Auto, EntryPoint = "GetWindowThreadProcessId")]
|
||||
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int pid);
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Unicode)]
|
||||
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Unicode)]
|
||||
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
|
||||
[DllImport(LibraryName, ExactSpelling = true)]
|
||||
public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
|
||||
|
||||
[DllImport(LibraryName, ExactSpelling = true)]
|
||||
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
|
||||
|
||||
[DllImport(LibraryName, ExactSpelling = true)]
|
||||
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool bRepaint);
|
||||
|
||||
// This static method is required because Win32 does not support
|
||||
// GetWindowLongPtr directly
|
||||
public static IntPtr GetWindowLongPtr(IntPtr hwnd, int nIndex)
|
||||
{
|
||||
return IntPtr.Size > 4
|
||||
? GetWindowLongPtr_x64(hwnd, nIndex)
|
||||
: new IntPtr(GetWindowLong(hwnd, nIndex));
|
||||
}
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Auto)]
|
||||
static extern int GetWindowLong(IntPtr hwnd, int nIndex);
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Auto, EntryPoint = "GetWindowLongPtr")]
|
||||
static extern IntPtr GetWindowLongPtr_x64(IntPtr hwnd, int nIndex);
|
||||
|
||||
// This static method is required because Win32 does not support
|
||||
// GetWindowLongPtr directly
|
||||
public static IntPtr SetWindowLongPtr(IntPtr hwnd, int nIndex, IntPtr dwNewLong)
|
||||
{
|
||||
return IntPtr.Size > 4
|
||||
? SetWindowLongPtr_x64(hwnd, nIndex, dwNewLong)
|
||||
: new IntPtr(SetWindowLong(hwnd, nIndex, dwNewLong.ToInt32()));
|
||||
}
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Auto)]
|
||||
static extern int SetWindowLong(IntPtr hwnd, int nIndex, int dwNewLong);
|
||||
|
||||
[DllImport(LibraryName, CharSet = CharSet.Auto, EntryPoint = "SetWindowLongPtr")]
|
||||
static extern IntPtr SetWindowLongPtr_x64(IntPtr hwnd, int nIndex, IntPtr dwNewLong);
|
||||
|
||||
public static void FlashWindow(IntPtr hwnd)
|
||||
{
|
||||
//ShowWindow(hwnd, (short)Cmd_SHOWWINDOWS.SW_NORMAL);
|
||||
//直接调用FlashWindow即可
|
||||
FlashWindow(hwnd, true);
|
||||
}
|
||||
|
||||
public static void FlashWindow(ref FLASHWINFO f)
|
||||
{
|
||||
//直接调用FlashWindow即可
|
||||
FlashWindowEx(ref f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
internal static class WinHttp
|
||||
{
|
||||
[DllImport("winhttp.dll", SetLastError = true)]
|
||||
internal static extern bool WinHttpGetIEProxyConfigForCurrentUser(ref WinHttpCurrentUserIEProxyConfig pProxyConfig);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct WinHttpCurrentUserIEProxyConfig
|
||||
{
|
||||
[MarshalAs(UnmanagedType.Bool)]
|
||||
public bool AutoDetect;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string AutoConfigUrl;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string Proxy;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string ProxyBypass;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace System
|
||||
{
|
||||
internal class WinInet
|
||||
{
|
||||
// For PInvoke: Initiates the enumeration of the cache groups in the Internet cache
|
||||
[DllImport(@"wininet",
|
||||
SetLastError = true,
|
||||
CharSet = CharSet.Auto,
|
||||
EntryPoint = "FindFirstUrlCacheGroup",
|
||||
CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern IntPtr FindFirstUrlCacheGroup(
|
||||
int dwFlags,
|
||||
int dwFilter,
|
||||
IntPtr lpSearchCondition,
|
||||
int dwSearchCondition,
|
||||
ref long lpGroupId,
|
||||
IntPtr lpReserved);
|
||||
|
||||
// For PInvoke: Retrieves the next cache group in a cache group enumeration
|
||||
[DllImport(@"wininet",
|
||||
SetLastError = true,
|
||||
CharSet = CharSet.Auto,
|
||||
EntryPoint = "FindNextUrlCacheGroup",
|
||||
CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern bool FindNextUrlCacheGroup(
|
||||
IntPtr hFind,
|
||||
ref long lpGroupId,
|
||||
IntPtr lpReserved);
|
||||
|
||||
// For PInvoke: Releases the specified GROUPID and any associated state in the cache index file
|
||||
[DllImport(@"wininet",
|
||||
SetLastError = true,
|
||||
CharSet = CharSet.Auto,
|
||||
EntryPoint = "DeleteUrlCacheGroup",
|
||||
CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern bool DeleteUrlCacheGroup(
|
||||
long groupId,
|
||||
int dwFlags,
|
||||
IntPtr lpReserved);
|
||||
|
||||
// For PInvoke: Begins the enumeration of the Internet cache
|
||||
[DllImport(@"wininet",
|
||||
SetLastError = true,
|
||||
CharSet = CharSet.Auto,
|
||||
EntryPoint = "FindFirstUrlCacheEntryA",
|
||||
CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern IntPtr FindFirstUrlCacheEntry(
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string lpszUrlSearchPattern,
|
||||
IntPtr lpFirstCacheEntryInfo,
|
||||
ref int lpdwFirstCacheEntryInfoBufferSize);
|
||||
|
||||
// For PInvoke: Retrieves the next entry in the Internet cache
|
||||
[DllImport(@"wininet",
|
||||
SetLastError = true,
|
||||
CharSet = CharSet.Auto,
|
||||
EntryPoint = "FindNextUrlCacheEntryA",
|
||||
CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern bool FindNextUrlCacheEntry(
|
||||
IntPtr hFind,
|
||||
IntPtr lpNextCacheEntryInfo,
|
||||
ref int lpdwNextCacheEntryInfoBufferSize);
|
||||
|
||||
// For PInvoke: Removes the file that is associated with the source name from the cache, if the file exists
|
||||
[DllImport(@"wininet",
|
||||
SetLastError = true,
|
||||
CharSet = CharSet.Auto,
|
||||
EntryPoint = "DeleteUrlCacheEntryA",
|
||||
CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern bool DeleteUrlCacheEntry(
|
||||
IntPtr lpszUrlName);
|
||||
|
||||
[DllImport("wininet.dll",
|
||||
SetLastError = true,
|
||||
CharSet = CharSet.Unicode,
|
||||
EntryPoint = "InternetGetCookieEx",
|
||||
CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern bool InternetGetCookieEx(
|
||||
string url,
|
||||
string? cookieName,
|
||||
StringBuilder cookieData,
|
||||
ref int size,
|
||||
int dwFlags,
|
||||
IntPtr lpReserved);
|
||||
|
||||
//Read HTTP Only
|
||||
const int InternetCookieHttponly = 0x2000;
|
||||
|
||||
public static CookieContainer? GetUriCookieContainer(Uri uri)
|
||||
{
|
||||
// First, create a null cookie container
|
||||
CookieContainer? cookies = null;
|
||||
|
||||
// Determine the size of the cookie
|
||||
var datasize = 8192 * 16;
|
||||
var cookieData = new StringBuilder(datasize);
|
||||
|
||||
// Call InternetGetCookieEx from wininet.dll
|
||||
if (!InternetGetCookieEx(uri.ToString(), null, cookieData, ref datasize, InternetCookieHttponly, IntPtr.Zero))
|
||||
{
|
||||
if (datasize < 0)
|
||||
return null;
|
||||
// Allocate stringbuilder large enough to hold the cookie
|
||||
cookieData = new StringBuilder(datasize);
|
||||
if (!InternetGetCookieEx(
|
||||
uri.ToString(),
|
||||
null, cookieData,
|
||||
ref datasize,
|
||||
InternetCookieHttponly,
|
||||
IntPtr.Zero))
|
||||
return null;
|
||||
}
|
||||
|
||||
// If the cookie contains data, add it to the cookie container
|
||||
if (cookieData.Length > 0)
|
||||
{
|
||||
cookies = new CookieContainer();
|
||||
cookies.SetCookies(uri, cookieData.ToString().Replace(';', ','));
|
||||
}
|
||||
|
||||
// Return the cookie container
|
||||
return cookies;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
//
|
||||
//
|
||||
// This file was generated, please do not edit it directly.
|
||||
//
|
||||
// Please see MilCodeGen.html for more information.
|
||||
//
|
||||
|
||||
// These types are aliased to match the unamanaged names used in interop
|
||||
|
||||
namespace System.Windows
|
||||
{
|
||||
[Serializable]
|
||||
partial struct Point : IFormattable
|
||||
{
|
||||
//------------------------------------------------------
|
||||
//
|
||||
// Public Methods
|
||||
//
|
||||
//------------------------------------------------------
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Compares two Point instances for exact equality.
|
||||
/// Note that double values can acquire error when operated upon, such that
|
||||
/// an exact comparison between two values which are logically equal may fail.
|
||||
/// Furthermore, using this equality operator, Double.NaN is not equal to itself.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// bool - true if the two Point instances are exactly equal, false otherwise
|
||||
/// </returns>
|
||||
/// <param name='point1'>The first Point to compare</param>
|
||||
/// <param name='point2'>The second Point to compare</param>
|
||||
public static bool operator ==(Point point1, Point point2)
|
||||
{
|
||||
return point1.X == point2.X &&
|
||||
point1.Y == point2.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two Point instances for exact inequality.
|
||||
/// Note that double values can acquire error when operated upon, such that
|
||||
/// an exact comparison between two values which are logically equal may fail.
|
||||
/// Furthermore, using this equality operator, Double.NaN is not equal to itself.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// bool - true if the two Point instances are exactly unequal, false otherwise
|
||||
/// </returns>
|
||||
/// <param name='point1'>The first Point to compare</param>
|
||||
/// <param name='point2'>The second Point to compare</param>
|
||||
public static bool operator !=(Point point1, Point point2)
|
||||
{
|
||||
return !(point1 == point2);
|
||||
}
|
||||
/// <summary>
|
||||
/// Compares two Point instances for object equality. In this equality
|
||||
/// Double.NaN is equal to itself, unlike in numeric equality.
|
||||
/// Note that double values can acquire error when operated upon, such that
|
||||
/// an exact comparison between two values which
|
||||
/// are logically equal may fail.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// bool - true if the two Point instances are exactly equal, false otherwise
|
||||
/// </returns>
|
||||
/// <param name='point1'>The first Point to compare</param>
|
||||
/// <param name='point2'>The second Point to compare</param>
|
||||
public static bool Equals(Point point1, Point point2)
|
||||
{
|
||||
return point1.X.Equals(point2.X) &&
|
||||
point1.Y.Equals(point2.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Equals - compares this Point with the passed in object. In this equality
|
||||
/// Double.NaN is equal to itself, unlike in numeric equality.
|
||||
/// Note that double values can acquire error when operated upon, such that
|
||||
/// an exact comparison between two values which
|
||||
/// are logically equal may fail.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// bool - true if the object is an instance of Point and if it's equal to "this".
|
||||
/// </returns>
|
||||
/// <param name='o'>The object to compare to "this"</param>
|
||||
public override bool Equals(object o)
|
||||
{
|
||||
if ((null == o) || !(o is Point))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Point value = (Point)o;
|
||||
return Point.Equals(this, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Equals - compares this Point with the passed in object. In this equality
|
||||
/// Double.NaN is equal to itself, unlike in numeric equality.
|
||||
/// Note that double values can acquire error when operated upon, such that
|
||||
/// an exact comparison between two values which
|
||||
/// are logically equal may fail.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// bool - true if "value" is equal to "this".
|
||||
/// </returns>
|
||||
/// <param name='value'>The Point to compare to "this"</param>
|
||||
public bool Equals(Point value)
|
||||
{
|
||||
return Point.Equals(this, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the HashCode for this Point
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// int - the HashCode for this Point
|
||||
/// </returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// Perform field-by-field XOR of HashCodes
|
||||
return X.GetHashCode() ^
|
||||
Y.GetHashCode();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
//------------------------------------------------------
|
||||
//
|
||||
// Public Properties
|
||||
//
|
||||
//------------------------------------------------------
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// X - double. Default value is 0.
|
||||
/// </summary>
|
||||
public double X
|
||||
{
|
||||
get
|
||||
{
|
||||
return _x;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_x = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Y - double. Default value is 0.
|
||||
/// </summary>
|
||||
public double Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return _y;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_y = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
//------------------------------------------------------
|
||||
//
|
||||
// Protected Methods
|
||||
//
|
||||
//------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------
|
||||
//
|
||||
// Internal Methods
|
||||
//
|
||||
//------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------
|
||||
//
|
||||
// Internal Properties
|
||||
//
|
||||
//------------------------------------------------------
|
||||
|
||||
#region Internal Properties
|
||||
|
||||
/// <summary>
|
||||
/// Creates a string representation of this object based on the current culture.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A string representation of this object.
|
||||
/// </returns>
|
||||
public override string ToString()
|
||||
{
|
||||
// Delegate to the internal method which implements all ToString calls.
|
||||
return ConvertToString(null /* format string */, null /* format provider */);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a string representation of this object based on the IFormatProvider
|
||||
/// passed in. If the provider is null, the CurrentCulture is used.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A string representation of this object.
|
||||
/// </returns>
|
||||
public string ToString(IFormatProvider provider)
|
||||
{
|
||||
// Delegate to the internal method which implements all ToString calls.
|
||||
return ConvertToString(null /* format string */, provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a string representation of this object based on the format string
|
||||
/// and IFormatProvider passed in.
|
||||
/// If the provider is null, the CurrentCulture is used.
|
||||
/// See the documentation for IFormattable for more information.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A string representation of this object.
|
||||
/// </returns>
|
||||
string IFormattable.ToString(string format, IFormatProvider provider)
|
||||
{
|
||||
// Delegate to the internal method which implements all ToString calls.
|
||||
return ConvertToString(format, provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a string representation of this object based on the format string
|
||||
/// and IFormatProvider passed in.
|
||||
/// If the provider is null, the CurrentCulture is used.
|
||||
/// See the documentation for IFormattable for more information.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A string representation of this object.
|
||||
/// </returns>
|
||||
internal string ConvertToString(string format, IFormatProvider provider)
|
||||
{
|
||||
// Helper to get the numeric list separator for a given culture.
|
||||
const char separator = ',';
|
||||
return String.Format(provider,
|
||||
"{1:" + format + "}{0}{2:" + format + "}",
|
||||
separator,
|
||||
_x,
|
||||
_y);
|
||||
}
|
||||
|
||||
#endregion Internal Properties
|
||||
|
||||
//------------------------------------------------------
|
||||
//
|
||||
// Dependency Properties
|
||||
//
|
||||
//------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------
|
||||
//
|
||||
// Internal Fields
|
||||
//
|
||||
//------------------------------------------------------
|
||||
|
||||
#region Internal Fields
|
||||
|
||||
internal double _x;
|
||||
internal double _y;
|
||||
|
||||
#endregion Internal Fields
|
||||
|
||||
#region Constructors
|
||||
|
||||
//------------------------------------------------------
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
//------------------------------------------------------
|
||||
|
||||
#endregion Constructors
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
//
|
||||
|
||||
namespace System.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Point - Defaults to 0,0
|
||||
/// </summary>
|
||||
public partial struct Point
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructor which accepts the X and Y values
|
||||
/// </summary>
|
||||
/// <param name="x">The value for the X coordinate of the new Point</param>
|
||||
/// <param name="y">The value for the Y coordinate of the new Point</param>
|
||||
public Point(double x, double y)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
}
|
||||
|
||||
#endregion Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Offset - update the location by adding offsetX to X and offsetY to Y
|
||||
/// </summary>
|
||||
/// <param name="offsetX"> The offset in the x dimension </param>
|
||||
/// <param name="offsetY"> The offset in the y dimension </param>
|
||||
public void Offset(double offsetX, double offsetY)
|
||||
{
|
||||
_x += offsetX;
|
||||
_y += offsetY;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user