Exemplo n.º 1
0
        public static bool DeleteFile(List <string> lstPaths, bool fShiftKey, IntPtr hwnd)
        {
            string s = MakeFILEOPPATHS(lstPaths);

            if (s.Length > 1)
            {
                SHFILEOPSTRUCT lpFileOp = new SHFILEOPSTRUCT();
                lpFileOp.hwnd   = hwnd;
                lpFileOp.wFunc  = 3;
                lpFileOp.pFrom  = Marshal.StringToHGlobalUni(s);
                lpFileOp.fFlags = fShiftKey ? ((short)0x4000) : ((short)0x40);
                try {
                    if (PInvoke.SHFileOperation(ref lpFileOp) == 0)
                    {
                        return(!lpFileOp.fAnyOperationsAborted);
                    }
                }
                catch (Exception exception) {
                    QTUtility2.MakeErrorLog(exception, null);
                }
                finally {
                    if (lpFileOp.pFrom != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(lpFileOp.pFrom);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public static bool DeleteFile(List <string> lstPaths, bool fShiftKey, IntPtr hwnd)
        {
            string s = MakeFILEOPPATHS(lstPaths);

            if (s.Length > 1)
            {
                using (SafePtr pFrom = new SafePtr(s)) {
                    SHFILEOPSTRUCT lpFileOp = new SHFILEOPSTRUCT {
                        hwnd   = hwnd,
                        wFunc  = 3,
                        pFrom  = pFrom,
                        fFlags = fShiftKey ? ((short)0x4000) : ((short)0x40)
                    };
                    try {
                        if (PInvoke.SHFileOperation(ref lpFileOp) == 0)
                        {
                            return(!lpFileOp.fAnyOperationsAborted);
                        }
                    }
                    catch (Exception exception) {
                        QTUtility2.MakeErrorLog(exception);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 3
0
 public static bool PasteFile(string pathTarget, IntPtr hwnd)
 {
     try {
         List <string> paths = ClipboardGetFileDropList(hwnd);
         if (paths.Count == 0)
         {
             return(false);
         }
         string s = MakeFILEOPPATHS(paths);
         if (s.Length > 1)
         {
             bool flag;
             if (pathTarget.Length != 3)
             {
                 pathTarget = pathTarget.TrimEnd(new char[] { '\\' });
             }
             pathTarget = GetTargetIfFolderLink(new DirectoryInfo(pathTarget), out flag).FullName;
             if (flag)
             {
                 bool  prefferdDropEffect = GetPrefferdDropEffect(hwnd);
                 short num = 0x40;
                 if (IsTargetPathContained(paths, pathTarget))
                 {
                     num = (short)(num | 8);
                 }
                 SHFILEOPSTRUCT lpFileOp = new SHFILEOPSTRUCT();
                 lpFileOp.hwnd   = hwnd;
                 lpFileOp.wFunc  = prefferdDropEffect ? 1 : 2;
                 lpFileOp.pFrom  = Marshal.StringToHGlobalUni(s);
                 lpFileOp.pTo    = Marshal.StringToHGlobalUni(pathTarget + '\0');
                 lpFileOp.fFlags = num;
                 try {
                     if (PInvoke.SHFileOperation(ref lpFileOp) == 0)
                     {
                         return(!lpFileOp.fAnyOperationsAborted);
                     }
                 }
                 catch (Exception exception) {
                     QTUtility2.MakeErrorLog(exception, null);
                 }
                 finally {
                     if (lpFileOp.pFrom != IntPtr.Zero)
                     {
                         Marshal.FreeHGlobal(lpFileOp.pFrom);
                     }
                     if (lpFileOp.pTo != IntPtr.Zero)
                     {
                         Marshal.FreeHGlobal(lpFileOp.pTo);
                     }
                 }
             }
         }
     }
     catch (Exception exception2) {
         QTUtility2.MakeErrorLog(exception2, null);
     }
     return(false);
 }
Exemplo n.º 4
0
 public static bool PasteFile(string pathTarget, IntPtr hwnd)
 {
     try {
         List <string> paths = ClipboardGetFileDropList(hwnd);
         if (paths.Count == 0)
         {
             return(false);
         }
         string s = MakeFILEOPPATHS(paths);
         if (s.Length > 1)
         {
             bool flag;
             if (pathTarget.Length != 3)
             {
                 pathTarget = pathTarget.TrimEnd(new char[] { '\\' });
             }
             pathTarget = GetTargetIfFolderLink(new DirectoryInfo(pathTarget), out flag).FullName;
             if (flag)
             {
                 bool  prefferdDropEffect = GetPrefferdDropEffect(hwnd);
                 short num = 0x40;
                 if (IsTargetPathContained(paths, pathTarget))
                 {
                     num = (short)(num | 8);
                 }
                 using (SafePtr pFrom = new SafePtr(s))
                     using (SafePtr pTo = new SafePtr(pathTarget + '\0')) {
                         SHFILEOPSTRUCT lpFileOp = new SHFILEOPSTRUCT {
                             hwnd   = hwnd,
                             wFunc  = prefferdDropEffect ? 1 : 2,
                             pFrom  = pFrom,
                             pTo    = pTo,
                             fFlags = num
                         };
                         try {
                             if (PInvoke.SHFileOperation(ref lpFileOp) == 0)
                             {
                                 return(!lpFileOp.fAnyOperationsAborted);
                             }
                         }
                         catch (Exception exception) {
                             QTUtility2.MakeErrorLog(exception);
                         }
                     }
             }
         }
     }
     catch (Exception exception2) {
         QTUtility2.MakeErrorLog(exception2, null);
     }
     return(false);
 }