mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Clean temp storage on FileSystemServer init
This commit is contained in:
parent
5c1a7920d2
commit
5b0c81fcf9
6 changed files with 68 additions and 11 deletions
|
@ -29,6 +29,13 @@ namespace LibHac.Fs
|
||||||
Time = timer ?? new StopWatchTimeSpanGenerator();
|
Time = timer ?? new StopWatchTimeSpanGenerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal FileSystemClient(FileSystemServer fsServer, IFileSystemProxy fsProxy, ITimeSpanGenerator timer)
|
||||||
|
{
|
||||||
|
FsSrv = fsServer;
|
||||||
|
FsProxy = fsProxy;
|
||||||
|
Time = timer ?? new StopWatchTimeSpanGenerator();
|
||||||
|
}
|
||||||
|
|
||||||
public bool HasFileSystemServer()
|
public bool HasFileSystemServer()
|
||||||
{
|
{
|
||||||
return FsSrv != null;
|
return FsSrv != null;
|
||||||
|
|
|
@ -12,10 +12,6 @@ namespace LibHac.FsService
|
||||||
public class FileSystemProxy : IFileSystemProxy
|
public class FileSystemProxy : IFileSystemProxy
|
||||||
{
|
{
|
||||||
private FileSystemProxyCore FsProxyCore { get; }
|
private FileSystemProxyCore FsProxyCore { get; }
|
||||||
|
|
||||||
/// <summary>The client instance to be used for internal operations like save indexer access.</summary>
|
|
||||||
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
|
||||||
private FileSystemClient FsClient { get; }
|
|
||||||
private FileSystemServer FsServer { get; }
|
private FileSystemServer FsServer { get; }
|
||||||
|
|
||||||
public long CurrentProcess { get; private set; }
|
public long CurrentProcess { get; private set; }
|
||||||
|
@ -25,10 +21,9 @@ namespace LibHac.FsService
|
||||||
public FsPath SaveDataRootPath { get; } = default;
|
public FsPath SaveDataRootPath { get; } = default;
|
||||||
public bool AutoCreateSaveData { get; private set; }
|
public bool AutoCreateSaveData { get; private set; }
|
||||||
|
|
||||||
internal FileSystemProxy(FileSystemProxyCore fsProxyCore, FileSystemClient fsClient, FileSystemServer fsServer)
|
internal FileSystemProxy(FileSystemProxyCore fsProxyCore, FileSystemServer fsServer)
|
||||||
{
|
{
|
||||||
FsProxyCore = fsProxyCore;
|
FsProxyCore = fsProxyCore;
|
||||||
FsClient = fsClient;
|
|
||||||
FsServer = fsServer;
|
FsServer = fsServer;
|
||||||
|
|
||||||
CurrentProcess = -1;
|
CurrentProcess = -1;
|
||||||
|
@ -1072,6 +1067,32 @@ namespace LibHac.FsService
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result CleanUpTemporaryStorage()
|
||||||
|
{
|
||||||
|
Result rc = FsProxyCore.OpenSaveDataDirectory(out IFileSystem saveDirFs, SaveDataSpaceId.Temporary,
|
||||||
|
string.Empty, false);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
rc = saveDirFs.CleanDirectoryRecursively("/");
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
SaveDataIndexerReader reader = default;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, SaveDataSpaceId.Temporary);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
reader.Indexer.Reset();
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
reader.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Result SetSdCardAccessibility(bool isAccessible)
|
public Result SetSdCardAccessibility(bool isAccessible)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|
|
@ -29,13 +29,15 @@ namespace LibHac.FsService
|
||||||
throw new ArgumentException("DeviceOperator must not be null");
|
throw new ArgumentException("DeviceOperator must not be null");
|
||||||
|
|
||||||
ExternalKeySet externalKeySet = config.ExternalKeySet ?? new ExternalKeySet();
|
ExternalKeySet externalKeySet = config.ExternalKeySet ?? new ExternalKeySet();
|
||||||
ITimeSpanGenerator timer = config.TimeSpanGenerator ?? new StopWatchTimeSpanGenerator();
|
Timer = config.TimeSpanGenerator ?? new StopWatchTimeSpanGenerator();
|
||||||
|
|
||||||
FsProxyCore = new FileSystemProxyCore(config.FsCreators, externalKeySet, config.DeviceOperator);
|
FsProxyCore = new FileSystemProxyCore(config.FsCreators, externalKeySet, config.DeviceOperator);
|
||||||
FsClient = new FileSystemClient(this, timer);
|
var fsProxy = new FileSystemProxy(FsProxyCore, this);
|
||||||
Timer = timer;
|
FsClient = new FileSystemClient(this, fsProxy, Timer);
|
||||||
|
|
||||||
SaveDataIndexerManager = new SaveDataIndexerManager(FsClient, SaveIndexerId);
|
SaveDataIndexerManager = new SaveDataIndexerManager(FsClient, SaveIndexerId);
|
||||||
|
|
||||||
|
fsProxy.CleanUpTemporaryStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -58,7 +60,7 @@ namespace LibHac.FsService
|
||||||
|
|
||||||
public IFileSystemProxy CreateFileSystemProxyService()
|
public IFileSystemProxy CreateFileSystemProxyService()
|
||||||
{
|
{
|
||||||
return new FileSystemProxy(FsProxyCore, FsClient, this);
|
return new FileSystemProxy(FsProxyCore, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace LibHac.FsService
|
||||||
public interface ISaveDataIndexer
|
public interface ISaveDataIndexer
|
||||||
{
|
{
|
||||||
Result Commit();
|
Result Commit();
|
||||||
|
Result Reset();
|
||||||
Result Add(out ulong saveDataId, ref SaveDataAttribute key);
|
Result Add(out ulong saveDataId, ref SaveDataAttribute key);
|
||||||
Result Get(out SaveDataIndexerValue value, ref SaveDataAttribute key);
|
Result Get(out SaveDataIndexerValue value, ref SaveDataAttribute key);
|
||||||
Result AddSystemSaveData(ref SaveDataAttribute key);
|
Result AddSystemSaveData(ref SaveDataAttribute key);
|
||||||
|
|
|
@ -112,6 +112,23 @@ namespace LibHac.FsService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result Reset()
|
||||||
|
{
|
||||||
|
lock (Locker)
|
||||||
|
{
|
||||||
|
IsKvdbLoaded = false;
|
||||||
|
|
||||||
|
Result rc = FsClient.DeleteSaveData(SaveDataId);
|
||||||
|
|
||||||
|
if (rc.IsSuccess() || rc == ResultFs.TargetNotFound)
|
||||||
|
{
|
||||||
|
Version++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Result Add(out ulong saveDataId, ref SaveDataAttribute key)
|
public Result Add(out ulong saveDataId, ref SaveDataAttribute key)
|
||||||
{
|
{
|
||||||
saveDataId = default;
|
saveDataId = default;
|
||||||
|
@ -525,7 +542,7 @@ namespace LibHac.FsService
|
||||||
{
|
{
|
||||||
// New key was inserted before the iterator's position
|
// New key was inserted before the iterator's position
|
||||||
// increment the position to compensate
|
// increment the position to compensate
|
||||||
if(reader.Position >= index)
|
if (reader.Position >= index)
|
||||||
{
|
{
|
||||||
reader.Position++;
|
reader.Position++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,15 @@ namespace LibHac.FsService
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result Reset()
|
||||||
|
{
|
||||||
|
lock (Locker)
|
||||||
|
{
|
||||||
|
IsKeyValueSet = false;
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Result Add(out ulong saveDataId, ref SaveDataAttribute key)
|
public Result Add(out ulong saveDataId, ref SaveDataAttribute key)
|
||||||
{
|
{
|
||||||
lock (Locker)
|
lock (Locker)
|
||||||
|
|
Loading…
Reference in a new issue