-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
318 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/Bannerlord.LauncherManager.Native/Adapters/LauncherStateProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Bannerlord.LauncherManager.External; | ||
using Bannerlord.LauncherManager.Models; | ||
|
||
using BUTR.NativeAOT.Shared; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Bannerlord.LauncherManager.Native.Adapters; | ||
|
||
internal sealed unsafe class LauncherStateProvider : ILauncherStateProvider | ||
{ | ||
private readonly param_ptr* _pOwner; | ||
private readonly N_SetGameParametersDelegate _setGameParameters; | ||
private readonly N_GetOptions _getOptions; | ||
private readonly N_GetState _getState; | ||
|
||
public LauncherStateProvider( | ||
param_ptr* pOwner, | ||
N_SetGameParametersDelegate setGameParameters, | ||
N_GetOptions getOptions, | ||
N_GetState getState) | ||
{ | ||
_pOwner = pOwner; | ||
_setGameParameters = setGameParameters; | ||
_getOptions = getOptions; | ||
_getState = getState; | ||
} | ||
|
||
public void SetGameParameters(string executable, IReadOnlyList<string> gameParameters) => SetGameParametersNative(executable, gameParameters); | ||
public LauncherOptions GetOptions() => GetOptionsNative(); | ||
public LauncherState GetState() => GetStateNative(); | ||
|
||
private void SetGameParametersNative(ReadOnlySpan<char> executable, IReadOnlyList<string> gameParameters) | ||
{ | ||
Logger.LogInput(); | ||
|
||
fixed (char* pExecutable = executable) | ||
fixed (char* pGameParameters = BUTR.NativeAOT.Shared.Utils.SerializeJson(gameParameters, Bindings.CustomSourceGenerationContext.IReadOnlyListString)) | ||
{ | ||
Logger.LogPinned(pExecutable, pGameParameters); | ||
|
||
using var result = SafeStructMallocHandle.Create(_setGameParameters(_pOwner, (param_string*) pExecutable, (param_json*) pGameParameters), true); | ||
result.ValueAsVoid(); | ||
} | ||
|
||
Logger.LogOutput(); | ||
} | ||
|
||
private LauncherOptions GetOptionsNative() | ||
{ | ||
Logger.LogInput(); | ||
|
||
using var result = SafeStructMallocHandle.Create(_getOptions(_pOwner), true); | ||
if (result.IsNull) return LauncherOptions.Empty; | ||
|
||
var returnResult = result.ValueAsJson(Bindings.CustomSourceGenerationContext.LauncherOptions)!; | ||
Logger.LogOutput(returnResult); | ||
return returnResult; | ||
} | ||
|
||
private LauncherState GetStateNative() | ||
{ | ||
Logger.LogInput(); | ||
|
||
using var result = SafeStructMallocHandle.Create(_getState(_pOwner), true); | ||
if (result.IsNull) return LauncherState.Empty; | ||
|
||
var returnResult = result.ValueAsJson(Bindings.CustomSourceGenerationContext.LauncherState)!; | ||
Logger.LogOutput(returnResult); | ||
return returnResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
src/Bannerlord.LauncherManager/External/CallbackLauncherProvider.cs
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/Bannerlord.LauncherManager/External/CallbackLauncherStateProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Bannerlord.LauncherManager.Models; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Bannerlord.LauncherManager.External; | ||
|
||
public sealed class CallbackLauncherStateProvider : ILauncherStateProvider | ||
{ | ||
private readonly Action<string, IReadOnlyList<string>> _setGameParameters; | ||
|
||
private readonly Func<LauncherOptions> _getOptions; | ||
private readonly Func<LauncherState> _getState; | ||
|
||
public CallbackLauncherStateProvider(Action<string, IReadOnlyList<string>> setGameParameters, Func<LauncherOptions> getOptions, Func<LauncherState> getState) | ||
{ | ||
_setGameParameters = setGameParameters; | ||
_getOptions = getOptions; | ||
_getState = getState; | ||
} | ||
|
||
public void SetGameParameters(string executable, IReadOnlyList<string> gameParameters) => _setGameParameters(executable, gameParameters); | ||
public LauncherOptions GetOptions() => _getOptions(); | ||
public LauncherState GetState() => _getState(); | ||
} |
Oops, something went wrong.