diff --git a/FrostyModManager/Windows/AddProfileWindow.xaml.cs b/FrostyModManager/Windows/AddProfileWindow.xaml.cs index b4d92ad71..85d6dc793 100644 --- a/FrostyModManager/Windows/AddProfileWindow.xaml.cs +++ b/FrostyModManager/Windows/AddProfileWindow.xaml.cs @@ -10,10 +10,12 @@ public partial class AddProfileWindow : FrostyDockableWindow { public string ProfileName { get; set; } - public AddProfileWindow() + public AddProfileWindow(string title = "Add Profile") { InitializeComponent(); + this.Title = title; + Window mainWin = Application.Current.MainWindow; if (mainWin != null) { diff --git a/FrostyModManager/Windows/MainWindow.xaml b/FrostyModManager/Windows/MainWindow.xaml index a92bfe4d3..c969e1e2d 100644 --- a/FrostyModManager/Windows/MainWindow.xaml +++ b/FrostyModManager/Windows/MainWindow.xaml @@ -92,6 +92,8 @@ + + diff --git a/FrostyModManager/Windows/MainWindow.xaml.cs b/FrostyModManager/Windows/MainWindow.xaml.cs index bc50d52fc..14fa44634 100644 --- a/FrostyModManager/Windows/MainWindow.xaml.cs +++ b/FrostyModManager/Windows/MainWindow.xaml.cs @@ -487,6 +487,68 @@ private void removeProfileButton_Click(object sender, RoutedEventArgs e) } } + private void packRename_Click(object sender, RoutedEventArgs e) { + + AddProfileWindow win = new AddProfileWindow("Rename Pack"); + win.ShowDialog(); + + if (win.DialogResult == true) { + string newPackName = win.ProfileName; + var oldPack = selectedPack; + + FrostyPack existingPack = packs.Find((FrostyPack a) => { + return a.Name.CompareTo(newPackName) == 0; + }); + + if (existingPack == null) { + Config.Rename(oldPack.Name, newPackName, ConfigScope.Pack); + + FrostyPack newPack = new FrostyPack(newPackName); + foreach (var mod in oldPack.AppliedMods) { + newPack.AppliedMods.Add(mod); + } + + packs.Add(newPack); + packs.Remove(oldPack); + + packsComboBox.Items.Refresh(); + packsComboBox.SelectedItem = newPack; + } + else FrostyMessageBox.Show("A pack with the same name already exists", "Frosty Mod Manager"); + + } + } + + private void packDuplicate_Click(object sender, RoutedEventArgs e) { + + AddProfileWindow win = new AddProfileWindow("Duplicate Pack"); + win.ShowDialog(); + + if (win.DialogResult == true) { + string newPackName = win.ProfileName; + var oldPack = selectedPack; + + FrostyPack existingPack = packs.Find((FrostyPack a) => { + return a.Name.CompareTo(newPackName) == 0; + }); + + if (existingPack == null) { + Config.Add(newPackName, ConfigScope.Pack); + + FrostyPack newPack = new FrostyPack(newPackName); + foreach (var mod in oldPack.AppliedMods) { + newPack.AppliedMods.Add(mod); + } + + packs.Add(newPack); + + packsComboBox.Items.Refresh(); + packsComboBox.SelectedItem = newPack; + } + else FrostyMessageBox.Show("A pack with the same name already exists", "Frosty Mod Manager"); + } + } + private void removeButton_Click(object sender, RoutedEventArgs e) { FrostyAppliedMod mod = appliedModsList.SelectedItem as FrostyAppliedMod; diff --git a/FrostyPlugin/Config.cs b/FrostyPlugin/Config.cs index 1b5119aac..08e0ec391 100644 --- a/FrostyPlugin/Config.cs +++ b/FrostyPlugin/Config.cs @@ -58,6 +58,17 @@ internal void Remove(string option, ConfigScope scope = ConfigScope.Game) } } + internal void Rename(string option, string newoption, ConfigScope scope = ConfigScope.Game) { + if (scope == ConfigScope.Pack) { + if (Packs.ContainsKey(option)) { + Packs.TryGetValue(option, out var value); + Packs.Add(newoption, value); + Packs.Remove(option); + } + + } + } + internal IEnumerable EnumerateKeys(ConfigScope scope = ConfigScope.Game) { if (scope == ConfigScope.Game) @@ -169,6 +180,13 @@ public static void Remove(string option, ConfigScope scope = ConfigScope.Global, Current.GlobalOptions.Remove(option); } + public static void Rename(string option, string newoption, ConfigScope scope = ConfigScope.Global, string profile = null) { + if (scope == ConfigScope.Game || scope == ConfigScope.Pack) + Current.Games[profile ?? ProfilesLibrary.ProfileName].Rename(option, newoption, scope); + else if (Current.GlobalOptions.ContainsKey(option)) + Current.GlobalOptions.Remove(option); + } + /// /// Determines whether the contains the specified key. ///