Create FileSystemClient

This commit is contained in:
Alex Barney 2019-08-31 10:15:49 -05:00
parent d6165d1097
commit dfff3b1ccf
20 changed files with 158 additions and 38 deletions

View file

@ -1,7 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using LibHac.Fs;
namespace LibHac.Fs.Accessors namespace LibHac.FsClient.Accessors
{ {
public class DirectoryAccessor : IDisposable public class DirectoryAccessor : IDisposable
{ {

View file

@ -1,6 +1,6 @@
using System; using System;
namespace LibHac.Fs.Accessors namespace LibHac.FsClient.Accessors
{ {
public struct DirectoryHandle : IDisposable public struct DirectoryHandle : IDisposable
{ {

View file

@ -1,6 +1,7 @@
using System; using System;
using LibHac.Fs;
namespace LibHac.Fs.Accessors namespace LibHac.FsClient.Accessors
{ {
public class FileAccessor : IFile public class FileAccessor : IFile
{ {

View file

@ -1,6 +1,6 @@
using System; using System;
namespace LibHac.Fs.Accessors namespace LibHac.FsClient.Accessors
{ {
public struct FileHandle : IDisposable public struct FileHandle : IDisposable
{ {

View file

@ -1,8 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using LibHac.Fs;
namespace LibHac.Fs.Accessors namespace LibHac.FsClient.Accessors
{ {
public class FileSystemAccessor public class FileSystemAccessor
{ {

View file

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using LibHac.Fs;
namespace LibHac.Fs.Accessors namespace LibHac.FsClient.Accessors
{ {
public class MountTable public class MountTable
{ {

View file

@ -0,0 +1,33 @@
using LibHac.FsService;
namespace LibHac.FsClient
{
public class FileSystemClient
{
private FileSystemServer FsSrv { get; }
private FileSystemProxy FsProxy { get; set; }
private FileSystemManager FsManager { get; }
private readonly object _fspInitLocker = new object();
public FileSystemClient(FileSystemServer fsServer, ITimeSpanGenerator timer)
{
FsSrv = fsServer;
FsManager = new FileSystemManager(timer);
}
private FileSystemProxy GetFileSystemProxyServiceObject()
{
if (FsProxy != null) return FsProxy;
lock (_fspInitLocker)
{
if (FsProxy != null) return FsProxy;
FsProxy = FsSrv.CreateFileSystemProxyService();
return FsProxy;
}
}
}
}

View file

@ -1,9 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using LibHac.Fs.Accessors; using LibHac.Fs;
using LibHac.FsClient.Accessors;
namespace LibHac.Fs namespace LibHac.FsClient
{ {
public class FileSystemManager public class FileSystemManager
{ {
@ -26,6 +27,11 @@ namespace LibHac.Fs
Time = timer; Time = timer;
} }
public FileSystemManager(ITimeSpanGenerator timer)
{
Time = timer;
}
public void Register(string mountName, IFileSystem fileSystem) public void Register(string mountName, IFileSystem fileSystem)
{ {
var accessor = new FileSystemAccessor(mountName, fileSystem, this); var accessor = new FileSystemAccessor(mountName, fileSystem, this);

View file

@ -1,9 +1,10 @@
using System; using System;
using System.Buffers; using System.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using LibHac.Fs.Accessors; using LibHac.Fs;
using LibHac.FsClient.Accessors;
namespace LibHac.Fs namespace LibHac.FsClient
{ {
public static class FileSystemManagerUtils public static class FileSystemManagerUtils
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace LibHac.Fs.Accessors namespace LibHac.FsClient
{ {
public interface IAccessLog public interface IAccessLog
{ {

View file

@ -0,0 +1,16 @@
using System;
using LibHac.FsService;
namespace LibHac.FsClient
{
/// <summary>
/// The default access logger that will output to the SD card via <see cref="FileSystemProxy"/>.
/// </summary>
public class SdCardAccessLog : IAccessLog
{
public void Log(TimeSpan startTime, TimeSpan endTime, int handleId, string message, string caller = "")
{
throw new NotImplementedException();
}
}
}

View file

@ -1,12 +1,17 @@
using System; using System;
using LibHac.Common; using LibHac.Common;
using LibHac.Fs; using LibHac.Fs;
using LibHac.FsClient;
namespace LibHac.FsService namespace LibHac.FsService
{ {
public class FileSystemProxy public class FileSystemProxy
{ {
private FileSystemProxyCore FsProxyCore { get; } private FileSystemProxyCore FsProxyCore { get; }
/// <summary>The client instance to be used for internal operations like save indexer access.</summary>
private FileSystemClient FsClient { get; }
public long CurrentProcess { get; private set; } public long CurrentProcess { get; private set; }
public long SaveDataSize { get; private set; } public long SaveDataSize { get; private set; }
@ -16,9 +21,10 @@ namespace LibHac.FsService
private const ulong SaveIndexerId = 0x8000000000000000; private const ulong SaveIndexerId = 0x8000000000000000;
internal FileSystemProxy(FileSystemProxyCore fsProxyCore) internal FileSystemProxy(FileSystemProxyCore fsProxyCore, FileSystemClient fsClient)
{ {
FsProxyCore = fsProxyCore; FsProxyCore = fsProxyCore;
FsClient = fsClient;
CurrentProcess = -1; CurrentProcess = -1;
SaveDataSize = 0x2000000; SaveDataSize = 0x2000000;
@ -146,7 +152,7 @@ namespace LibHac.FsService
if (saveDataId != SaveIndexerId) if (saveDataId != SaveIndexerId)
{ {
if(hasFixedId) if (hasFixedId)
{ {
// todo: remove save indexer entry // todo: remove save indexer entry
} }

View file

@ -0,0 +1,55 @@
using LibHac.FsClient;
using LibHac.FsService.Creators;
namespace LibHac.FsService
{
public class FileSystemServer
{
private FileSystemProxyCore FsProxyCore { get; }
/// <summary>The client instance to be used for internal operations like save indexer access.</summary>
private FileSystemClient FsClient { get; }
private ITimeSpanGenerator Timer { get; }
/// <summary>
/// Creates a new <see cref="FileSystemServer"/> with a new default <see cref="ITimeSpanGenerator"/>.
/// </summary>
/// <param name="fsCreators">The <see cref="FileSystemCreators"/> used for creating filesystems.</param>
public FileSystemServer(FileSystemCreators fsCreators) : this(fsCreators, new StopWatchTimeSpanGenerator()) { }
/// <summary>
/// Creates a new <see cref="FileSystemServer"/>.
/// </summary>
/// <param name="fsCreators">The <see cref="FileSystemCreators"/> used for creating filesystems.</param>
/// <param name="timer">The <see cref="ITimeSpanGenerator"/> to use for access log timestamps.</param>
public FileSystemServer(FileSystemCreators fsCreators, ITimeSpanGenerator timer)
{
FsProxyCore = new FileSystemProxyCore(fsCreators);
FsClient = new FileSystemClient(this, timer);
Timer = timer;
}
/// <summary>
/// Creates a new <see cref="FileSystemClient"/> using this <see cref="FileSystemServer"/>'s
/// <see cref="ITimeSpanGenerator"/> for the client's access log.
/// </summary>
/// <returns>The created <see cref="FileSystemClient"/>.</returns>
public FileSystemClient CreateFileSystemClient() => CreateFileSystemClient(Timer);
/// <summary>
/// Creates a new <see cref="FileSystemClient"/>.
/// </summary>
/// <param name="timer">The <see cref="ITimeSpanGenerator"/> to use for the created
/// <see cref="FileSystemClient"/>'s access log.</param>
/// <returns>The created <see cref="FileSystemClient"/>.</returns>
public FileSystemClient CreateFileSystemClient(ITimeSpanGenerator timer)
{
return new FileSystemClient(this, timer);
}
public FileSystemProxy CreateFileSystemProxyService()
{
return new FileSystemProxy(FsProxyCore, FsClient);
}
}
}

View file

@ -1,19 +0,0 @@
using LibHac.FsService.Creators;
namespace LibHac.FsService
{
public class FileSystemService
{
private FileSystemProxyCore FsProxyCore { get; }
public FileSystemService(FileSystemCreators fsCreators)
{
FsProxyCore = new FileSystemProxyCore(fsCreators);
}
public FileSystemProxy CreateFileSystemProxyService()
{
return new FileSystemProxy(FsProxyCore);
}
}
}

View file

@ -1,4 +1,6 @@
using LibHac.Fs; using LibHac.FsClient;
using LibHac.FsService;
using LibHac.FsService.Creators;
namespace LibHac namespace LibHac
{ {
@ -7,6 +9,9 @@ namespace LibHac
internal ITimeSpanGenerator Time { get; } internal ITimeSpanGenerator Time { get; }
public FileSystemManager Fs { get; } public FileSystemManager Fs { get; }
public FileSystemServer FsSrv { get; private set; }
private readonly object _initLocker = new object();
public Horizon() public Horizon()
{ {
@ -19,5 +24,16 @@ namespace LibHac
Fs = new FileSystemManager(this, timer); Fs = new FileSystemManager(this, timer);
} }
public void InitializeFileSystemServer(FileSystemCreators fsCreators)
{
if (FsSrv != null) return;
lock (_initLocker)
{
if (FsSrv != null) return;
FsSrv = new FileSystemServer(fsCreators);
}
}
} }
} }

View file

@ -1,10 +1,9 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using LibHac;
namespace hactoolnet namespace LibHac
{ {
public class TimeSpanTimer : ITimeSpanGenerator public class StopWatchTimeSpanGenerator : ITimeSpanGenerator
{ {
private Stopwatch Timer = Stopwatch.StartNew(); private Stopwatch Timer = Stopwatch.StartNew();

View file

@ -2,7 +2,7 @@
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using LibHac; using LibHac;
using LibHac.Fs.Accessors; using LibHac.FsClient;
namespace hactoolnet namespace hactoolnet
{ {

View file

@ -2,7 +2,8 @@
using System.Buffers; using System.Buffers;
using LibHac; using LibHac;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.Accessors; using LibHac.FsClient;
using LibHac.FsClient.Accessors;
namespace hactoolnet namespace hactoolnet
{ {

View file

@ -3,6 +3,7 @@ using System.Text;
using LibHac; using LibHac;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.NcaUtils; using LibHac.Fs.NcaUtils;
using LibHac.FsClient;
using LibHac.Npdm; using LibHac.Npdm;
using static hactoolnet.Print; using static hactoolnet.Print;

View file

@ -6,6 +6,7 @@ using System.Text;
using LibHac; using LibHac;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.Save; using LibHac.Fs.Save;
using LibHac.FsClient;
using static hactoolnet.Print; using static hactoolnet.Print;
namespace hactoolnet namespace hactoolnet