コード例 #1
0
ファイル: Commands.cs プロジェクト: alexf2/CQG
            public override void Execute(FileSysEmulator fse)
            {
                FileSysEmulator.FileSystemItem srcItem = _sourcePath.Resolved.ResolvedFsi;
                if ((srcItem is FileSysEmulator.FsLink) || (srcItem is FileSysEmulator.FsDir) || (srcItem is FileSysEmulator.FsFile))
                {
                    FileSysEmulator.FileSystemItem dst = _destPath.Resolved.ResolvedFsi;
                    if (dst is FileSysEmulator.FsLink)
                    {
                        dst = fse.GetTargetItemOfLink((FileSysEmulator.FsLink)dst);
                    }
                    if (!(dst is FileSysEmulator.FsContainer))
                    {
                        throw new ApplicationException(String.Format("Can't copy '{0}' to '{1}.'", srcItem.GetFullPath(), dst.GetFullPath()));
                    }

                    FileSysEmulator.FsContainer parent       = (FileSysEmulator.FsContainer)srcItem.Parent;
                    FileSysEmulator.FsContainer dstContainer = (FileSysEmulator.FsContainer)dst;
                    if ((FileSysEmulator.FsContainer)srcItem.Parent == dstContainer)
                    {
                        throw new ApplicationException(String.Format("Can't copy the '{0}' over itself.", srcItem.GetFullPath()));
                    }

                    fse.StartCopying(srcItem);
                    parent.CopyItem(srcItem, dstContainer);
                    fse.EndCopying();
                }
                else
                {
                    throw new ApplicationException(String.Format("Can't copy the '{0}'.", srcItem.GetFullPath()));
                }
            }
コード例 #2
0
ファイル: Commands.cs プロジェクト: alexf2/CQG
            public override void Execute(FileSysEmulator fse)
            {
                FileSysEmulator.FileSystemItem itemSrc = _sourcePath.Resolved.ResolvedFsi;

                if (itemSrc.HasHardLink)
                {
                    throw new ApplicationException(String.Format("Can't move the '{0}' because it has hardlinks pointing to.", itemSrc.GetFullPath()));
                }

                FileSysEmulator.FsContainer parent = (FileSysEmulator.FsContainer)itemSrc.Parent;

                _destPath.PathTarget = ArgInfo.TargetType.Dir;
                _destPath.Resolve(fse);
                _destPath.Resolved.ResolvedFsi = fse.SearchResolvedPath(_destPath);

                if ((itemSrc is FileSysEmulator.FsDir) || (itemSrc is FileSysEmulator.FsLink))
                {
                    if (_destPath.Resolved.ResolvedFsi == null)
                    {
                        throw new ApplicationException(String.Format("Can't move the '{0}' because destination '{1}' is not found.", itemSrc.GetFullPath(), _destPath.Resolved.Arg));
                    }

                    FileSysEmulator.FsContainer dst = (FileSysEmulator.FsContainer)_destPath.Resolved.ResolvedFsi;
                    if ((itemSrc is FileSysEmulator.FsDir) && itemSrc == dst)
                    {
                        throw new ApplicationException(String.Format("Can't move the '{0}' over itself.", itemSrc.GetFullPath(), _destPath.Resolved.Arg));
                    }
                    parent.MoveItem(itemSrc, dst);
                }
                else if (itemSrc is FileSysEmulator.FsFile)
                {
                    if (_destPath.Resolved.ResolvedFsi == null)
                    {
                        ArgInfo filename;
                        _destPath.SeparateLastStep(out filename, ArgInfo.TargetType.Dir, ArgInfo.TargetType.File);
                        _destPath.Resolve(fse);
                        _destPath.Resolved.ResolvedFsi = fse.SearchResolvedPath(_destPath);
                        if (_destPath.Resolved.ResolvedFsi == null)
                        {
                            throw new ApplicationException(String.Format("Can't move the '{0}' because destination '{1}' is not found.", itemSrc.GetFullPath(), _destPath.Resolved.Arg));
                        }

                        itemSrc.RenameItem(filename.Arg);
                        FileSysEmulator.FsContainer dst = (FileSysEmulator.FsContainer)_destPath.Resolved.ResolvedFsi;
                        parent.MoveItem(itemSrc, dst);
                    }
                    else
                    {
                        FileSysEmulator.FsContainer dst = (FileSysEmulator.FsContainer)_destPath.Resolved.ResolvedFsi;
                        parent.MoveItem(itemSrc, dst);
                    }
                }
                else
                {
                    throw new ApplicationException(String.Format("Can't move the '{0}'.", itemSrc.GetFullPath()));
                }
            }