-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
79 changed files
with
3,090 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace WebRaid.CsWin32 | ||
{ | ||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello, World!"); | ||
|
||
var sync = new SyncRootManager(); | ||
var connect = sync.Connect(); | ||
|
||
Console.WriteLine($"Pfad: {sync.Pfad}"); | ||
|
||
Console.ReadLine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
using System.Runtime.InteropServices; | ||
using System.Security.Principal; | ||
using Vanara.Extensions; | ||
using Vanara.PInvoke; | ||
using Windows.Security.Cryptography; | ||
using Windows.Storage; | ||
using Windows.Storage.Provider; | ||
using static Vanara.PInvoke.CldApi; | ||
|
||
namespace WebRaid.CsWin32 | ||
{ | ||
public class SyncRootManager | ||
{ | ||
public string Pfad=> SyncRootPath; | ||
internal static readonly string SyncRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "TestCloud"); | ||
internal static readonly Guid StorageProviderId = Guid.Parse("BEE7B8DC-9699-4561-910D-D3B2F6A923A9"); | ||
|
||
internal const string CloudName = "Test Cloud"; | ||
internal const string StorageProviderAccount = "SomeAccount"; | ||
|
||
private readonly CF_CALLBACK_REGISTRATION[] _callbacks = [ | ||
new CF_CALLBACK_REGISTRATION | ||
{ | ||
Type = CF_CALLBACK_TYPE.CF_CALLBACK_TYPE_FETCH_PLACEHOLDERS, | ||
Callback = new CF_CALLBACK((in CF_CALLBACK_INFO x, in CF_CALLBACK_PARAMETERS y) => CfExecutePlaceholdersFetch(new FileSystemItem | ||
{ | ||
Id = Guid.NewGuid(), | ||
RelativePath = "testFile.txt", | ||
FileAttributes = System.IO.FileAttributes.Normal, | ||
CreationTime = DateTime.Now, | ||
LastAccessTime = DateTime.Now, | ||
LastWriteTime = DateTime.Now, | ||
Size = 15654654 | ||
}, x)), | ||
}, | ||
new CF_CALLBACK_REGISTRATION | ||
{ | ||
Type = CF_CALLBACK_TYPE.CF_CALLBACK_TYPE_NONE | ||
}]; | ||
|
||
public CF_CONNECTION_KEY ConnectionKey { get; private set; } | ||
|
||
public async Task Connect() | ||
{ | ||
EnsureFeatureSupported(); | ||
EnsureSyncRootPathCreated(); | ||
|
||
StorageProviderSyncRootManager.Register(await CreateSyncRoot()); | ||
|
||
CfConnectSyncRoot( | ||
SyncRootPath, | ||
_callbacks, | ||
nint.Zero, | ||
CF_CONNECT_FLAGS.CF_CONNECT_FLAG_REQUIRE_PROCESS_INFO | CF_CONNECT_FLAGS.CF_CONNECT_FLAG_REQUIRE_FULL_FILE_PATH, | ||
out var connectionKey); | ||
|
||
ConnectionKey = connectionKey; | ||
|
||
CfUpdateSyncProviderStatus(ConnectionKey, CF_SYNC_PROVIDER_STATUS.CF_PROVIDER_STATUS_IDLE); | ||
} | ||
|
||
private static void EnsureFeatureSupported() | ||
{ | ||
if (!StorageProviderSyncRootManager.IsSupported()) | ||
{ | ||
throw new NotSupportedException("Cloud API is not supported on this machine."); | ||
} | ||
} | ||
|
||
private static void EnsureSyncRootPathCreated() | ||
{ | ||
if (!Directory.Exists(SyncRootPath)) | ||
{ | ||
Directory.CreateDirectory(SyncRootPath); | ||
} | ||
} | ||
|
||
private static async Task<StorageProviderSyncRootInfo> CreateSyncRoot() | ||
{ | ||
StorageProviderSyncRootInfo syncRoot = new() | ||
{ | ||
Id = GetSyncRootId(), | ||
ProviderId = StorageProviderId, | ||
Path = await StorageFolder.GetFolderFromPathAsync(SyncRootPath), | ||
AllowPinning = true, | ||
DisplayNameResource = CloudName, | ||
HardlinkPolicy = StorageProviderHardlinkPolicy.Allowed, | ||
HydrationPolicy = StorageProviderHydrationPolicy.Partial, | ||
HydrationPolicyModifier = StorageProviderHydrationPolicyModifier.AutoDehydrationAllowed | StorageProviderHydrationPolicyModifier.StreamingAllowed, | ||
InSyncPolicy = StorageProviderInSyncPolicy.FileLastWriteTime, | ||
PopulationPolicy = StorageProviderPopulationPolicy.Full, | ||
ProtectionMode = StorageProviderProtectionMode.Unknown, | ||
Version = "1.0.0", | ||
IconResource = "%SystemRoot%\\system32\\charmap.exe,0", | ||
ShowSiblingsAsGroup = false, | ||
RecycleBinUri = null, | ||
Context = CryptographicBuffer.ConvertStringToBinary(GetSyncRootId(), BinaryStringEncoding.Utf8) | ||
}; | ||
|
||
return syncRoot; | ||
|
||
} | ||
|
||
private static string GetSyncRootId() | ||
=> $"{StorageProviderId}!{WindowsIdentity.GetCurrent().User}!{StorageProviderAccount}"; | ||
|
||
#region Placeholder creation | ||
private static void CfExecutePlaceholdersFetch(FileSystemItem placeholder, CF_CALLBACK_INFO callbackInfo) | ||
{ | ||
CF_OPERATION_INFO operationInfo = CreateOperationInfo(callbackInfo, CF_OPERATION_TYPE.CF_OPERATION_TYPE_TRANSFER_PLACEHOLDERS); | ||
CF_PLACEHOLDER_CREATE_INFO nativePlaceholder = CreatePlaceholder(placeholder); | ||
|
||
IntPtr placeholderArray = Marshal.AllocHGlobal(Marshal.SizeOf<CF_PLACEHOLDER_CREATE_INFO>()); | ||
Marshal.StructureToPtr(nativePlaceholder, placeholderArray, false); | ||
|
||
CF_OPERATION_PARAMETERS.TRANSFERPLACEHOLDERS placeholdersFetchParameter = new() | ||
{ | ||
PlaceholderArray = placeholderArray, | ||
Flags = CF_OPERATION_TRANSFER_PLACEHOLDERS_FLAGS.CF_OPERATION_TRANSFER_PLACEHOLDERS_FLAG_DISABLE_ON_DEMAND_POPULATION, | ||
PlaceholderCount = 1, | ||
CompletionStatus = NTStatus.STATUS_SUCCESS, | ||
PlaceholderTotalCount = 1, | ||
}; | ||
|
||
CF_OPERATION_PARAMETERS opParams = CF_OPERATION_PARAMETERS.Create(placeholdersFetchParameter); | ||
|
||
HRESULT result = CfExecute(operationInfo, ref opParams); | ||
result.ThrowIfFailed(); | ||
|
||
Marshal.FreeHGlobal(placeholderArray); | ||
Marshal.FreeHGlobal(nativePlaceholder.FileIdentity); | ||
} | ||
|
||
private static CF_PLACEHOLDER_CREATE_INFO CreatePlaceholder(FileSystemItem placeholder) | ||
{ | ||
CF_PLACEHOLDER_CREATE_INFO cfInfo = new() | ||
{ | ||
FileIdentity = Marshal.StringToHGlobalUni("a"), | ||
FileIdentityLength = 2 * 2, | ||
RelativeFileName = placeholder.RelativePath, | ||
FsMetadata = new CF_FS_METADATA | ||
{ | ||
FileSize = placeholder.Size, | ||
BasicInfo = new Kernel32.FILE_BASIC_INFO | ||
{ | ||
FileAttributes = (FileFlagsAndAttributes)placeholder.FileAttributes, | ||
CreationTime = FileTimeExtensions.MakeFILETIME((ulong)placeholder.CreationTime.ToFileTime()), | ||
LastWriteTime = FileTimeExtensions.MakeFILETIME((ulong)placeholder.LastWriteTime.ToFileTime()), | ||
LastAccessTime = FileTimeExtensions.MakeFILETIME((ulong)placeholder.LastAccessTime.ToFileTime()), | ||
ChangeTime = FileTimeExtensions.MakeFILETIME((ulong)placeholder.LastWriteTime.ToFileTime()) | ||
} | ||
}, | ||
Flags = CF_PLACEHOLDER_CREATE_FLAGS.CF_PLACEHOLDER_CREATE_FLAG_MARK_IN_SYNC | ||
}; | ||
|
||
return cfInfo; | ||
} | ||
|
||
private static CF_OPERATION_INFO CreateOperationInfo(in CF_CALLBACK_INFO CallbackInfo, CF_OPERATION_TYPE OperationType) | ||
{ | ||
CF_OPERATION_INFO opInfo = new() | ||
{ | ||
Type = OperationType, | ||
ConnectionKey = CallbackInfo.ConnectionKey, | ||
TransferKey = CallbackInfo.TransferKey, | ||
CorrelationVector = CallbackInfo.CorrelationVector, | ||
RequestKey = CallbackInfo.RequestKey | ||
}; | ||
|
||
opInfo.StructSize = (uint)Marshal.SizeOf(opInfo); | ||
return opInfo; | ||
} | ||
|
||
public class FileSystemItem | ||
{ | ||
public Guid Id { get; set; } | ||
public string RelativePath { get; set; } | ||
public long Size { get; set; } | ||
public System.IO.FileAttributes FileAttributes { get; set; } | ||
public DateTimeOffset CreationTime { get; set; } | ||
public DateTimeOffset LastWriteTime { get; set; } | ||
public DateTimeOffset LastAccessTime { get; set; } | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PublishAot>true</PublishAot> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Vanara.PInvoke.CldApi" Version="3.4.17" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
WebRaid.Main.WinService/WebRaid - Backup (1).Main.WinService.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<Version>0.1.0-dev011</Version> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="$(Configuration) == 'Debug'"> | ||
<BumpLabel>dev</BumpLabel> | ||
<BumpLabelDigits>3</BumpLabelDigits> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(Configuration) == 'Release'"> | ||
<BumpPatch>True</BumpPatch> | ||
<BumpResetLabel>dev</BumpResetLabel> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" /> | ||
<PackageReference Include="MSBump" Version="2.3.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\WebRaid.Main\WebRaid.Main.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
30 changes: 30 additions & 0 deletions
30
WebRaid.Main.WinService/WebRaid - Backup.Main.WinService.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<Version>0.1.0-dev011</Version> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="$(Configuration) == 'Debug'"> | ||
<BumpLabel>dev</BumpLabel> | ||
<BumpLabelDigits>3</BumpLabelDigits> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(Configuration) == 'Release'"> | ||
<BumpPatch>True</BumpPatch> | ||
<BumpResetLabel>dev</BumpResetLabel> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" /> | ||
<PackageReference Include="MSBump" Version="2.3.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\WebRaid.Main\Server\WebRaid.Main.Server.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"dotnet-ef": { | ||
"version": "6.0.3", | ||
"commands": [ | ||
"dotnet-ef" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
</Found> | ||
<NotFound> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p>Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
Oops, something went wrong.