Skip to content

Commit

Permalink
v5.6.16382.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ITHitBuild committed Jul 8, 2022
1 parent 73080a6 commit 0329171
Show file tree
Hide file tree
Showing 32 changed files with 220 additions and 214 deletions.
2 changes: 1 addition & 1 deletion Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem" Version="5.6.16274.0-Beta2" />
<PackageReference Include="ITHit.FileSystem" Version="5.6.16382.0" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Windows/Common/Core/Common.Windows.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="5.6.16274.0-Beta2" />
<PackageReference Include="ITHit.FileSystem.Windows" Version="5.6.16274.0-Beta2" />
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="5.6.16382.0" />
<PackageReference Include="ITHit.FileSystem.Windows" Version="5.6.16382.0" />
<ProjectReference Include="..\..\..\Common\Common.csproj" />
</ItemGroup>
</Project>
96 changes: 0 additions & 96 deletions Windows/Common/Core/FsPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ namespace ITHit.FileSystem.Samples.Common.Windows
/// </summary>
public static class FsPath
{
/// <summary>
/// Returns true if the path points to a file. False - otherwise.
/// </summary>
/// <remarks>Throws exception if the file/folder does not exists.</remarks>
/// <param name="path">Path to the file or folder.</param>
/// <returns>True if the path is file. False - otherwise.</returns>
public static bool IsFile(string path)
{
return !IsFolder(path);
}

/// <summary>
/// Returns true if the path points to a folder. False - otherwise.
/// </summary>
Expand All @@ -48,32 +37,6 @@ public static bool Exists(string path)
return File.Exists(path) || Directory.Exists(path);
}

public static FileSystemItemType GetItemType(string path)
{
return FsPath.IsFile(path) ? FileSystemItemType.File : FileSystemItemType.Folder;
}

/// <summary>
/// Returns storage item or null if item does not eists.
/// </summary>
/// <param name="path">Path to the file or folder.</param>
/// <returns>
/// Instance of <see cref="Windows.Storage.StorageFile"/> or <see cref="Windows.Storage.StorageFolder"/>
/// that corresponds to path or null if item does not exists.
/// </returns>
public static async Task<IStorageItem> GetStorageItemAsync(string path)
{
if (File.Exists(path))
{
return await StorageFile.GetFileFromPathAsync(path);
}
if (Directory.Exists(path))
{
return await StorageFolder.GetFolderFromPathAsync(path);
}
return null;
}

/// <summary>
/// Returns folder or file item or null if the item does not exists.
/// </summary>
Expand All @@ -94,64 +57,5 @@ public static FileSystemInfo GetFileSystemItem(string path)
}
return null;
}

/// <summary>
/// Gets file or folder attributes in a human-readable form.
/// </summary>
/// <param name="path">Path to the file or folder.</param>
/// <returns>String that represents file or folder attributes or null if the file/folder is not found.</returns>
public static string GetAttString(string path)
{
if (WindowsFileSystemItem.TryGetAttributes(path, out FileAttributes? attributes))
{
return WindowsFileSystemItem.GetFileAttributesString(attributes.Value);
}
else
{
return null;
}
}

/// <summary>
/// Gets formatted file size or null for folders or if the file is not found.
/// </summary>
/// <param name="path">Path to a file or folder.</param>
public static string Size(string path)
{
if (!File.Exists(path))
{
return null;
}

long length;
try
{
length = new FileInfo(path).Length;
}
catch
{
return null;
}

return FormatBytes(length);
}

/// <summary>
/// Formats bytes to string.
/// </summary>
/// <param name="length">Bytes to format.</param>
/// <returns>Human readable bytes string.</returns>
public static string FormatBytes(long length)
{
string[] suf = { "b ", "KB", "MB", "GB", "TB", "PB", "EB" };
if (length == 0)
{
return "0" + suf[0];
}
long bytes = Math.Abs(length);
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
return (Math.Sign(length) * num).ToString() + suf[place];
}
}
}
65 changes: 62 additions & 3 deletions Windows/Common/Core/LogFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void LogDebug(IEngine sender, EngineMessageEventArgs e)
/// <param name="level">Log level.</param>
private void WriteLog(IEngine sender, EngineMessageEventArgs e, log4net.Core.Level level)
{
string att = FsPath.GetAttString(e.TargetPath ?? e.SourcePath);
string att = GetAttString(e.TargetPath ?? e.SourcePath);
string process = null;
byte? priorityHint = null;
string fileId = null;
Expand All @@ -207,7 +207,7 @@ private void WriteLog(IEngine sender, EngineMessageEventArgs e, log4net.Core.Lev
process = System.IO.Path.GetFileName(e.OperationContext.ProcessInfo?.ImagePath);
priorityHint = e.OperationContext.PriorityHint;
fileId = (e.OperationContext as IWindowsOperationContext).FileId.ToString();
size = FsPath.FormatBytes((e.OperationContext as IWindowsOperationContext).FileSize);
size = FormatBytes((e.OperationContext as IWindowsOperationContext).FileSize);
}

string sourcePath = e.SourcePath?.FitString(sourcePathWidth, 6);
Expand All @@ -221,8 +221,8 @@ private void WriteLog(IEngine sender, EngineMessageEventArgs e, log4net.Core.Lev
if (ex != null)
{
message += Environment.NewLine;
log.Error(message, ex);
}
log.Error(message, ex);
}
else if (level == log4net.Core.Level.Info)
{
Expand Down Expand Up @@ -250,6 +250,65 @@ private void PrintHeader()
log.Info(Format("Time", "Process Name", "Prty", "FS ID", "RS ID", "Component", "Line", "Caller Member Name", "Caller File Path", "Message", "Source Path", "Attributes", "Target Path"));
log.Info(Format("----", "------------", "----", "_____", "_____", "---------", "____", "------------------", "----------------", "-------", "-----------", "----------", "-----------"));
}

/// <summary>
/// Gets file or folder attributes in a human-readable form.
/// </summary>
/// <param name="path">Path to the file or folder.</param>
/// <returns>String that represents file or folder attributes or null if the file/folder is not found.</returns>
public static string GetAttString(string path)
{
if (WindowsFileSystemItem.TryGetAttributes(path, out System.IO.FileAttributes? attributes))
{
return WindowsFileSystemItem.GetFileAttributesString(attributes.Value);
}
else
{
return null;
}
}

/// <summary>
/// Gets formatted file size or null for folders or if the file is not found.
/// </summary>
/// <param name="path">Path to a file or folder.</param>
public static string Size(string path)
{
if (!File.Exists(path))
{
return null;
}

long length;
try
{
length = new FileInfo(path).Length;
}
catch
{
return null;
}

return FormatBytes(length);
}

/// <summary>
/// Formats bytes to string.
/// </summary>
/// <param name="length">Bytes to format.</param>
/// <returns>Human readable bytes string.</returns>
public static string FormatBytes(long length)
{
string[] suf = { "b ", "KB", "MB", "GB", "TB", "PB", "EB" };
if (length == 0)
{
return "0" + suf[0];
}
long bytes = Math.Abs(length);
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
return (Math.Sign(length) * num).ToString() + suf[place];
}
}

static class StringExtensions
Expand Down
2 changes: 1 addition & 1 deletion Windows/Common/Core/Registrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static async Task<bool> IsRegisteredAsync(string path)
try
{
StorageProviderSyncRootManager.GetSyncRootInformationForFolder(storageFolder);
return FileSystem.Windows.PlaceholderItem.IsPlaceholder(path);
return true;
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows" Version="5.6.16274.0-Beta2" />
<PackageReference Include="ITHit.FileSystem.Windows" Version="5.6.16382.0" />
<ProjectReference Include="..\..\..\Common\Common.csproj" />
<ProjectReference Include="..\Core\Common.Windows.Core.csproj" />
</ItemGroup>
Expand Down
16 changes: 5 additions & 11 deletions Windows/Common/VirtualDrive/VirtualEngineBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,22 @@ public VirtualEngineBase(
}

/// <inheritdoc/>
public override async Task<bool> FilterAsync(SyncDirection direction, OperationType operationType, string path, FileSystemItemType itemType, string newPath = null, FileAttributes? attributes = null, IOperationContext operationContext = null)
public override async Task<bool> FilterAsync(SyncDirection direction, OperationType operationType, string path, FileSystemItemType itemType, string newPath = null, IOperationContext operationContext = null)
{
// Use the code below to filter based on files and folders attributes.
//if (await new AttributesFilter(FileAttributes.Hidden | FileAttributes.Temporary).FilterAsync(direction, operationType, path, itemType, newPath, attributes))
//{
// LogDebug($"{nameof(AttributesFilter)} filtered {operationType}", path, newPath, operationContext);
// return true;
//}

if (await new ZipFilter().FilterAsync(direction, operationType, path, itemType, newPath, attributes))

if (await new ZipFilter().FilterAsync(direction, operationType, path, itemType, newPath))
{
LogDebug($"{nameof(ZipFilter)} filtered {operationType}", path, newPath, operationContext);
return true;
}

if (await new MsOfficeFilter().FilterAsync(direction, operationType, path, itemType, newPath, attributes))
if (await new MsOfficeFilter().FilterAsync(direction, operationType, path, itemType, newPath))
{
LogDebug($"{nameof(MsOfficeFilter)} filtered {operationType}", path, newPath, operationContext);
return true;
}

if (await new AutoCadFilter().FilterAsync(direction, operationType, path, itemType, newPath, attributes))
if (await new AutoCadFilter().FilterAsync(direction, operationType, path, itemType, newPath))
{
LogDebug($"{nameof(AutoCadFilter)} filtered {operationType}", path, newPath, operationContext);
return true;
Expand Down
10 changes: 5 additions & 5 deletions Windows/VirtualDrive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<li>NTFS file system.</li>
</ul>
<h2 class="heading-link" id="nav_configuringthesample">Configuring the Sample<a class="list-link d-inline" href="https://www.userfilesystem.com/examples/virtual_file_system/#nav_configuringthesample"></a></h2>
<p>By default, the sample will use the&nbsp;<span class="code">\RemoteStorage\</span>&nbsp;folder, located under the project root, to simulate the remote storage file structure. It will mount the user file system under the&nbsp;<span class="code">%USERPROFILE%\VFS\</span>&nbsp;folder (typically&nbsp;<span class="code">C:\Users\&lt;username&gt;\VirtualDrive\</span>).</p>
<p>To specify the folder that will be used for remote storage simulation edit the&nbsp;<span class="code">"RemoteStorageRootPath"</span>&nbsp;parameter in&nbsp;<span class="code">appsettings.json</span>. This could be either an absolute path or a path relative to the application root.</p>
<p>To specify the user file system folder edit the&nbsp;<span class="code">"UserFileSystemRootPath"</span>&nbsp;parameter&nbsp;in&nbsp;<span class="code">appsettings.json</span>.</p>
<p>By default, the sample will use the&nbsp;<code class="code">\RemoteStorage\</code>&nbsp;folder, located under the project root, to simulate the remote storage file structure. It will mount the user file system under the&nbsp;<code class="code">%USERPROFILE%\VFS\</code>&nbsp;folder (typically&nbsp;<code class="code">C:\Users\&lt;username&gt;\VirtualDrive\</code>).</p>
<p>To specify the folder that will be used for remote storage simulation edit the&nbsp;<code class="code">"RemoteStorageRootPath"</code>&nbsp;parameter in&nbsp;<code class="code">appsettings.json</code>. This could be either an absolute path or a path relative to the application root.</p>
<p>To specify the user file system folder edit the&nbsp;<code class="code">"UserFileSystemRootPath"</code>&nbsp;parameter&nbsp;in&nbsp;<code class="code">appsettings.json</code>.</p>
<h2 class="heading-link" id="nav_settingthelicense">Setting the License<a class="list-link d-inline" href="https://www.userfilesystem.com/examples/virtual_file_system/#nav_settingthelicense"></a></h2>
<p>To run the example, you will need a valid IT Hit User File System Engine for .NET License. You can download the license in&nbsp;the&nbsp;<a title="IT Hit User File System for .NET Download" href="https://www.userfilesystem.com/download/">product download area</a>.&nbsp;Note that the Engine is fully functional with a trial license and does not have any limitations. The trial license is valid for one month and the engine will stop working after this. You can check the expiration date inside the license file.&nbsp;Download the license file and specify its content in the&nbsp;<span class="code">UserFileSystemLicense</span>&nbsp;field in&nbsp;<span class="code">appsettings.json</span>&nbsp;file.&nbsp;Set the license content directly as a value (NOT as a path to the license file). Do not forget to escape quotes: \":</p>
<p>To run the example, you will need a valid IT Hit User File System Engine for .NET License. You can download the license in&nbsp;the&nbsp;<a title="IT Hit User File System for .NET Download" href="https://www.userfilesystem.com/download/">product download area</a>.&nbsp;Note that the Engine is fully functional with a trial license and does not have any limitations. The trial license is valid for one month and the engine will stop working after this. You can check the expiration date inside the license file.&nbsp;Download the license file and specify its content in the&nbsp;<code class="code">UserFileSystemLicense</code>&nbsp;field in&nbsp;<code class="code">appsettings.json</code>&nbsp;file.&nbsp;Set the license content directly as a value (NOT as a path to the license file). Do not forget to escape quotes: \":</p>
<pre class="brush:xml;auto-links:false;toolbar:false">"UserFileSystemLicense": "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;License…</pre>
<p>You can also run the sample&nbsp;without explicitly specifying a license&nbsp;for 5 days. In this case,&nbsp;the&nbsp;Engine will automatically request the trial license from the IT Hit website https://www.userfilesystem.com. Make sure it is accessible via firewalls if any. After 5 days the Engine will stop working. To extend the trial period you will need to download a license in a&nbsp;<a title="IT Hit User File System for .NET Download" href="https://www.userfilesystem.com/download/">product download area</a>&nbsp;and specify it in&nbsp;<span class="code">appsettings.json</span></p>
<p>You can also run the sample&nbsp;without explicitly specifying a license&nbsp;for 5 days. In this case,&nbsp;the&nbsp;Engine will automatically request the trial license from the IT Hit website https://www.userfilesystem.com. Make sure it is accessible via firewalls if any. After 5 days the Engine will stop working. To extend the trial period you will need to download a license in a&nbsp;<a title="IT Hit User File System for .NET Download" href="https://www.userfilesystem.com/download/">product download area</a>&nbsp;and specify it in&nbsp;<code class="code">appsettings.json</code></p>
<h2 class="heading-link" id="nav_runningthesample">Running the Sample<a class="list-link d-inline" href="https://www.userfilesystem.com/examples/virtual_file_system/#nav_runningthesample"></a></h2>
<p>To run the sample open the project in Visual Studio and run the project in debug mode. When starting in the debug mode, it will automatically create a folder in which the virtual file system will reside, register the virtual drive with the platform and then open&nbsp;two instances of Windows File Manager, one of which will show a virtual drive and another a folder simulating remote storage.&nbsp;</p>
<p>You can find more about running and stopping the sample as well as about basic synchronization features in the&nbsp;<a title="Virtual File System Sample for Windows" href="https://www.userfilesystem.com/examples/virtual_file_system/">Virtual File System</a>&nbsp;sample description.&nbsp;</p>
Expand Down
4 changes: 1 addition & 3 deletions Windows/VirtualDrive/VirtualDrive.ShellExtension/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using ITHit.FileSystem.Windows.ShellExtension;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.Storage.Provider;

using ITHit.FileSystem.Windows.ShellExtension.ComInfrastructure;


namespace VirtualDrive.ShellExtension
{
class Program
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ITHit.FileSystem.Windows.ShellExtension" Version="5.6.16274.0-Beta2" />
<PackageReference Include="ITHit.FileSystem.Windows.ShellExtension" Version="5.6.16382.0" />
</ItemGroup>
<ItemGroup>
<None Update="log4net.config">
Expand Down
21 changes: 20 additions & 1 deletion Windows/VirtualDrive/VirtualDrive/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,26 @@ public static string GetRemoteStoragePathById(byte[] remoteStorageId)
/// <returns>True if the method completed successfully, false - otherwise.</returns>
public static bool TryGetRemoteStoragePathById(byte[] remoteStorageId, out string remoteStoragePath)
{
return WindowsFileSystemItem.TryGetPathByItemId(remoteStorageId, out 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;
}

/// <summary>
/// Returns true if the path points to a recycle bin folder.
/// </summary>
/// <param name="path">Path to the file or folder.</param>
private static bool IsRecycleBin(string path)
{
return path.IndexOf("\\$Recycle.Bin", StringComparison.InvariantCultureIgnoreCase) != -1;
}

/// <summary>
Expand Down
Loading

0 comments on commit 0329171

Please sign in to comment.