user management plus fix coresettings read error plus minor tweaks

This commit is contained in:
Dexrn ZacAttack
2025-02-24 22:56:24 -08:00
parent d1d0858438
commit 1d5dfd4ae9
16 changed files with 223 additions and 90 deletions

View File

@@ -20,7 +20,7 @@
<Grid Name="expanderButtons" Grid.Row="1" Margin="10 0 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3.5*"/>
</Grid.ColumnDefinitions>
<SplitButton x:Name="unregisterButton" Grid.Column="0" Content="Remove" HorizontalAlignment="Left" Click="HandleUnregister">
<SplitButton.Flyout>
@@ -36,6 +36,9 @@
<Button x:Name="manageModsButton" Margin="10 0 0 0" HorizontalAlignment="Left" Click="ShowModManager" ToolTipService.ToolTip="Manage mods">
<SymbolIcon Symbol="Manage"></SymbolIcon>
</Button>
<Button x:Name="manageSavesButton" Margin="10 0 0 0" HorizontalAlignment="Left" Click="ShowSaveManager" ToolTipService.ToolTip="Manage saves">
<SymbolIcon Symbol="Save"></SymbolIcon>
</Button>
<Button x:Name="viewFolderButton" Margin="10 0 0 0" HorizontalAlignment="Left" Click="OpenFolder" ToolTipService.ToolTip="View install folder">
<SymbolIcon Symbol="Folder"></SymbolIcon>
</Button>

View File

@@ -11,6 +11,7 @@ using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Storage.Streams;
using WinDurango.UI.Dialogs;
using WinDurango.UI.Pages;
using WinDurango.UI.Pages.Dialog;
using WinDurango.UI.Settings;
using WinDurango.UI.Utils;
@@ -75,7 +76,14 @@ namespace WinDurango.UI.Controls
private async void ShowModManager(object sender, RoutedEventArgs e)
{
PageDialog pgd = new PageDialog(typeof(ModMan), _package.InstalledPath, $"Installed mods for {_package.DisplayName}");
PageDialog pgd = new PageDialog(typeof(ModManPage), _package.InstalledPath, $"Installed mods for {_package.DisplayName}");
pgd.XamlRoot = App.MainWindow.Content.XamlRoot;
await pgd.ShowAsync();
}
private async void ShowSaveManager(object sender, RoutedEventArgs e)
{
PageDialog pgd = new PageDialog(typeof(NotImplementedPage), null, $"{_package.DisplayName} saves");
pgd.XamlRoot = App.MainWindow.Content.XamlRoot;
await pgd.ShowAsync();
}

View File

@@ -4,16 +4,26 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WinDurango.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Margin="10, 10, 10, 10">
<StackPanel Margin="5, 0, 0, 0">
<TextBlock Name="Info2" Margin="0,0,0,10" FontWeight="Bold"></TextBlock>
<TextBlock Text="Username:"></TextBlock>
<TextBox Name="Username"></TextBox>
<TextBlock Text="User ID:"></TextBlock>
<TextBox Name="UserId"></TextBox>
</StackPanel>
mc:Ignorable="d" Margin="0, 0, 0, 10"
Background="{ThemeResource AcrylicBackgroundFillColorBaseBrush}"
Padding="10, 10, 10, 10" CornerRadius="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Margin="5, 0, 0, 0" Grid.Column="0">
<TextBlock Text="Username"></TextBlock>
<TextBox Name="Username" LostFocus="Save"></TextBox>
<TextBlock Text="User ID"></TextBlock>
<TextBox Name="UserId" TextChanged="UserId_TextChanged" LostFocus="Save"></TextBox>
</StackPanel>
<StackPanel Grid.Column="1" Margin="5, 16, 0, 0">
<Button Name="deleteButton" Click="DeleteUser">
<SymbolIcon Symbol="Delete"></SymbolIcon>
</Button>
</StackPanel>
</Grid>
</StackPanel>

View File

@@ -1,5 +1,11 @@
using System;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using System;
using WinDurango.UI.Pages.Dialog;
using WinDurango.UI.Settings;
using WinDurango.UI.Utils;
namespace WinDurango.UI.Controls
{
@@ -11,23 +17,65 @@ namespace WinDurango.UI.Controls
{
this.InitializeComponent();
this.user = user;
this.Info2.Text = $"User {user.Id.ToString()}";
this.Username.Text = user.Name;
this.UserId.Text = user.Id.ToString();
}
public void Save(object sender, RoutedEventArgs e) => Save();
public void Save()
{
int index = App.CoreSettings.Settings.Users.IndexOf(this.user);
user.Name = this.Username.Text;
bool shouldSave = false;
ulong id;
if (!ulong.TryParse(this.UserId.Text, out id))
throw new Exception($"Cannot parse id field of user {this.user.Id}");
{
Logger.WriteError($"Cannot parse id field ({this.UserId.Text}) of user {this.user.Name}");
}
else
{
if (user.Id != id)
{
user.Id = id;
shouldSave = true;
}
}
user.Id = id;
if (user.Name != this.Username.Text)
{
user.Name = this.Username.Text;
shouldSave = true;
}
App.CoreSettings.Settings.Users[index] = user;
App.CoreSettings.Save();
if (shouldSave)
{
App.CoreSettings.Settings.Users[index] = user;
App.CoreSettings.Save();
}
}
private void DeleteUser(object sender, RoutedEventArgs e)
{
var parent = VisualTreeHelper.GetParent(this);
while (parent != null && !(parent is UserManPage))
{
parent = VisualTreeHelper.GetParent(parent);
}
if (parent != null)
((UserManPage)parent).RemoveElement(this);
App.CoreSettings.Settings.Users.Remove(user);
}
private void UserId_TextChanged(object sender, Microsoft.UI.Xaml.Controls.TextChangedEventArgs e)
{
TextBox box = (TextBox)sender;
ulong id;
if (!ulong.TryParse(box.Text, out id))
box.Foreground = new SolidColorBrush(Colors.IndianRed);
else
box.Foreground = new SolidColorBrush(Colors.White);
}
}
}

View File

@@ -10,7 +10,7 @@
<ScrollViewer>
<Grid>
<Grid Background="{ThemeResource AcrylicBackgroundFillColorBaseBrush}" Padding="10, 10, 10, 10" CornerRadius="5" Margin="0, 0, 0, 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>

View File

@@ -68,12 +68,12 @@ namespace WinDurango.UI.Controls
flyout.Hide();
File.Delete(_dllPath);
var parent = VisualTreeHelper.GetParent(this);
while (parent != null && !(parent is ModMan))
while (parent != null && !(parent is ModManPage))
{
parent = VisualTreeHelper.GetParent(parent);
}
if (parent != null)
((ModMan)parent).RemoveElement(this);
((ModManPage)parent).RemoveElement(this);
};
flyout.Content = new StackPanel

View File

@@ -40,7 +40,6 @@
x:Name="navView">
<NavigationView.MenuItems>
<NavigationViewItem Icon="AllApps" Content="Home" Tag="AppsListPage"/>
<NavigationViewItem Icon="Save" Content="Save Manager" Tag="NotImplementedPage"/>
</NavigationView.MenuItems>
<NavigationView.FooterMenuItems>
<NavigationViewItem Content="About" Tag="AboutPage">

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Page
x:Class="WinDurango.UI.Pages.Dialog.ModMan"
x:Class="WinDurango.UI.Pages.Dialog.ModManPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WinDurango.UI.Pages.Dialog"
@@ -19,8 +19,8 @@
<TextBlock Name="noMods" Visibility="Collapsed">No mods found.</TextBlock>
<StackPanel Name="modList"></StackPanel>
</StackPanel>
<Button HorizontalAlignment="Right" Margin="0, 10, 0, 0" Content="Open mods folder" Name="openModsFolder" Click="OpenModsFolder"></Button>
<Button HorizontalAlignment="Right" Margin="0, 10, 0, 0" Content="Create mods folder" Name="createModsFolder" Click="CreateModsFolder" Visibility="Collapsed"></Button>
<Button HorizontalAlignment="Right" Margin="0, 5, 0, 0" Content="Open mods folder" Name="openModsFolder" Click="OpenModsFolder"></Button>
<Button HorizontalAlignment="Right" Margin="0, 5, 0, 0" Content="Create mods folder" Name="createModsFolder" Click="CreateModsFolder" Visibility="Collapsed"></Button>
</StackPanel>
</ScrollViewer>
</Grid>

View File

@@ -10,12 +10,12 @@ using WinDurango.UI.Utils;
namespace WinDurango.UI.Pages.Dialog
{
public sealed partial class ModMan : Page
public sealed partial class ModManPage : Page
{
private string _modsPath;
private string _packagePath;
public ModMan()
public ModManPage()
{
this.InitializeComponent();
}

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Page
x:Class="WinDurango.UI.Pages.Dialog.UserManPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WinDurango.UI.Pages.Dialog"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:ct="using:CommunityToolkit.WinUI.Controls">
<Grid>
<ct:DockPanel>
<ScrollViewer ct:DockPanel.Dock="Top" MaxHeight="400">
<StackPanel Name="userList"/>
</ScrollViewer>
<Button Name="addUser" ct:DockPanel.Dock="Bottom" HorizontalAlignment="Right" Click="AddUser" Margin="0, 10, 0, 0">
<SymbolIcon Symbol="Add"></SymbolIcon>
</Button>
</ct:DockPanel>
</Grid>
</Page>

View File

@@ -0,0 +1,68 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using WinDurango.UI.Controls;
using WinDurango.UI.Dialogs;
using WinDurango.UI.Settings;
using WinDurango.UI.Utils;
namespace WinDurango.UI.Pages.Dialog
{
public sealed partial class UserManPage : Page
{
public UserManPage()
{
this.InitializeComponent();
var parent = VisualTreeHelper.GetParent(this);
while (parent != null && !(parent is PageDialog))
{
parent = VisualTreeHelper.GetParent(parent);
}
if (parent != null)
((PageDialog)parent).PrimaryButtonText = "Cancel";
LoadUsers();
}
public void RemoveElement(LayerUser element)
{
userList.Children.Remove(element);
}
public void LoadUsers()
{
userList.Children.Clear();
foreach (CoreConfigData.User settingsUser in App.CoreSettings.Settings.Users)
{
userList.Children.Add(new LayerUser(settingsUser));
}
}
private void AddUser(object sender, RoutedEventArgs e)
{
CoreConfigData.User user = new CoreConfigData.User
{
Name = $"durangler{CoreConfigData.User.GetFreeId()}",
Id = CoreConfigData.User.GetFreeId()
};
App.CoreSettings.Settings.Users.Add(user);
userList.Children.Add(new LayerUser(user));
App.CoreSettings.Save();
Logger.WriteInformation($"Added user {user.Name}");
}
}
}

View File

@@ -12,19 +12,7 @@
<ScrollViewer>
<StackPanel>
<TextBlock Margin="0 5 0 5" Text="Layer Settings" FontSize="16" FontWeight="Bold"/>
<TextBlock Margin="0 5 0 5" Text="Users (UI UNFINISHED)" FontSize="16" FontWeight="Bold"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel x:Name="LayerUser" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" CornerRadius="12"></StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<ComboBox x:Name="SelectUser" SelectionChanged="OnUserSelect"></ComboBox>
<Button Name="saveUsers" Content="Save" Click="SaveUsers"></Button>
</StackPanel>
</Grid>
<Button Margin="0 5 0 5" Click="ManageUsers">Manage users</Button>
<TextBlock Margin="0 5 0 5" Text="Debug" FontSize="16" FontWeight="Bold"/>
<ToggleSwitch OnContent="Enable console" OffContent="Enable console" Toggled="OnToggleSetting" Tag="EnableConsole" Name="ConsoleToggle"/>
<ToggleSwitch OnContent="Enable debug logging" OffContent="Enable debug logging" Toggled="OnToggleSetting" Tag="DebugLogging" Name="DebugLogToggle"/>

View File

@@ -1,8 +1,11 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using WinDurango.UI.Controls;
using WinDurango.UI.Dialogs;
using WinDurango.UI.Pages.Dialog;
using WinDurango.UI.Settings;
@@ -10,28 +13,9 @@ namespace WinDurango.UI.Pages.Settings
{
public partial class WdSettingsPage : Page
{
public List<LayerUser> users = new();
public WdSettingsPage()
{
this.InitializeComponent();
LoadUsers();
}
public void LoadUsers()
{
SelectUser.Items.Clear();
users.Clear();
foreach (CoreConfigData.User settingsUser in App.CoreSettings.Settings.Users)
{
users.Add(new LayerUser(settingsUser));
ComboBoxItem item = new ComboBoxItem
{
Content = $"User {settingsUser.Id} ({settingsUser.Name})",
Tag = settingsUser.Id.ToString()
};
SelectUser.Items.Add(item);
}
}
public CoreConfigData.User GetUser(ulong id)
@@ -47,35 +31,16 @@ namespace WinDurango.UI.Pages.Settings
}
}
private void SaveUsers(object sender, RoutedEventArgs e)
private async void ManageUsers(object sender, RoutedEventArgs e)
{
foreach (var userElement in users)
{
if (userElement.GetType() != typeof(LayerUser))
continue;
userElement.Save();
}
PageDialog pgd = new PageDialog(typeof(UserManPage), null, $"Users");
pgd.XamlRoot = App.MainWindow.Content.XamlRoot;
await pgd.ShowAsync();
}
private void OpenAppData(object sender, RoutedEventArgs e)
{
Process.Start(new ProcessStartInfo(App.CoreDataDir) { UseShellExecute = true });
}
private void OnUserSelect(object sender, SelectionChangedEventArgs e)
{
if (sender is not ComboBox box)
return;
ComboBoxItem item = (ComboBoxItem)box.SelectedItem;
if (item.Tag is not string tag || !ulong.TryParse(tag, out ulong id)) return;
LayerUser.Children.Clear();
var user = users.Find(user => user.user.Id.ToString() == item.Tag.ToString());
LayerUser.Children.Add(user);
}
}
}

View File

@@ -46,6 +46,20 @@ namespace WinDurango.UI.Settings
{
public string Name { get; set; } = "durangler";
public ulong Id { get; set; } = 0;
public static ulong GetFreeId()
{
var ids = new HashSet<ulong>(App.CoreSettings.Settings.Users.Select(usr => usr.Id));
for (ulong i = 1; i < ulong.MaxValue; i++)
{
if (!ids.Contains(i))
return i;
}
return 0;
}
}
public class ControllerKeybind
@@ -65,11 +79,11 @@ namespace WinDurango.UI.Settings
public List<User> Users { get; set; } = [
new User() {
Name = "durangler",
Name = "durangler0",
Id = 0
},
new User() {
Name = "durangled",
Name = "durangler1",
Id = 1
},
new User() {
@@ -77,7 +91,7 @@ namespace WinDurango.UI.Settings
Id = 2
},
new User() {
Name = "durangled2",
Name = "durangler3",
Id = 3
},
@@ -107,7 +121,8 @@ namespace WinDurango.UI.Settings
try
{
string json = File.ReadAllText(_settingsFile);
Settings = JsonSerializer.Deserialize<CoreConfigData>(json);
JsonSerializerOptions options = new JsonSerializerOptions { Converters = { new BindingsConverter() } };
Settings = JsonSerializer.Deserialize<CoreConfigData>(json, options);
if (Settings == null)
throw new Exception("loadedSettings is null... wtf?");

View File

@@ -134,7 +134,7 @@ namespace WinDurango.UI.Utils
try
{
Logger.WriteInformation($"Reading manifest...");
controller?.UpdateText("Packages.ReadingManifest".GetLocalizedString());
controller?.UpdateText(GetLocalizedText("/Packages/ReadingManifest"));
string manifest;
await using (var stream = File.OpenRead(manifestPath))
{
@@ -168,12 +168,12 @@ namespace WinDurango.UI.Utils
controller?.UpdateProgress(60.0);
controller?.UpdateText("Packages.GettingAppInfo".GetLocalizedString());
controller?.UpdateText(GetLocalizedText("/Packages/GettingAppInfo"));
Package recentPkg = GetMostRecentlyInstalledPackage();
if (addInstalledPackage)
{
controller?.UpdateText($"Ui.UpdatingAppList".GetLocalizedString());
controller?.UpdateText(GetLocalizedText("/Ui/UpdatingAppList"));
controller?.UpdateProgress(80.0);
App.InstalledPackages.AddPackage(recentPkg);
controller?.UpdateProgress(90.0);

View File

@@ -45,6 +45,7 @@
<None Remove="Pages\AboutPage.xaml" />
<None Remove="Pages\AppsListPage.xaml" />
<None Remove="Pages\Dialog\ModManPage.xaml" />
<None Remove="Pages\Dialog\UserManPage.xaml" />
<None Remove="Pages\NotImplementedPage.xaml" />
<None Remove="Pages\SettingsPage.xaml" />
</ItemGroup>
@@ -193,4 +194,10 @@
<ItemGroup>
<PRIResource Remove="Strings\en-US\Ui.resw" />
</ItemGroup>
<ItemGroup>
<Page Update="Pages\Dialog\UserManPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>