diff --git a/src/LibHac/Fs/Accessors/DirectoryAccessor.cs b/src/LibHac/FsClient/Accessors/DirectoryAccessor.cs
similarity index 95%
rename from src/LibHac/Fs/Accessors/DirectoryAccessor.cs
rename to src/LibHac/FsClient/Accessors/DirectoryAccessor.cs
index e3b3141e..94df1121 100644
--- a/src/LibHac/Fs/Accessors/DirectoryAccessor.cs
+++ b/src/LibHac/FsClient/Accessors/DirectoryAccessor.cs
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
+using LibHac.Fs;
-namespace LibHac.Fs.Accessors
+namespace LibHac.FsClient.Accessors
{
public class DirectoryAccessor : IDisposable
{
diff --git a/src/LibHac/Fs/Accessors/DirectoryHandle.cs b/src/LibHac/FsClient/Accessors/DirectoryHandle.cs
similarity index 92%
rename from src/LibHac/Fs/Accessors/DirectoryHandle.cs
rename to src/LibHac/FsClient/Accessors/DirectoryHandle.cs
index d4804306..05f8fb67 100644
--- a/src/LibHac/Fs/Accessors/DirectoryHandle.cs
+++ b/src/LibHac/FsClient/Accessors/DirectoryHandle.cs
@@ -1,6 +1,6 @@
using System;
-namespace LibHac.Fs.Accessors
+namespace LibHac.FsClient.Accessors
{
public struct DirectoryHandle : IDisposable
{
diff --git a/src/LibHac/Fs/Accessors/FileAccessor.cs b/src/LibHac/FsClient/Accessors/FileAccessor.cs
similarity index 97%
rename from src/LibHac/Fs/Accessors/FileAccessor.cs
rename to src/LibHac/FsClient/Accessors/FileAccessor.cs
index a269f639..f69bec1f 100644
--- a/src/LibHac/Fs/Accessors/FileAccessor.cs
+++ b/src/LibHac/FsClient/Accessors/FileAccessor.cs
@@ -1,6 +1,7 @@
using System;
+using LibHac.Fs;
-namespace LibHac.Fs.Accessors
+namespace LibHac.FsClient.Accessors
{
public class FileAccessor : IFile
{
diff --git a/src/LibHac/Fs/Accessors/FileHandle.cs b/src/LibHac/FsClient/Accessors/FileHandle.cs
similarity index 91%
rename from src/LibHac/Fs/Accessors/FileHandle.cs
rename to src/LibHac/FsClient/Accessors/FileHandle.cs
index da454f4d..df7c8fa4 100644
--- a/src/LibHac/Fs/Accessors/FileHandle.cs
+++ b/src/LibHac/FsClient/Accessors/FileHandle.cs
@@ -1,6 +1,6 @@
using System;
-namespace LibHac.Fs.Accessors
+namespace LibHac.FsClient.Accessors
{
public struct FileHandle : IDisposable
{
diff --git a/src/LibHac/Fs/Accessors/FileSystemAccessor.cs b/src/LibHac/FsClient/Accessors/FileSystemAccessor.cs
similarity index 98%
rename from src/LibHac/Fs/Accessors/FileSystemAccessor.cs
rename to src/LibHac/FsClient/Accessors/FileSystemAccessor.cs
index 3e8293fd..391f7381 100644
--- a/src/LibHac/Fs/Accessors/FileSystemAccessor.cs
+++ b/src/LibHac/FsClient/Accessors/FileSystemAccessor.cs
@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using LibHac.Fs;
-namespace LibHac.Fs.Accessors
+namespace LibHac.FsClient.Accessors
{
public class FileSystemAccessor
{
diff --git a/src/LibHac/Fs/Accessors/MountTable.cs b/src/LibHac/FsClient/Accessors/MountTable.cs
similarity index 96%
rename from src/LibHac/Fs/Accessors/MountTable.cs
rename to src/LibHac/FsClient/Accessors/MountTable.cs
index ec9f94cb..de87b56e 100644
--- a/src/LibHac/Fs/Accessors/MountTable.cs
+++ b/src/LibHac/FsClient/Accessors/MountTable.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
+using LibHac.Fs;
-namespace LibHac.Fs.Accessors
+namespace LibHac.FsClient.Accessors
{
public class MountTable
{
diff --git a/src/LibHac/FsClient/FileSystemClient.cs b/src/LibHac/FsClient/FileSystemClient.cs
new file mode 100644
index 00000000..9076769a
--- /dev/null
+++ b/src/LibHac/FsClient/FileSystemClient.cs
@@ -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;
+ }
+ }
+ }
+}
diff --git a/src/LibHac/Fs/FileSystemManager.cs b/src/LibHac/FsClient/FileSystemManager.cs
similarity index 99%
rename from src/LibHac/Fs/FileSystemManager.cs
rename to src/LibHac/FsClient/FileSystemManager.cs
index 973ce264..ecd228d0 100644
--- a/src/LibHac/Fs/FileSystemManager.cs
+++ b/src/LibHac/FsClient/FileSystemManager.cs
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
-using LibHac.Fs.Accessors;
+using LibHac.Fs;
+using LibHac.FsClient.Accessors;
-namespace LibHac.Fs
+namespace LibHac.FsClient
{
public class FileSystemManager
{
@@ -26,6 +27,11 @@ namespace LibHac.Fs
Time = timer;
}
+ public FileSystemManager(ITimeSpanGenerator timer)
+ {
+ Time = timer;
+ }
+
public void Register(string mountName, IFileSystem fileSystem)
{
var accessor = new FileSystemAccessor(mountName, fileSystem, this);
diff --git a/src/LibHac/Fs/FileSystemManagerUtils.cs b/src/LibHac/FsClient/FileSystemManagerUtils.cs
similarity index 98%
rename from src/LibHac/Fs/FileSystemManagerUtils.cs
rename to src/LibHac/FsClient/FileSystemManagerUtils.cs
index 7e0498f7..5cdd0807 100644
--- a/src/LibHac/Fs/FileSystemManagerUtils.cs
+++ b/src/LibHac/FsClient/FileSystemManagerUtils.cs
@@ -1,9 +1,10 @@
using System;
using System.Buffers;
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
{
diff --git a/src/LibHac/Fs/Accessors/IAccessLog.cs b/src/LibHac/FsClient/IAccessLog.cs
similarity index 88%
rename from src/LibHac/Fs/Accessors/IAccessLog.cs
rename to src/LibHac/FsClient/IAccessLog.cs
index 3ff9ed53..b145e32f 100644
--- a/src/LibHac/Fs/Accessors/IAccessLog.cs
+++ b/src/LibHac/FsClient/IAccessLog.cs
@@ -1,7 +1,7 @@
using System;
using System.Runtime.CompilerServices;
-namespace LibHac.Fs.Accessors
+namespace LibHac.FsClient
{
public interface IAccessLog
{
diff --git a/src/LibHac/FsClient/SdCardAccessLog.cs b/src/LibHac/FsClient/SdCardAccessLog.cs
new file mode 100644
index 00000000..d3b97ae9
--- /dev/null
+++ b/src/LibHac/FsClient/SdCardAccessLog.cs
@@ -0,0 +1,16 @@
+using System;
+using LibHac.FsService;
+
+namespace LibHac.FsClient
+{
+ ///
+ /// The default access logger that will output to the SD card via .
+ ///
+ public class SdCardAccessLog : IAccessLog
+ {
+ public void Log(TimeSpan startTime, TimeSpan endTime, int handleId, string message, string caller = "")
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/LibHac/FsService/FileSystemProxy.cs b/src/LibHac/FsService/FileSystemProxy.cs
index 6e5b675b..f43fca19 100644
--- a/src/LibHac/FsService/FileSystemProxy.cs
+++ b/src/LibHac/FsService/FileSystemProxy.cs
@@ -1,12 +1,17 @@
using System;
using LibHac.Common;
using LibHac.Fs;
+using LibHac.FsClient;
namespace LibHac.FsService
{
public class FileSystemProxy
{
private FileSystemProxyCore FsProxyCore { get; }
+
+ /// The client instance to be used for internal operations like save indexer access.
+ private FileSystemClient FsClient { get; }
+
public long CurrentProcess { get; private set; }
public long SaveDataSize { get; private set; }
@@ -16,9 +21,10 @@ namespace LibHac.FsService
private const ulong SaveIndexerId = 0x8000000000000000;
- internal FileSystemProxy(FileSystemProxyCore fsProxyCore)
+ internal FileSystemProxy(FileSystemProxyCore fsProxyCore, FileSystemClient fsClient)
{
FsProxyCore = fsProxyCore;
+ FsClient = fsClient;
CurrentProcess = -1;
SaveDataSize = 0x2000000;
@@ -146,7 +152,7 @@ namespace LibHac.FsService
if (saveDataId != SaveIndexerId)
{
- if(hasFixedId)
+ if (hasFixedId)
{
// todo: remove save indexer entry
}
diff --git a/src/LibHac/FsService/FileSystemServer.cs b/src/LibHac/FsService/FileSystemServer.cs
new file mode 100644
index 00000000..974a8f34
--- /dev/null
+++ b/src/LibHac/FsService/FileSystemServer.cs
@@ -0,0 +1,55 @@
+using LibHac.FsClient;
+using LibHac.FsService.Creators;
+
+namespace LibHac.FsService
+{
+ public class FileSystemServer
+ {
+ private FileSystemProxyCore FsProxyCore { get; }
+
+ /// The client instance to be used for internal operations like save indexer access.
+ private FileSystemClient FsClient { get; }
+ private ITimeSpanGenerator Timer { get; }
+
+ ///
+ /// Creates a new with a new default .
+ ///
+ /// The used for creating filesystems.
+ public FileSystemServer(FileSystemCreators fsCreators) : this(fsCreators, new StopWatchTimeSpanGenerator()) { }
+
+ ///
+ /// Creates a new .
+ ///
+ /// The used for creating filesystems.
+ /// The to use for access log timestamps.
+ public FileSystemServer(FileSystemCreators fsCreators, ITimeSpanGenerator timer)
+ {
+ FsProxyCore = new FileSystemProxyCore(fsCreators);
+ FsClient = new FileSystemClient(this, timer);
+ Timer = timer;
+ }
+
+ ///
+ /// Creates a new using this 's
+ /// for the client's access log.
+ ///
+ /// The created .
+ public FileSystemClient CreateFileSystemClient() => CreateFileSystemClient(Timer);
+
+ ///
+ /// Creates a new .
+ ///
+ /// The to use for the created
+ /// 's access log.
+ /// The created .
+ public FileSystemClient CreateFileSystemClient(ITimeSpanGenerator timer)
+ {
+ return new FileSystemClient(this, timer);
+ }
+
+ public FileSystemProxy CreateFileSystemProxyService()
+ {
+ return new FileSystemProxy(FsProxyCore, FsClient);
+ }
+ }
+}
diff --git a/src/LibHac/FsService/FileSystemService.cs b/src/LibHac/FsService/FileSystemService.cs
deleted file mode 100644
index 7597dd3e..00000000
--- a/src/LibHac/FsService/FileSystemService.cs
+++ /dev/null
@@ -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);
- }
- }
-}
diff --git a/src/LibHac/Horizon.cs b/src/LibHac/Horizon.cs
index 6e55025d..370dc5b2 100644
--- a/src/LibHac/Horizon.cs
+++ b/src/LibHac/Horizon.cs
@@ -1,4 +1,6 @@
-using LibHac.Fs;
+using LibHac.FsClient;
+using LibHac.FsService;
+using LibHac.FsService.Creators;
namespace LibHac
{
@@ -7,6 +9,9 @@ namespace LibHac
internal ITimeSpanGenerator Time { get; }
public FileSystemManager Fs { get; }
+ public FileSystemServer FsSrv { get; private set; }
+
+ private readonly object _initLocker = new object();
public Horizon()
{
@@ -19,5 +24,16 @@ namespace LibHac
Fs = new FileSystemManager(this, timer);
}
+
+ public void InitializeFileSystemServer(FileSystemCreators fsCreators)
+ {
+ if (FsSrv != null) return;
+
+ lock (_initLocker)
+ {
+ if (FsSrv != null) return;
+ FsSrv = new FileSystemServer(fsCreators);
+ }
+ }
}
}
diff --git a/src/hactoolnet/TimeSpanTimer.cs b/src/LibHac/StopWatchTimeSpanGenerator.cs
similarity index 70%
rename from src/hactoolnet/TimeSpanTimer.cs
rename to src/LibHac/StopWatchTimeSpanGenerator.cs
index 9235181d..c10e9da2 100644
--- a/src/hactoolnet/TimeSpanTimer.cs
+++ b/src/LibHac/StopWatchTimeSpanGenerator.cs
@@ -1,10 +1,9 @@
using System;
using System.Diagnostics;
-using LibHac;
-namespace hactoolnet
+namespace LibHac
{
- public class TimeSpanTimer : ITimeSpanGenerator
+ public class StopWatchTimeSpanGenerator : ITimeSpanGenerator
{
private Stopwatch Timer = Stopwatch.StartNew();
diff --git a/src/hactoolnet/AccessLog.cs b/src/hactoolnet/AccessLog.cs
index 89226520..f7f505c0 100644
--- a/src/hactoolnet/AccessLog.cs
+++ b/src/hactoolnet/AccessLog.cs
@@ -2,7 +2,7 @@
using System.IO;
using System.Runtime.CompilerServices;
using LibHac;
-using LibHac.Fs.Accessors;
+using LibHac.FsClient;
namespace hactoolnet
{
diff --git a/src/hactoolnet/FsUtils.cs b/src/hactoolnet/FsUtils.cs
index 6ece0c28..eb752b27 100644
--- a/src/hactoolnet/FsUtils.cs
+++ b/src/hactoolnet/FsUtils.cs
@@ -2,7 +2,8 @@
using System.Buffers;
using LibHac;
using LibHac.Fs;
-using LibHac.Fs.Accessors;
+using LibHac.FsClient;
+using LibHac.FsClient.Accessors;
namespace hactoolnet
{
diff --git a/src/hactoolnet/ProcessNca.cs b/src/hactoolnet/ProcessNca.cs
index 7f644940..f7b7f09d 100644
--- a/src/hactoolnet/ProcessNca.cs
+++ b/src/hactoolnet/ProcessNca.cs
@@ -3,6 +3,7 @@ using System.Text;
using LibHac;
using LibHac.Fs;
using LibHac.Fs.NcaUtils;
+using LibHac.FsClient;
using LibHac.Npdm;
using static hactoolnet.Print;
diff --git a/src/hactoolnet/ProcessSave.cs b/src/hactoolnet/ProcessSave.cs
index 349a6dc7..c973401f 100644
--- a/src/hactoolnet/ProcessSave.cs
+++ b/src/hactoolnet/ProcessSave.cs
@@ -6,6 +6,7 @@ using System.Text;
using LibHac;
using LibHac.Fs;
using LibHac.Fs.Save;
+using LibHac.FsClient;
using static hactoolnet.Print;
namespace hactoolnet