@page "/Settings/Integrations/Steam" @using LANCommander.Server.Settings @using LANCommander.Server.UI.Pages.Settings.Components @using LANCommander.Steam.Abstractions @using LANCommander.Steam.Enums @using LANCommander.Steam.Models @using Microsoft.Extensions.Options @inject ISteamCmdService SteamCmdService @inject ISteamCmdProfileStore SteamCmdProfileStore @inject IOptions Settings @inject SettingsProvider SettingsProvider @inject IMessageService MessageService @inject ILogger Logger @attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
@code { string _rootPath = Path.GetPathRoot(Directory.GetCurrentDirectory()); SteamCmdConnectionStatus _connectionStatus; List _profiles = []; string _username; string _password; bool _processingLogin; protected override async Task OnInitializedAsync() { _profiles = (await SteamCmdService.GetProfilesAsync()).ToList(); if (!_profiles.Any()) AddProfile(); } void AddProfile() { _profiles.Add(new SteamCmdProfile()); } async Task RemoveProfile(SteamCmdProfile profile) { if (!string.IsNullOrWhiteSpace(profile.Username)) { var logoutMessage = new MessageConfig { Content = "Logging out of Steam...", Duration = 0, Key = Guid.NewGuid().ToString() }; MessageService.Loading(logoutMessage); await SteamCmdService.LogoutAsync(profile.Username); await SteamCmdService.DeleteProfileAsync(profile.Username); logoutMessage.Content = "Successfully logged out from Steam!"; logoutMessage.Duration = 3; _profiles = (await SteamCmdService.GetProfilesAsync()).ToList(); MessageService.Success(logoutMessage); } if (!_profiles.Any()) AddProfile(); } async Task Save() { try { foreach (var profile in _profiles) { await SteamCmdService.SaveProfileAsync(profile); } SettingsProvider.Update(s => s.Steam.Path = SteamCmdService.ExecutablePath); MessageService.Success("Settings saved!"); } catch (Exception ex) { MessageService.Error("An unknown error occurred."); Logger.LogError(ex, "An unknown error occurred."); } } async Task AutoDetectPath() { var path = await SteamCmdService.AutoDetectSteamCmdPathAsync(); if (!string.IsNullOrWhiteSpace(path)) { SteamCmdService.ExecutablePath = path; SettingsProvider.Update(s => { s.Steam.Path = path; }); } else MessageService.Error("Could not automatically find SteamCMD! Is it installed?"); } }