public RatelimitWindow() { InitializeComponent(); PInvokeHelper.DisableMinimizeButton(this); PInvokeHelper.DisableMaximizeButton(this); _vm = new RatelimitWindowViewModel(); DataContext = _vm; _vm.RefreshCommand = new RelayCommand(async o => { RefreshButton.IsEnabled = false; await _vm.Refresh(); RefreshButton.IsEnabled = true; }); _vm.RefreshCommand.Execute(null); }
/// <summary> /// /// </summary> /// <param name="s"></param> /// <param name="e"></param> /// <returns></returns> public static MatExpr operator /(double s, MatExpr e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } e.ThrowIfDisposed(); try { var retPtr = NativeMethods.core_operatorDivide_DoubleMatExpr(s, e.CvPtr); GC.KeepAlive(e); return(new MatExpr(retPtr)); } catch (BadImageFormatException ex) { throw PInvokeHelper.CreateException(ex); } }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="s"></param> /// <returns></returns> public static MatExpr operator -(MatExpr e, Scalar s) { if (e == null) { throw new ArgumentNullException(nameof(e)); } e.ThrowIfDisposed(); try { var retPtr = NativeMethods.core_operatorSubtract_MatExprScalar(e.CvPtr, s); GC.KeepAlive(e); return(new MatExpr(retPtr)); } catch (BadImageFormatException ex) { throw PInvokeHelper.CreateException(ex); } }
/// <summary> /// Checks whether PInvoke functions can be called /// </summary> public static void TryPInvoke() { if (tried) { return; } tried = true; try { core_Mat_sizeof(); } catch (DllNotFoundException e) { var exception = PInvokeHelper.CreateException(e); try { Debug.WriteLine(exception.Message); } catch { } throw exception; } catch (BadImageFormatException e) { var exception = PInvokeHelper.CreateException(e); try { Debug.WriteLine(exception.Message); } catch { } throw exception; } catch (Exception e) { Exception ex = e.InnerException ?? e; try { Debug.WriteLine(ex.Message); } catch { } throw; } }
public static void SetFileAttributes(string filePath, FileAttributes attributes) { filePath = CheckAddLongPathPrefix(filePath); if (!PInvokeHelper.SetFileAttributes(filePath, attributes)) { // http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx. var lastWin32Error = Marshal.GetLastWin32Error(); throw new Win32Exception( lastWin32Error, string.Format( Resources.ErrorSettingAttributes, lastWin32Error, filePath, attributes, CheckAddDotEnd(new Win32Exception(lastWin32Error).Message))); } }
/// <summary> /// Displays the image in the specified window /// </summary> /// <param name="winname">Name of the window.</param> /// <param name="mat">Image to be shown.</param> public static void ImShow(string winname, Mat mat) { if (string.IsNullOrEmpty(winname)) { throw new ArgumentNullException("nameof(winname)"); } if (mat == null) { throw new ArgumentNullException("nameof(mat)"); } try { NativeMethods.highgui_imshow(winname, mat.CvPtr); } catch (BadImageFormatException ex) { throw PInvokeHelper.CreateException(ex); } }
public static void DeleteDirectory(string folderPath, bool recursive) { folderPath = CheckAddLongPathPrefix(folderPath); if (DirectoryExists(folderPath)) { if (recursive) { var files = GetFiles(folderPath); var dirs = GetDirectories(folderPath); foreach (var file in files) { DeleteFile(file.FullName); } foreach (var dir in dirs) { DeleteDirectory(dir.FullName, true); } } if (!PInvokeHelper.RemoveDirectory(folderPath)) { { // http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx. var lastWin32Error = Marshal.GetLastWin32Error(); if (lastWin32Error != PInvokeHelper.ERROR_NO_MORE_FILES) { throw new Win32Exception( lastWin32Error, string.Format( Resources.ErrorDeletingFolder, lastWin32Error, folderPath, CheckAddDotEnd(new Win32Exception(lastWin32Error).Message))); } } } } }
public CustomSizeWindow(ImageLoader.FitMode currentFit) { InitializeComponent(); PInvokeHelper.DisableMinimizeButton(this); PInvokeHelper.DisableMaximizeButton(this); switch (currentFit) { case ImageLoader.FitMode.Fill: Fill.IsChecked = true; break; case ImageLoader.FitMode.Stretch: Stretch.IsChecked = true; break; default: throw new ArgumentOutOfRangeException(nameof(currentFit), currentFit, null); } }
/// <summary> /// static constructor /// </summary> static StereoBM_GPU() { try { SizeOf = (int)GpuInvoke.StereoBM_GPU_sizeof(); } catch (DllNotFoundException e) { PInvokeHelper.DllImportError(e); throw; } catch (BadImageFormatException e) { PInvokeHelper.DllImportError(e); throw; } catch (Exception) { throw; } }
public static bool FileExists(string filePath) { filePath = CheckAddLongPathPrefix(filePath); var wIn32FileAttributeData = default(PInvokeHelper.WIN32_FILE_ATTRIBUTE_DATA); var b = PInvokeHelper.GetFileAttributesEx(filePath, 0, ref wIn32FileAttributeData); return(b && wIn32FileAttributeData.dwFileAttributes != -1 && (wIn32FileAttributeData.dwFileAttributes & 16) == 0); // -- //var a = PInvokeHelper.GetFileAttributes(filePath); //if ((a & PInvokeHelper.INVALID_FILE_ATTRIBUTES) == PInvokeHelper.INVALID_FILE_ATTRIBUTES) //{ // return false; //} //else //{ // return (a & PInvokeHelper.FILE_ATTRIBUTE_DIRECTORY) == 0; //} // -- //filePath = CheckAddLongPathPrefix(filePath); //PInvokeHelper.WIN32_FIND_DATA fd; //var result = PInvokeHelper.FindFirstFile(filePath.TrimEnd('\\'), out fd); //if (result.ToInt32() == PInvokeHelper.ERROR_FILE_NOT_FOUND || result == PInvokeHelper.INVALID_HANDLE_VALUE) //{ // return false; //} //else //{ // return ((int)fd.dwFileAttributes & PInvokeHelper.FILE_ATTRIBUTE_DIRECTORY) == 0; //} }
public static ZlpDirectoryInfo[] GetDirectories(string directoryPath, string pattern) { directoryPath = CheckAddLongPathPrefix(directoryPath); var results = new List <ZlpDirectoryInfo>(); PInvokeHelper.WIN32_FIND_DATA findData; var findHandle = PInvokeHelper.FindFirstFile(directoryPath.TrimEnd('\\') + @"\" + pattern, out findData); if (findHandle != PInvokeHelper.INVALID_HANDLE_VALUE) { try { bool found; do { var currentFileName = findData.cFileName; // if this is a directory, find its contents if (((int)findData.dwFileAttributes & PInvokeHelper.FILE_ATTRIBUTE_DIRECTORY) != 0) { if (currentFileName != @"." && currentFileName != @"..") { results.Add(new ZlpDirectoryInfo(ZlpPathHelper.Combine(directoryPath, currentFileName))); } } // find next found = PInvokeHelper.FindNextFile(findHandle, out findData); } while (found); } finally { // close the find handle PInvokeHelper.FindClose(findHandle); } } return(results.ToArray()); }
/// <summary> /// /// </summary> /// <param name="e1"></param> /// <param name="e2"></param> /// <returns></returns> public static MatExpr operator /(MatExpr e1, MatExpr e2) { if (e1 == null) { throw new ArgumentNullException("e1"); } if (e2 == null) { throw new ArgumentNullException("e2"); } e1.ThrowIfDisposed(); e2.ThrowIfDisposed(); try { IntPtr retPtr = NativeMethods.core_operatorDivide_MatExprMatExpr(e1.CvPtr, e2.CvPtr); return(new MatExpr(retPtr)); } catch (BadImageFormatException ex) { throw PInvokeHelper.CreateException(ex); } }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="m"></param> /// <returns></returns> public static MatExpr operator *(MatExpr e, Mat m) { if (e == null) { throw new ArgumentNullException("e"); } if (m == null) { throw new ArgumentNullException("m"); } e.ThrowIfDisposed(); m.ThrowIfDisposed(); try { IntPtr retPtr = NativeMethods.core_operatorMultiply_MatExprMat(e.CvPtr, m.CvPtr); return(new MatExpr(retPtr)); } catch (BadImageFormatException ex) { throw PInvokeHelper.CreateException(ex); } }
public static void MoveDirectory( string sourceFolderPath, string destinationFolderPath) { sourceFolderPath = CheckAddLongPathPrefix(sourceFolderPath); destinationFolderPath = CheckAddLongPathPrefix(destinationFolderPath); if (!PInvokeHelper.MoveFile(sourceFolderPath, destinationFolderPath)) { // http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx. var lastWin32Error = Marshal.GetLastWin32Error(); throw new Win32Exception( lastWin32Error, string.Format( Resources.ErrorMovingFolder, lastWin32Error, sourceFolderPath, destinationFolderPath, CheckAddDotEnd(new Win32Exception(lastWin32Error).Message))); } }
/// <summary> /// /// </summary> /// <param name="m"></param> /// <param name="e"></param> /// <returns></returns> public static MatExpr operator /(Mat m, MatExpr e) { if (m == null) { throw new ArgumentNullException("m"); } if (e == null) { throw new ArgumentNullException("e"); } m.ThrowIfDisposed(); e.ThrowIfDisposed(); try { IntPtr retPtr = NativeMethods.core_operatorDivide_MatMatExpr(m.CvPtr, e.CvPtr); return(new MatExpr(retPtr)); } catch (BadImageFormatException ex) { throw PInvokeHelper.CreateException(ex); } }
public static void CopyFile( string sourceFilePath, string destinationFilePath, bool overwriteExisting) { sourceFilePath = CheckAddLongPathPrefix(sourceFilePath); destinationFilePath = CheckAddLongPathPrefix(destinationFilePath); if (!PInvokeHelper.CopyFile(sourceFilePath, destinationFilePath, !overwriteExisting)) { // http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx. var lastWin32Error = Marshal.GetLastWin32Error(); throw new Win32Exception( lastWin32Error, string.Format( Resources.ErrorCopyingFile, lastWin32Error, sourceFilePath, destinationFilePath, CheckAddDotEnd(new Win32Exception(lastWin32Error).Message))); } }
private void Pipe_OnProcessEvent(int layerIndex, IntPtr data, int width, int height, int outputIndex) { if (layerIndex == cameraView.VideoPipe.DarknetIndex) { if (width > 0) { personBox = PInvokeHelper.GetPInvokeArray <PersonBox>(width, data); Loom.QueueOnMainThread(() => { if (personBox == null) { return; } string msg = string.Empty; foreach (var px in personBox) { msg += " " + px.prob; } label.text = $"人数:{width} {msg}"; }); } } }
/// <summary> /// Saves an image to a specified file. /// </summary> /// <param name="fileName"></param> /// <param name="img"></param> /// <param name="prms"></param> /// <returns></returns> public static bool ImWrite(string fileName, Mat img, int[] prms = null) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } if (img == null) { throw new ArgumentNullException(nameof(img)); } if (prms == null) { prms = new int[0]; } try { return(NativeMethods.highgui_imwrite(fileName, img.CvPtr, prms, prms.Length) != 0); } catch (BadImageFormatException ex) { throw PInvokeHelper.CreateException(ex); } }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="m"></param> /// <returns></returns> public static MatExpr operator /(MatExpr e, Mat m) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (m == null) { throw new ArgumentNullException(nameof(m)); } e.ThrowIfDisposed(); m.ThrowIfDisposed(); try { IntPtr retPtr = NativeMethods.core_operatorDivide_MatExprMat(e.CvPtr, m.CvPtr); GC.KeepAlive(e); GC.KeepAlive(m); return(new MatExpr(retPtr)); } catch (BadImageFormatException ex) { throw PInvokeHelper.CreateException(ex); } }
/// <summary> /// Pass the file handle to the <see cref="System.IO.FileStream"/> constructor. /// The <see cref="System.IO.FileStream"/> will close the handle. /// </summary> public static SafeFileHandle CreateFileHandle( string filePath, CreationDisposition creationDisposition, FileAccess fileAccess, FileShare fileShare) { filePath = CheckAddLongPathPrefix(filePath); // Create a file with generic write access var fileHandle = PInvokeHelper.CreateFile( filePath, fileAccess, fileShare, IntPtr.Zero, creationDisposition, 0, IntPtr.Zero); // Check for errors. var lastWin32Error = Marshal.GetLastWin32Error(); if (fileHandle.IsInvalid) { throw new Win32Exception( lastWin32Error, string.Format( Resources.ErrorCreatingFileHandle, lastWin32Error, filePath, CheckAddDotEnd(new Win32Exception(lastWin32Error).Message))); } // Pass the file handle to FileStream. FileStream will close the handle. return(fileHandle); }
/// <summary> /// /// </summary> /// <param name="m"></param> /// <param name="e"></param> /// <returns></returns> public static MatExpr operator *(Mat m, MatExpr e) { if (m == null) { throw new ArgumentNullException(nameof(m)); } if (e == null) { throw new ArgumentNullException(nameof(e)); } m.ThrowIfDisposed(); e.ThrowIfDisposed(); try { var retPtr = NativeMethods.core_operatorMultiply_MatMatExpr(m.CvPtr, e.CvPtr); GC.KeepAlive(m); GC.KeepAlive(e); return(new MatExpr(retPtr)); } catch (BadImageFormatException ex) { throw PInvokeHelper.CreateException(ex); } }
public static bool IsVolumeCaseSensitive(string path) { if (PInvokeOK) { StringBuilder VolLabel = new StringBuilder(256); // Label UInt32 VolFlags = new UInt32(); StringBuilder FSName = new StringBuilder(256); // File System Name UInt32 SerNum = 0; UInt32 MaxCompLen = 0; PInvokeHelper.GetVolumeInformationWrapper(path, VolLabel, (UInt32)VolLabel.Capacity, ref SerNum, ref MaxCompLen, ref VolFlags, FSName, (UInt32)FSName.Capacity); return((((VolumeFlags)VolFlags) & VolumeFlags.CaseSensitive) == VolumeFlags.CaseSensitive); } return(IsUnix); }
/// <summary> /// /// </summary> /// <param name="e1"></param> /// <param name="e2"></param> /// <returns></returns> public static MatExpr operator *(MatExpr e1, MatExpr e2) { if (e1 == null) { throw new ArgumentNullException(nameof(e1)); } if (e2 == null) { throw new ArgumentNullException(nameof(e2)); } e1.ThrowIfDisposed(); e2.ThrowIfDisposed(); try { IntPtr retPtr = NativeMethods.core_operatorMultiply_MatExprMatExpr(e1.CvPtr, e2.CvPtr); GC.KeepAlive(e1); GC.KeepAlive(e2); return(new MatExpr(retPtr)); } catch (BadImageFormatException ex) { throw PInvokeHelper.CreateException(ex); } }
private void Pipe_OnProcessEvent(int layerIndex, IntPtr data, int width, int height, int outputIndex) { if (layerIndex == VideoPipe.OutIndex) { displayWF.UpdateImage(width, height, data); } else if (layerIndex == VideoPipe.DarknetIndex) { if (width > 0) { personBox = PInvokeHelper.GetPInvokeArray <PersonBox>(width, data); Action action = () => { if (personBox == null) { return; } string msg = string.Empty; foreach (var px in personBox) { msg += " " + px.prob; } this.label3.Text = $"人数:{width} {msg}"; }; this.TryBeginInvoke(action); } else { Action action = () => { this.label3.Text = $"无人"; }; this.TryBeginInvoke(action); } } }
// http://www.dotnet247.com/247reference/msgs/21/108780.aspx public static string GetFileOwner( string filePath) { filePath = CheckAddLongPathPrefix(filePath); IntPtr pZero; IntPtr pSid; IntPtr psd; // Not used here var errorReturn = PInvokeHelper.GetNamedSecurityInfo( filePath, PInvokeHelper.SeFileObject, PInvokeHelper.OwnerSecurityInformation, out pSid, out pZero, out pZero, out pZero, out psd); if (errorReturn == 0) { const int bufferSize = 64; var buffer = new StringBuilder(); var accounLength = bufferSize; var domainLength = bufferSize; int sidNameUse; var account = new StringBuilder(bufferSize); var domain = new StringBuilder(bufferSize); errorReturn = PInvokeHelper.LookupAccountSid( null, pSid, account, ref accounLength, domain, ref domainLength, out sidNameUse); if (errorReturn == 0) { // http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx. var lastWin32Error = Marshal.GetLastWin32Error(); throw new Win32Exception( lastWin32Error, string.Format( Resources.ErrorLookingUpSid, lastWin32Error, filePath, CheckAddDotEnd(new Win32Exception(lastWin32Error).Message))); } else { buffer.Append(domain); buffer.Append(@"\"); buffer.Append(account); return(buffer.ToString()); } } else { // http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx. var lastWin32Error = Marshal.GetLastWin32Error(); throw new Win32Exception( lastWin32Error, string.Format( Resources.ErrorGettingSecurityInfo, lastWin32Error, filePath, CheckAddDotEnd(new Win32Exception(lastWin32Error).Message))); } }
private void GetCurrentGlyph(out GlyphSlotRec glyph) { glyph = PInvokeHelper.PtrToStructure <GlyphSlotRec>(_rec.glyph); }
public static long GetFileLength(string filePath) { Trace.TraceInformation(@"About to get file length for path '{0}'.", filePath); // 2014-06-10, Uwe Keim: Weil das auf 64-bit-Windows 8 nicht sauber läuft, // zunächst mal bei kürzeren Pfaden die eingebaute Methode nehmen. if (!MustBeLongPath(filePath)) { return(new FileInfo(filePath).Length); } filePath = CheckAddLongPathPrefix(filePath); PInvokeHelper.WIN32_FIND_DATA fd; var result = PInvokeHelper.FindFirstFile(filePath.TrimEnd('\\'), out fd); if (result == PInvokeHelper.INVALID_HANDLE_VALUE) { return(0); } try { if (result.ToInt64() == PInvokeHelper.ERROR_FILE_NOT_FOUND) { return(0); } else { var sfh = new SafeFileHandle(result, false); if (sfh.IsInvalid) { var num = Marshal.GetLastWin32Error(); if ((num == 2 || num == 3 || num == 21)) // http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx { return(0); } else { return(0); } } // http://zetalongpaths.codeplex.com/discussions/580478#post1351470 // https://mcdrummerman.wordpress.com/2010/07/13/win32_find_data-and-negative-file-sizes/ //store nFileSizeLow long fDataFSize = (long)fd.nFileSizeLow; //store individual file size for later accounting usage long fileSize = 0; if (fDataFSize < 0 && (long)fd.nFileSizeHigh > 0) { fileSize = fDataFSize + 0x100000000 + ((long)fd.nFileSizeHigh * 0x100000000); } else { if ((long)fd.nFileSizeHigh > 0) { fileSize = fDataFSize + ((long)fd.nFileSizeHigh * 0x100000000); } else if (fDataFSize < 0) { fileSize = (fDataFSize + 0x100000000); } else { fileSize = fDataFSize; } } return(fileSize); /* * var low = fd.nFileSizeLow; * var high = fd.nFileSizeHigh; * * //return (high * (0xffffffff + 1)) + low; * //return (((ulong)high) << 32) + low; * var l = ((high << 0x20) | (low & 0xffffffffL)); * // Copied from FileInfo.Length via Reflector.NET. * return (ulong) l;*/ var low = fd.nFileSizeLow; var high = fd.nFileSizeHigh; Trace.TraceInformation(@"FindFirstFile returned LOW = {0}, HIGH = {1}.", low, high); Trace.Flush(); try { return((long)high << 32 | ((long)low & (long)(0xffffffffL))); //try //{ //var sign = ((long) high << 32 | (low & 0xffffffffL)); //try //{ //return sign <= 0 ? 0 : unchecked((ulong) sign); //} // catch (OverflowException x) // { // var y = new OverflowException(@"Error getting file length (cast).", x); // y.Data[@"low"] = low; // y.Data[@"high"] = high; // y.Data[@"signed value"] = sign; // throw y; // } //} //catch (OverflowException x) //{ // var y = new OverflowException(@"Error getting file length (sign).", x); // y.Data[@"low"] = low; // y.Data[@"high"] = high; // throw y; //} } catch (OverflowException x) { Trace.TraceInformation( @"Got overflow exception ('{3}') for path '{0}'. LOW = {1}, HIGH = {2}.", filePath, low, high, x.Message); Trace.Flush(); throw; } } } finally { PInvokeHelper.FindClose(result); } }
public UploadingWindow() { InitializeComponent(); PInvokeHelper.DisableMinimizeButton(this); PInvokeHelper.DisableMaximizeButton(this); }
public unsafe void DispatchInput(params INPUT[] inputs) { PInvokeHelper.ThrowWin32ErrorIfFalse(() => SendInput(inputs.Length, inputs, sizeof(INPUT)) == inputs.Length); }
public static FileAttributes GetFileAttributes(string filePath) { filePath = CheckAddLongPathPrefix(filePath); return((FileAttributes)PInvokeHelper.GetFileAttributes(filePath)); }