From 8173a9123518d1b9c2153758167421fcbe9cf758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sat, 22 Jan 2022 19:56:30 +0100 Subject: [PATCH] feat(sample): add external memory browser sample --- NosSmooth.sln | 15 +++++ .../ExternalBrowser/ExternalBrowser.csproj | 14 +++++ Samples/ExternalBrowser/Program.cs | 57 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 Samples/ExternalBrowser/ExternalBrowser.csproj create mode 100644 Samples/ExternalBrowser/Program.cs diff --git a/NosSmooth.sln b/NosSmooth.sln index f2be101daf6e57e7bd5b13520b077ab2ea58a727..5806e50b38603cbb34982814bbf90efda5ba37aa 100644 --- a/NosSmooth.sln +++ b/NosSmooth.sln @@ -56,6 +56,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NosSmooth.PacketSerializer. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NosSmooth.ChatCommands", "Local\NosSmooth.ChatCommands\NosSmooth.ChatCommands.csproj", "{7DC7FC22-EFA6-4EB0-8E75-99F746E50F6E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExternalBrowser", "Samples\ExternalBrowser\ExternalBrowser.csproj", "{A3BCC882-6DCD-4326-8BC2-A5C78AD10361}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -282,6 +284,18 @@ Global {7DC7FC22-EFA6-4EB0-8E75-99F746E50F6E}.Release|x64.Build.0 = Release|Any CPU {7DC7FC22-EFA6-4EB0-8E75-99F746E50F6E}.Release|x86.ActiveCfg = Release|Any CPU {7DC7FC22-EFA6-4EB0-8E75-99F746E50F6E}.Release|x86.Build.0 = Release|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Debug|x64.ActiveCfg = Debug|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Debug|x64.Build.0 = Debug|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Debug|x86.ActiveCfg = Debug|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Debug|x86.Build.0 = Debug|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Release|Any CPU.Build.0 = Release|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Release|x64.ActiveCfg = Release|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Release|x64.Build.0 = Release|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Release|x86.ActiveCfg = Release|Any CPU + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -306,6 +320,7 @@ Global {86B4ED0C-CD28-4C6C-B58E-B4B1F7AAD683} = {54A49AC2-55B3-4156-8023-41C56719EBB5} {CF03BCEA-EB5B-427F-8576-7DA7EB869BDC} = {54A49AC2-55B3-4156-8023-41C56719EBB5} {7DC7FC22-EFA6-4EB0-8E75-99F746E50F6E} = {6078AE6E-7CD0-48E4-84E0-EB164D8881DA} + {A3BCC882-6DCD-4326-8BC2-A5C78AD10361} = {F20FE754-FDEA-4F3A-93D4-0750CB9EBB33} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C5F46653-4DEC-429B-8580-4ED18ED9B4CA} diff --git a/Samples/ExternalBrowser/ExternalBrowser.csproj b/Samples/ExternalBrowser/ExternalBrowser.csproj new file mode 100644 index 0000000000000000000000000000000000000000..9efd227b67086275bffff6f5b5b06c62207ffc67 --- /dev/null +++ b/Samples/ExternalBrowser/ExternalBrowser.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/Samples/ExternalBrowser/Program.cs b/Samples/ExternalBrowser/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..dbec37b7bb510cb50e4c9d6f05117977947d35f4 --- /dev/null +++ b/Samples/ExternalBrowser/Program.cs @@ -0,0 +1,57 @@ +// +// Program.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Diagnostics; +using NosSmooth.LocalBinding; +using NosSmooth.LocalBinding.Options; + +namespace ExternalBrowser; + +/// +/// The entrypoint class for ExternalBrowser. +/// +public class Program +{ + /// + /// The entrypoint method for ExternalBrowser. + /// + /// The arguments. + public static void Main(string[] arguments) + { + var playerManagerOptions = new CharacterBindingOptions(); + var sceneManagerOptions = new SceneManagerBindingOptions(); + + foreach (var argument in arguments) + { + Process[] processes; + + if (int.TryParse(argument, out var processId)) + { + processes = new Process[] { Process.GetProcessById(processId) }; + } + else + { + processes = Process + .GetProcesses() + .Where(x => x.ProcessName.Contains(argument)) + .ToArray(); + } + + foreach (var process in processes) + { + var externalBrowser = new ExternalNosBrowser(process, playerManagerOptions, sceneManagerOptions); + var playerManager = externalBrowser.GetPlayerManager(); + if (!playerManager.IsSuccess) + { + Console.Error.WriteLine($"Could not get the player manager: {playerManager.Error.Message}"); + continue; + } + + Console.WriteLine($"Player in process {process.Id} is named {playerManager.Entity.Player.Name}"); + } + } + } +} \ No newline at end of file