mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Create FileSystemClient
This commit is contained in:
parent
d6165d1097
commit
dfff3b1ccf
20 changed files with 158 additions and 38 deletions
|
@ -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
|
||||||
{
|
{
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace LibHac.Fs.Accessors
|
namespace LibHac.FsClient.Accessors
|
||||||
{
|
{
|
||||||
public struct DirectoryHandle : IDisposable
|
public struct DirectoryHandle : IDisposable
|
||||||
{
|
{
|
|
@ -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
|
||||||
{
|
{
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace LibHac.Fs.Accessors
|
namespace LibHac.FsClient.Accessors
|
||||||
{
|
{
|
||||||
public struct FileHandle : IDisposable
|
public struct FileHandle : IDisposable
|
||||||
{
|
{
|
|
@ -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
|
||||||
{
|
{
|
|
@ -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
|
||||||
{
|
{
|
33
src/LibHac/FsClient/FileSystemClient.cs
Normal file
33
src/LibHac/FsClient/FileSystemClient.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
|
@ -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
|
||||||
{
|
{
|
|
@ -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
|
||||||
{
|
{
|
16
src/LibHac/FsClient/SdCardAccessLog.cs
Normal file
16
src/LibHac/FsClient/SdCardAccessLog.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
55
src/LibHac/FsService/FileSystemServer.cs
Normal file
55
src/LibHac/FsService/FileSystemServer.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue