From bd7451ff2f5a5e50f9f1e2edb8177e45e0dd990e Mon Sep 17 00:00:00 2001 From: Alex Bezdieniezhnykh Date: Mon, 25 Nov 2024 15:50:07 +0200 Subject: [PATCH] dll loader done --- Azaion.Common/Services/ResourceLoader.cs | 6 ++--- Azaion.Suite/App.xaml.cs | 14 +++++----- Azaion.Suite/Azaion.Suite.csproj | 7 +++++ Azaion.Suite/upload.cmd | 33 ++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 Azaion.Suite/upload.cmd diff --git a/Azaion.Common/Services/ResourceLoader.cs b/Azaion.Common/Services/ResourceLoader.cs index 82a33f5..8eaf052 100644 --- a/Azaion.Common/Services/ResourceLoader.cs +++ b/Azaion.Common/Services/ResourceLoader.cs @@ -7,7 +7,7 @@ namespace Azaion.Common.Services; public interface IResourceLoader { Task Load(string fileName, CancellationToken cancellationToken = default); - Assembly LoadAssembly(string asmName); + Assembly? LoadAssembly(string asmName); } public class ResourceLoader(AzaionApiClient api, ApiCredentials credentials) : IResourceLoader @@ -18,12 +18,12 @@ public class ResourceLoader(AzaionApiClient api, ApiCredentials credentials) : I "Azaion.Dataset" ]; - public Assembly LoadAssembly(string resourceName) + public Assembly? LoadAssembly(string resourceName) { var assemblyName = resourceName.Split(',').First(); if (EncryptedResources.Contains(assemblyName)) { - var stream = Load(assemblyName).GetAwaiter().GetResult(); + var stream = Load($"{assemblyName}.dll").GetAwaiter().GetResult(); return Assembly.Load(stream.ToArray()); } diff --git a/Azaion.Suite/App.xaml.cs b/Azaion.Suite/App.xaml.cs index 0f2dca3..58b6826 100644 --- a/Azaion.Suite/App.xaml.cs +++ b/Azaion.Suite/App.xaml.cs @@ -40,12 +40,13 @@ public partial class App new ConfigUpdater().CheckConfig(); var result = Parser.Default.ParseArguments(Environment.GetCommandLineArgs()); - if (result.Errors.Any()) - return; - var apiCreds = result.Value; + + var apiCreds = !result.Errors.Any() + ? result.Value + : new ApiCredentials(); ResourceLoader = new ResourceLoader(CreateApiClient(apiCreds), apiCreds); - AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => ResourceLoader.LoadAssembly(args.Name); + //AppDomain.CurrentDomain.AssemblyResolve += (_, args) => ResourceLoader.LoadAssembly(args.Name); } private static AzaionApiClient CreateApiClient(ApiCredentials credentials) @@ -172,10 +173,11 @@ public partial class App private WindowEnum GetParentWindow(FrameworkElement? element) { + if (element?.GetType().Name == "LibVLCSharp.WPF.ForegroundWindow") + return WindowEnum.Annotator; + while (element != null && element is not TabItem) - { element = element.Parent as FrameworkElement; - } if (element is not TabItem || element.Tag == null) return WindowEnum.None; diff --git a/Azaion.Suite/Azaion.Suite.csproj b/Azaion.Suite/Azaion.Suite.csproj index cfc5ef2..cb5a641 100644 --- a/Azaion.Suite/Azaion.Suite.csproj +++ b/Azaion.Suite/Azaion.Suite.csproj @@ -33,4 +33,11 @@ + + + + + + + diff --git a/Azaion.Suite/upload.cmd b/Azaion.Suite/upload.cmd new file mode 100644 index 0000000..b013bc4 --- /dev/null +++ b/Azaion.Suite/upload.cmd @@ -0,0 +1,33 @@ +setlocal enabledelayedexpansion + +set LOGIN_URL=https://api.azaion.com/login +set RESOURCE_URL=https://api.azaion.com/resources +set EMAIL=uploader@azaion.com +set PASSWORD=Az@1on_10Upl0@der +set FILE_TO_UPLOAD=bin\Release\net8.0-windows\secure\Azaion.Annotator.dll + +echo Logging in and retrieving token... +for /f "tokens=*" %%i in ('curl -s -X POST -H "Content-Type: application/json" ^ + -d "{\"email\":\"%EMAIL%\",\"password\":\"%PASSWORD%\"}" %LOGIN_URL%') do set RESPONSE=%%i + +for /f "tokens=2 delims=:" %%a in ('echo %RESPONSE% ^| findstr /i "token"') do ( + set "TOKEN=%%a" + set "TOKEN=!TOKEN:~1,-1!" + set "TOKEN=!TOKEN:~0,-2!" +) + +echo Token retrieved: %TOKEN% + +:: Step 2: Upload the DLL file +if not exist "%FILE_TO_UPLOAD%" ( + echo File %FILE_TO_UPLOAD% does not exist. Exiting... + exit /b 1 +) + +echo Uploading file to resources... +curl -X POST -H "Authorization: Bearer %TOKEN%" ^ + -H "Content-Type: application/octet-stream" ^ + --data-binary @"%FILE_TO_UPLOAD%" ^ + %RESOURCE_URL% + +echo Done! \ No newline at end of file