Skip to content

Commit 2f7973c

Browse files
committed
v2.5.5091.0
1 parent f9b99b5 commit 2f7973c

File tree

100 files changed

+1763
-0
lines changed

Some content is hidden

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

100 files changed

+1763
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using System.Threading;
4+
using Foundation;
5+
using ITHit.FileSystem;
6+
7+
namespace FileProviderExtension
8+
{
9+
public static class NSLogHelper
10+
{
11+
[DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")]
12+
extern static void NSLog(IntPtr format, [MarshalAs(UnmanagedType.LPStr)] string s);
13+
14+
public static void NSLog(string format, params object[] args)
15+
{
16+
var fmt = NSString.CreateNative("%s");
17+
var val = (args is null || args.Length == 0) ? format : string.Format(format, args);
18+
19+
NSLog(fmt, val);
20+
NSString.ReleaseNative(fmt);
21+
}
22+
}
23+
24+
public class ConsoleLogger: ILogger
25+
{
26+
private const string appName = "[ITHit.Filesystem.Mac]";
27+
private readonly string componentName;
28+
29+
public ConsoleLogger(string componentName)
30+
{
31+
this.componentName = componentName;
32+
}
33+
34+
public void LogError(string message, string sourcePath = null, string targetPath = null, Exception ex = null)
35+
{
36+
LogError($"\n{DateTimeOffset.Now} [{Thread.CurrentThread.ManagedThreadId,2}] {componentName,-26}{message,-45} {sourcePath,-80}", ex);
37+
}
38+
39+
public void LogMessage(string message, string sourcePath = null, string targetPath = null)
40+
{
41+
LogDebug($"\n{DateTimeOffset.Now} [{Thread.CurrentThread.ManagedThreadId,2}] {componentName,-26}{message,-45} {sourcePath,-80} {targetPath}");
42+
}
43+
44+
private void LogError(string str, Exception ex)
45+
{
46+
if(ex != null)
47+
{
48+
str += $"\nException Message:{ex?.Message}\nException Stack Trace:{ex?.StackTrace}";
49+
}
50+
51+
LogWithLevel("[ERROR]", str);
52+
}
53+
54+
private void LogDebug(string str)
55+
{
56+
#if DEBUG
57+
LogWithLevel("[DEBUG]", str);
58+
#endif
59+
}
60+
61+
private void LogWithLevel(string logLevelStr, string str)
62+
{
63+
NSLogHelper.NSLog(logLevelStr + " " + appName + " " + str);
64+
}
65+
}
66+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.application-groups</key>
8+
<array>
9+
<string>$(TeamIdentifierPrefix)group.com.userfilesystem.vfs</string>
10+
</array>
11+
<key>com.apple.security.files.downloads.read-write</key>
12+
<true/>
13+
<key>com.apple.security.assets.pictures.read-write</key>
14+
<true/>
15+
<key>com.apple.security.assets.music.read-write</key>
16+
<true/>
17+
<key>com.apple.security.assets.movies.read-write</key>
18+
<true/>
19+
<key>com.apple.security.files.user-selected.read-write</key>
20+
<true/>
21+
<key>com.apple.security.cs.allow-jit</key>
22+
<true/>
23+
</dict>
24+
</plist>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{30EDD98F-A449-4A9F-A718-EE480181C619}</ProjectGuid>
7+
<ProjectTypeGuids>{10CE9E57-9141-4DF0-916A-2C4FD4EE2A73};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
8+
<OutputType>Library</OutputType>
9+
<RootNamespace>FileProviderExtension</RootNamespace>
10+
<AssemblyName>FileProviderExtension</AssemblyName>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
13+
<ReleaseVersion>2.5.5091.0</ReleaseVersion>
14+
<UseXamMacFullFramework>true</UseXamMacFullFramework>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug</OutputPath>
21+
<DefineConstants>DEBUG;</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
<EnableCodeSigning>true</EnableCodeSigning>
25+
<CodeSigningKey>Mac Developer</CodeSigningKey>
26+
<CreatePackage>false</CreatePackage>
27+
<EnablePackageSigning>false</EnablePackageSigning>
28+
<IncludeMonoRuntime>false</IncludeMonoRuntime>
29+
<UseSGen>true</UseSGen>
30+
<UseRefCounting>true</UseRefCounting>
31+
<HttpClientHandler></HttpClientHandler>
32+
<LinkMode>None</LinkMode>
33+
<AOTMode>None</AOTMode>
34+
<PackageSigningKey>3rd Party Mac Developer Installer</PackageSigningKey>
35+
<CodeSignProvision>Automatic</CodeSignProvision>
36+
<LangVersion>9.0</LangVersion>
37+
<UseHardenedRuntime>true</UseHardenedRuntime>
38+
<XamMacArch>x86_64</XamMacArch>
39+
<CodeSignEntitlements>Entitlements.plist</CodeSignEntitlements>
40+
</PropertyGroup>
41+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
42+
<DebugType>pdbonly</DebugType>
43+
<Optimize>true</Optimize>
44+
<OutputPath>bin\Release</OutputPath>
45+
<DefineConstants></DefineConstants>
46+
<ErrorReport>prompt</ErrorReport>
47+
<WarningLevel>4</WarningLevel>
48+
<EnableCodeSigning>false</EnableCodeSigning>
49+
<CreatePackage>true</CreatePackage>
50+
<EnablePackageSigning>false</EnablePackageSigning>
51+
<IncludeMonoRuntime>true</IncludeMonoRuntime>
52+
<UseSGen>true</UseSGen>
53+
<UseRefCounting>true</UseRefCounting>
54+
<CodeSignEntitlements>Entitlements.plist</CodeSignEntitlements>
55+
<LinkMode>None</LinkMode>
56+
<HttpClientHandler></HttpClientHandler>
57+
<AOTMode>None</AOTMode>
58+
<LangVersion>9.0</LangVersion>
59+
<UseHardenedRuntime>true</UseHardenedRuntime>
60+
</PropertyGroup>
61+
<ItemGroup>
62+
<Reference Include="System" />
63+
<Reference Include="System.Core" />
64+
<Reference Include="Xamarin.Mac" />
65+
<Reference Include="ITHit.FileSystem">
66+
<HintPath>..\packages\ITHit.FileSystem.2.5.5091\lib\netstandard2.0\ITHit.FileSystem.dll</HintPath>
67+
</Reference>
68+
<Reference Include="ITHit.FileSystem.Mac">
69+
<HintPath>..\packages\ITHit.FileSystem.Mac.2.5.5091-Alpha\lib\xamarinmac20\ITHit.FileSystem.Mac.dll</HintPath>
70+
</Reference>
71+
</ItemGroup>
72+
<ItemGroup>
73+
<Folder Include="Resources\" />
74+
</ItemGroup>
75+
<ItemGroup>
76+
<None Include="Info.plist" />
77+
<None Include="Entitlements.plist" />
78+
<None Include="packages.config" />
79+
</ItemGroup>
80+
<ItemGroup>
81+
<Compile Include="VfsFolder.cs" />
82+
<Compile Include="VfsEngine.cs" />
83+
<Compile Include="VfsFile.cs" />
84+
<Compile Include="VfsFileSystemItem.cs" />
85+
<Compile Include="ConsoleLogger.cs" />
86+
<Compile Include="Mapping.cs" />
87+
<Compile Include="RemoteStorageMonitor.cs" />
88+
</ItemGroup>
89+
<ItemGroup>
90+
<ProjectReference Include="..\ITHit.FileSystem.Mac\ITHit.FileSystem.Mac.csproj">
91+
<Project>{32B330A5-C736-4962-93B7-E2261770497C}</Project>
92+
<Name>ITHit.FileSystem.Mac</Name>
93+
</ProjectReference>
94+
<ProjectReference Include="..\VirtualFilesystemCommon\VirtualFilesystemCommon.csproj">
95+
<Project>{8A146BCC-DE6F-436F-9C25-67AD964E473F}</Project>
96+
<Name>VirtualFilesystemCommon</Name>
97+
</ProjectReference>
98+
</ItemGroup>
99+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.AppExtension.CSharp.targets" />
100+
</Project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleDisplayName</key>
8+
<string>FileProviderExtension</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>com.userfilesystem.vfs.app.extension</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>FileProviderExtension</string>
15+
<key>CFBundlePackageType</key>
16+
<string>XPC!</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>LSMinimumSystemVersion</key>
24+
<string>10.15</string>
25+
<key>LSUIElement</key>
26+
<true/>
27+
<key>NSExtension</key>
28+
<dict>
29+
<key>NSExtensionAttributes</key>
30+
<dict/>
31+
<key>NSExtensionPointIdentifier</key>
32+
<string>com.apple.fileprovider-nonui</string>
33+
<key>NSExtensionPrincipalClass</key>
34+
<string>VfsEngine</string>
35+
<key>NSExtensionFileProviderSupportsEnumeration</key>
36+
<true/>
37+
</dict>
38+
<key>NSPrincipalClass</key>
39+
<string>NSApplication</string>
40+
</dict>
41+
</plist>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System.IO;
2+
using ITHit.FileSystem;
3+
using VirtualFilesystemCommon;
4+
5+
namespace FileProviderExtension
6+
{
7+
/// <summary>
8+
/// Maps a user file system path to the remote storage path and back.
9+
/// </summary>
10+
/// <remarks>You will change methods of this class to map the user file system path to your remote storage path.</remarks>
11+
internal static class Mapping
12+
{
13+
/// <summary>
14+
/// Returns a remote storage URI that corresponds to the user file system path.
15+
/// </summary>
16+
/// <param name="userFileSystemPath">Full path in the user file system.</param>
17+
/// <returns>Remote storage URI that corresponds to the <paramref name="userFileSystemPath"/>.</returns>
18+
public static string MapPath(string userFileSystemPath)
19+
{
20+
// Get path relative to the virtual root.
21+
string relativePath = userFileSystemPath.TrimEnd(Path.DirectorySeparatorChar).Substring(
22+
AppGroupSettings.GetUserRootPath().TrimEnd(Path.DirectorySeparatorChar).Length);
23+
24+
string path = $"{AppGroupSettings.GetRemoteRootPath().TrimEnd(Path.DirectorySeparatorChar)}{relativePath}";
25+
return path;
26+
}
27+
28+
/// <summary>
29+
/// Returns a user file system path that corresponds to the remote storage URI.
30+
/// </summary>
31+
/// <param name="remoteStorageUri">Remote storage URI.</param>
32+
/// <returns>Path in the user file system that corresponds to the <paramref name="remoteStorageUri"/>.</returns>
33+
public static string ReverseMapPath(string remoteStorageUri)
34+
{
35+
// Get path relative to the virtual root.
36+
string relativePath = remoteStorageUri.TrimEnd(Path.DirectorySeparatorChar).Substring(
37+
AppGroupSettings.GetRemoteRootPath().TrimEnd(Path.DirectorySeparatorChar).Length);
38+
39+
string path = $"{AppGroupSettings.GetUserRootPath().TrimEnd(Path.DirectorySeparatorChar)}{relativePath}";
40+
return path;
41+
}
42+
43+
/// <summary>
44+
/// Gets a user file system item info from the remote storage data.
45+
/// </summary>
46+
/// <param name="remoteStorageItem">Remote storage item info.</param>
47+
/// <returns>User file system item info.</returns>
48+
public static IFileSystemItemMetadata GetUserFileSysteItemBasicInfo(FileSystemInfo remoteStorageItem, ILogger logger)
49+
{
50+
VfsFileSystemItem userFileSystemItem;
51+
52+
if (remoteStorageItem is FileInfo)
53+
{
54+
FileInfo remoteStorageFile = (FileInfo)remoteStorageItem;
55+
userFileSystemItem = new VfsFile(remoteStorageFile.FullName, remoteStorageFile.Attributes, remoteStorageFile.CreationTime,
56+
remoteStorageFile.LastWriteTime, remoteStorageFile.LastAccessTime, remoteStorageFile.Length, logger);
57+
}
58+
else
59+
{
60+
userFileSystemItem = new VfsFolder(remoteStorageItem.FullName, remoteStorageItem.Attributes, remoteStorageItem.CreationTime,
61+
remoteStorageItem.LastWriteTime, remoteStorageItem.LastAccessTime, logger);
62+
}
63+
64+
userFileSystemItem.Name = remoteStorageItem.FullName;
65+
userFileSystemItem.Attributes = remoteStorageItem.Attributes;
66+
userFileSystemItem.CreationTime = remoteStorageItem.CreationTime;
67+
userFileSystemItem.LastWriteTime = remoteStorageItem.LastWriteTime;
68+
userFileSystemItem.LastAccessTime = remoteStorageItem.LastAccessTime;
69+
userFileSystemItem.ChangeTime = remoteStorageItem.LastWriteTime;
70+
71+
// You will send the ETag to
72+
// the server inside If-Match header togeter with updated content from client.
73+
// This will make sure the changes on the server is not overwritten.
74+
//
75+
// In this sample, for the sake of simplicity, we use file last write time instead of ETag.
76+
userFileSystemItem.ETag = remoteStorageItem.LastWriteTime.ToBinary().ToString();
77+
78+
// If the item is locked by another user, set the LockedByAnotherUser to true.
79+
// Here we just use the read-only attribute from remote storage item for demo purposes.
80+
userFileSystemItem.LockedByAnotherUser = (remoteStorageItem.Attributes & FileAttributes.ReadOnly) != 0;
81+
82+
if (remoteStorageItem is FileInfo)
83+
{
84+
((VfsFile)userFileSystemItem).Length = ((FileInfo)remoteStorageItem).Length;
85+
};
86+
87+
return userFileSystemItem;
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)