wabbajack/Wabbajack.CLI/Program.cs

68 lines
2.8 KiB
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System;
using System.CommandLine;
using System.CommandLine.IO;
using System.ComponentModel;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Octokit;
using Wabbajack.CLI.TypeConverters;
2020-01-31 22:38:56 +00:00
using Wabbajack.CLI.Verbs;
2021-09-27 12:42:46 +00:00
using Wabbajack.DTOs.GitHub;
using Wabbajack.Networking.Http;
using Wabbajack.Networking.Http.Interfaces;
using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Server.Lib;
using Wabbajack.Services.OSIntegrated;
using Wabbajack.VFS;
using Client = Wabbajack.Networking.GitHub.Client;
2020-01-31 22:38:56 +00:00
2021-10-23 16:51:17 +00:00
namespace Wabbajack.CLI;
internal class Program
2020-01-31 22:38:56 +00:00
{
2021-10-23 16:51:17 +00:00
private static async Task<int> Main(string[] args)
2020-01-31 22:38:56 +00:00
{
2021-10-23 16:51:17 +00:00
TypeDescriptor.AddAttributes(typeof(AbsolutePath),
new TypeConverterAttribute(typeof(AbsolutePathTypeConverter)));
TypeDescriptor.AddAttributes(typeof(List),
new TypeConverterAttribute(typeof(ModListCategoryConverter)));
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
var host = Host.CreateDefaultBuilder(Array.Empty<string>())
.ConfigureServices((host, services) =>
{
services.AddSingleton(new JsonSerializerOptions());
services.AddSingleton<HttpClient, HttpClient>();
services.AddSingleton<IHttpDownloader, SingleThreadedDownloader>();
services.AddSingleton<IConsole, SystemConsole>();
services.AddSingleton<CommandLineBuilder, CommandLineBuilder>();
services.AddSingleton<TemporaryFileManager>();
services.AddSingleton<FileExtractor.FileExtractor>();
services.AddSingleton(new VFSCache(KnownFolders.EntryPoint.Combine("vfscache.sqlite")));
services.AddSingleton(new ParallelOptions {MaxDegreeOfParallelism = Environment.ProcessorCount});
services.AddSingleton<Client>();
services.AddSingleton<Networking.WabbajackClientApi.Client>();
services.AddSingleton(s => new GitHubClient(new ProductHeaderValue("wabbajack")));
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
services.AddOSIntegrated();
services.AddServerLib();
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
services.AddTransient<Context>();
services.AddSingleton<IVerb, HashFile>();
services.AddSingleton<IVerb, VFSIndexFolder>();
services.AddSingleton<IVerb, Encrypt>();
services.AddSingleton<IVerb, Decrypt>();
services.AddSingleton<IVerb, ValidateLists>();
services.AddSingleton<IVerb, DownloadCef>();
services.AddSingleton<IVerb, DownloadUrl>();
}).Build();
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
var service = host.Services.GetService<CommandLineBuilder>();
return await service!.Run(args);
2020-01-31 22:38:56 +00:00
}
2021-09-27 12:42:46 +00:00
}