-
Notifications
You must be signed in to change notification settings - Fork 40
/
Services.cs
138 lines (123 loc) · 4.81 KB
/
Services.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System.Text.Json;
using Microsoft.Extensions.DependencyInjection;
using NexusMods.Abstractions.App.Settings;
using NexusMods.Abstractions.DataModel.Entities;
using NexusMods.Abstractions.Games;
using NexusMods.Abstractions.Installers;
using NexusMods.Abstractions.Serialization;
using NexusMods.Activities;
using NexusMods.App.Listeners;
using NexusMods.App.UI;
using NexusMods.CLI;
using NexusMods.CrossPlatform;
using NexusMods.DataModel;
using NexusMods.FileExtractor;
using NexusMods.Games.AdvancedInstaller;
using NexusMods.Games.AdvancedInstaller.UI;
using NexusMods.Games.BethesdaGameStudios;
using NexusMods.Games.BladeAndSorcery;
using NexusMods.Games.DarkestDungeon;
using NexusMods.Games.FOMOD;
using NexusMods.Games.FOMOD.UI;
using NexusMods.Games.Generic;
using NexusMods.Games.MountAndBlade2Bannerlord;
using NexusMods.Games.RedEngine;
using NexusMods.Games.Reshade;
using NexusMods.Games.Sifu;
using NexusMods.Games.StardewValley;
using NexusMods.Games.TestHarness;
using NexusMods.Networking.Downloaders;
using NexusMods.Networking.HttpDownloader;
using NexusMods.Networking.NexusWebApi;
using NexusMods.Paths;
using NexusMods.ProxyConsole;
using NexusMods.SingleProcess;
using NexusMods.StandardGameLocators;
using NexusMods.Telemetry;
using NexusMods.Telemetry.OpenTelemetry;
using OpenTelemetry.Exporter;
namespace NexusMods.App;
public static class Services
{
public static IServiceCollection AddListeners(this IServiceCollection services)
{
services.AddSingleton<NxmRpcListener>();
return services;
}
public static IServiceCollection AddApp(this IServiceCollection services,
AppConfig? config = null,
bool addStandardGameLocators = true,
bool slimMode = false)
{
config ??= new AppConfig();
if (!slimMode)
{
services
.AddSingleton<IAppConfigManager, AppConfigManager>(provider =>
new AppConfigManager(config, provider.GetRequiredService<JsonSerializerOptions>()))
.AddSingleton<CommandLineConfigurator>()
.AddCLI()
.AddUI(config.LauncherSettings)
.AddSingleton<App>()
.AddGuidedInstallerUi()
.AddAdvancedInstaller()
.AddAdvancedInstallerUi()
.AddFileExtractors(config.FileExtractorSettings)
.AddDataModel(config.DataModelSettings)
.AddDataModelBaseEntities()
.AddDataModelEntities()
.AddInstallerTypes()
.AddGames()
.AddActivityMonitor()
.AddCrossPlatform()
.AddBethesdaGameStudios()
.AddRedEngineGames()
.AddGenericGameSupport()
.AddReshade()
.AddFomod()
.AddDarkestDungeon()
.AddBladeAndSorcery()
.AddSifu()
.AddStardewValley()
.AddMountAndBladeBannerlord()
.AddNexusWebApi()
.AddAdvancedHttpDownloader(config.HttpDownloaderSettings)
.AddTestHarness()
.AddSingleton<HttpClient>()
.AddListeners()
.AddDownloaders();
services = OpenTelemetryRegistration.AddTelemetry(services, new OpenTelemetrySettings
{
IsEnabled = config.EnableTelemetry ?? false,
EnableMetrics = true,
EnableTracing = true,
ApplicationName = Telemetry.LibraryInfo.AssemblyName,
ApplicationVersion = Telemetry.LibraryInfo.AssemblyVersion,
ExporterProtocol = OtlpExportProtocol.HttpProtobuf,
ExporterMetricsEndpoint = new Uri("https://collector.nexusmods.com/v1/metrics"),
ExporterTracesEndpoint = new Uri("https://collector.nexusmods.com/v1/traces")
}).ConfigureTelemetry(Telemetry.LibraryInfo, configureMetrics: Telemetry.SetupTelemetry);
if (addStandardGameLocators)
services.AddStandardGameLocators();
}
services
.AddFileSystem()
.AddSingleton<IStartupHandler, StartupHandler>()
.AddSingleProcess()
.AddSingleton(s =>
{
var fs = s.GetRequiredService<IFileSystem>();
var directory = fs.OS.MatchPlatform(
() => fs.GetKnownPath(KnownPath.TempDirectory),
() => fs.GetKnownPath(KnownPath.XDG_RUNTIME_DIR),
() => throw new PlatformNotSupportedException()
);
return new SingleProcessSettings
{
SyncFile = directory.Combine("NexusMods.App-single_process.sync")
};
})
.AddDefaultRenderers();
return services;
}
}