Skip to content

Commit a4217df

Browse files
committed
v4.0.10509.0-Beta
1 parent f732d22 commit a4217df

Some content is hidden

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

50 files changed

+1096
-600
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
################################################################################
2+
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3+
################################################################################
4+
5+
.vs/
6+
bin/
7+
obj/
8+
*.user
9+
*.cache

Common/Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<Description>Contains functionality common for all Virtual Drive samples, both for Windows and macOS.</Description>
99
</PropertyGroup>
1010
<ItemGroup>
11-
<PackageReference Include="ITHit.FileSystem" Version="4.0.10312.0-Beta" />
11+
<PackageReference Include="ITHit.FileSystem" Version="4.0.10509.0-Beta" />
1212
</ItemGroup>
1313
</Project>

Common/FileSystemItemMetadataExt.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,9 @@ public class FileSystemItemMetadataExt : IFileSystemItemMetadata
4242
public string ETag { get; set; }
4343

4444
/// <summary>
45-
/// Indicates if the item is locked by another user in the remote storage.
46-
/// This will set a read-only flag on this item.
45+
/// Indicates if the item is locked in the remote storage.
4746
/// </summary>
48-
/// <remarks>
49-
/// Note that the read-only flag is a convenience-only feature.
50-
/// Typically the user will be notified by the application that the item can not be saved if
51-
/// she/he tries to update this item .
52-
/// Read-only flag does not protect this item from modifications.
53-
/// </remarks>
54-
public bool LockedByAnotherUser { get; set; } = false;
47+
public bool IsLocked { get; set; } = false;
5548

5649
/// <summary>
5750
/// Custom columns data to be displayed in the file manager.

Windows/Common/Common.Windows.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
1313
</ItemGroup>
1414
<ItemGroup>
15-
<PackageReference Include="ITHit.FileSystem.Windows" Version="4.0.10312.0-Beta" />
15+
<PackageReference Include="ITHit.FileSystem.Windows" Version="4.0.10509.0-Beta" />
1616
<ProjectReference Include="..\..\Common\Common.csproj" />
1717
</ItemGroup>
1818
</Project>

Windows/Common/ETagManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,19 @@ internal async Task MoveToAsync(string userFileSystemNewPath)
111111
/// </summary>
112112
internal void DeleteETag()
113113
{
114-
File.Delete(eTagFilePath);
114+
if (File.Exists(eTagFilePath))
115+
{
116+
File.Delete(eTagFilePath);
117+
}
115118

119+
/*
116120
// If this is a folder, delete all eTags in this folder.
117121
string eTagFolderPath = GetETagFilePath(userFileSystemPath);
118122
if (Directory.Exists(eTagFolderPath))
119123
{
120124
Directory.Delete(eTagFolderPath, true);
121125
}
126+
*/
122127
}
123128

124129
/// <summary>

Windows/Common/ExternalDataManager.cs

Lines changed: 26 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ namespace ITHit.FileSystem.Samples.Common.Windows
1616
/// </summary>
1717
/// <remarks>
1818
/// This class stores all custom data associated with the item outside of the placeholder.
19-
/// We can not store item ID and custom data inside placeholder (using <see cref="IFileSystemItemMetadata.CustomData"/>
20-
/// and <see cref="ITHit.FileSystem.Windows.PlaceholderItem.GetCustomData"/>) because of the MS Office transactional save,
19+
/// We can not store item ID and custom data inside of the placeholder (using <see cref="IFileSystemItemMetadata.CustomData"/>
20+
/// and <see cref="ITHit.FileSystem.Windows.PlaceholderItem.GetCustomData"/>) because of the MS Office and AutoCAD transactional save,
2121
/// which renames and deletes the file, so all custom data is lost.
2222
/// </remarks>
2323
public class ExternalDataManager
@@ -80,8 +80,8 @@ public ExternalDataManager(
8080
/// Indicates if the item was saved to the remote storage.
8181
/// </summary>
8282
/// <remarks>
83-
/// MS Office transactional save, deletes and recreates the file.
84-
/// To detect if this is a new file we must store some marker ouside of the file,
83+
/// MS Office and AutoCAD transactional save, deletes and recreates the file.
84+
/// To detect if this is a new file, we must store some marker ouside of the file,
8585
/// for the marker to survive the transactional save operation.
8686
/// </remarks>
8787
public bool IsNew
@@ -226,68 +226,16 @@ private async Task SetIconAsync(bool set, int id, string iconFile = null, string
226226
}
227227
}
228228

229-
/*
230-
/// <summary>
231-
/// Sets or removes icon.
232-
/// </summary>
233-
/// <param name="set">True to display the icon. False - to remove the icon.</param>
234-
private async Task SetIconAsync(bool set, int? id = null, string iconFile = null, string description = null)
235-
{
236-
IStorageItem storageItem = await FsPath.GetStorageItemAsync(userFileSystemPath);
237-
238-
if (storageItem == null)
239-
{
240-
// This method may be called on temp files, typically created by MS Office, that exist for a short period of time.
241-
// StorageProviderItemProperties.SetAsync(null,) causes AccessViolationException
242-
// which is not handled by .NET (or handled by HandleProcessCorruptedStateExceptions) and causes a fatal crush.
243-
return;
244-
}
245-
246-
try
247-
{
248-
if (set)
249-
{
250-
StorageProviderItemProperty propState = new StorageProviderItemProperty()
251-
{
252-
Id = id.Value,
253-
Value = description,
254-
IconResource = Path.Combine(virtualDrive.Settings.IconsFolderPath, iconFile)
255-
};
256-
await StorageProviderItemProperties.SetAsync(storageItem, new StorageProviderItemProperty[] { propState });
257-
}
258-
else
259-
{
260-
await StorageProviderItemProperties.SetAsync(storageItem, new StorageProviderItemProperty[] { });
261-
}
262-
}
263-
264-
// Setting status icon failes for blocked files.
265-
catch (FileNotFoundException)
266-
{
267-
268-
}
269-
catch (COMException)
270-
{
271-
// "Error HRESULT E_FAIL has been returned from a call to a COM component."
272-
}
273-
catch (Exception ex)
274-
{
275-
if (ex.HResult == -2147024499)
276-
{
277-
// "The operation failed due to a conflicting cloud file property lock. (0x8007018D)"
278-
}
279-
else
280-
{
281-
// Rethrow the exception preserving stack trace of the original exception.
282-
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
283-
}
284-
}
285-
}
286-
*/
287-
288229
/// <summary>
289-
/// Sets or removes read-only attribute on files.
230+
/// Indicates if the item is locked by another user in the remote storage.
231+
/// This will call sets or removes the read-only flag in case the item is a file.
290232
/// </summary>
233+
/// <remarks>
234+
/// Call this method if the item is locked by another user. This will set read-only arrtibute on files.
235+
/// Note that the read-only flag is a convenience-only feature. It does not protect files from modifications.
236+
/// Typically the user will be notified by the application that the item can not be saved if
237+
/// the application tries to update this item.
238+
/// </remarks>
291239
/// <param name="set">True to set the read-only attribute. False - to remove the read-only attribute.</param>
292240
public async Task<bool> SetLockedByAnotherUserAsync(bool set)
293241
{
@@ -549,25 +497,32 @@ private async Task CustomColumnsMoveToAsync(string userFileSystemNewPath)
549497
/// <summary>
550498
/// Deletes all custom data associated with the item.
551499
/// </summary>
552-
public void Delete()
500+
/// <param name="recursive">Deletes all data for subfolders if true.</param>
501+
public void Delete(bool recursive = true)
553502
{
554503
DeleteCustomColumns();
555504
ETagManager.DeleteETag();
556505
LockManager.DeleteLock();
506+
507+
if(recursive)
508+
{
509+
// If this is a folder, delete all custom columns in this folder.
510+
string customColumnsFolderPath = GetColumnsFilePath(userFileSystemPath);
511+
if (Directory.Exists(customColumnsFolderPath))
512+
{
513+
Directory.Delete(customColumnsFolderPath, true);
514+
}
515+
}
557516
}
558517

559518
/// <summary>
560519
/// Deletes custom columns associated with a file.
561520
/// </summary>
562521
private void DeleteCustomColumns()
563522
{
564-
File.Delete(customColumnsFilePath);
565-
566-
// If this is a folder, delete all custom columns in this folder.
567-
string customColumnsFolderPath = GetColumnsFilePath(userFileSystemPath);
568-
if (Directory.Exists(customColumnsFolderPath))
523+
if (File.Exists(customColumnsFilePath))
569524
{
570-
Directory.Delete(customColumnsFolderPath, true);
525+
File.Delete(customColumnsFilePath);
571526
}
572527
}
573528
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.IO;
5+
6+
7+
namespace ITHit.FileSystem.Samples.Common.Windows
8+
{
9+
/// <summary>
10+
/// Provides methods to detect AutoCAD files that should not be synced to the remote storage,
11+
/// such as AutoCAD temporary files and AutoCAD lock files.
12+
/// </summary>
13+
/// <remarks>
14+
/// AutoCAD lock files (.dwl and .dwl2), are marked as hidden and filtered by the <see cref="FilterHelper.IsHiddenOrTemp"/> method.
15+
/// </remarks>
16+
internal class AutoCadFilterHelper
17+
{
18+
/// <summary>
19+
/// Returns true if the file should NOT be synched to the remote storage. False - otherwise.
20+
/// </summary>
21+
/// <param name="path">Path to a file or folder.</param>
22+
public static bool AvoidSync(string path)
23+
{
24+
return IsAutoCadTemp(path) || FilterHelper.IsHiddenOrTemp(path);
25+
}
26+
27+
/// <summary>
28+
/// Returns true if the file has .tmp extension, false - otherwise.
29+
/// </summary>
30+
/// <param name="path">Path to a file.</param>
31+
/// <remarks>
32+
/// sav1ea4afdc.tmp
33+
/// Mechanical - Multileaders8f31c74f.tmp
34+
/// Mechanical - Multileaders.bak
35+
/// atmp91130947
36+
/// </remarks>
37+
private static bool IsAutoCadTemp(string path)
38+
{
39+
string extension = Path.GetExtension(path);
40+
return (extension.Equals(".tmp", StringComparison.InvariantCultureIgnoreCase)
41+
|| extension.Equals(".bak", StringComparison.InvariantCultureIgnoreCase)
42+
|| (string.IsNullOrEmpty(extension) && Path.GetFileName(path).StartsWith("atmp", StringComparison.InvariantCultureIgnoreCase))
43+
);
44+
}
45+
46+
/// <summary>
47+
/// Returns true if file system contains an AutoCAD lock-file (.dwl or .dwl2) in file
48+
/// system that corresponds to the provided path to AutoCAD file. False - otherwise.
49+
/// </summary>
50+
/// <param name="path">Path to the AutoCAD file.</param>
51+
internal static bool IsAutoCadLocked(string path)
52+
{
53+
string lockPath = GetLockPathFromAutoCadPath(path);
54+
return lockPath != null;
55+
}
56+
57+
/// <summary>
58+
/// Returns AutoCAD lock file path if such file exists. Null - otherwise.
59+
/// </summary>
60+
/// <param name="msOfficeFilePath">AutoCAD file path.</param>
61+
/// <returns>Lock file path or null if the lock file is not found.</returns>
62+
/// <remarks>
63+
/// file.dwg -> file.dwl
64+
/// </remarks>
65+
private static string GetLockPathFromAutoCadPath(string autoCadFilePath)
66+
{
67+
string lockFilePath = Path.ChangeExtension(autoCadFilePath, "dwl");
68+
return File.Exists(lockFilePath) ? lockFilePath : null;
69+
}
70+
}
71+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.IO;
5+
6+
7+
namespace ITHit.FileSystem.Samples.Common.Windows
8+
{
9+
/// <summary>
10+
/// Provides methods to detect hidden files, temporary files, lock files and files moved to recycle bin.
11+
/// </summary>
12+
public class FilterHelper
13+
{
14+
/// <summary>
15+
/// Returns true if the file should NOT be synched to the remote storage. False - otherwise.
16+
/// </summary>
17+
/// <param name="path">Path to a file or folder.</param>
18+
public static bool AvoidSync(string path)
19+
{
20+
return MsOfficeFilterHelper.AvoidSync(path) || AutoCadFilterHelper.AvoidSync(path) || IsHiddenOrTemp(path);
21+
}
22+
23+
/// <summary>
24+
/// Returns true if file system contains an application lock-file (~$*.docx, *.dwl, *.dwl2) in file
25+
/// system that corresponds to the provided path to the file file. False - otherwise.
26+
/// </summary>
27+
/// <param name="path">Path to the file to check the lock-file for.</param>
28+
public static bool IsAppLocked(string path)
29+
{
30+
return MsOfficeFilterHelper.IsMsOfficeLocked(path) || AutoCadFilterHelper.IsAutoCadLocked(path);
31+
}
32+
33+
34+
/// <summary>
35+
/// Returns true if the path points to a recycle bin folder.
36+
/// </summary>
37+
/// <param name="path">Path to the file or folder.</param>
38+
public static bool IsRecycleBin(string path)
39+
{
40+
return path.IndexOf("\\$Recycle.Bin", StringComparison.InvariantCultureIgnoreCase) != -1;
41+
}
42+
43+
/// <summary>
44+
/// Returns true if the file or folder is marked with Hidden or Temporaty attributes.
45+
/// </summary>
46+
/// <param name="path">Path to a file or folder.</param>
47+
/// <returns>
48+
/// True if the file or folder is marked with Hidden or Temporaty attributes.
49+
/// Returns false if no Hidden or Temporaty attributes found or file/folder does not exists.
50+
/// </returns>
51+
internal static bool IsHiddenOrTemp(string path)
52+
{
53+
if (!System.IO.File.Exists(path) && !System.IO.Directory.Exists(path))
54+
{
55+
return false;
56+
}
57+
58+
FileAttributes att = System.IO.File.GetAttributes(path);
59+
return ((att & System.IO.FileAttributes.Hidden) != 0)
60+
|| ((att & System.IO.FileAttributes.Temporary) != 0);
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)