aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-03-25 17:46:56 +0200
committerAvi Levkovich <avi@twine-s.com>2020-03-25 17:46:56 +0200
commitaa732a33f7c63ce4438ec2b79fedb641ffd22b05 (patch)
tree86ccf57c1dfb6801de16f15d681539c02b007508 /Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs
parentd29da53d6f71f45749c0ede5b4cd7281ed3a270e (diff)
parent8f57d4962fa84499c8a153ebfff6e7766434ee1c (diff)
downloadTango-aa732a33f7c63ce4438ec2b79fedb641ffd22b05.tar.gz
Tango-aa732a33f7c63ce4438ec2b79fedb641ffd22b05.zip
merge conflicts -take remote
Diffstat (limited to 'Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs')
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs106
1 files changed, 99 insertions, 7 deletions
diff --git a/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs b/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs
index 44c8f1901..46ca080a2 100644
--- a/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs
+++ b/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using Tango.Core.Helpers;
using Tango.FileSystem.Network;
namespace Tango.FileSystem
@@ -72,15 +73,18 @@ namespace Tango.FileSystem
});
}
- foreach (var file in Directory.GetFiles(request.Path))
+ if (!request.FoldersOnly)
{
- items.Add(new FileSystemItemDTO()
+ foreach (var file in Directory.GetFiles(request.Path, request.Filter != null ? request.Filter : "*.*"))
{
- Path = file,
- Type = FileSystemItemType.File,
- DateModified = File.GetLastWriteTimeUtc(file),
- Size = new FileInfo(file).Length
- });
+ items.Add(new FileSystemItemDTO()
+ {
+ Path = file,
+ Type = FileSystemItemType.File,
+ DateModified = File.GetLastWriteTimeUtc(file),
+ Size = new FileInfo(file).Length
+ });
+ }
}
return new FileSystemItemDTO()
@@ -91,6 +95,32 @@ namespace Tango.FileSystem
};
}
+ public Task<FileSystemItem> GetFolder(String path, bool foldersOnly = false, String filter = "*.*")
+ {
+ return Task.Factory.StartNew<FileSystemItem>(() =>
+ {
+ return FileSystemItem.FromDTO(GetFolder(new GetFileSystemItemRequest()
+ {
+ Path = path,
+ FoldersOnly = foldersOnly,
+ Filter = filter,
+ }));
+ });
+ }
+
+ public Task<FileSystemItem> GetFolder(Environment.SpecialFolder specialFolder, bool foldersOnly = false, String filter = "*.*")
+ {
+ return Task.Factory.StartNew<FileSystemItem>(() =>
+ {
+ return FileSystemItem.FromDTO(GetFolder(new GetFileSystemItemRequest()
+ {
+ SpecialFolder = specialFolder,
+ FoldersOnly = foldersOnly,
+ Filter = filter,
+ }));
+ });
+ }
+
public void Delete(String path)
{
if (Directory.Exists(path))
@@ -106,5 +136,67 @@ namespace Tango.FileSystem
throw new FileNotFoundException("Could not locate the specified file or directory.");
}
}
+
+ public void Move(MoveRequest request)
+ {
+ if (Directory.Exists(request.Destination))
+ {
+ throw new IOException($"'{Path.GetFileName(request.Destination)}' already exists on the target folder.");
+ }
+
+ if (File.Exists(request.Source))
+ {
+ File.Move(request.Source, request.Destination);
+ }
+ else if (Directory.Exists(request.Source))
+ {
+ Directory.Move(request.Source, request.Destination);
+ }
+ else
+ {
+ throw new FileNotFoundException("Could not locate the source file or folder.");
+ }
+ }
+
+ public void Copy(CopyRequest request)
+ {
+ if (File.Exists(request.Source))
+ {
+ if (request.Source == request.Destination)
+ {
+ while (File.Exists(request.Destination))
+ {
+ request.Destination = Path.Combine(Path.GetDirectoryName(request.Destination), Path.GetFileNameWithoutExtension(request.Destination)) + " copy" + Path.GetExtension(request.Destination);
+ }
+ }
+ File.Copy(request.Source, request.Destination, true);
+ }
+ else if (Directory.Exists(request.Source))
+ {
+ Directory.CreateDirectory(Path.GetDirectoryName(request.Destination));
+ PathHelper.CopyDirectory(request.Source, request.Destination, true);
+ }
+ else
+ {
+ throw new FileNotFoundException("Could not locate the source file or folder.");
+ }
+ }
+
+ public FileSystemItemDTO CreateFolder(String path, String folderName)
+ {
+ String fullPath = Path.Combine(path, folderName);
+
+ if (Directory.Exists(fullPath))
+ {
+ throw new IOException("The specified directory name already exists.");
+ }
+
+ Directory.CreateDirectory(fullPath);
+
+ return GetFolder(new GetFileSystemItemRequest()
+ {
+ Path = fullPath
+ });
+ }
}
}