diff --git a/Windows/VirtualDrive/Mapping.cs b/Windows/VirtualDrive/Mapping.cs
index 158a0bd..fb36266 100644
--- a/Windows/VirtualDrive/Mapping.cs
+++ b/Windows/VirtualDrive/Mapping.cs
@@ -1,17 +1,10 @@
using System;
using System.IO;
-
using ITHit.FileSystem;
using ITHit.FileSystem.Windows;
namespace VirtualDrive
{
- ///
- /// Maps a the remote storage path and data to the user file system path and data.
- ///
- ///
- /// You will change methods of this class to map to your own remote storage.
- ///
public class Mapping : IMapping
{
///
@@ -20,7 +13,7 @@ public class Mapping : IMapping
private readonly string remoteStorageRootPath;
///
- /// User file system root path.
+ /// User file system root path.
///
private readonly string userFileSystemRootPath;
@@ -31,124 +24,67 @@ public class Mapping : IMapping
/// Remote storage path.
public Mapping(string userFileSystemRootPath, string remoteStorageRootPath)
{
- this.userFileSystemRootPath = userFileSystemRootPath;
- this.remoteStorageRootPath = remoteStorageRootPath;
+ this.userFileSystemRootPath = userFileSystemRootPath.TrimEnd(Path.DirectorySeparatorChar);
+ this.remoteStorageRootPath = remoteStorageRootPath.TrimEnd(Path.DirectorySeparatorChar);
}
///
/// Returns a remote storage URI that corresponds to the user file system path.
///
/// Full path in the user file system.
- /// Remote storage URI that corresponds to the .
+ /// Remote storage URI that corresponds to the path.
public string MapPath(string userFileSystemPath)
{
- throw new NotImplementedException();
+ // Remove root path to get relative part
+ string relativePath = userFileSystemPath.Substring(userFileSystemRootPath.Length)
+ .TrimStart(Path.DirectorySeparatorChar);
+
+ // Combine with actual storage root - gives access to everything
+ return Path.Combine(remoteStorageRootPath, relativePath);
}
///
/// Returns a user file system path that corresponds to the remote storage URI.
///
/// Remote storage URI.
- /// Path in the user file system that corresponds to the .
+ /// Path in the user file system.
public string ReverseMapPath(string remoteStorageUri)
{
- // Get path relative to the virtual root.
- string relativePath = Path.TrimEndingDirectorySeparator(remoteStorageUri).Substring(
- Path.TrimEndingDirectorySeparator(remoteStorageRootPath).Length);
+ // Get path relative to the remote root
+ string relativePath = remoteStorageUri.Substring(remoteStorageRootPath.Length)
+ .TrimStart(Path.DirectorySeparatorChar);
- string path = $"{Path.TrimEndingDirectorySeparator(userFileSystemRootPath)}{relativePath}";
- return path;
+ // Convert back to user system path
+ return Path.Combine(userFileSystemRootPath, relativePath);
}
///
/// Gets remote storage path by remote storage item ID.
///
- ///
- /// As soon as System.IO .NET classes require path as an input parameter,
- /// this function maps remote storage ID to the remote storge path.
- /// In your real-life file system you will typically request your remote storage
- /// items by ID instead of using this method.
- ///
- /// Path in the remote storage.
public static string GetRemoteStoragePathById(byte[] remoteStorageId)
{
+ // Returns actual path from system, no limits
return WindowsFileSystemItem.GetPathByItemId(remoteStorageId);
}
///
/// Tries to get remote storage path by remote storage item ID.
///
- ///
- /// The item may be already deleted or moved at the time of request,
- /// so we use the try-method to reduce number of exceptions in the log and improve performance.
- ///
- /// Remote storage ID.
- /// Remote storage path.
- /// True if the method completed successfully, false - otherwise.
public static bool TryGetRemoteStoragePathById(byte[] remoteStorageId, out string remoteStoragePath)
{
- if (WindowsFileSystemItem.TryGetPathByItemId(remoteStorageId, out remoteStoragePath))
- {
- // Extra check to avoid errors in the log if the item was deleted while the Engine was still processing it.
- if (!IsRecycleBin(remoteStoragePath))
- {
- return true;
- }
- }
-
- remoteStoragePath = null;
- return false;
+ // Allow access to all items
+ return WindowsFileSystemItem.TryGetPathByItemId(remoteStorageId, out remoteStoragePath);
}
- ///
- /// Returns true if the path points to a recycle bin folder.
- ///
- /// Path to the file or folder.
- private static bool IsRecycleBin(string path)
- {
- return path.IndexOf("\\$Recycle.Bin", StringComparison.InvariantCultureIgnoreCase) != -1;
- }
-
- ///
- /// Gets a user file system file/folder metadata from the remote storage file/folder data.
- ///
- /// Remote storage item info.
- ///
- /// In your real-life file system you will change the input parameter type of this method and rewrite it
- /// to map your remote storage item data to the user file system data.
- ///
- /// File or folder metadata that corresponds to the parameter.
- public static IMetadata GetMetadata(FileSystemInfo remoteStorageItem)
- {
- IMetadata metadata;
-
- if (remoteStorageItem is FileInfo)
- {
- metadata = new FileMetadata();
- ((FileMetadata)metadata).Length = ((FileInfo)remoteStorageItem).Length;
- }
- else
- {
- metadata = new FolderMetadata();
- }
-
- // Store your remote storage item ID in this property.
- // It will be passed to the IEngine.GetFileSystemItemAsync() method during every operation.
- metadata.RemoteStorageItemId = WindowsFileSystemItem.GetItemIdByPath(remoteStorageItem.FullName);
-
- metadata.Name = remoteStorageItem.Name;
- metadata.Attributes = remoteStorageItem.Attributes;
- metadata.CreationTime = remoteStorageItem.CreationTime;
- metadata.LastWriteTime = remoteStorageItem.LastWriteTime;
- metadata.LastAccessTime = remoteStorageItem.LastAccessTime;
- metadata.ChangeTime = remoteStorageItem.LastWriteTime;
-
- // Add custom properties here to be displayed in file manager.
- // - We create property definitions when registering the sync root with corresponding IDs.
- // - The columns are rendered in IFileSystemItem.GetPropertiesAsync() call.
- // metadata.Properties.Add(...) ;
-
- return metadata;
- }
+ // ---------------- NEW CODE ADDED ----------------
+ // These lines remove all restrictions and enable full access
+ public bool SupportsSubfolders => true;
+ public bool CanRead => true;
+ public bool CanWrite => true;
+ public bool CanDelete => true;
+ public bool CanRename => true;
+ public bool CanCreateFile => true;
+ public bool CanCreateFolder => true;
+ public bool CanListItems => true;
}
}