ref SHFILEOPSTRUCT64 lpFileOp); // Address of an SHFILEOPSTRUCT structure that contains information // this function needs to carry out the specified operation. This // parameter must contain a valid value that is not NULL. You are // responsibile for validating the value. If you do not validate it, // you will experience unexpected results. public static Int32 SHFileOperation(ref SHFILEOPSTRUCT lpFileOp) { MachineType mt = GetMachineType(); Int32 result; switch (mt) { case MachineType.win32: SHFILEOPSTRUCT32 fos32 = new SHFILEOPSTRUCT32(lpFileOp); result = SHFileOperation32(ref fos32); lpFileOp.CopyFrom(fos32); break; case MachineType.win64: SHFILEOPSTRUCT64 fos64 = new SHFILEOPSTRUCT64(lpFileOp); result = SHFileOperation64(ref fos64); lpFileOp.CopyFrom(fos64); break; default: throw new ArgumentException("Hell, what kind of computer are you using? It's not 32 and not 64 bit"); } return(result); }
private static int SHFileOperation(FileOperationType func, string path, FileOperationFlags flags, IntPtr parent) { if (Marshal.SizeOf(typeof(IntPtr)) == 4) { var fs = new SHFILEOPSTRUCT32 { hwnd = parent, wFunc = func, pFrom = path, fFlags = flags }; return(SHFileOperation32(ref fs)); } else { var fs = new SHFILEOPSTRUCT64 { hwnd = parent, wFunc = func, pFrom = path, fFlags = flags }; return(SHFileOperation64(ref fs)); } }
public void moveToRecycle(string path) { SHFILEOPSTRUCT32 fileop = new SHFILEOPSTRUCT32(); fileop.wFunc = FO_DELETE; fileop.pFrom = path + '\0' + '\0'; fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; SHFileOperation(ref fileop); }
public void moveToRecycle(string path) { SHFILEOPSTRUCT32 fileop = new SHFILEOPSTRUCT32(); fileop.wFunc = FO_DELETE; fileop.pFrom = path + '\0' + '\0'; fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; SHFileOperation(ref fileop); }
public String lpszProgressTitle; // Address of a string to use as the title of a progress dialog box. // This member is used only if fFlags includes the // FOF_SIMPLEPROGRESS flag. public void CopyFrom(SHFILEOPSTRUCT32 initializer) { this.hwnd = initializer.hwnd; this.wFunc = initializer.wFunc; this.pFrom = initializer.pFrom; this.pTo = initializer.pTo; this.fFlags = initializer.fFlags; this.fAnyOperationsAborted = initializer.fAnyOperationsAborted; this.hNameMappings = initializer.hNameMappings; this.lpszProgressTitle = initializer.lpszProgressTitle; }
public static void DeleteToRecycleBin(params string[] paths) { int result; var hWnd = Process.GetCurrentProcess().MainWindowHandle; var wFunc = FILEOP_Func.FO_DELETE; var fFlags = FILEOP_Flags.FOF_SILENT | FILEOP_Flags.FOF_NOCONFIRMATION | FILEOP_Flags.FOF_ALLOWUNDO; var pFrom = string.Concat(paths.Select(p => $"{p}\0")) + "\0"; var lpszProgressTitle = string.Empty + "\0"; if (IntPtr.Size == 8) { var operation = new SHFILEOPSTRUCT64 { hWnd = hWnd, wFunc = wFunc, fFlags = fFlags, pFrom = pFrom, pTo = null, lpszProgressTitle = lpszProgressTitle, }; result = NativeMethods.SHFileOperation64(ref operation); } else { var operation = new SHFILEOPSTRUCT32 { hWnd = hWnd, wFunc = wFunc, fFlags = fFlags, pFrom = pFrom, pTo = null, lpszProgressTitle = lpszProgressTitle, }; result = NativeMethods.SHFileOperation32(ref operation); } switch (result) { case 0: break; } }
//private const int FOF_NOCONFIRMATION = 0x10; //No prompt dialogs public static bool DeleteFileToRecycleBin(string filePath) { int retVal; if (IntPtr.Size == 4) //32 bit { var shf = new SHFILEOPSTRUCT32(); shf.wFunc = FO_DELETE; shf.fFlags = FOF_ALLOWUNDO; shf.pFrom = filePath + "\0"; retVal = SHFileOperation32(ref shf); } else //64 bit (almost exactly the same, but without "Pack = 1" set. { var shf = new SHFILEOPSTRUCT64(); shf.wFunc = FO_DELETE; shf.fFlags = FOF_ALLOWUNDO; shf.pFrom = filePath + "\0"; retVal = SHFileOperation64(ref shf); } return(retVal == 0); }
public static extern Int32 SHFileOperation32( ref SHFILEOPSTRUCT32 lpFileOp);
public UInt32 wFunc; // Value that indicates which operation to perform. #endregion Fields #region Methods // This member is used only if fFlags includes the // FOF_SIMPLEPROGRESS flag. public void CopyFrom(SHFILEOPSTRUCT32 initializer) { this.hwnd = initializer.hwnd; this.wFunc = initializer.wFunc; this.pFrom = initializer.pFrom; this.pTo = initializer.pTo; this.fFlags = initializer.fFlags; this.fAnyOperationsAborted = initializer.fAnyOperationsAborted; this.hNameMappings = initializer.hNameMappings; this.lpszProgressTitle = initializer.lpszProgressTitle; }
public static extern Int32 SHFileOperation32( ref SHFILEOPSTRUCT32 lpFileOp);
// this function needs to carry out the specified operation. This // parameter must contain a valid value that is not NULL. You are // responsibile for validating the value. If you do not validate it, // you will experience unexpected results. public static Int32 SHFileOperation(ref SHFILEOPSTRUCT lpFileOp) { MachineType mt = GetMachineType(); Int32 result; switch (mt) { case MachineType.win32: SHFILEOPSTRUCT32 fos32 = new SHFILEOPSTRUCT32(lpFileOp); result = SHFileOperation32(ref fos32); lpFileOp.CopyFrom(fos32); break; case MachineType.win64: SHFILEOPSTRUCT64 fos64 = new SHFILEOPSTRUCT64(lpFileOp); result = SHFileOperation64(ref fos64); lpFileOp.CopyFrom(fos64); break; default: throw new ArgumentException("Hell, what kind of computer are you using? It's not 32 and not 64 bit"); } return result; }
private static extern int SHFileOperation32(ref SHFILEOPSTRUCT32 FileOp);
private static extern int SHFileOperation32([In, Out] ref SHFILEOPSTRUCT32 lpFileOp);
public static extern int SHFileOperation(ref SHFILEOPSTRUCT32 FileOp);
private static void CopyFileSystemEntries(string[] sources, string target) { if (Environment.Is64BitProcess) { SHFILEOPSTRUCT64 copyCommand = new SHFILEOPSTRUCT64(); copyCommand.hwnd = IntPtr.Zero; copyCommand.wFunc = FO_Func.FO_COPY; copyCommand.fFlags = FILEOP_FLAGS.FOF_NO_CONNECTED_ELEMENTS | FILEOP_FLAGS.FOF_ALLOWUNDO; copyCommand.lpszProgressTitle = "CoCoMO - COPYING"; copyCommand.pTo = target + "\0\0"; var sb = new StringBuilder(); foreach (var sourceItem in sources) { sb.Append(sourceItem + "\0"); } sb.Append("\0\0"); copyCommand.pFrom = sb.ToString(); var result = SHFileOperationW64(ref copyCommand); if (result != 0 && result != 0x75 && result != 0x4C7) { //0 is success, others are 'user cancelled' UI.Error("SHFileOperationW64 returned " + result.ToString()); } } else { SHFILEOPSTRUCT32 copyCommand = new SHFILEOPSTRUCT32(); copyCommand.hwnd = IntPtr.Zero; copyCommand.wFunc = FO_Func.FO_COPY; copyCommand.fFlags = FILEOP_FLAGS.FOF_NO_CONNECTED_ELEMENTS | FILEOP_FLAGS.FOF_ALLOWUNDO; copyCommand.lpszProgressTitle = "CoCoMO - COPYING"; copyCommand.pTo = target + "\0\0"; var sb = new StringBuilder(); foreach (var sourceItem in sources) { sb.Append(sourceItem + "\0"); } sb.Append("\0\0"); copyCommand.pFrom = sb.ToString(); var result = SHFileOperationW32(ref copyCommand); if (result != 0 && result != 0x75 && result != 0x4C7) { //0 is success, others are 'user cancelled' UI.Error("SHFileOperationW32 returned " + result.ToString()); } } }
public static extern int SHFileOperation(ref SHFILEOPSTRUCT32 FileOp);