mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add TimeService
This commit is contained in:
parent
9826178fb6
commit
c29fed67c1
5 changed files with 97 additions and 8 deletions
|
@ -8,6 +8,7 @@ namespace LibHac.FsSrv
|
|||
public BaseFileSystemServiceImpl BaseFileSystemService { get; set; }
|
||||
public NcaFileSystemServiceImpl NcaFileSystemService { get; set; }
|
||||
public SaveDataFileSystemServiceImpl SaveDataFileSystemService { get; set; }
|
||||
public TimeServiceImpl TimeService { get; set; }
|
||||
public ProgramRegistryServiceImpl ProgramRegistryService { get; set; }
|
||||
public AccessLogServiceImpl AccessLogService { get; set; }
|
||||
}
|
||||
|
|
|
@ -25,11 +25,6 @@ namespace LibHac.FsSrv
|
|||
CurrentProcess = ulong.MaxValue;
|
||||
}
|
||||
|
||||
private ProgramIndexRegistryService GetProgramIndexRegistryService()
|
||||
{
|
||||
return new ProgramIndexRegistryService(FsProxyCore.Config.ProgramRegistryService, CurrentProcess);
|
||||
}
|
||||
|
||||
public Result OpenFileSystemWithId(out ReferenceCountedDisposable<IFileSystemSf> fileSystem, in FspPath path,
|
||||
ulong id, FileSystemProxyType fsType)
|
||||
{
|
||||
|
@ -746,9 +741,9 @@ namespace LibHac.FsSrv
|
|||
return saveFsService.QuerySaveDataTotalSize(out totalSize, dataSize, journalSize);
|
||||
}
|
||||
|
||||
public Result SetCurrentPosixTimeWithTimeDifference(long time, int difference)
|
||||
public Result SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return GetTimeService().SetCurrentPosixTimeWithTimeDifference(currentTime, timeDifference);
|
||||
}
|
||||
|
||||
public Result GetRightsId(out RightsId rightsId, ProgramId programId, StorageId storageId)
|
||||
|
@ -1005,6 +1000,16 @@ namespace LibHac.FsSrv
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
private TimeService GetTimeService()
|
||||
{
|
||||
return new TimeService(FsProxyCore.Config.TimeService, CurrentProcess);
|
||||
}
|
||||
|
||||
private ProgramIndexRegistryService GetProgramIndexRegistryService()
|
||||
{
|
||||
return new ProgramIndexRegistryService(FsProxyCore.Config.ProgramRegistryService, CurrentProcess);
|
||||
}
|
||||
|
||||
private AccessLogService GetAccessLogService()
|
||||
{
|
||||
return new AccessLogService(FsProxyCore.Config.AccessLogService, CurrentProcess);
|
||||
|
|
|
@ -96,6 +96,11 @@ namespace LibHac.FsSrv
|
|||
var programRegistryService = new ProgramRegistryServiceImpl(this);
|
||||
var programRegistry = new ProgramRegistryImpl(programRegistryService);
|
||||
|
||||
var timeServiceConfig = new TimeServiceImpl.Configuration();
|
||||
timeServiceConfig.HorizonClient = Hos;
|
||||
timeServiceConfig.ProgramRegistry = programRegistry;
|
||||
var timeService = new TimeServiceImpl(in timeServiceConfig);
|
||||
|
||||
var baseFsServiceConfig = new BaseFileSystemServiceImpl.Configuration();
|
||||
baseFsServiceConfig.BisFileSystemCreator = config.FsCreators.BuiltInStorageFileSystemCreator;
|
||||
baseFsServiceConfig.GameCardFileSystemCreator = config.FsCreators.GameCardFileSystemCreator;
|
||||
|
@ -148,6 +153,7 @@ namespace LibHac.FsSrv
|
|||
BaseFileSystemService = baseFsService,
|
||||
NcaFileSystemService = ncaFsService,
|
||||
SaveDataFileSystemService = saveFsService,
|
||||
TimeService = timeService,
|
||||
ProgramRegistryService = programRegistryService,
|
||||
AccessLogService = accessLogService
|
||||
};
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace LibHac.FsSrv
|
|||
Result UnregisterAllExternalKey();
|
||||
Result GetRightsIdByPath(out RightsId rightsId, in FspPath path);
|
||||
Result GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, in FspPath path);
|
||||
Result SetCurrentPosixTimeWithTimeDifference(long time, int difference);
|
||||
Result SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference);
|
||||
Result GetFreeSpaceSizeForSaveData(out long freeSpaceSize, SaveDataSpaceId spaceId);
|
||||
Result VerifySaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId, OutBuffer readBuffer);
|
||||
Result CorruptSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId);
|
||||
|
|
77
src/LibHac/FsSrv/TimeService.cs
Normal file
77
src/LibHac/FsSrv/TimeService.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using LibHac.Fs;
|
||||
using LibHac.FsSrv.Impl;
|
||||
|
||||
namespace LibHac.FsSrv
|
||||
{
|
||||
public readonly struct TimeService
|
||||
{
|
||||
private readonly TimeServiceImpl _serviceImpl;
|
||||
private readonly ulong _processId;
|
||||
|
||||
public TimeService(TimeServiceImpl serviceImpl, ulong processId)
|
||||
{
|
||||
_serviceImpl = serviceImpl;
|
||||
_processId = processId;
|
||||
}
|
||||
|
||||
public Result SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference)
|
||||
{
|
||||
Result rc = GetProgramInfo(out ProgramInfo programInfo);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (!programInfo.AccessControl.CanCall(OperationType.SetCurrentPosixTime))
|
||||
return ResultFs.PermissionDenied.Log();
|
||||
|
||||
return _serviceImpl.SetCurrentPosixTimeWithTimeDifference(currentTime, timeDifference);
|
||||
}
|
||||
|
||||
private Result GetProgramInfo(out ProgramInfo programInfo)
|
||||
{
|
||||
return _serviceImpl.GetProgramInfo(out programInfo, _processId);
|
||||
}
|
||||
}
|
||||
|
||||
public class TimeServiceImpl
|
||||
{
|
||||
private Configuration _config;
|
||||
private long _baseTime;
|
||||
private int _timeDifference;
|
||||
private object _lockObject;
|
||||
|
||||
public TimeServiceImpl(in Configuration configuration)
|
||||
{
|
||||
_config = configuration;
|
||||
_baseTime = 0;
|
||||
_timeDifference = 0;
|
||||
_lockObject = new object();
|
||||
}
|
||||
|
||||
// The entire Configuration struct is a LibHac addition to avoid using global state
|
||||
public struct Configuration
|
||||
{
|
||||
public HorizonClient HorizonClient;
|
||||
public ProgramRegistryImpl ProgramRegistry;
|
||||
}
|
||||
|
||||
public Result GetCurrentPosixTime(out long time)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result GetCurrentPosixTimeWithTimeDifference(out long currentTime, out int timeDifference)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal Result GetProgramInfo(out ProgramInfo programInfo, ulong processId)
|
||||
{
|
||||
return _config.ProgramRegistry.GetProgramInfo(out programInfo, processId);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue