[Draft] Update 0.8 (#46)

* move stuff out into file transfer manager

* obnoxious unsupported version text, adjustments to filetransfermanager

* add back file upload transfer progress

* restructure code

* cleanup some more stuff I guess

* downloadids by playername

* individual anim/sound bs

* fix migration stuff, finalize impl of individual sound/anim pause

* fixes with logging stuff

* move download manager to transient

* rework dl ui first iteration

* some refactoring and cleanup

* more code cleanup

* refactoring

* switch to hostbuilder

* some more rework I guess

* more refactoring

* clean up mediator calls and disposal

* fun code cleanup

* push error message when log level is set to anything but information in non-debug builds

* remove notificationservice

* move message to after login

* add download bars to gameworld

* fixes download progress bar

* set gpose ui min and max size

* remove unnecessary usings

* adjustments to reconnection logic

* add options to set visible/offline groups visibility

* add impl of uploading display, transfer list in settings ui

* attempt to fix issues with server selection

* add back download status to compact ui

* make dl bar fixed size based

* some fixes for upload/download handling

* adjust text from Syncing back to Uploading

---------

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
Co-authored-by: Stanley Dimant <stanley.dimant@varian.com>
This commit is contained in:
rootdarkarchon
2023-03-14 19:48:35 +01:00
committed by GitHub
parent 0824ba434b
commit 0c87e84f25
109 changed files with 7323 additions and 6488 deletions

View File

@@ -1,28 +1,27 @@
using Dalamud.Game.Command;
using Dalamud.Plugin;
using Dalamud.Interface.ImGuiFileDialog;
using MareSynchronos.Managers;
using MareSynchronos.WebAPI;
using Dalamud.Interface.Windowing;
using MareSynchronos.UI;
using MareSynchronos.Utils;
using MareSynchronos.FileCache;
using MareSynchronos.FileCache;
using MareSynchronos.MareConfiguration;
using MareSynchronos.Mediator;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.PlayerData.Services;
using MareSynchronos.Services;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Reflection;
namespace MareSynchronos;
#pragma warning disable S125 // Sections of code should not be commented out
/*
(..,,...,,,,,+/, ,,.....,,+
..,,+++/((###%%%&&%%#(+,,.,,,+++,,,,//,,#&@@@@%+.
...+//////////(/,,,,++,.,(###((//////////,.. .,#@@%/./
,..+/////////+///,.,. ,&@@@@,,/////////////+,.. ,(##+,.
,,.+//////////++++++.. ./#%#,+/////////////+,....,/((,..,
+..////////////+++++++... .../##(,,////////////////++,,,+/(((+,
+,.+//////////////+++++++,.,,,/(((+.,////////////////////////((((#/,,
/+.+//////////++++/++++++++++,,...,++///////////////////////////((((##,
(..,,...,,,,,+/, ,,.....,,+
..,,+++/((###%%%&&%%#(+,,.,,,+++,,,,//,,#&@@@@%+.
...+//////////(/,,,,++,.,(###((//////////,.. .,#@@%/./
,..+/////////+///,.,. ,&@@@@,,/////////////+,.. ,(##+,.
,,.+//////////++++++.. ./#%#,+/////////////+,....,/((,..,
+..////////////+++++++... .../##(,,////////////////++,,,+/(((+,
+,.+//////////////+++++++,.,,,/(((+.,////////////////////////((((#/,,
/+.+//////////++++/++++++++++,,...,++///////////////////////////((((##,
/,.////////+++++++++++++++++++++////////+++//////++/+++++//////////((((#(+,
/+.+////////+++++++++++++++++++++++++++++++++++++++++++++++++++++/////((((##+
+,.///////////////+++++++++++++++++++++++++++++++++++++++++++++++++++///((((%/
@@ -30,202 +29,137 @@ namespace MareSynchronos;
+,./////////////////+++++++++++++++++++++++++++++++++++++++++++++++,,+++++///((,
...////////++/++++++++++++++++++++++++,,++++++++++++++++++++++++++++++++++++//(,,
..//+,+///++++++++++++++++++,,,,+++,,,,,,,,,,,,++++++++,,+++++++++++++++++++//,,+
..,++,.++++++++++++++++++++++,,,,,,,,,,,,,,,,,,,++++++++,,,,,,,,,,++++++++++...
..+++,.+++++++++++++++++++,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,++,..,.
..,++++,,+++++++++++,+,,,,,,,,,,..,+++++++++,,,,,,.....................,//+,+
....,+++++,.,+++++++++++,,,,,,,,.+///(((((((((((((///////////////////////(((+,,,
.....,++++++++++..,+++++++++++,,.,,,.////////(((((((((((((((////////////////////+,,/
.....,++++++++++++,..,,+++++++++,,.,../////////////////((((((((((//////////////////,,+
...,,+++++++++++++,.,,.,,,+++++++++,.,/////////////////(((//++++++++++++++//+++++++++/,,
....,++++++++++++++,.,++.,++++++++++++.,+////////////////////+++++++++++++++++++++++++///,,..
...,++++++++++++++++..+++..+++++++++++++.,//////////////////////////++++++++++++///////++++......
...++++++++++++++++++..++++.,++,++++++++++.+///////////////////////////////////////////++++++..,,,..
...+++++++++++++++++++..+++++..,+,,+++++++++.+//////////////////////////////////////////+++++++...,,,,..
..++++++++++++++++++++..++++++..,+,,+++++++++.+//////////////////////////////////////++++++++++,....,,,,..
...+++//(//////+++++++++..++++++,.,+++++++++++++,..,....,,,+++///////////////////////++++++++++++..,,,,,,,,...
..,++/(((((//////+++++++,.,++++++,,.,,,+++++++++++++++++++++++,.++////////////////////+++++++++++.....,,,,,,,...
..,//#(((((///////+++++++..++++++++++,...,++,++++++++++++++++,...+++/////////////////////+,,,+++... ....,,,,,,...
..,++,.++++++++++++++++++++++,,,,,,,,,,,,,,,,,,,++++++++,,,,,,,,,,++++++++++...
..+++,.+++++++++++++++++++,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,++,..,.
..,++++,,+++++++++++,+,,,,,,,,,,..,+++++++++,,,,,,.....................,//+,+
....,+++++,.,+++++++++++,,,,,,,,.+///(((((((((((((///////////////////////(((+,,,
.....,++++++++++..,+++++++++++,,.,,,.////////(((((((((((((((////////////////////+,,/
.....,++++++++++++,..,,+++++++++,,.,../////////////////((((((((((//////////////////,,+
...,,+++++++++++++,.,,.,,,+++++++++,.,/////////////////(((//++++++++++++++//+++++++++/,,
....,++++++++++++++,.,++.,++++++++++++.,+////////////////////+++++++++++++++++++++++++///,,..
...,++++++++++++++++..+++..+++++++++++++.,//////////////////////////++++++++++++///////++++......
...++++++++++++++++++..++++.,++,++++++++++.+///////////////////////////////////////////++++++..,,,..
...+++++++++++++++++++..+++++..,+,,+++++++++.+//////////////////////////////////////////+++++++...,,,,..
..++++++++++++++++++++..++++++..,+,,+++++++++.+//////////////////////////////////////++++++++++,....,,,,..
...+++//(//////+++++++++..++++++,.,+++++++++++++,..,....,,,+++///////////////////////++++++++++++..,,,,,,,,...
..,++/(((((//////+++++++,.,++++++,,.,,,+++++++++++++++++++++++,.++////////////////////+++++++++++.....,,,,,,,...
..,//#(((((///////+++++++..++++++++++,...,++,++++++++++++++++,...+++/////////////////////+,,,+++... ....,,,,,,...
...+//(((((//////////++++++..+++++++++++++++,......,,,,++++++,,,..+++////////////////////////+,.... ...,,,,,,,...
..,//((((////////////++++++..++++++/+++++++++++++,,...,,........,+/+//////////////////////((((/+,.. ....,.,,,,..
...+/////////////////////+++..++++++/+///+++++++++++++++++++++///+/+////////////////////////(((((/+... .......,,...
..++////+++//////////////++++.+++++++++///////++++++++////////////////////////////////////+++/(((((/+.. .....,,...
.,++++++++///////////////++++..++++//////////////////////////////////////////////////////++++++/((((++.. ........
.+++++++++////////////////++++,.+++/////////////////////////////////////////////////////+++++++++/((/++..
.,++++++++//////////////////++++,.+++//////////////////////////////////////////////////+++++++++++++//+++..
.++++++++//////////////////////+/,.,+++////((((////////////////////////////////////////++++++++++++++++++...
.++++++++///////////////////////+++..++++//((((((((///////////////////////////////////++++++++++++++++++++ .
.++++++///////////////////////////++,.,+++++/(((((((((/////////////////////////////+++++++++++++++++++++++,..
.++++++////////////////////////////+++,.,+++++++/((((((((//////////////////////////++++++++++++++++++++++++..
.+++++++///////////////////++////////++++,.,+++++++++///////////+////////////////+++++++++++++++++++++++++,..
..++++++++++//////////////////////+++++++..+...,+++++++++++++++/++++++++++++++++++++++++++++++++++++++++++,...
..++++++++++++///////////////+++++++,...,,,,,.,....,,,,+++++++++++++++++++++++++++++++++++++++++++++++,,,,...
...++++++++++++++++++++++++++,,,,...,,,,,,,,,..,,++,,,.,,,,,,,,,,,,,,,,,,+++++++++++++++++++++++++,,,,,,,,..
...+++++++++++++++,,,,,,,,....,,,,,,,,,,,,,,,..,,++++++,,,,,,,,,,,,,,,,+++++++++++++++++++++++++,,,,,,,,,..
...++++++++++++,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...,++++++++++++++++++++++++++++++++++++++++++++,,,,,,,,,,...
,....,++++++++++++++,,,+++++++,,,,,,,,,,,,,,,,,.,++++++++++++++++++++++++++++++++++++++++++++,,,,,,,,..
..,//((((////////////++++++..++++++/+++++++++++++,,...,,........,+/+//////////////////////((((/+,.. ....,.,,,,..
...+/////////////////////+++..++++++/+///+++++++++++++++++++++///+/+////////////////////////(((((/+... .......,,...
..++////+++//////////////++++.+++++++++///////++++++++////////////////////////////////////+++/(((((/+.. .....,,...
.,++++++++///////////////++++..++++//////////////////////////////////////////////////////++++++/((((++.. ........
.+++++++++////////////////++++,.+++/////////////////////////////////////////////////////+++++++++/((/++..
.,++++++++//////////////////++++,.+++//////////////////////////////////////////////////+++++++++++++//+++..
.++++++++//////////////////////+/,.,+++////((((////////////////////////////////////////++++++++++++++++++...
.++++++++///////////////////////+++..++++//((((((((///////////////////////////////////++++++++++++++++++++ .
.++++++///////////////////////////++,.,+++++/(((((((((/////////////////////////////+++++++++++++++++++++++,..
.++++++////////////////////////////+++,.,+++++++/((((((((//////////////////////////++++++++++++++++++++++++..
.+++++++///////////////////++////////++++,.,+++++++++///////////+////////////////+++++++++++++++++++++++++,..
..++++++++++//////////////////////+++++++..+...,+++++++++++++++/++++++++++++++++++++++++++++++++++++++++++,...
..++++++++++++///////////////+++++++,...,,,,,.,....,,,,+++++++++++++++++++++++++++++++++++++++++++++++,,,,...
...++++++++++++++++++++++++++,,,,...,,,,,,,,,..,,++,,,.,,,,,,,,,,,,,,,,,,+++++++++++++++++++++++++,,,,,,,,..
...+++++++++++++++,,,,,,,,....,,,,,,,,,,,,,,,..,,++++++,,,,,,,,,,,,,,,,+++++++++++++++++++++++++,,,,,,,,,..
...++++++++++++,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...,++++++++++++++++++++++++++++++++++++++++++++,,,,,,,,,,...
,....,++++++++++++++,,,+++++++,,,,,,,,,,,,,,,,,.,++++++++++++++++++++++++++++++++++++++++++++,,,,,,,,..
*/
#pragma warning restore S125 // Sections of code should not be commented out
public class MarePlugin : MediatorSubscriberBase, IDisposable
public class MarePlugin : MediatorSubscriberBase, IHostedService
{
private readonly ServiceProvider _serviceProvider;
private const string _commandName = "/mare";
private readonly DalamudUtilService _dalamudUtil;
private readonly MareConfigService _mareConfigService;
private readonly ServerConfigurationManager _serverConfigurationManager;
private readonly IServiceScopeFactory _serviceScopeFactory;
private IServiceScope? _runtimeServiceScope;
public MarePlugin(ILogger<MarePlugin> logger, ServiceProvider serviceProvider, MareMediator mediator) : base(logger, mediator)
public MarePlugin(ILogger<MarePlugin> logger, MareConfigService mareConfigService,
ServerConfigurationManager serverConfigurationManager,
DalamudUtilService dalamudUtil,
IServiceScopeFactory serviceScopeFactory, MareMediator mediator) : base(logger, mediator)
{
_serviceProvider = serviceProvider;
_serviceProvider.GetRequiredService<ConfigurationMigrator>().Migrate();
mediator.Subscribe<SwitchToMainUiMessage>(this, (_) => Task.Run(WaitForPlayerAndLaunchCharacterManager));
mediator.Subscribe<DalamudLoginMessage>(this, (_) => DalamudUtilOnLogIn());
mediator.Subscribe<DalamudLogoutMessage>(this, (_) => DalamudUtilOnLogOut());
serviceProvider.GetRequiredService<SettingsUi>();
serviceProvider.GetRequiredService<CompactUi>();
serviceProvider.GetRequiredService<GposeUi>();
serviceProvider.GetRequiredService<IntroUi>();
serviceProvider.GetRequiredService<DownloadUi>();
serviceProvider.GetRequiredService<NotificationService>();
_mareConfigService = mareConfigService;
_serverConfigurationManager = serverConfigurationManager;
_dalamudUtil = dalamudUtil;
_serviceScopeFactory = serviceScopeFactory;
}
public override void Dispose()
public Task StartAsync(CancellationToken cancellationToken)
{
base.Dispose();
var version = Assembly.GetExecutingAssembly().GetName().Version!;
Logger.LogInformation("Launching {name} {major}.{minor}.{build}", "Mare Synchronos", version.Major, version.Minor, version.Build);
_serviceProvider.GetRequiredService<CommandManager>().RemoveHandler(_commandName);
Mediator.Subscribe<SwitchToMainUiMessage>(this, (_) => Task.Run(WaitForPlayerAndLaunchCharacterManager));
Mediator.Subscribe<DalamudLoginMessage>(this, (_) => DalamudUtilOnLogIn());
Mediator.Subscribe<DalamudLogoutMessage>(this, (_) => DalamudUtilOnLogOut());
_runtimeServiceScope?.Dispose();
_serviceProvider.Dispose();
return Task.CompletedTask;
}
_logger.LogDebug("Shut down");
public Task StopAsync(CancellationToken cancellationToken)
{
UnsubscribeAll();
DalamudUtilOnLogOut();
Logger.LogDebug("Halting MarePlugin");
return Task.CompletedTask;
}
private void DalamudUtilOnLogIn()
{
_logger?.LogDebug("Client login");
Logger?.LogDebug("Client login");
var pi = _serviceProvider.GetRequiredService<DalamudPluginInterface>();
pi.UiBuilder.Draw += Draw;
pi.UiBuilder.OpenConfigUi += OpenUi;
_serviceProvider.GetRequiredService<CommandManager>().AddHandler(_commandName, new CommandInfo(OnCommand)
{
HelpMessage = "Opens the Mare Synchronos UI",
});
if (!_serviceProvider.GetRequiredService<MareConfigService>().Current.HasValidSetup()
|| !_serviceProvider.GetRequiredService<ServerConfigurationManager>().HasValidConfig())
{
_serviceProvider.GetRequiredService<MareMediator>().Publish(new SwitchToIntroUiMessage());
return;
}
_serviceProvider.GetRequiredService<PeriodicFileScanner>().StartScan();
Task.Run(WaitForPlayerAndLaunchCharacterManager);
}
private void DalamudUtilOnLogOut()
{
_logger?.LogDebug("Client logout");
Logger?.LogDebug("Client logout");
_runtimeServiceScope?.Dispose();
var pi = _serviceProvider.GetRequiredService<DalamudPluginInterface>();
pi.UiBuilder.Draw -= Draw;
pi.UiBuilder.OpenConfigUi -= OpenUi;
_serviceProvider.GetRequiredService<CommandManager>().RemoveHandler(_commandName);
}
private async Task WaitForPlayerAndLaunchCharacterManager()
{
var dalamudUtil = _serviceProvider.GetRequiredService<DalamudUtil>();
while (!dalamudUtil.IsPlayerPresent)
while (!_dalamudUtil.IsPlayerPresent)
{
await Task.Delay(100).ConfigureAwait(false);
}
try
{
_logger?.LogDebug("Launching Managers");
Logger?.LogDebug("Launching Managers");
_runtimeServiceScope?.Dispose();
_runtimeServiceScope = _serviceProvider.CreateScope();
_runtimeServiceScope = _serviceScopeFactory.CreateScope();
_runtimeServiceScope.ServiceProvider.GetRequiredService<UiService>();
_runtimeServiceScope.ServiceProvider.GetRequiredService<CommandManagerService>();
if (!_mareConfigService.Current.HasValidSetup() || !_serverConfigurationManager.HasValidConfig())
{
Mediator.Publish(new SwitchToIntroUiMessage());
return;
}
_runtimeServiceScope.ServiceProvider.GetRequiredService<PeriodicFileScanner>().StartScan();
_runtimeServiceScope.ServiceProvider.GetRequiredService<CacheCreationService>();
_runtimeServiceScope.ServiceProvider.GetRequiredService<TransientResourceManager>();
_runtimeServiceScope.ServiceProvider.GetRequiredService<OnlinePlayerManager>();
_runtimeServiceScope.ServiceProvider.GetRequiredService<NotificationService>();
#if !DEBUG
if (_mareConfigService.Current.LogLevel != LogLevel.Information)
{
Mediator.Publish(new NotificationMessage("Abnormal Log Level",
$"Your log level is set to '{_mareConfigService.Current.LogLevel}' which is not recommended for normal usage. Set it to '{LogLevel.Information}' in \"Mare Settings -> Debug\" unless instructed otherwise.",
Dalamud.Interface.Internal.Notifications.NotificationType.Error, 15000));
}
#endif
}
catch (Exception ex)
{
_logger?.LogCritical(ex, "Error during launch of managers");
Logger?.LogCritical(ex, "Error during launch of managers");
}
}
private void Draw()
{
_serviceProvider.GetRequiredService<WindowSystem>().Draw();
_serviceProvider.GetRequiredService<FileDialogManager>().Draw();
}
private void OnCommand(string command, string args)
{
var splitArgs = args.ToLowerInvariant().Trim().Split(" ", StringSplitOptions.RemoveEmptyEntries);
if (splitArgs == null || splitArgs.Length == 0)
{
// Interpret this as toggling the UI
OpenUi();
return;
}
if (string.Equals(splitArgs[0], "toggle", StringComparison.OrdinalIgnoreCase))
{
var serverConfigurationManager = _serviceProvider.GetRequiredService<ServerConfigurationManager>();
if (serverConfigurationManager.CurrentServer == null) return;
var fullPause = splitArgs.Length > 1 ? splitArgs[1] switch
{
"on" => false,
"off" => true,
_ => !serverConfigurationManager.CurrentServer.FullPause,
} : !serverConfigurationManager.CurrentServer.FullPause;
if (fullPause != serverConfigurationManager.CurrentServer.FullPause)
{
serverConfigurationManager.CurrentServer.FullPause = fullPause;
serverConfigurationManager.Save();
_ = _serviceProvider.GetRequiredService<ApiController>().CreateConnections();
}
}
else if (string.Equals(splitArgs[0], "gpose", StringComparison.OrdinalIgnoreCase))
{
_serviceProvider.GetRequiredService<GposeUi>().Toggle();
}
else if (string.Equals(splitArgs[0], "rescan", StringComparison.OrdinalIgnoreCase))
{
_serviceProvider.GetRequiredService<PeriodicFileScanner>().InvokeScan(forced: true);
}
else if (string.Equals(splitArgs[0], "perf", StringComparison.OrdinalIgnoreCase))
{
if (splitArgs.Length > 1 && int.TryParse(splitArgs[1], out var limitBySeconds))
{
_serviceProvider.GetRequiredService<PerformanceCollector>().PrintPerformanceStats(limitBySeconds);
}
else
{
_serviceProvider.GetRequiredService<PerformanceCollector>().PrintPerformanceStats();
}
}
else if (string.Equals(splitArgs[0], "medi", StringComparison.OrdinalIgnoreCase))
{
_serviceProvider.GetRequiredService<MareMediator>().PrintSubscriberInfo();
}
}
private void OpenUi()
{
if (_serviceProvider.GetRequiredService<MareConfigService>().Current.HasValidSetup())
_serviceProvider.GetRequiredService<CompactUi>().Toggle();
else
_serviceProvider.GetRequiredService<IntroUi>().Toggle();
}
}
}