Ejemplo n.º 1
0
        protected bool AddExistingItem(String file, String type)
        {
            if (!File.Exists(file))
            {
                MessageBox.Show(String.Format("File {0} is not exist!", file), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            // 如果当前文件夹不存在,进行文件复制的时候就会出问题;
            if (!Directory.Exists(this.FolderPath))
            {
                Directory.CreateDirectory(this.FolderPath);
            }

            if (String.IsNullOrEmpty(type))
            {
                PcsFileInfo fileInfo = PcsFileInfo.GetPcsFileInfo(file);
                type = fileInfo == null ? String.Empty : fileInfo.type;
            }

            // 如果新旧文件为同一个文件,并且目标文件已经存在,则退出;
            String fileName = Path.GetFileName(file);
            String newFile  = Path.Combine(this.FolderPath, fileName);

            // 如果项目中不存在该文件名
            if (!this.FileNameCanUsed(newFile, type, false))
            {
                // 文件名冲突;
                MessageBox.Show(String.Format("FileName {0} is existing in project!", fileName), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            if (file.Equals(newFile, StringComparison.OrdinalIgnoreCase))
            {
                // 目标文件与newFile为同一个文件,则直接导入;
                return(this.AddExistingItem(FileCreateFactory.CreateFile(newFile, type)));
            }
            else if (File.Exists(newFile))
            {
                // 目标文件与的newFile不为同一个文件,单newFile已经存在;
                MessageBox.Show(String.Format("File {0} is existing in {1}!", newFile, this.FolderPath), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            // 复制文件
            if (FileName.CopyFile(file, newFile))
            {
                return(this.AddExistingItem(FileCreateFactory.CreateFile(newFile, String.Empty)));
            }

            return(false);
        }
Ejemplo n.º 2
0
        public override void DoPaste()
        {
            foreach (ViFileInfo item in this.TheSolution.ClipBoardFiles)
            {
                if (item.GetParent() != this)
                {
                    // 只用系统中的文件才可以执行剪切操作
                    if (this.AddExistingItem(item.FullName, item.Type))
                    {
                        if (item.IsCutting)
                        {
                            item.DoDelete(false);
                        }
                    }
                }
                else
                {
                    // 从当前文件夹中剪切文件,然后粘贴到当前文件夹中,没有任何意义;
                    if (item.IsCutting)
                    {
                        item.IsCutting = false;
                        return;
                    }

                    // 目标文件在当前文件夹下,则文件名进行递增处理
                    String newFile = FileName.IncreateFileName(item.FullName, (file, name) =>
                    {
                        return(this.CurrProject.FileNameCanUsed(name, item.Type));
                    }, "{0} - Copy ({1}){2}");
                    if (FileName.CopyFile(item.FullName, newFile))
                    {
                        this.AddExistingItem(newFile, item.Type);
                    }
                }
            }
        }