Esempio n. 1
0
            public override void Execute(FileSysEmulator fse)
            {
                FileSysEmulator.FileSystemItem itemLinkTo = _sourcePath.Resolved.ResolvedFsi;
                if (itemLinkTo is FileSysEmulator.FsLink)
                {
                    throw new ApplicationException("Can't create link to link.");
                }

                FileSysEmulator.FileSystemItem targetContainer = _destPath.Resolved.ResolvedFsi;
                if (targetContainer is FileSysEmulator.FsLink)
                {
                    targetContainer = fse.GetTargetItemOfLink((FileSysEmulator.FsLink)targetContainer);
                }

                if (targetContainer is FileSysEmulator.FsDir)
                {
                    FileSysEmulator.FsDir dir = (FileSysEmulator.FsDir)targetContainer;
                    dir.AddLink(itemLinkTo, true);
                }
                else if (targetContainer is FileSysEmulator.FsDrive)
                {
                    FileSysEmulator.FsDrive drv = (FileSysEmulator.FsDrive)targetContainer;
                    drv.AddLink(itemLinkTo, true);
                }
                else
                {
                    throw new ApplicationException(String.Format("Unsupported link target '{0}'.", targetContainer.GetType().Name));
                }
            }
Esempio n. 2
0
            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()));
                }
            }
Esempio n. 3
0
            public override void Execute(FileSysEmulator fse)
            {
                FileSysEmulator.FileSystemItem item = _treeToRemove.Resolved.ResolvedFsi;
                if (item is FileSysEmulator.FsLink)
                {
                    item = fse.GetTargetItemOfLink((FileSysEmulator.FsLink)item);
                }

                if (item is FileSysEmulator.FsDrive)
                {
                    throw new ApplicationException(String.Format("Can't remove '{0}'.", item.GetFullPath()));
                }

                FileSysEmulator.FsDir dir = (FileSysEmulator.FsDir)item;

                if (fse.CurrentDrive.CurrentDir != null)
                {
                    FileSysEmulator.FileSystemItem drT = fse.CurrentDrive.CurrentDir;
                    Boolean found = false;
                    for ( ; drT != null && !(drT is FileSysEmulator.FsRoot); drT = drT.Parent)
                    {
                        if (drT == dir)
                        {
                            found = true; break;
                        }
                    }
                    if (found)
                    {
                        throw new ApplicationException(String.Format("Can't remove '{0}' with subtree because it contains the current directory.", item.GetFullPath()));
                    }
                }

                fse.RemoveItem(item);
            }
Esempio n. 4
0
 protected virtual void InternalClonemembers(FileSystemItem src)
 {
     //base.InternalClonemembers();
     _id = FileSysEmulator.GetNextId();
     src.Owner._copyingMapOfIDs.Add(src.ID, _id);
     _parent = null;
     _links  = new List <FsLink>();
 }
Esempio n. 5
0
            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()));
                }
            }
Esempio n. 6
0
 public override void Execute(FileSysEmulator fse)
 {
     FileSysEmulator.FileSystemItem item = _sourceFilePath.Resolved.ResolvedFsi;
     if ((item is FileSysEmulator.FsFile) || (item is FileSysEmulator.FsLink))
     {
         fse.RemoveItem(item);
     }
     else
     {
         throw new ApplicationException(String.Format("Command 'Del' can't remove '{0}'.", item.GetFullPath()));
     }
 }
Esempio n. 7
0
            public override void Execute(FileSysEmulator fse)
            {
                FileSysEmulator.FileSystemItem item = _newCurrDir.Resolved.ResolvedFsi;
                if (item is FileSysEmulator.FsLink)
                {
                    item = fse.GetTargetItemOfLink((FileSysEmulator.FsLink)item);
                }

                fse.CurrentDrive = item.GetParentDrive();
                if (item is FileSysEmulator.FsDir)
                {
                    fse.CurrentDrive.CurrentDir = (FileSysEmulator.FsDir)item;
                }
                else if (item is FileSysEmulator.FsDrive)
                {
                    fse.CurrentDrive.CurrentDir = null;
                }
            }
Esempio n. 8
0
            public override void Execute(FileSysEmulator fse)
            {
                FileSysEmulator.FileSystemItem item = _targetDir.Resolved.ResolvedFsi;

                if (item is FileSysEmulator.FsLink)
                {
                    item = fse.GetTargetItemOfLink((FileSysEmulator.FsLink)item);
                }

                if (item is FileSysEmulator.FsDrive)
                {
                    FileSysEmulator.FsDrive drv = (FileSysEmulator.FsDrive)item;
                    drv.AddDir(_newSubDir.Arg.Replace("\\", ""));
                }
                else
                {
                    FileSysEmulator.FsDir dir = (FileSysEmulator.FsDir)item;
                    dir.AddDir(_newSubDir.Arg.Replace("\\", ""));
                }
            }
Esempio n. 9
0
            public override void Execute(FileSysEmulator fse)
            {
                FileSysEmulator.FileSystemItem item = _dirPath.Resolved.ResolvedFsi;
                if (item is FileSysEmulator.FsLink)
                {
                    item = fse.GetTargetItemOfLink((FileSysEmulator.FsLink)item);
                }

                FileSysEmulator.FsDir dir = (FileSysEmulator.FsDir)item;
                if (!dir.IsEmpty)
                {
                    throw new ApplicationException(String.Format("Can't remove '{0}' because it isn't empty.", item.GetFullPath()));
                }
                if (dir == fse.CurrentDrive.CurrentDir)
                {
                    throw new ApplicationException(String.Format("Can't remove '{0}' because it is current.", item.GetFullPath()));
                }

                fse.RemoveItem(item);
            }
Esempio n. 10
0
        public void Resolve(FileSysEmulator fse)
        {
            FileSysEmulator.FsDrive currDrv = fse.CurrentDrive;
            if (currDrv == null)
            {
                throw new ApplicationException(String.Format("Can't resolve path '{0}': there isn't current drive.", ToString()));
            }

            _resolved = (ArgInfo)this.MemberwiseClone();
            _resolved._locationSteps = new String[0];

            if (_drive.Length == 0)
            {
                _resolved._drive = currDrv.Name;
            }

            if (_relativity == PathType.RelativeToDir || _relativity == PathType.RelativeToDriveDir)
            {
                _resolved._relativity = PathType.RelativeToDriveRoot;
                FileSysEmulator.FsDir currDir = currDrv.CurrentDir;
                if (currDir != null)
                {
                    List <String> lst = currDir.GetLocationSteps(false);
                    lst.AddRange(_locationSteps);
                    _resolved._locationSteps = lst.ToArray();
                }
                else
                {
                    _resolved._locationSteps = _locationSteps;
                }
            }
            else
            {
                _resolved._locationSteps = _locationSteps;
            }


            _resolved._arg = _resolved.GetFullPath();
        }
Esempio n. 11
0
            public override void Execute(FileSysEmulator fse)
            {
                FileSysEmulator.FileSystemItem dirWhere = _pathWhereToMake.Resolved.ResolvedFsi;

                if (dirWhere is FileSysEmulator.FsLink)
                {
                    dirWhere = fse.GetTargetItemOfLink((FileSysEmulator.FsLink)dirWhere);
                }

                if (dirWhere is FileSysEmulator.FsDir)
                {
                    ((FileSysEmulator.FsDir)dirWhere).AddFile(_fileName.Arg);
                }
                else if (dirWhere is FileSysEmulator.FsDrive)
                {
                    ((FileSysEmulator.FsDrive)dirWhere).AddFile(_fileName.Arg);
                }
                else
                {
                    throw new ApplicationException(String.Format("Can't create file '{0}' in '{1}'.", _fileName.Arg, dirWhere.ToString()));
                }
            }
Esempio n. 12
0
 public FsRoot(FileSysEmulator owner) : base("The file system root")
 {
     //AssignName( Name );
     Owner = owner;
 }
Esempio n. 13
0
 public FileSystemItem(String name)
 {
     _id = FileSysEmulator.GetNextId();
     AssignName(name);
 }
Esempio n. 14
0
 public abstract void Execute(FileSysEmulator fse);