aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy@twine-s.com>2020-12-30 15:12:05 +0000
committerRoy Ben Shabat <Roy@twine-s.com>2020-12-30 15:12:05 +0000
commitb88a5d8fbfb4da46ec0e8f64b79fd83013a9de38 (patch)
treeea725abc39def99a755b041c13cba1fe0d594ddc /Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs
parent1bdcaa9f51303bbff682507f31fb3b4414692ca4 (diff)
parentd33c19b3ac6803de4b5c8d475832efef131c1a45 (diff)
downloadTango-b88a5d8fbfb4da46ec0e8f64b79fd83013a9de38.tar.gz
Tango-b88a5d8fbfb4da46ec0e8f64b79fd83013a9de38.zip
Merged PR 6: Revert "Hope it is fine"
Revert "Hope it is fine" Reverted commit `1344a54c`.
Diffstat (limited to 'Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs')
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs109
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;
+ }
+ }
+ }
+}