Skip to content

Commit d846102

Browse files
committed
v9.0.27334.0-Beta
1 parent c8749e0 commit d846102

File tree

145 files changed

+1361
-3915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1361
-3915
lines changed

Common/Common.csproj

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
<Platforms>AnyCPU;x64</Platforms>
1111
</PropertyGroup>
1212
<ItemGroup>
13-
<PackageReference Include="ITHit.FileSystem.Windows" Version="8.5.27248.0" />
14-
<PackageReference Include="ITHit.FileSystem" Version="8.5.27248.0" />
13+
<Compile Remove="FileMetadataExt.cs" />
14+
<Compile Remove="FileSystemItemMetadataExt.cs" />
15+
<Compile Remove="FolderMetadataExt.cs" />
16+
</ItemGroup>
17+
<ItemGroup>
18+
<PackageReference Include="ITHit.FileSystem.Windows" Version="9.0.27334.0-Beta" />
19+
<PackageReference Include="ITHit.FileSystem" Version="9.0.27334.0-Beta" />
1520
</ItemGroup>
1621
</Project>

Common/FileMetadataExt.cs

-17
This file was deleted.

Common/FileSystemItemMetadataExt.cs

-21
This file was deleted.

Common/FolderMetadataExt.cs

-13
This file was deleted.

Windows/Common/Core/Commands.cs

+58-32
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace ITHit.FileSystem.Samples.Common.Windows
1616
{
1717
/// <summary>
18-
/// Commands sent from tray app and comnsole.
18+
/// Commands sent from tray app and console.
1919
/// </summary>
2020
public class Commands
2121
{
@@ -30,7 +30,7 @@ public class Commands
3030
public ISyncService RemoteStorageMonitor;
3131

3232
/// <summary>
33-
/// Remote storaage path.
33+
/// Remote storage path.
3434
/// </summary>
3535
private readonly string RemoteStorageRootPath;
3636

@@ -39,6 +39,12 @@ public class Commands
3939
/// </summary>
4040
private readonly ILog log;
4141

42+
/// <summary>
43+
/// Initializes a new instance of the <see cref="Commands"/> class.
44+
/// </summary>
45+
/// <param name="engine">The engine instance.</param>
46+
/// <param name="remoteStorageRootPath">The remote storage root path.</param>
47+
/// <param name="log">The logger instance.</param>
4248
public Commands(EngineWindows engine, string remoteStorageRootPath, ILog log)
4349
{
4450
this.Engine = engine;
@@ -47,7 +53,7 @@ public Commands(EngineWindows engine, string remoteStorageRootPath, ILog log)
4753
}
4854

4955
/// <summary>
50-
/// Start/stop the Engine and all sync services.
56+
/// Start or stop the Engine and all sync services.
5157
/// </summary>
5258
public async Task StartStopEngineAsync()
5359
{
@@ -64,7 +70,7 @@ public async Task StartStopEngineAsync()
6470
}
6571

6672
/// <summary>
67-
/// Start/stop synchronization service.
73+
/// Start or stop the synchronization service.
6874
/// </summary>
6975
public async Task StartStopSynchronizationAsync()
7076
{
@@ -85,9 +91,12 @@ public async Task StartStopSynchronizationAsync()
8591
}
8692
}
8793

94+
/// <summary>
95+
/// Start or stop the remote storage monitor.
96+
/// </summary>
8897
public async Task StartStopRemoteStorageMonitorAsync()
8998
{
90-
if(RemoteStorageMonitor == null)
99+
if (RemoteStorageMonitor == null)
91100
{
92101
Engine.Logger.LogError("Remote storage monitor is null.", Engine.Path);
93102
return;
@@ -98,7 +107,6 @@ public async Task StartStopRemoteStorageMonitorAsync()
98107
if (Engine.State != EngineState.Running)
99108
{
100109
Engine.Logger.LogError("Failed to start. The Engine must be running.", Engine.Path);
101-
//Engine.RemoteStorageMonitor.Logger.LogError("Failed to start. The Engine must be running.");
102110
return;
103111
}
104112
await RemoteStorageMonitor.StartAsync();
@@ -110,37 +118,59 @@ public async Task StartStopRemoteStorageMonitorAsync()
110118
}
111119

112120
/// <summary>
113-
/// Opens path with associated application.
121+
/// Opens the specified path with the associated application.
114122
/// </summary>
115-
/// <param name="path">Path to the file or folder.</param>
123+
/// <param name="path">The path to the file or folder.</param>
116124
public static void Open(string path)
117125
{
118-
ProcessStartInfo startInfo = new ProcessStartInfo(path);
119-
startInfo.UseShellExecute = true; // Open window only if not opened already.
126+
ProcessStartInfo startInfo = new ProcessStartInfo(path)
127+
{
128+
UseShellExecute = true // Open window only if not opened already.
129+
};
120130
using (Process ufsWinFileManager = Process.Start(startInfo))
121131
{
122-
123132
}
124133
}
125134

126135
/// <summary>
127-
/// Open root user file system folder in Windows Explorer.
136+
/// Tries to open the specified path.
128137
/// </summary>
129-
public async Task OpenRootFolderAsync()
138+
/// <param name="path">The path to the file or folder.</param>
139+
/// <returns>True if the path was opened successfully, otherwise false.</returns>
140+
public bool TryOpen(string path)
130141
{
131-
Open(Engine.Path);
142+
return TryOpen(path, log);
132143
}
133144

134145
/// <summary>
135-
/// Open remote storage.
146+
/// Tries to open the specified path.
136147
/// </summary>
137-
public async Task OpenRemoteStorageAsync()
148+
/// <param name="path">The path to the file or folder.</param>
149+
/// <returns>True if the path was opened successfully, otherwise false.</returns>
150+
public static bool TryOpen(string path, ILog? log = null)
138151
{
139-
Open(RemoteStorageRootPath);
152+
try
153+
{
154+
if (!string.IsNullOrEmpty(path) && (File.Exists(path) || Directory.Exists(path)))
155+
{
156+
Open(path);
157+
return true;
158+
}
159+
else
160+
{
161+
log?.Warn($"The path {path} does not exist.");
162+
}
163+
}
164+
catch (Exception ex)
165+
{
166+
log?.Error($"Failed to open {path}.", ex);
167+
}
168+
169+
return false;
140170
}
141171

142172
/// <summary>
143-
/// Opens support portal.
173+
/// Opens the support portal.
144174
/// </summary>
145175
public static async Task OpenSupportPortalAsync()
146176
{
@@ -155,11 +185,11 @@ public async Task EngineExitAsync()
155185
await StopEngineAsync();
156186
log.Info($"\n\n{RemoteStorageRootPath}");
157187
log.Info("\nAll downloaded file / folder placeholders remain in file system. Restart the application to continue managing files.");
158-
log.Info("\nYou can edit documents when the app is not running and than start the app to sync all changes to the remote storage.\n");
188+
log.Info("\nYou can edit documents when the app is not running and then start the app to sync all changes to the remote storage.\n");
159189
}
160190

161191
/// <summary>
162-
/// Stop the Engine and all sync services.
192+
/// Stops the Engine and all sync services.
163193
/// </summary>
164194
public async Task StopEngineAsync()
165195
{
@@ -173,31 +203,27 @@ public async Task StopEngineAsync()
173203
/// <summary>
174204
/// Opens Windows File Manager with both remote storage and user file system for testing.
175205
/// </summary>
176-
/// <param name="openRemoteStorage">True if the Remote Storage must be opened. False - otherwise.</param>
206+
/// <param name="openRemoteStorage">True if the Remote Storage must be opened. False otherwise.</param>
177207
/// <param name="engineIndex">Index used to position Windows Explorer window to show this user file system.</param>
178-
/// <param name="totalEngines">Total number of Engined that will be mounted by this app.</param>
208+
/// <param name="totalEngines">Total number of Engines that will be mounted by this app.</param>
209+
/// <param name="userFileSystemWindowName">Name of the user file system window.</param>
210+
/// <param name="cancellationToken">Cancellation token.</param>
179211
/// <remarks>This method is provided solely for the development and testing convenience.</remarks>
180212
public void ShowTestEnvironment(string userFileSystemWindowName, bool openRemoteStorage = true, CancellationToken cancellationToken = default, int engineIndex = 0, int totalEngines = 1)
181213
{
182-
int numWindowsPerEngine = 2; //openRemoteStorage ? 2 : 1; // Each engine shows 2 windows - remote storage and UFS.
183-
int horizintalIndex = engineIndex * numWindowsPerEngine;
214+
int numWindowsPerEngine = 2; // Each engine shows 2 windows - remote storage and UFS.
215+
int horizontalIndex = engineIndex * numWindowsPerEngine;
184216
int totalWindows = totalEngines * numWindowsPerEngine;
185217

186218
// Open remote storage.
187219
if (openRemoteStorage)
188220
{
189-
Commands.Open(RemoteStorageRootPath);
190-
//string rsWindowName = Path.GetFileName(RemoteStorageRootPath.TrimEnd('\\'));
191-
//IntPtr hWndRemoteStorage = WindowManager.FindWindow(rsWindowName, cancellationToken);
192-
//WindowManager.PositionFileSystemWindow(hWndRemoteStorage, horizintalIndex, totalWindows);
221+
TryOpen(RemoteStorageRootPath);
193222
}
194223

195224
// Open Windows File Manager with user file system.
196-
Commands.Open(Engine.Path);
197-
//IntPtr hWndUserFileSystem = WindowManager.FindWindow(userFileSystemWindowName, cancellationToken);
198-
//WindowManager.PositionFileSystemWindow(hWndUserFileSystem, horizintalIndex + 1, totalWindows);
225+
TryOpen(Engine.Path);
199226
}
200-
201227
#endif
202228
}
203229
}

Windows/Common/Core/Common.Windows.Core.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.26100.1742" />
2424
</ItemGroup>
2525
<ItemGroup>
26-
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="8.5.27248.0" />
27-
<PackageReference Include="ITHit.FileSystem.Windows" Version="8.5.27248.0" />
26+
<PackageReference Include="ITHit.FileSystem.Windows.Package" Version="9.0.27334.0-Beta" />
27+
<PackageReference Include="ITHit.FileSystem.Windows" Version="9.0.27334.0-Beta" />
2828
<ProjectReference Include="..\..\..\Common\Common.csproj" />
2929
</ItemGroup>
3030
</Project>

Windows/Common/Core/ConsoleProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public async Task ProcessUserInputAsync(Action? onAppExit = null)
107107

108108
case ConsoleKey.L:
109109
// Open log file.
110-
Windows.Commands.Open(logFormatter.LogFilePath);
110+
Windows.Commands.TryOpen(logFormatter.LogFilePath);
111111
break;
112112

113113
case ConsoleKey.B:

Windows/Common/Core/LogFormatter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public static string FormatBytes(long length)
316316
}
317317
long bytes = Math.Abs(length);
318318
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
319-
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
319+
double num = Math.Round(bytes / Math.Pow(1024, place), 0);
320320
return (Math.Sign(length) * num).ToString() + suf[place];
321321
}
322322

Windows/Common/VirtualDrive/Common.Windows.VirtualDrive.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<Compile Remove="IVirtualFolder.cs" />
1414
</ItemGroup>
1515
<ItemGroup>
16-
<PackageReference Include="ITHit.FileSystem.Windows.AppHelper" Version="8.5.27248.0" />
17-
<PackageReference Include="ITHit.FileSystem.Windows" Version="8.5.27248.0" />
16+
<PackageReference Include="ITHit.FileSystem.Windows.AppHelper" Version="9.0.27334.0-Beta" />
17+
<PackageReference Include="ITHit.FileSystem.Windows" Version="9.0.27334.0-Beta" />
1818
<ProjectReference Include="..\..\..\Common\Common.csproj" />
1919
<ProjectReference Include="..\Core\Common.Windows.Core.csproj" />
2020
</ItemGroup>

Windows/Common/VirtualDrive/CustomDataExtensions.cs

+13-31
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,24 @@ namespace ITHit.FileSystem.Samples.Common.Windows
1313
public static class CustomDataExtensions
1414
{
1515
/// <summary>
16-
/// Saves all custom metadata properties, such as locks, to storage associated with an item.
17-
/// This data that is displayed in custom columns in file manager.
16+
/// Tries to get lock info.
1817
/// </summary>
18+
/// <remarks>This method returns only currently active lock. It does NOT return expired lock.</remarks>
1919
/// <param name="properties">Custom data attached to the item.</param>
20-
/// <param name="metadata">Remote storage item metadata.</param>
21-
public static void SaveProperties(this ICustomData properties, FileSystemItemMetadataExt metadata)
20+
/// <param name="serverLockInfo">Lock info.</param>
21+
/// <returns>True if method succeeded and the item is locked. False if the method failed or the item is not locked.</returns>
22+
public static bool TryGetActiveLockInfo(this IPropertiesDictionary properties, out ServerLockInfo serverLockInfo)
2223
{
23-
ICustomDataWindows propertiesWindows = properties as ICustomDataWindows;
24-
string path = propertiesWindows.Placeholder.Path;
25-
VirtualEngineBase engine = propertiesWindows.Placeholder.Engine as VirtualEngineBase;
26-
27-
// Save or delete lock.
28-
if (metadata.Lock != null)
29-
{
30-
properties.SetLockInfo(metadata.Lock);
31-
32-
if (!properties.GetEngine().IsCurrentUser(metadata.Lock.Owner))
33-
{
34-
if (engine.SetLockReadOnly)
35-
{
36-
new FileInfo(path).IsReadOnly = true;
37-
}
38-
}
39-
}
40-
else
24+
if (properties.TryGetValue<ServerLockInfo>("LockInfo", out ServerLockInfo lockInfo))
4125
{
42-
if(properties.TryDeleteLockInfo())
26+
if (lockInfo.LockExpirationDateUtc > DateTimeOffset.Now)
4327
{
44-
// If the file was locked and the lock was succesefully
45-
// deleted we also remove the read-only attribute.
46-
if (engine.SetLockReadOnly)
47-
{
48-
new FileInfo(path).IsReadOnly = false;
49-
}
28+
serverLockInfo = lockInfo;
29+
return true;
5030
}
5131
}
32+
serverLockInfo = null;
33+
return false;
5234
}
5335

5436
/// <summary>
@@ -57,7 +39,7 @@ public static void SaveProperties(this ICustomData properties, FileSystemItemMet
5739
/// <param name="properties">Custom data attached to the item.</param>
5840
/// <param name="serverLockInfo">Lock info.</param>
5941
/// <returns>True if method succeeded and the item is locked. False if the method failed or the item is not locked.</returns>
60-
public static bool TryGetLockInfo(this ICustomData properties, out ServerLockInfo serverLockInfo)
42+
public static bool TryGetActiveLockInfo(this ICustomData properties, out ServerLockInfo serverLockInfo)
6143
{
6244
if (properties.TryGetValue("LockInfo", out IDataItem propLockInfo))
6345
{
@@ -82,7 +64,7 @@ public static bool TryGetLockInfo(this ICustomData properties, out ServerLockInf
8264
/// <returns>True if method succeeded and the item is locked by current user. False if the method failed or the item is not locked by current user.</returns>
8365
public static bool TryGetCurrentUserLockToken(this ICustomData properties, out string lockToken)
8466
{
85-
if (properties.TryGetLockInfo(out ServerLockInfo lockInfo))
67+
if (properties.TryGetActiveLockInfo(out ServerLockInfo lockInfo))
8668
{
8769
if (properties.GetEngine().IsCurrentUser(lockInfo.Owner))
8870
{

Windows/Common/VirtualDrive/MenuCommandLock.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public async Task<string> GetToolTipAsync(IEnumerable<string> filesPath)
121121
bool isLocked = false;
122122
if (engine.Placeholders.TryGetItem(userFileSystemPath, out PlaceholderItem placeholder))
123123
{
124-
if (placeholder.Properties.TryGetLockInfo(out ServerLockInfo lockInfo))
124+
if (placeholder.Properties.TryGetActiveLockInfo(out ServerLockInfo lockInfo))
125125
{
126126
// Detect if locked by this user.
127127
if (!engine.IsCurrentUser(lockInfo.Owner))

0 commit comments

Comments
 (0)