GameData Changes

- when changing the gamedata files (add, delete, reload) it will reload all the gamedata files and repopulate the server managers.
- updated the viewmodels to check for valid class names.
This commit is contained in:
Brett Hewitson 2022-06-17 18:41:05 +10:00
parent 1bf04ed33e
commit 479e4a64dc
33 changed files with 427 additions and 305 deletions

View file

@ -1,7 +1,7 @@
using Microsoft.WindowsAPICodePack.Dialogs;
using ServerManagerTool.Common.Model;
using ServerManagerTool.Common.Utils;
using ServerManagerTool.Lib;
using ServerManagerTool.Lib.ViewModel;
using ServerManagerTool.Utils;
using System;
using System.Collections.Generic;
@ -19,60 +19,6 @@ namespace ServerManagerTool
/// </summary>
public partial class GameDataWindow : Window
{
public class GameDataFileList : SortableObservableCollection<GameDataFile>
{
public override string ToString()
{
return $"{nameof(GameDataFile)} - {Count}";
}
}
public class GameDataFile : DependencyObject
{
public static readonly DependencyProperty CreatedDateProperty = DependencyProperty.Register(nameof(CreatedDate), typeof(DateTime), typeof(GameDataFile), new PropertyMetadata(DateTime.MinValue));
public static readonly DependencyProperty FileProperty = DependencyProperty.Register(nameof(File), typeof(string), typeof(GameDataFile), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty FileNameProperty = DependencyProperty.Register(nameof(FileName), typeof(string), typeof(GameDataFile), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty IsUserDataProperty = DependencyProperty.Register(nameof(IsUserData), typeof(bool), typeof(GameDataFile), new PropertyMetadata(true));
public static readonly DependencyProperty VersionProperty = DependencyProperty.Register(nameof(Version), typeof(string), typeof(GameDataFile), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty HasErrorProperty = DependencyProperty.Register(nameof(HasError), typeof(bool), typeof(GameDataFile), new PropertyMetadata(false));
public DateTime CreatedDate
{
get { return (DateTime)GetValue(CreatedDateProperty); }
set { SetValue(CreatedDateProperty, value); }
}
public string File
{
get { return (string)GetValue(FileProperty); }
set { SetValue(FileProperty, value); }
}
public string FileName
{
get { return (string)GetValue(FileNameProperty); }
set { SetValue(FileNameProperty, value); }
}
public bool IsUserData
{
get { return (bool)GetValue(IsUserDataProperty); }
set { SetValue(IsUserDataProperty, value); }
}
public string Version
{
get { return (string)GetValue(VersionProperty); }
set { SetValue(VersionProperty, value); }
}
public bool HasError
{
get { return (bool)GetValue(HasErrorProperty); }
set { SetValue(HasErrorProperty, value); }
}
}
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
public static readonly DependencyProperty GameDataFilesProperty = DependencyProperty.Register(nameof(GameDataFiles), typeof(GameDataFileList), typeof(GameDataWindow), new PropertyMetadata(null));
@ -117,6 +63,7 @@ namespace ServerManagerTool
try
{
AddGameDataFile(GameData.UserDataFolder, dialog.FileName);
GameData.Reload();
}
catch (Exception ex)
{
@ -135,6 +82,7 @@ namespace ServerManagerTool
{
DeleteAllGameDataFiles(GameData.UserDataFolder);
}
GameData.Reload();
}
catch (Exception ex)
{
@ -166,6 +114,7 @@ namespace ServerManagerTool
try
{
ReloadGameDataFiles();
GameData.Reload();
}
catch (Exception ex)
{
@ -182,6 +131,7 @@ namespace ServerManagerTool
{
var gameDataItem = ((GameDataFile)((Button)e.Source).DataContext);
DeleteGameDataFile(gameDataItem.File, true);
GameData.Reload();
}
catch (Exception ex)
{

View file

@ -246,6 +246,13 @@ namespace ServerManagerTool
this.Activate();
}
protected override void OnClosed(EventArgs e)
{
GlobalizedApplication.Instance.GlobalizationManager.ResourceDictionaryChangedEvent -= ResourceDictionaryChangedEvent;
base.OnClosed(e);
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
if (DiscordBotHelper.HasRunningCommands)

View file

@ -245,6 +245,7 @@ namespace ServerManagerTool
// hook into the language change event
GlobalizedApplication.Instance.GlobalizationManager.ResourceDictionaryChangedEvent += ResourceDictionaryChangedEvent;
GameData.GameDataLoaded += GameData_GameDataLoaded;
}
#region Properties
@ -684,13 +685,19 @@ namespace ServerManagerTool
return new RCONWindow(parameters);
}
private void ResourceDictionaryChangedEvent(object source, ResourceDictionaryChangedEventArgs e)
private void GameData_GameDataLoaded(object sender, EventArgs e)
{
PopulateRconInputModesComboBox();
}
private void ResourceDictionaryChangedEvent(object source, ResourceDictionaryChangedEventArgs e)
{
GameData_GameDataLoaded(source, e);
}
protected override void OnClosed(EventArgs e)
{
GameData.GameDataLoaded -= GameData_GameDataLoaded;
GlobalizedApplication.Instance.GlobalizationManager.ResourceDictionaryChangedEvent -= ResourceDictionaryChangedEvent;
if (this.RCONParameters?.Server?.Runtime != null)

View file

@ -3,9 +3,10 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ServerManagerTool"
xmlns:sm="clr-namespace:ServerManagerTool"
mc:Ignorable="d"
MinWidth="800" MinHeight="600" Width="800" Height="700" ResizeMode="CanResizeWithGrip" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
Closing="SettingsWindow_Closing"
Icon="../Art/favicon.ico" Title="{DynamicResource Settings_Title}" >
<Window.Resources>
<ResourceDictionary>
@ -16,6 +17,6 @@
</ResourceDictionary>
</Window.Resources>
<Grid>
<local:GlobalSettingsControl x:Name="globalSettingsControl" HorizontalAlignment="Stretch" VerticalContentAlignment="Stretch" Background="{StaticResource BeigeGradient}"/>
<sm:GlobalSettingsControl x:Name="globalSettingsControl" HorizontalAlignment="Stretch" VerticalContentAlignment="Stretch" Background="{StaticResource BeigeGradient}"/>
</Grid>
</Window>

View file

@ -1,5 +1,6 @@
using ServerManagerTool.Common.Utils;
using System;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Windows;
@ -20,8 +21,15 @@ namespace ServerManagerTool
WindowUtils.RemoveDefaultResourceDictionary(this, Config.Default.DefaultGlobalizationFile);
}
private void SettingsWindow_Closing(object sender, CancelEventArgs e)
{
if (!globalSettingsControl.IsEnabled)
e.Cancel = true;
}
protected override void OnClosed(EventArgs e)
{
globalSettingsControl.CloseControl();
globalSettingsControl.ApplyChangesToConfig();
if (SecurityUtils.IsAdministrator())