Esempio n. 1
0
        private void 添加_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Multiselect = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ShellFileOperation fo     = new ShellFileOperation();
                String[]           source = openFileDialog1.FileNames;
                String[]           dest   = new String[openFileDialog1.FileNames.Length];

                for (int i = 0; i < openFileDialog1.FileNames.Length; i++)
                {
                    dest[i] = FileCore.NewName(workpath + "\\" + Path.GetFileName(openFileDialog1.FileNames[i]));
                }

                fo.Operation   = FileOperations.FO_COPY;
                fo.OwnerWindow = this.Handle;
                fo.SourceFiles = source;
                fo.DestFiles   = dest;

                if (!fo.DoOperation())
                {
                    MessageBox.Show("添加文件过程中出错!", "附件", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                LoadData(workpath);
            }
        }
Esempio n. 2
0
        private void  除_Click(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection SelectedItem = new ListView.SelectedListViewItemCollection(listView1);
            DialogResult d = MessageBox.Show("删除选中的 " + SelectedItem.Count + " 项?", "附件", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            String[]           source = new string[SelectedItem.Count];
            ShellFileOperation fo     = new ShellFileOperation();

            fo.Operation   = FileOperations.FO_DELETE;
            fo.OwnerWindow = this.Handle;
            fo.SourceFiles = source;

            if (d == DialogResult.Yes)
            {
                for (int i = 0; i < SelectedItem.Count; i++)
                {
                    source[i] = workpath + "\\" + SelectedItem[i].Text;
                }

                if (!fo.DoOperation())
                {
                    MessageBox.Show("删除文件过程中出错!", "附件", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                for (int i = 0; i < SelectedItem.Count;)
                {
                    listView1.Items.Remove(SelectedItem[i]);
                }

                LoadData(workpath);
            }
        }
Esempio n. 3
0
        private bool SaveFileElevatedRights()
        {
            var tempFileName = Path.GetTempFileName();

            File.WriteAllText(tempFileName, textBoxScript.Editor.Text);

            var fo = new ShellFileOperation
            {
                OperationFlags = ShellFileOperation.ShellFileOperationFlags.FOF_SILENT |
                                 ShellFileOperation.ShellFileOperationFlags.FOF_NOCONFIRMATION |
                                 ShellFileOperation.ShellFileOperationFlags.FOFX_SHOWELEVATIONPROMPT |
                                 ShellFileOperation.ShellFileOperationFlags.FOFX_NOCOPYHOOKS |
                                 ShellFileOperation.ShellFileOperationFlags.FOFX_REQUIREELEVATION
            };

            var source = new String[1];
            var dest   = new String[1];

            source[0] = tempFileName;
            dest[0]   = m_File;

            fo.Operation   = ShellFileOperation.FileOperations.FO_MOVE;
            fo.OwnerWindow = Handle;
            fo.SourceFiles = source;
            fo.DestFiles   = dest;

            return(fo.DoOperation());
        }
Esempio n. 4
0
        public static bool MoveFiles(List <FileCopyData> Files, bool copy, Form1 mainWindow)
        {
            // move some files
            ShellFileOperation fo = new ShellFileOperation();

            List <string> source = new List <string>();
            List <string> dest   = new List <string>();

            foreach (FileCopyData fileData in Files)
            {
                source.Add(fileData.SourceFullFilePath);
                // _fileFolder + Path.DirectorySeparatorChar  + _newFileName;
                dest.Add(fileData.DestinationFolder + Path.DirectorySeparatorChar + fileData.DestinationFileName);
            }

            if (copy)
            {
                fo.Operation = ShellFileOperation.FileOperations.FO_COPY;
            }
            else
            {
                fo.Operation = ShellFileOperation.FileOperations.FO_MOVE;
            }
            fo.OwnerWindow = mainWindow.Handle;
            fo.SourceFiles = source;
            fo.DestFiles   = dest;

            bool RetVal = fo.DoOperation();

            if (RetVal)
            {
                foreach (ShellNameMapping newName in fo.NameMappings)
                {
                    for (int i = 0; i < Files.Count; i++)
                    {
                        if (newName.DestinationPath == (Files[i].DestinationFolder + Files[i].DestinationFileName))
                        {
                            FileInfo newFile = new FileInfo(newName.RenamedDestinationPath);
                            Files[i].DestinationFileName = newFile.Name;
                        }
                    }
                }
                //MessageBox.Show("Copy Complete without errors!");
                return(true);
            }
            else
            {
                MessageBox.Show("Copy Complete with errors!");
            }

            //fo.NameMappings.Length;

            //CopyFilesDialog copyfiles = new CopyFilesDialog(Files, copy);
            //copyfiles.Show();

            return(false);
        }
Esempio n. 5
0
        private void NavigateFiles(NavigateFileOperation operation)
        {
            if (operation == NavigateFileOperation.Next || operation == NavigateFileOperation.Previous)
            {
                TreeNode n = this.fileList.SelectedNode;
                int      i = this.fileList.Nodes.IndexOf(n);

                if (i == -1)
                {
                    i = operation == NavigateFileOperation.Next ? 0 : this.fileList.Nodes.Count - 1;
                }
                else
                {
                    i += operation == NavigateFileOperation.Next ? 1 : -1;
                }

                if (i >= 0 && i < this.fileList.Nodes.Count)
                {
                    n = this.fileList.Nodes[i];
                    this.fileList.SelectedNode = n;
                }
            }

            if (operation == NavigateFileOperation.Delete)
            {
                TreeNode n = this.fileList.SelectedNode;
                if (n != null && n.Tag is FileSystemInfo)
                {
                    ShellFileOperation fo = new ShellFileOperation();
                    int i = this.fileList.Nodes.IndexOf(n);

                    fo.Operation   = ShellFileOperation.FileOperations.FO_DELETE;
                    fo.OwnerWindow = this.Handle;
                    fo.SourceFiles = new string[] { ((FileSystemInfo)n.Tag).FullName };;

                    bool RetVal = fo.DoOperation();
                    if (RetVal)
                    {
                        // delete was successful -> update the list
                        RefreshFileList(currentDirectory, true);

                        if (i >= this.fileList.Nodes.Count)
                        {
                            i = this.fileList.Nodes.Count - 1;
                        }

                        if (i >= 0 && i < this.fileList.Nodes.Count)
                        {
                            n = this.fileList.Nodes[i];
                            this.fileList.SelectedNode = n;
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        public static int Execute(QuickMediaSorterProjectTriggerAction action, FileInfo fileInfo)
        {
            QuickMediaSorterProjectTriggerAction rolebackAction = new QuickMediaSorterProjectTriggerAction();
            int step = 0;

            switch (action.ActionTypeEnum)
            {
            case ObjectModel.ActionType.None:
                break;

            case ObjectModel.ActionType.Next:
                step = 1;
                break;

            case ObjectModel.ActionType.Previous:
                step = -1;
                break;

            case ObjectModel.ActionType.Delete:
                step = 1;
                fileInfo.Delete();
                break;

            case ObjectModel.ActionType.Copy:
                List <string> l = new List <string>()
                {
                    fileInfo.FullName
                };
                ShellFileOperation.CopyItems(l, action.FullPathFolder);
                //fileInfo.CopyTo(PathHelper.GetFullPath(action.FullPathFolder, fileInfo.Name));
                step = 1;
                break;

            case ObjectModel.ActionType.Move:
                List <string> l1 = new List <string>()
                {
                    fileInfo.FullName
                };
                ShellFileOperation.MoveItems(l1, action.FullPathFolder);
                //fileInfo.MoveTo(PathHelper.GetFullPath(action.FullPathFolder, fileInfo.Name));
                step = 1;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }


            return(step);
        }
Esempio n. 7
0
        public void Execute()
        {
            foreach (var kv in _mapping)
            {
                CopyEventArgs e = new CopyEventArgs(kv.Value);

                CopyFilesInfo copyFilesInfo = kv.Value;
                string        fullPath      = PathHelper.GetFullPath(kv.Key, true);
                copyFilesInfo.SetStart();
                OnCopyStatusChanged?.Invoke(this, e);

                try
                {
                    Debug.Print("Copying {0} files to {1}", copyFilesInfo.FileList.Count(), fullPath);
                    if (ShellFileOperation.CopyItems(copyFilesInfo.FileList, fullPath))
                    {
                        copyFilesInfo.SetFinished();
                    }
                    else
                    {
                        copyFilesInfo.SetCancelled();
                    }
                }
                catch (Exception ex)
                {
                    copyFilesInfo.SetError(ex);
                    throw;
                }

                OnCopyStatusChanged?.Invoke(this, e);

                if (copyFilesInfo.Status == COPY_STATUS.CANCELLED)
                {
                    break;
                }
            }

            try
            {
                Debug.Print($"Moving all files to backup ({PathHelper.AppPath("backup")})");
                string backupPath = PathHelper.GetFullPath(PathHelper.AppPath("backup"), false);
                ShellFileOperation.DeleteCompletelySilent(backupPath);
                ShellFileOperation.MoveItems(_dicFiles.Keys.ToList(), PathHelper.GetFullPath(backupPath, true));
            }
            catch (Exception ex)
            {
                ErrorHandler.Handle(ex, "Error while backing up the files after the main operation has finished.");
            }
        }
Esempio n. 8
0
        int copy(string path_s, string path_t)
        {
            List <DirectoryInfo> dics = IOExtension.GetAllDirectorys(IOExtension.MakeDir(path_s));

            dics.ForEach((inx, dic) =>
            {
                IOExtension.MakeDir(true, dic.FullName.Replace(path_s, path_t));
            });
            _setlog($"创建完成{dics.Count}个文件夹");
            List <FileInfo> allfile = IOExtension.GetAllFiles(IOExtension.MakeDir(path_s));

            return(ShellFileOperation.Copy(
                       allfile.Select(a => a.FullName),
                       allfile.Select(a => a.FullName.Replace(path_s, path_t))
                       ));
        }
Esempio n. 9
0
 public static bool DeleteFileSystemItemProperties(Form owner, string path)
 {
     try
     {
         var fo = new ShellFileOperation();
         fo.Operation   = ShellFileOperation.FileOperations.FO_DELETE;
         fo.OwnerWindow = owner.Handle;
         fo.SourceFiles = new string[] { path };
         return(fo.DoOperation());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, Application.ProductName,
                         MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return(false);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Delete a list of files.
        /// </summary>
        /// <param name="hwnd">The parent window for progress display etc.</param>
        /// <param name="names">An array of source file names</param>
        /// <param name="title">The title to display</param>
        /// <returns>true on success, false on error</returns>
        public static bool DeleteFiles(IntPtr hwnd, string[] names, string title, out bool AnyOperationsAborted)
        {
            if (names == null)
                throw new ArgumentNullException("fromNames");

            ShellFileOperation sfo = new ShellFileOperation();
            sfo.wFunc = ShellFileOperation.FO_Func.FO_DELETE;
            sfo.hwnd = hwnd;
            sfo.lpszProgressTitle = title;
            sfo.pFrom = MakeFileNameList(names);
            sfo.pTo = "";

            bool returnValue = sfo.Execute();

            AnyOperationsAborted = sfo.fAnyOperationsAborted;

            return returnValue;
        }
Esempio n. 11
0
        private ShellFileOperation CreateFileOperation(bool move)
        {
            ShellFileOperation fo = new ShellFileOperation();

            int c = 0;

            foreach (KeyValuePair <string, string> pair in OldNameAndNewName)
            {
                if (pair.Key.ToLower() != pair.Value.ToLower())
                {
                    c++;
                }
            }

            String[] source = new String[c];
            String[] dest   = new String[c];

            int i = 0;

            foreach (KeyValuePair <string, string> pair in OldNameAndNewName)
            {
                if (pair.Key.ToLower() != pair.Value.ToLower())
                {
                    source[i] = pair.Key;
                    dest[i]   = pair.Value;
                    i++;
                }
            }

            fo.Operation = move
                               ? ShellFileOperation.FileOperations.FO_MOVE
                               : ShellFileOperation.FileOperations.FO_COPY;
//            fo.OwnerWindow = this.Handle;
            fo.SourceFiles = source;
            fo.DestFiles   = dest;

            fo.OperationFlags = ShellFileOperation.ShellFileOperationFlags.FOF_NOCONFIRMMKDIR
                                | ShellFileOperation.ShellFileOperationFlags.FOF_MULTIDESTFILES
                                | ShellFileOperation.ShellFileOperationFlags.FOF_ALLOWUNDO
                                | ShellFileOperation.ShellFileOperationFlags.FOF_WANTMAPPINGHANDLE;

            return(fo);
        }
Esempio n. 12
0
        public bool CopyMove(bool move)
        {
            ShellFileOperation fo = CreateFileOperation(move);
            bool ret = fo.DoOperation();

            foreach (ShellNameMapping mapping in fo.NameMappings)
            {
                foreach (KeyValuePair <string, string> pair in OldNameAndNewName)
                {
                    if (pair.Value.ToLower() == mapping.DestinationPath.ToLower())
                    {
                        OldNameAndNewName[pair.Key] = mapping.RenamedDestinationPath;
                        break;
                    }
                }
            }

            return(ret);
        }
Esempio n. 13
0
        protected override void OnDrop(DragEventArgs e)
        {
            if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList() && Keyboard.IsKeyDown(Key.LeftCtrl))
            {
                var srs = ((System.Windows.DataObject)e.Data).GetFileDropList().Cast <string>();

                path = H.GetLnk(path) ?? path;
                if (Directory.Exists(path))
                {
                    ShellFileOperation fo = new ShellFileOperation();
                    fo.SourceFiles = srs.ToArray();
                    fo.DestFiles   = dest(srs, path).ToArray();
                    fo.Operation   = ShellLib.ShellFileOperation.FileOperations.FO_MOVE;
                    fo.DoOperation();
                }
                e.Handled = true;
            }


            base.OnDrop(e);
            window.Hide();
        }
        public static void Paste(string directory)
        {
            //FilenamePhotoProvider fpp = new FilenamePhotoProvider();
            string [] filedst = new String[nbFile];
            for (int n = 0; n < nbFile; n++)
            {
                char [] separator = new char[1];
                separator[0]='_';
                string [] liststr = file[n].Split(separator);
                if (liststr.Length == 2)
                {
                    FilenamePhotoProvider fpp = new FilenamePhotoProvider(liststr[0]);
                    List<String> result = fpp.getPossibleFilename(directory, 1);
                    filedst[n] = result[0];
                }
                else
                {
                    FileInfo fi = new FileInfo(file[n]);
                    filedst[n] =  DirUtil.JoinDirAndFile(directory ,fi.Name);
                }
            }

            ShellFileOperation sfo = new ShellFileOperation();
            sfo.SourceFiles = file;
            sfo.DestFiles = filedst;
            if (_copy)
            {
                sfo.Operation = ShellFileOperation.FileOperations.FO_COPY;
                sfo.ProgressTitle="Copy";
            }
            if (_cut)
            {
                sfo.Operation = ShellFileOperation.FileOperations.FO_MOVE;
                sfo.ProgressTitle = "Move";
            }
            sfo.DoOperation();
        }
Esempio n. 15
0
        protected override void WndProc(ref Message Msg)
        {
            if (Msg.Msg == 0x0233)// WM_DROPFILES
            {
                uint FilesCount = Win32API.DragQueryFile((int)Msg.WParam, 0xFFFFFFFF, null, 0);

                StringBuilder FileName = new StringBuilder(1024);

                ShellFileOperation fo     = new ShellFileOperation();
                String[]           source = new String[FilesCount];
                String[]           dest   = new String[FilesCount];
                for (uint i = 0; i < FilesCount; i++)
                {
                    Win32API.DragQueryFile((int)Msg.WParam, i, FileName, 1024);
                    source[i] = FileName.ToString();
                    dest[i]   = FileCore.NewName(workpath + "\\" + Path.GetFileName(FileName.ToString()));
                }
                Win32API.DragFinish((int)Msg.WParam);

                fo.Operation   = FileOperations.FO_COPY;
                fo.OwnerWindow = this.Handle;
                fo.SourceFiles = source;
                fo.DestFiles   = dest;

                if (!fo.DoOperation())
                {
                    MessageBox.Show("添加文件过程中出错!", "附件", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }



                LoadData(workpath);

                return;
            }
            base.WndProc(ref Msg);
        }
Esempio n. 16
0
        /// <summary>
        /// Copy a list of files.
        /// </summary>
        /// <param name="hwnd">The parent window for progress display etc.</param>
        /// <param name="fromNames">An array of source file names</param>
        /// <param name="toNames">An array of destination file names</param>
        /// <param name="title">The title to display</param>
        /// <returns>true on success, false on error</returns>
        public static bool CopyFiles(IntPtr hwnd, string[] fromNames, string[] toNames, bool overwrite, string title, out bool AnyOperationsAborted)
        {
            if (fromNames == null)
                throw new ArgumentNullException("fromNames");
            if (toNames == null)
                throw new ArgumentNullException("toNames");
            if (fromNames.Length != toNames.Length)
                throw new ApplicationException("Source and destination file name arrays must have same length");

            ShellFileOperation sfo = new ShellFileOperation();
            sfo.wFunc = ShellFileOperation.FO_Func.FO_COPY;
            sfo.hwnd = hwnd;
            sfo.lpszProgressTitle = title;
            sfo.fFlags.FOF_MULTIDESTFILES = true;
            sfo.fFlags.FOF_NOCONFIRMATION = overwrite;
            sfo.pFrom = MakeFileNameList(fromNames);
            sfo.pTo = MakeFileNameList(toNames);

            bool returnValue = sfo.Execute();

            AnyOperationsAborted = sfo.fAnyOperationsAborted;

            return returnValue;
        }
Esempio n. 17
0
 private void DeleteDirectory(string dir)
 {
     string[] dirs = new string[1];
     dirs[0] = dir;
     ShellFileOperation sfo = new ShellFileOperation();
     sfo.SourceFiles = dirs;
     sfo.Operation = ShellFileOperation.FileOperations.FO_DELETE;
     sfo.DoOperation();
 }
Esempio n. 18
0
        private bool SaveFileElevatedRights()
        {
            var tempFileName = Path.GetTempFileName();
            File.WriteAllText(tempFileName, textBoxScript.Editor.Text);

            var fo = new ShellFileOperation
            {
                OperationFlags = ShellFileOperation.ShellFileOperationFlags.FOF_SILENT |
                                 ShellFileOperation.ShellFileOperationFlags.FOF_NOCONFIRMATION |
                                 ShellFileOperation.ShellFileOperationFlags.FOFX_SHOWELEVATIONPROMPT |
                                 ShellFileOperation.ShellFileOperationFlags.FOFX_NOCOPYHOOKS |
                                 ShellFileOperation.ShellFileOperationFlags.FOFX_REQUIREELEVATION
            };

            var source = new string[1];
            var dest = new string[1];

            source[0] = tempFileName;
            dest[0] = m_File;

            fo.Operation = ShellFileOperation.FileOperations.FO_MOVE;
            fo.OwnerWindow = Handle;
            fo.SourceFiles = source;
            fo.DestFiles = dest;

            return fo.DoOperation();
        }
Esempio n. 19
0
 // 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 extern Int32 SHFileOperation(ref ShellFileOperation lpFileOp);
Esempio n. 20
0
        private void toolStripButtonImportPhoto_Click(object sender, EventArgs e)
        {
            FWizardImport wizard = new FWizardImport(nodephotographer,nodeCategory);
            if (wizard.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (wizard.hasError == false)
                {
                    this.Cursor = Cursors.WaitCursor;
                    ShellFileOperation sfo = new ShellFileOperation();
                    sfo.Operation = ShellFileOperation.FileOperations.FO_COPY;
                    //sfo.OperationFlags = ShellFileOperation.ShellFileOperationFlags.FOF_SIMPLEPROGRESS;
                    sfo.OwnerWindow = this.Handle;
                    sfo.SourceFiles = wizard.ListImage;
                    sfo.DestFiles = wizard.DstImage;
                    sfo.ProgressTitle = "Import...";
                    sfo.DoOperation();

                    toolStripProgressBarThumb.Visible = true;
                    toolStripProgressBarThumb.Minimum = 0;
                    toolStripProgressBarThumb.Maximum = sfo.DestFiles.Length;
                    ThumbMaker tm = new ThumbMaker();
                    tm.processFiles(sfo.DestFiles, wizard.DirectoryDst + "\\miniatures\\", delegate(int f, string m)
                    {
                        if (f == -1)
                        {
                           toolStripStatusLabel1.Text = m;
                          //treeView1.SelectedNode = ncat;
                        }
                        else
                        {
                            toolStripStatusLabel1.Text = " Processing thumbnail File " + f.ToString();
                            toolStripProgressBarThumb.Value = f;
                            if (toolStripProgressBarThumb.Maximum-1 == f)
                            {

                                NodeCategory ncat = wizard.getSelectedCategory();
                                tabControl1.SelectedIndex = 0;
                                try
                                {
                                    PopulateListView(new DirectoryInfo(ncat.getDirectory()));
                                }
                                catch (Exception exp)
                                {
                                    MessageBox.Show("Error in category " + exp.Message);
                                }
                                FillGuiCategory(ncat);
                                //TreeNode node = (TreeNode)nodeCategory;
                                //ExpandNode(nodeCategory, node);
                                //nodeCategory.Expand();
                            }
                        }
                    });
                    this.Cursor = Cursors.Arrow;
                    toolStripProgressBarThumb.Visible = false;
                }
                else
                {
                    MessageBox.Show("Error Happen in the wizard configuration please try again ");
                }
            }
        }
Esempio n. 21
0
        private void SHCopyFiles(string[] sourceFiles, string destinationFolder)
        {
            ShellFileOperation fo = new ShellFileOperation();
            List<string> destinationFiles = new List<string>();

            foreach (string sourceFile in sourceFiles)
            {
                destinationFiles.Add(Path.Combine(destinationFolder, Path.GetFileName(sourceFile)));
            }

            fo.InvokeOperation(this.Handle, FileOperations.Copy, sourceFiles, destinationFiles.ToArray());
        }
Esempio n. 22
0
        private void SHCopyFiles(string[] sourceFiles, string destinationFolder)
        {
            ShellFileOperation fo = new ShellFileOperation();

            fo.InvokeOperation(this.Handle, FileOperations.Copy, sourceFiles, sourceFiles.Select(sourceFile => Path.Combine(destinationFolder, Path.GetFileName(sourceFile))).ToArray());
        }
Esempio n. 23
0
 private void btn_run_Click(object sender, EventArgs e)
 {
     new Thread(() =>
     {
         try
         {
             setEnable(false);
             _setlog("源文件夹:" + tb_s.Text);
             _setlog("目标文件夹:" + tb_t.Text);
             var allfile = IOExtension.GetAllFiles(tb_s.Text);
             if (allfile == null || allfile.Count == 0)
             {
                 _setlog("源文件夹为空....,请重新选择");
                 setEnable(true);
                 return;
             }
             var allfilet = IOExtension.GetAllFiles(tb_t.Text);
             if (allfilet != null && allfilet.Count != 0)
             {
                 _setlog("目标文件夹必须为空....,请重新选择");
                 setEnable(true);
                 return;
             }
             _setlog($"获取到文件{allfile.Count}个,共计大小{ IOExtension.CountSize(allfile.Sum(a => a.Length)) }");
             _setlog("清除目标路径");
             IOExtension.DeleteFile(tb_t.Text);
             _setlog("开始复制文件");
             int i = copy(tb_s.Text.Trim(), tb_t.Text.Trim());
             if (i != 0)
             {
                 if (i == 1223)
                 {
                     IOExtension.DeleteFile(tb_t.Text);
                     _setlog("用户取消,删除目标文件夹文件");
                 }
                 else
                 {
                     _setlog(ShellFileOperation.GetErrorString(i));
                 }
                 setEnable(true);
                 return;
             }
             _setlog("复制完成,删除原始文件");
             IOExtension.DeleteFile(tb_s.Text);
             _setlog("开始设置目录");
             RunCmd cmd  = new RunCmd();
             cmd.Output += (str) =>
             {
                 if (str == "c:\\>")
                 {
                     _setlog($"完成,请通过\"{tb_s.Text}\"检查文件是否存在");
                     setEnable(true);
                 }
             };
             cmd.Run($"mklink /j \"{tb_s.Text}\" \"{tb_t.Text}\"");
         }
         catch (Exception ex)
         {
             _setlog(ex.Message);
             setEnable(true);
         }
     }).Start();
 }
Esempio n. 24
0
        private void imageListView1_DropFiles(object sender, DropFileEventArgs e)
        {
            if (treeView1.SelectedNode.GetType().Name == "NodeCategory")
              {
              NodeCategory nCat = (NodeCategory)treeView1.SelectedNode;
              if (nCat.IsLeaf() == false)
              {
                  MessageBox.Show("You can't drop on a category with child ");
                  e.Cancel = true;
                  return;
              }
            FChoosePhotographer choosePhotographer = new FChoosePhotographer(nodephotographer);
            if (choosePhotographer.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                FilenamePhotoProvider fpp = new FilenamePhotoProvider(choosePhotographer.Photographe);

                ImageListView.ImageListViewSelectedItemCollection selected = imageListView1.SelectedItems;
                String DirectoryDst = nCat.getDirectory();
                List<string> Lfile = fpp.getPossibleFilename(DirectoryDst, e.FileNames.Length);

                string[] fileDst = new String[Lfile.Count];

                int n = 0;
                foreach (String s in Lfile)
                {
                    fileDst[n] = s;
                    n++;
                }

                this.Cursor = Cursors.WaitCursor;
                ShellFileOperation sfo = new ShellFileOperation();
                sfo.Operation = ShellFileOperation.FileOperations.FO_COPY;
                sfo.OwnerWindow = this.Handle;
                sfo.SourceFiles = e.FileNames;
                sfo.DestFiles =fileDst;
                sfo.ProgressTitle = "Import...";
                sfo.DoOperation();

                toolStripProgressBarThumb.Visible = true;
                toolStripProgressBarThumb.Minimum = 0;
                toolStripProgressBarThumb.Maximum = sfo.DestFiles.Length;
                ThumbMaker tm = new ThumbMaker();

                  tm.processFiles(sfo.DestFiles, DirectoryDst + "\\miniatures\\", delegate(int f, string m)
                  {
                        if (f == -1)
                        {
                           toolStripStatusLabel1.Text = m;
                        }
                        else
                        {
                            toolStripStatusLabel1.Text = " Processing thumbnail File " + f.ToString();
                            toolStripProgressBarThumb.Value = f;
                            if (toolStripProgressBarThumb.Maximum-1 == f)
                            {
                                tabControl1.SelectedIndex = 0;
                                try
                                {
                                    PopulateListView(new DirectoryInfo(nCat.getDirectory()));
                                }
                                catch (Exception exp)
                                {
                                    MessageBox.Show("Error in category " + exp.Message);
                                }
                                FillGuiCategory(nCat);
                                //TreeNode node = (TreeNode)nodeCategory;
                                //ExpandNode(nodeCategory, node);
                                //nodeCategory.Expand();
                            }
                        }
                    });
                    this.Cursor = Cursors.Arrow;
                    toolStripProgressBarThumb.Visible = false;
                }
                else
                {
                    MessageBox.Show("Error Happen in the wizard configuration please try again ");
                }

                 }
             e.Cancel = true;
        }
Esempio n. 25
0
        protected override void OnDrop(DragEventArgs e)
        {
            if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList() && Keyboard.IsKeyDown(Key.LeftCtrl))
            {
                var srs =((System.Windows.DataObject)e.Data).GetFileDropList().Cast<string>();

                path = H.GetLnk(path) ?? path;
                if (Directory.Exists(path))
                {
                    ShellFileOperation fo = new ShellFileOperation();
                    fo.SourceFiles = srs.ToArray();
                    fo.DestFiles = dest(srs, path).ToArray();
                    fo.Operation = ShellLib.ShellFileOperation.FileOperations.FO_MOVE;
                    fo.DoOperation();

                }
                e.Handled = true;
            }

            base.OnDrop(e);
            window.Hide();
        }
Esempio n. 26
0
        private bool DeleteFiles(ImageListView imgListView,bool iscategory=false)
        {
            ImageListView.ImageListViewSelectedItemCollection selected = imgListView.SelectedItems;
            // On multiplie par deux pour les images et miniatures.
            String[] files;
            List<String> imgFile = new List<string>();

            try
               {

              foreach (ImageListViewItem img in selected)
               {

                    imgFile.Add(img.FileName);
                    FileInfo fi = new FileInfo(img.FileName);
                    FileInfo fiMiniature = new FileInfo(DirUtil.JoinDirAndFile(fi.DirectoryName, "miniatures/") + fi.Name);
                    if (fiMiniature.Exists && iscategory)
                    {
                        imgFile.Add(DirUtil.JoinDirAndFile(fi.DirectoryName, "miniatures/") + fi.Name);
                    }
              }

              files = new string[imgFile.Count];
              for (int n = 0; n < imgFile.Count; n++)
              {
                files[n] = imgFile[n];
              }
            ShellFileOperation sfo = new ShellFileOperation();
            sfo.SourceFiles = files;
            sfo.Operation = ShellFileOperation.FileOperations.FO_DELETE;
            return sfo.DoOperation();
            }
            catch (Exception e)
                {
                    MessageBox.Show(" Error deleting \n " + e.Message);
                }
            return false;
        }