Skip to content

Commit

Permalink
[Editor] Fixed issue where editor mods did not get removed (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoushou1106 committed Aug 8, 2023
1 parent 1b34dcc commit d0e9a65
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
31 changes: 25 additions & 6 deletions FrostyEditor/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,19 +386,25 @@ private void launchButton_Click(object sender, RoutedEventArgs e)
// setup ability to cancel the process
CancellationTokenSource cancelToken = new CancellationTokenSource();

Random r = new Random();
string editorModName = $"EditorMod{r.Next(1000, 9999).ToString("D4")}.fbmod";
launchButton.IsEnabled = false;

// get all mods
List<string> modPaths = new List<string>();

DirectoryInfo modDirectory = new DirectoryInfo($"Mods/{ProfilesLibrary.ProfileName}");
foreach (string modPath in Directory.EnumerateFiles($"Mods/{ProfilesLibrary.ProfileName}/", "*.fbmod", SearchOption.AllDirectories))
modPaths.Add(Path.GetFileName(modPath));

{
if(Path.GetFileName(modPath).Contains("EditorMod"))
File.Delete(modPath);
else
modPaths.Add(Path.GetFileName(modPath));
}

Random r = new Random();
string editorModName = $"EditorMod_{r.Next(1000, 9999).ToString("D4")}.fbmod";

// create temporary editor mod
ModSettings editorSettings = new ModSettings { Title = "Editor Mod", Author = "Frosty Editor", Version = "1", Category = "Editor" };
ModSettings editorSettings = new ModSettings { Title = editorModName, Author = "Frosty Editor", Version = App.Version, Category = "Editor"};

// apply mod
string additionalArgs = Config.Get<string>("CommandLineArgs", "", ConfigScope.Game) + " ";
Expand All @@ -420,13 +426,26 @@ private void launchButton_Click(object sender, RoutedEventArgs e)
task.Update("Exporting Mod");
ExportMod(editorSettings, $"Mods/{ProfilesLibrary.ProfileName}/{editorModName}", true);
modPaths.Add(editorModName);
App.Logger.Log("Editor temporary Mod saved to {0}", $"Mods/{ProfilesLibrary.ProfileName}/{editorModName}");
// allow cancelling in case of a big mod (will cancel after processing the mod)
// @todo: add cancellation to different stages of mod exportation, to allow cancelling
// at any stage of a large mod
cancelToken.Token.ThrowIfCancellationRequested();
// Remove mods.json
task.Update("Removing mods.json");
string gamePatchPath = "Patch";
if (ProfilesLibrary.DataVersion == (int)ProfileVersion.Fifa17 || ProfilesLibrary.DataVersion == (int)ProfileVersion.DragonAgeInquisition || ProfilesLibrary.DataVersion == (int)ProfileVersion.Battlefield4 || ProfilesLibrary.DataVersion == (int)ProfileVersion.NeedForSpeed || ProfilesLibrary.DataVersion == (int)ProfileVersion.PlantsVsZombiesGardenWarfare2 || ProfilesLibrary.DataVersion == (int)ProfileVersion.NeedForSpeedRivals)
gamePatchPath = "Update\\Patch\\Data";
else if (ProfilesLibrary.DataVersion == (int)ProfileVersion.PlantsVsZombiesBattleforNeighborville || ProfilesLibrary.DataVersion == (int)ProfileVersion.Battlefield5) //bfn and bfv dont have a patch directory
gamePatchPath = "Data";
if (File.Exists(App.FileSystem.BasePath + $"\\ModData\\{App.SelectedPack}\\{gamePatchPath}\\mods.json"))
{
File.Delete(App.FileSystem.BasePath + $"\\ModData\\{App.SelectedPack}\\{gamePatchPath}\\mods.json");
App.Logger.Log("Removed mods.json");
}
task.Update("");
executor.Run(App.FileSystem, cancelToken.Token, task.TaskLogger, $"Mods/{ProfilesLibrary.ProfileName}/", App.SelectedPack, additionalArgs.Trim(), modPaths.ToArray());
Expand Down
2 changes: 1 addition & 1 deletion FrostyEditor/Windows/PrelaunchWindow2.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void IterateSubKeys(RegistryKey subKey, ref int totalCount)

private void RemoveConfigButton_Click(object sender, RoutedEventArgs e)
{
if (FrostyMessageBox.Show("Are you sure you want to delete this configuration?", "Frosty Mod Manager", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
if (FrostyMessageBox.Show("Are you sure you want to delete this configuration?", "Frosty Editor", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
FrostyConfiguration selectedItem = ConfigList.SelectedItem as FrostyConfiguration;

Expand Down
4 changes: 4 additions & 0 deletions FrostyModSupport/FrostyModExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,10 @@ public int Run(FileSystem inFs, CancellationToken cancelToken, ILogger inLogger,
// create the frosty mod list file
File.WriteAllText(Path.Combine(modDataPath, patchPath, "mods.json"), JsonConvert.SerializeObject(GenerateModInfoList(modPaths, rootPath), Formatting.Indented));
}
else
{
App.Logger.Log("Launching with previously generated data.");
}

cancelToken.ThrowIfCancellationRequested();

Expand Down

0 comments on commit d0e9a65

Please sign in to comment.