Skip to content

Commit

Permalink
Removed ILoadOrderPersistenceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Nov 4, 2024
1 parent cf81293 commit eb4adeb
Show file tree
Hide file tree
Showing 12 changed files with 7 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ namespace Bannerlord::LauncherManager
Napi::Value TestModule(const CallbackInfo &info);
Napi::Value DialogTestFileOpen(const CallbackInfo &info);
Napi::Value DialogTestWarning(const CallbackInfo &info);
void SaveLoadOrder(const CallbackInfo &info);
Napi::Value LoadLoadOrder(const CallbackInfo &info);
void SetGameParameterLoadOrder(const CallbackInfo &info);

private:
Expand Down Expand Up @@ -114,8 +112,6 @@ namespace Bannerlord::LauncherManager
InstanceMethod<&LauncherManager::SetGameStore>("setGameStore", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
InstanceMethod<&LauncherManager::GetGamePlatform>("getGamePlatform", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
InstanceMethod<&LauncherManager::SetGameParameterContinueLastSaveFile>("setGameParameterContinueLastSaveFile", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
InstanceMethod<&LauncherManager::SaveLoadOrder>("saveLoadOrder", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
InstanceMethod<&LauncherManager::LoadLoadOrder>("loadLoadOrder", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
InstanceMethod<&LauncherManager::SetGameParameterLoadOrder>("setGameParameterLoadOrder", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
});

Expand Down Expand Up @@ -822,23 +818,6 @@ namespace Bannerlord::LauncherManager
ThrowOrReturn(env, result);
}

void LauncherManager::SaveLoadOrder(const CallbackInfo &info)
{
const auto env = info.Env();
const auto loadOrder = JSONStringify(env, info[0].As<Object>());

const auto loadOrderCopy = CopyWithFree(loadOrder.Utf16Value());

const auto result = ve_save_load_order(this->_pInstance, loadOrderCopy.get());
return ThrowOrReturn(env, result);
}
Napi::Value LauncherManager::LoadLoadOrder(const CallbackInfo &info)
{
const auto env = info.Env();

const auto result = ve_load_load_order(this->_pInstance);
return ThrowOrReturnJson(env, result);
}
void LauncherManager::SetGameParameterLoadOrder(const CallbackInfo &info)
{
const auto env = info.Env();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ export class NativeLauncherManager implements LauncherManagerWithoutConstructor
public dialogTestFileOpen = (): Promise<string> => {
return this.manager.dialogTestFileOpen();
}
public saveLoadOrder = (loadOrder: types.LoadOrder): void => {
return this.manager.saveLoadOrder(loadOrder);
}
public loadLoadOrder = (): types.LoadOrder => {
return this.manager.loadLoadOrder();
}
public setGameParameterLoadOrder = (loadOrder: types.LoadOrder): void => {
return this.manager.setGameParameterLoadOrder(loadOrder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,5 @@ export type LauncherManager = {
dialogTestWarning(): Promise<string>;
dialogTestFileOpen(): Promise<string>;

saveLoadOrder(loadOrder: LoadOrder): void;
loadLoadOrder(): LoadOrder;
setGameParameterLoadOrder(loadOrder: LoadOrder): void;
}

This file was deleted.

50 changes: 0 additions & 50 deletions src/Bannerlord.LauncherManager.Native/Bindings.LauncherManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public static unsafe partial class Bindings
Marshal.GetDelegateForFunctionPointer<N_GetOptions>(new IntPtr(p_get_options)),
Marshal.GetDelegateForFunctionPointer<N_GetState>(new IntPtr(p_get_state))
),
loadOrderPersistenceProvider: new LoadOrderPersistenceProvider(p_owner,
Marshal.GetDelegateForFunctionPointer<N_GetLoadOrderDelegate>(new IntPtr(p_load_load_order)),
Marshal.GetDelegateForFunctionPointer<N_SetLoadOrderDelegate>(new IntPtr(p_save_load_order))
),
notificationProvider: new NotificationProvider(p_owner,
Marshal.GetDelegateForFunctionPointer<N_SendNotificationDelegate>(new IntPtr(p_send_notification))
),
Expand Down Expand Up @@ -225,52 +221,6 @@ public static unsafe partial class Bindings
}


[UnmanagedCallersOnly(EntryPoint = "ve_load_load_order", CallConvs = [typeof(CallConvCdecl)])]
public static return_value_json* LoadLoadOrder(param_ptr* p_handle)
{
Logger.LogInput();
try
{
if (p_handle is null || LauncherManagerHandlerNative.FromPointer(p_handle) is not { } handler)
return return_value_json.AsError(BUTR.NativeAOT.Shared.Utils.Copy("Handler is null or wrong!", false), false);

var result = handler.LoadLoadOrder();

Logger.LogOutput(result);
return return_value_json.AsValue(result, CustomSourceGenerationContext.LoadOrder, false);
}
catch (Exception e)
{
Logger.LogException(e);
return return_value_json.AsException(e, false);
}
}

[UnmanagedCallersOnly(EntryPoint = "ve_save_load_order", CallConvs = [typeof(CallConvCdecl)])]
public static return_value_void* SaveLoadOrder(param_ptr* p_handle, param_json* p_load_order)
{
Logger.LogInput(p_load_order);
try
{
if (p_handle is null || LauncherManagerHandlerNative.FromPointer(p_handle) is not { } handler)
return return_value_void.AsError(BUTR.NativeAOT.Shared.Utils.Copy("Handler is null or wrong!", false), false);

//if (p_load_order is null)
// return return_value_void.AsValue(false);

var loadOrder = BUTR.NativeAOT.Shared.Utils.DeserializeJson(p_load_order, CustomSourceGenerationContext.LoadOrder);
handler.SaveLoadOrder(loadOrder);

Logger.LogOutput();
return return_value_void.AsValue(false);
}
catch (Exception e)
{
Logger.LogException(e);
return return_value_void.AsException(e, false);
}
}

[UnmanagedCallersOnly(EntryPoint = "ve_refresh_modules", CallConvs = [typeof(CallConvCdecl)])]
public static return_value_void* RefreshModules(param_ptr* p_handle)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Bannerlord.LauncherManager.Native/Callbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ namespace Bannerlord.LauncherManager.Native;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate return_value_void* N_SetGameParametersDelegate(param_ptr* p_owner, param_string* p_executable, param_json* p_game_parameters);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate return_value_json* N_GetLoadOrderDelegate(param_ptr* p_owner);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate return_value_void* N_SetLoadOrderDelegate(param_ptr* p_owner, param_json* p_load_order);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate return_value_void* N_SendNotificationDelegate(param_ptr* p_owner, param_string* p_id, param_string* p_type, param_string* p_message, param_uint displayMs);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate return_value_void* N_SendDialogDelegate(param_ptr* p_owner, param_string* p_type, param_string* p_title, param_string* p_message, param_json* p_filters, param_ptr* p_callback_handler, delegate* unmanaged[Cdecl]<param_ptr*, param_string*, void> p_callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ internal sealed unsafe class LauncherManagerHandlerNative : LauncherManagerHandl
public LauncherManagerHandlerNative(param_ptr* pOwner,
ILauncherStateProvider launcherStateUProvider,
IGameInfoProvider gameInfoProvider,
ILoadOrderPersistenceProvider loadOrderPersistenceProvider,
IFileSystemProvider fileSystemProvider,
IDialogProvider dialogProvider,
INotificationProvider notificationProvider,
ILoadOrderStateProvider loadOrderStateProvider) :
base(launcherStateUProvider, gameInfoProvider, loadOrderPersistenceProvider, fileSystemProvider, dialogProvider, notificationProvider, loadOrderStateProvider)
base(launcherStateUProvider, gameInfoProvider, fileSystemProvider, dialogProvider, notificationProvider, loadOrderStateProvider)
{
OwnerPtr = pOwner;
HandlePtr = (VoidPtr*) GCHandle.ToIntPtr(GCHandle.Alloc(this, GCHandleType.Normal)).ToPointer();
Expand All @@ -58,9 +57,6 @@ public void Dispose()
ReleaseUnmanagedResources();
}

public new void SaveLoadOrder(LoadOrder loadOrder) => base.SaveLoadOrder(loadOrder);
public new LoadOrder LoadLoadOrder() => base.LoadLoadOrder();

public new void SetGameParameterLoadOrder(LoadOrder loadOrder) => base.SetGameParameterLoadOrder(loadOrder);


Expand Down

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions src/Bannerlord.LauncherManager/LauncherManagerHandler.Callbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,6 @@ protected internal void RefreshGameParameters(string executable, IReadOnlyList<s
LauncherStateProvider.SetGameParameters(executable, gameParameters);
}

/// <summary>
/// Callback<br/>
/// </summary>
protected internal LoadOrder LoadLoadOrder()
{
ThrowIfNotInitialized();
return LoadOrderPersistenceProvider.LoadLoadOrder();
}

/// <summary>
/// Callback<br/>
/// </summary>
protected internal void SaveLoadOrder(LoadOrder loadOrder)
{
ThrowIfNotInitialized();
LoadOrderPersistenceProvider.SaveLoadOrder(loadOrder);

SetGameParameterLoadOrder(loadOrder);
}

/// <summary>
/// Callback<br/>
/// </summary>
Expand Down
12 changes: 5 additions & 7 deletions src/Bannerlord.LauncherManager/LauncherManagerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public partial class LauncherManagerHandler
private bool _isInitialized;
protected ILauncherStateProvider LauncherStateProvider { get; private set; } = default!;
protected IGameInfoProvider GameInfoProvider { get; private set; } = default!;
protected ILoadOrderPersistenceProvider LoadOrderPersistenceProvider { get; private set; } = default!;
protected IFileSystemProvider FileSystemProvider { get; private set; } = default!;
protected IDialogProvider DialogProvider { get; private set; } = default!;
protected INotificationProvider NotificationProvider { get; private set; } = default!;
Expand All @@ -34,26 +33,25 @@ public LauncherManagerHandler()
];
}

protected void Initialize(ILauncherStateProvider launcherStateProvider, IGameInfoProvider gameInfoProvider, ILoadOrderPersistenceProvider loadOrderPersistenceProvider,
IFileSystemProvider fileSystemProvider, IDialogProvider dialogProvider, INotificationProvider notificationProvider, ILoadOrderStateProvider loadOrderStateProvider)
protected void Initialize(ILauncherStateProvider launcherStateProvider, IGameInfoProvider gameInfoProvider, IFileSystemProvider fileSystemProvider,
IDialogProvider dialogProvider, INotificationProvider notificationProvider, ILoadOrderStateProvider loadOrderStateProvider)
{
if (_isInitialized)
throw new LauncherManagerInitializedTwiceException();

_isInitialized = true;
LauncherStateProvider = launcherStateProvider;
GameInfoProvider = gameInfoProvider;
LoadOrderPersistenceProvider = loadOrderPersistenceProvider;
FileSystemProvider = fileSystemProvider;
DialogProvider = dialogProvider;
NotificationProvider = notificationProvider;
LoadOrderStateProvider = loadOrderStateProvider;
}

public LauncherManagerHandler(ILauncherStateProvider launcherStateProvider, IGameInfoProvider gameInfoProvider, ILoadOrderPersistenceProvider loadOrderPersistenceProvider,
IFileSystemProvider fileSystemProvider, IDialogProvider dialogProvider, INotificationProvider notificationProvider, ILoadOrderStateProvider loadOrderStateProvider) : this()
public LauncherManagerHandler(ILauncherStateProvider launcherStateProvider, IGameInfoProvider gameInfoProvider, IFileSystemProvider fileSystemProvider,
IDialogProvider dialogProvider, INotificationProvider notificationProvider, ILoadOrderStateProvider loadOrderStateProvider) : this()
{
Initialize(launcherStateProvider, gameInfoProvider, loadOrderPersistenceProvider, fileSystemProvider, dialogProvider, notificationProvider, loadOrderStateProvider);
Initialize(launcherStateProvider, gameInfoProvider, fileSystemProvider, dialogProvider, notificationProvider, loadOrderStateProvider);
}

/// <summary>
Expand Down
23 changes: 1 addition & 22 deletions test/Bannerlord.LauncherManager.Tests/HandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ public class LauncherManagerHandlerExposer : LauncherManagerHandler
public LauncherManagerHandlerExposer(
ILauncherStateProvider launcherStateUProvider,
IGameInfoProvider gameInfoProvider,
ILoadOrderPersistenceProvider loadOrderPersistenceProvider,
IFileSystemProvider fileSystemProvider,
IDialogProvider dialogProviderProvider,
INotificationProvider notificationProviderProvider,
ILoadOrderStateProvider loadOrderStateProvider) :
base(launcherStateUProvider, gameInfoProvider, loadOrderPersistenceProvider, fileSystemProvider, dialogProviderProvider, notificationProviderProvider, loadOrderStateProvider)
base(launcherStateUProvider, gameInfoProvider, fileSystemProvider, dialogProviderProvider, notificationProviderProvider, loadOrderStateProvider)
{ }

public new IReadOnlyList<ModuleInfoExtendedWithMetadata> GetModules() => base.GetModules();
Expand Down Expand Up @@ -99,10 +98,6 @@ public void Sorter_Sort_Test()
getOptions: null!,
getState: null!
),
loadOrderPersistenceProvider: new CallbackLoadOrderPersistenceProvider(
loadLoadOrder: null!,
saveLoadOrder: lo => loadOrder = lo
),
loadOrderStateProvider: new CallbackLoadOrderStateProvider(
getAllModuleViewModels: () => moduleViewModels,
getModuleViewModels: () => moduleViewModels,
Expand Down Expand Up @@ -168,10 +163,6 @@ public void OrderBy_Test()
getOptions: () => new LauncherOptions(false),
getState: () => new LauncherState(true)
),
loadOrderPersistenceProvider: new CallbackLoadOrderPersistenceProvider(
loadLoadOrder: null!,
saveLoadOrder: lo => loadOrder = lo
),
loadOrderStateProvider: new CallbackLoadOrderStateProvider(
getAllModuleViewModels: () => moduleViewModels,
getModuleViewModels: () => moduleViewModels,
Expand Down Expand Up @@ -229,10 +220,6 @@ public void ModuleProvider_GetModules_Test()
getOptions: null!,
getState: null!
),
loadOrderPersistenceProvider: new CallbackLoadOrderPersistenceProvider(
loadLoadOrder: null!,
saveLoadOrder: null!
),
loadOrderStateProvider: new CallbackLoadOrderStateProvider(
getAllModuleViewModels: null!,
getModuleViewModels: null!,
Expand Down Expand Up @@ -276,10 +263,6 @@ public void Handler_TestModule_tTest()
getOptions: null!,
getState: null!
),
loadOrderPersistenceProvider: new CallbackLoadOrderPersistenceProvider(
loadLoadOrder: null!,
saveLoadOrder: null!
),
loadOrderStateProvider: new CallbackLoadOrderStateProvider(
getAllModuleViewModels: null!,
getModuleViewModels: null!,
Expand Down Expand Up @@ -334,10 +317,6 @@ public void Handler_InstallModule_Test()
getOptions: null!,
getState: null!
),
loadOrderPersistenceProvider: new CallbackLoadOrderPersistenceProvider(
loadLoadOrder: null!,
saveLoadOrder: null!
),
loadOrderStateProvider: new CallbackLoadOrderStateProvider(
getAllModuleViewModels: null!,
getModuleViewModels: null!,
Expand Down

0 comments on commit eb4adeb

Please sign in to comment.