diff options
| author | Roy Ben Shabat <Roy@twine-s.com> | 2020-12-30 15:11:34 +0000 |
|---|---|---|
| committer | Roy Ben Shabat <Roy@twine-s.com> | 2020-12-30 15:11:34 +0000 |
| commit | d33c19b3ac6803de4b5c8d475832efef131c1a45 (patch) | |
| tree | ea725abc39def99a755b041c13cba1fe0d594ddc /Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs | |
| parent | 1bdcaa9f51303bbff682507f31fb3b4414692ca4 (diff) | |
| download | Tango-d33c19b3ac6803de4b5c8d475832efef131c1a45.tar.gz Tango-d33c19b3ac6803de4b5c8d475832efef131c1a45.zip | |
Revert "Hope it is fine"
Diffstat (limited to 'Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs b/Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs new file mode 100644 index 000000000..c78a11732 --- /dev/null +++ b/Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; +using Tango.Core; +using Tango.FileSystem.Network; + +namespace Tango.FileSystem +{ + public abstract class FileSystemItem : ExtendedObject + { + private String _path; + public String Path + { + get { return _path; } + set { _path = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(Name)); } + } + + public FileSystemItemType Type { get; protected set; } + + public abstract String Description { get; } + + public DateTime DateModified { get; set; } + + public DateTime DateCreated { get; set; } + + public long Size { get; set; } + + public String Name + { + get { return OnGetName(); } + } + + public FileSystemItem() + { + DateModified = DateTime.Now; + Size = 1000 * 1000; + } + + protected virtual String OnGetName() + { + return System.IO.Path.GetFileName(Path); + } + + public override string ToString() + { + return Name; + } + + public static FileSystemItem FromDTO(FileSystemItemDTO dto) + { + FileSystemItem item = null; + + if (dto.Type == FileSystemItemType.Drive) + { + item = new DriveItem() + { + DriveType = dto.DriveType, + Label = dto.DriveLabel, + Items = dto.Items?.Select(x => FromDTO(x)).ToObservableCollection() + }; + } + else if (dto.Type == FileSystemItemType.Folder) + { + item = new FolderItem() + { + Items = dto.Items?.Select(x => FromDTO(x)).ToObservableCollection(), + IsRoot = dto.IsRoot, + }; + } + else if (dto.Type == FileSystemItemType.File) + { + item = new FileItem(); + } + + item.DateModified = dto.DateModified; + item.DateCreated = dto.DateCreated; + item.Path = dto.Path; + item.Size = dto.Size; + item.Type = dto.Type; + + return item; + } + + public String GetParent() + { + if (Path == "/") return null; + + String root = System.IO.Path.GetPathRoot(Path); + var parent = Directory.GetParent(Path); + + if (root == "\\") + { + return parent.FullName.Replace(parent.Root.FullName, "/").Replace("\\", "/"); + } + else if (parent != null) + { + return parent.FullName; + } + else + { + return null; + } + } + } +} |
