Skip to content

Commit

Permalink
hope vs dont add space
Browse files Browse the repository at this point in the history
  • Loading branch information
shoushou1106 committed Aug 28, 2023
1 parent af67c71 commit 1dd7706
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 50 deletions.
9 changes: 3 additions & 6 deletions FrostyEditor/Utils/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,11 @@ public static IEnumerable<string> GameProfiles
/// </summary>
/// <param name="profile">The profile name.</param>
/// <param name="gamePath">The path to the game.</param>
public static void AddGame(string profile, string gamePath)
public static bool AddGame(string profile, string gamePath)
{
s_current ??= new InternalConfig();

if (!s_current.Games.ContainsKey(profile))
{
s_current.Games.Add(profile, new GameOptions(gamePath));
}

return s_current.Games.TryAdd(profile, new GameOptions(gamePath));
}

/// <summary>
Expand Down
50 changes: 6 additions & 44 deletions FrostyEditor/ViewModels/Windows/ProfileSelectWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Frosty.Sdk;
using Frosty.Sdk.Profiles;
using FrostyEditor.Utils;
using FrostyEditor.Views;
using FrostyEditor.Views.Windows;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace FrostyEditor.ViewModels.Windows;

Expand Down Expand Up @@ -44,11 +46,6 @@ public ProfileSelectWindowViewModel()
// init ProfilesLibrary to load all profile json files
ProfilesLibrary.Initialize();

RefreshProfileList();
}

public void RefreshProfileList()
{
Profiles.Clear();
foreach (string profile in Config.GameProfiles)
{
Expand All @@ -68,25 +65,9 @@ public void RefreshProfileList()
[RelayCommand]
private async Task AddProfile()
{
FilePickerFileType Exe = 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" }
};

IReadOnlyList<IStorageFile>? files = await FileService.OpenFilesAsync(new FilePickerOpenOptions
{
Title = "Select Game Executable",
FileTypeFilter = new[]
{
Exe
#if DEBUG
, FilePickerFileTypes.All
#endif
},
AllowMultiple = false
});

Expand All @@ -107,28 +88,8 @@ private async Task AddProfile()
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)
if (Config.AddGame(key, Path.GetDirectoryName(file.Path.LocalPath) ?? string.Empty))
{
Config.AddGame(key, Path.GetDirectoryName(file.Path.LocalPath) ?? string.Empty);
Profiles.Add(new ProfileConfig(key));
}
}
Expand All @@ -140,10 +101,11 @@ private void DeleteProfile()
{
if (SelectedProfile is not null)
{
Config.RemoveGame(SelectedProfile.Key);
ProfileConfig config = new(SelectedProfile.Key);
Config.RemoveGame(config.Key);
Profiles.Remove(config);
Config.Save(App.ConfigPath);
}
RefreshProfileList();
}

[RelayCommand]
Expand Down

0 comments on commit 1dd7706

Please sign in to comment.