public AbsolutePath (string path, StorageDirectory dir) { Orignal = path; if (RootPathRegx.IsMatch(path)) { Absolute = path; IsOrignalAbsolute = true;this.Storage = Storaging.Storage.Root; return; } if (path.StartsWith("/") || path.StartsWith("\\")) { if (dir.StorageType.IsStorage()) { Absolute = dir.FullName + path.TrimEnd('\\', '/'); this.Storage = dir as Storage; } else { Absolute = dir.Storage + path.TrimEnd('\\', '/'); this.Storage = dir.InternalStorage; } IsOrignalAbsolute = false ; return; } if (dir.FullName == null) { Absolute = path; IsOrignalAbsolute = true; this.Storage = Storaging.Storage.Root; return; } Absolute = dir.FullName + "/" + path.Trim('\\', '/'); IsOrignalAbsolute = false; this.Storage = dir.StorageType == StorageTypes.Storage ? dir as Storage : dir.InternalStorage; }
protected StorageItem(StorageTypes storageType, FileSystemInfo info,StorageDirectory parent,Storage root=null) { this.StorageType = storageType; this.FileSystemInfo = info; this._parent = parent; this.InternalStorage = root; }
StorageDirectory GetParent() { if (_parent == null) { var fullname = _fullName= this.FileSystemInfo.FullName.Replace("\\", "/"); var lastSlash = fullname.LastIndexOf("/"); if (lastSlash < 0) return this.InternalStorage; _parent = new StorageDirectory(new DirectoryInfo(fullname.Substring(0, lastSlash)), null, this.InternalStorage); } return _parent; }
void InternalListItems(List<IStorageItem> result ,StorageDirectory dir, bool includeSubs = false, StorageTypes itemType = StorageTypes.All) { var dirInfo = (dir.FileSystemInfo as DirectoryInfo); if (itemType.IsFile()) { var subInfos = dirInfo .GetFiles(); foreach (var sub in subInfos) { result.Add(new StorageFile(sub, dir,this.InternalStorage)); } } if (itemType.IsDirectory() || includeSubs) { var subs = dirInfo.GetDirectories(); foreach (var sub in subs) { var subItem = new StorageDirectory(sub, dir, this.InternalStorage); if(itemType.IsDirectory())result.Add(subItem); if (includeSubs) InternalListItems(result, subItem, includeSubs, itemType); } } }
protected internal StorageDirectory(DirectoryInfo info, StorageDirectory parent,Storage storage) : base(StorageTypes.Directory, info, parent, storage) { }
internal Storage(StorageDirectory dir) : base(dir.FileSystemInfo as DirectoryInfo, null, dir.InternalStorage) { this.StorageType = StorageTypes.Storage; }
protected internal StorageFile(FileInfo info,StorageDirectory parent, Storage root) :base(StorageTypes.File , info, parent,root) { }