From 84d993d0bb0f7c27ae48f6312a9f668fbc0d3f7b Mon Sep 17 00:00:00 2001 From: shoushou1106 <100991210+shoushou1106@users.noreply.github.com> Date: Mon, 28 Aug 2023 17:38:25 +0800 Subject: [PATCH 01/38] [Editor] change Add add Delete change Window size & Title --- FrostyEditor/Languages/en-US.axaml | 2 + .../Windows/ProfileSelectWindowViewModel.cs | 82 +++++++++++++++++-- .../Views/Windows/ProfileSelectWindow.axaml | 8 +- 3 files changed, 80 insertions(+), 12 deletions(-) diff --git a/FrostyEditor/Languages/en-US.axaml b/FrostyEditor/Languages/en-US.axaml index 3942532c6..a127e8ab7 100644 --- a/FrostyEditor/Languages/en-US.axaml +++ b/FrostyEditor/Languages/en-US.axaml @@ -7,8 +7,10 @@ Help + Frosty Editor - Select Profile Select Add + Delete Cancel diff --git a/FrostyEditor/ViewModels/Windows/ProfileSelectWindowViewModel.cs b/FrostyEditor/ViewModels/Windows/ProfileSelectWindowViewModel.cs index b959694fa..909ba0678 100644 --- a/FrostyEditor/ViewModels/Windows/ProfileSelectWindowViewModel.cs +++ b/FrostyEditor/ViewModels/Windows/ProfileSelectWindowViewModel.cs @@ -43,13 +43,19 @@ public ProfileSelectWindowViewModel() { // init ProfilesLibrary to load all profile json files ProfilesLibrary.Initialize(); - + + RefreshProfileList(); + } + + public void RefreshProfileList() + { + Profiles.Clear(); foreach (string profile in Config.GameProfiles) { ProfileConfig config = new(profile); if (File.Exists(config.FileName)) { - Profiles.Add(config); + Profiles.Add(config); } else { @@ -59,12 +65,28 @@ public ProfileSelectWindowViewModel() Config.Save(App.ConfigPath); } + public static FilePickerFileType ImageExe { get; } = new("Executable") + { + Patterns = new[] { "*.exe" }, + // https://developer.apple.com/documentation/uniformtypeidentifiers/uttype/3551492-exe + AppleUniformTypeIdentifiers = new[] { "exe" }, + // https://www.iana.org/assignments/media-types/application/vnd.microsoft.portable-executable + MimeTypes = new[] { "vnd.microsoft.portable-executable" } + }; + [RelayCommand] private async Task AddProfile() { IReadOnlyList? files = await FileService.OpenFilesAsync(new FilePickerOpenOptions { Title = "Select Game Executable", + FileTypeFilter = new[] + { + ImageExe +#if DEBUG + , FilePickerFileTypes.All +#endif + }, AllowMultiple = false }); @@ -76,12 +98,54 @@ private async Task AddProfile() foreach (IStorageFile file in files) { string key = Path.GetFileNameWithoutExtension(file.Name); - Config.AddGame(key, Path.GetDirectoryName(file.Path.LocalPath) ?? string.Empty); - Profiles.Add(new ProfileConfig(key)); + + // Check if profile exists + if (!ProfilesLibrary.HasProfile(key)) + { + // TODO: Add MessageBox + //FrostyMessageBox.Show($"There was an error when trying to load {key} using specified profile.", "Frosty Toolsuite"); + continue; + } + + // Make sure config doesn't already exist + bool isProfileExist = false; + foreach (string profile in Config.GameProfiles) + { + if (key == profile) + { + // TODO: Add MessageBox + //FrostyMessageBox.Show($"{key} already has a configuration."); + isProfileExist = true; + break; + } + } + + if (ProfilesLibrary.HasAntiCheat) + { + // TODO: Add MessageBox + //FrostyMessageBox.Show($"{key} contains EasyAntiCheat. We will not support nor assist anyone who attempts to bypass it."); + } + + if (!isProfileExist) + { + Config.AddGame(key, Path.GetDirectoryName(file.Path.LocalPath) ?? string.Empty); + Profiles.Add(new ProfileConfig(key)); + } } Config.Save(App.ConfigPath); } + [RelayCommand] + private void DeleteProfile() + { + if (SelectedProfile is not null) + { + Config.RemoveGame(SelectedProfile.Key); + Config.Save(App.ConfigPath); + } + RefreshProfileList(); + } + [RelayCommand] private void SelectProfile() { @@ -90,23 +154,23 @@ private void SelectProfile() Window? window = desktopLifetime.MainWindow; ProfileTaskWindowViewModel viewModel = new(); - + desktopLifetime.MainWindow = new ProfileTaskWindow { DataContext = viewModel }; - + desktopLifetime.MainWindow.Loaded += async (_, _) => { await viewModel.Setup(SelectedProfile.Key, SelectedProfile.Path); }; - + desktopLifetime.MainWindow.Show(); - + window?.Close(); } } - + [RelayCommand] private void Cancel() { diff --git a/FrostyEditor/Views/Windows/ProfileSelectWindow.axaml b/FrostyEditor/Views/Windows/ProfileSelectWindow.axaml index f99645287..951e6b158 100644 --- a/FrostyEditor/Views/Windows/ProfileSelectWindow.axaml +++ b/FrostyEditor/Views/Windows/ProfileSelectWindow.axaml @@ -3,9 +3,10 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:FrostyEditor.ViewModels.Windows" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + mc:Ignorable="d" + Width="1000" Height="600" x:Class="FrostyEditor.Views.Windows.ProfileSelectWindow" - Title="ProfileSelectWindow" + Title="{StaticResource ID_PROFILE_TITLE}" x:DataType="vm:ProfileSelectWindowViewModel" x:CompileBindings="True"> @@ -24,7 +25,7 @@ - + @@ -33,6 +34,7 @@