From eb4adeb6294e34dbd79003b4f2d999224d8e3584 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Tue, 5 Nov 2024 00:27:04 +0200 Subject: [PATCH] Removed ILoadOrderPersistenceProvider --- .../src/Bannerlord.LauncherManager.hpp | 21 -------- .../src/lib/LauncherManager.ts | 6 --- .../src/lib/types/LauncherManager.ts | 2 - .../Adapters/LoadOrderPersistenceProvider.cs | 52 ------------------- .../Bindings.LauncherManager.cs | 50 ------------------ .../Callbacks.cs | 4 -- .../LauncherManagerHandlerNative.cs | 6 +-- .../CallbackLoadOrderPersistenceProvider.cs | 20 ------- .../External/ILoadOrderPersistenceProvider.cs | 18 ------- .../LauncherManagerHandler.Callbacks.cs | 20 ------- .../LauncherManagerHandler.cs | 12 ++--- .../HandlerTests.cs | 23 +------- 12 files changed, 7 insertions(+), 227 deletions(-) delete mode 100644 src/Bannerlord.LauncherManager.Native/Adapters/LoadOrderPersistenceProvider.cs delete mode 100644 src/Bannerlord.LauncherManager/External/CallbackLoadOrderPersistenceProvider.cs delete mode 100644 src/Bannerlord.LauncherManager/External/ILoadOrderPersistenceProvider.cs diff --git a/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.LauncherManager.hpp b/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.LauncherManager.hpp index fd09bb1..4990bd5 100644 --- a/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.LauncherManager.hpp +++ b/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.LauncherManager.hpp @@ -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: @@ -114,8 +112,6 @@ namespace Bannerlord::LauncherManager InstanceMethod<&LauncherManager::SetGameStore>("setGameStore", static_cast(napi_writable | napi_configurable)), InstanceMethod<&LauncherManager::GetGamePlatform>("getGamePlatform", static_cast(napi_writable | napi_configurable)), InstanceMethod<&LauncherManager::SetGameParameterContinueLastSaveFile>("setGameParameterContinueLastSaveFile", static_cast(napi_writable | napi_configurable)), - InstanceMethod<&LauncherManager::SaveLoadOrder>("saveLoadOrder", static_cast(napi_writable | napi_configurable)), - InstanceMethod<&LauncherManager::LoadLoadOrder>("loadLoadOrder", static_cast(napi_writable | napi_configurable)), InstanceMethod<&LauncherManager::SetGameParameterLoadOrder>("setGameParameterLoadOrder", static_cast(napi_writable | napi_configurable)), }); @@ -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()); - - 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(); diff --git a/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/LauncherManager.ts b/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/LauncherManager.ts index 81613fe..affda8d 100644 --- a/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/LauncherManager.ts +++ b/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/LauncherManager.ts @@ -125,12 +125,6 @@ export class NativeLauncherManager implements LauncherManagerWithoutConstructor public dialogTestFileOpen = (): Promise => { 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); } diff --git a/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/types/LauncherManager.ts b/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/types/LauncherManager.ts index 0edbdec..f11005e 100644 --- a/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/types/LauncherManager.ts +++ b/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/types/LauncherManager.ts @@ -120,7 +120,5 @@ export type LauncherManager = { dialogTestWarning(): Promise; dialogTestFileOpen(): Promise; - saveLoadOrder(loadOrder: LoadOrder): void; - loadLoadOrder(): LoadOrder; setGameParameterLoadOrder(loadOrder: LoadOrder): void; } diff --git a/src/Bannerlord.LauncherManager.Native/Adapters/LoadOrderPersistenceProvider.cs b/src/Bannerlord.LauncherManager.Native/Adapters/LoadOrderPersistenceProvider.cs deleted file mode 100644 index cf8dbdf..0000000 --- a/src/Bannerlord.LauncherManager.Native/Adapters/LoadOrderPersistenceProvider.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Bannerlord.LauncherManager.External; -using Bannerlord.LauncherManager.Models; - -using BUTR.NativeAOT.Shared; - -namespace Bannerlord.LauncherManager.Native.Adapters; - -internal sealed unsafe class LoadOrderPersistenceProvider : ILoadOrderPersistenceProvider -{ - private readonly param_ptr* _pOwner; - private readonly N_GetLoadOrderDelegate _getLoadOrder; - private readonly N_SetLoadOrderDelegate _setLoadOrder; - - public LoadOrderPersistenceProvider(param_ptr* pOwner, N_GetLoadOrderDelegate getLoadOrder, N_SetLoadOrderDelegate setLoadOrder) - { - _pOwner = pOwner; - _getLoadOrder = getLoadOrder; - _setLoadOrder = setLoadOrder; - } - - public LoadOrder LoadLoadOrder() => LoadLoadOrderNative(); - public void SaveLoadOrder(LoadOrder loadOrder) => SaveLoadOrderNative(loadOrder); - - private LoadOrder LoadLoadOrderNative() - { - Logger.LogInput(); - - using var result = SafeStructMallocHandle.Create(_getLoadOrder(_pOwner), true); - - var returnResult = result.ValueAsJson(Bindings.CustomSourceGenerationContext.LoadOrder) ?? new LoadOrder(); - returnResult.Sanitize(); - Logger.LogOutput(returnResult); - return returnResult; - } - - private void SaveLoadOrderNative(LoadOrder loadOrder) - { - Logger.LogInput(); - - loadOrder.Sanitize(); - - fixed (char* pLoadOrder = BUTR.NativeAOT.Shared.Utils.SerializeJson(loadOrder, Bindings.CustomSourceGenerationContext.LoadOrder) ?? string.Empty) - { - Logger.LogPinned(pLoadOrder); - - using var result = SafeStructMallocHandle.Create(_setLoadOrder(_pOwner, (param_json*) pLoadOrder), true); - result.ValueAsVoid(); - } - - Logger.LogOutput(); - } -} \ No newline at end of file diff --git a/src/Bannerlord.LauncherManager.Native/Bindings.LauncherManager.cs b/src/Bannerlord.LauncherManager.Native/Bindings.LauncherManager.cs index 8b31757..e013020 100644 --- a/src/Bannerlord.LauncherManager.Native/Bindings.LauncherManager.cs +++ b/src/Bannerlord.LauncherManager.Native/Bindings.LauncherManager.cs @@ -60,10 +60,6 @@ public static unsafe partial class Bindings Marshal.GetDelegateForFunctionPointer(new IntPtr(p_get_options)), Marshal.GetDelegateForFunctionPointer(new IntPtr(p_get_state)) ), - loadOrderPersistenceProvider: new LoadOrderPersistenceProvider(p_owner, - Marshal.GetDelegateForFunctionPointer(new IntPtr(p_load_load_order)), - Marshal.GetDelegateForFunctionPointer(new IntPtr(p_save_load_order)) - ), notificationProvider: new NotificationProvider(p_owner, Marshal.GetDelegateForFunctionPointer(new IntPtr(p_send_notification)) ), @@ -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) { diff --git a/src/Bannerlord.LauncherManager.Native/Callbacks.cs b/src/Bannerlord.LauncherManager.Native/Callbacks.cs index 7ace8ab..6e62782 100644 --- a/src/Bannerlord.LauncherManager.Native/Callbacks.cs +++ b/src/Bannerlord.LauncherManager.Native/Callbacks.cs @@ -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] p_callback); diff --git a/src/Bannerlord.LauncherManager.Native/LauncherManagerHandlerNative.cs b/src/Bannerlord.LauncherManager.Native/LauncherManagerHandlerNative.cs index 297cbbe..e11206b 100644 --- a/src/Bannerlord.LauncherManager.Native/LauncherManagerHandlerNative.cs +++ b/src/Bannerlord.LauncherManager.Native/LauncherManagerHandlerNative.cs @@ -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(); @@ -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); diff --git a/src/Bannerlord.LauncherManager/External/CallbackLoadOrderPersistenceProvider.cs b/src/Bannerlord.LauncherManager/External/CallbackLoadOrderPersistenceProvider.cs deleted file mode 100644 index b009ed8..0000000 --- a/src/Bannerlord.LauncherManager/External/CallbackLoadOrderPersistenceProvider.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Bannerlord.LauncherManager.Models; - -using System; - -namespace Bannerlord.LauncherManager.External.UI; - -public sealed class CallbackLoadOrderPersistenceProvider : ILoadOrderPersistenceProvider -{ - private readonly Func _loadLoadOrder; - private readonly Action _saveLoadOrder; - - public CallbackLoadOrderPersistenceProvider(Func loadLoadOrder, Action saveLoadOrder) - { - _loadLoadOrder = loadLoadOrder; - _saveLoadOrder = saveLoadOrder; - } - - public LoadOrder LoadLoadOrder() => _loadLoadOrder(); - public void SaveLoadOrder(LoadOrder loadOrder) => _saveLoadOrder(loadOrder); -} \ No newline at end of file diff --git a/src/Bannerlord.LauncherManager/External/ILoadOrderPersistenceProvider.cs b/src/Bannerlord.LauncherManager/External/ILoadOrderPersistenceProvider.cs deleted file mode 100644 index d0cb609..0000000 --- a/src/Bannerlord.LauncherManager/External/ILoadOrderPersistenceProvider.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Bannerlord.LauncherManager.Models; - -namespace Bannerlord.LauncherManager.External; - -public interface ILoadOrderPersistenceProvider -{ - /// - /// Loads the LoadOrder from a persistent storage - /// - /// - LoadOrder LoadLoadOrder(); - - /// - /// Saves the LoadOrder to a persistent storage - /// - /// - void SaveLoadOrder(LoadOrder loadOrder); -} \ No newline at end of file diff --git a/src/Bannerlord.LauncherManager/LauncherManagerHandler.Callbacks.cs b/src/Bannerlord.LauncherManager/LauncherManagerHandler.Callbacks.cs index 06a3cb0..cfdf24d 100644 --- a/src/Bannerlord.LauncherManager/LauncherManagerHandler.Callbacks.cs +++ b/src/Bannerlord.LauncherManager/LauncherManagerHandler.Callbacks.cs @@ -16,26 +16,6 @@ protected internal void RefreshGameParameters(string executable, IReadOnlyList - /// Callback
- /// - protected internal LoadOrder LoadLoadOrder() - { - ThrowIfNotInitialized(); - return LoadOrderPersistenceProvider.LoadLoadOrder(); - } - - /// - /// Callback
- ///
- protected internal void SaveLoadOrder(LoadOrder loadOrder) - { - ThrowIfNotInitialized(); - LoadOrderPersistenceProvider.SaveLoadOrder(loadOrder); - - SetGameParameterLoadOrder(loadOrder); - } - /// /// Callback
///
diff --git a/src/Bannerlord.LauncherManager/LauncherManagerHandler.cs b/src/Bannerlord.LauncherManager/LauncherManagerHandler.cs index d3b3964..728d273 100644 --- a/src/Bannerlord.LauncherManager/LauncherManagerHandler.cs +++ b/src/Bannerlord.LauncherManager/LauncherManagerHandler.cs @@ -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!; @@ -34,8 +33,8 @@ 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(); @@ -43,17 +42,16 @@ protected void Initialize(ILauncherStateProvider launcherStateProvider, IGameInf _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); } /// diff --git a/test/Bannerlord.LauncherManager.Tests/HandlerTests.cs b/test/Bannerlord.LauncherManager.Tests/HandlerTests.cs index be1f60d..90dd392 100644 --- a/test/Bannerlord.LauncherManager.Tests/HandlerTests.cs +++ b/test/Bannerlord.LauncherManager.Tests/HandlerTests.cs @@ -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 GetModules() => base.GetModules(); @@ -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, @@ -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, @@ -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!, @@ -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!, @@ -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!,