Skip to content

Commit

Permalink
FMTProj compatibility with "other" games
Browse files Browse the repository at this point in the history
  • Loading branch information
paulov-t committed May 1, 2023
1 parent 7469a2a commit 9047c65
Showing 1 changed file with 55 additions and 21 deletions.
76 changes: 55 additions & 21 deletions FrostbiteModdingUI/Windows/DefaultEditor.xaml.cs
Expand Up @@ -13,6 +13,7 @@
using FrostySdk.Frostbite;
using FrostySdk.IO;
using FrostySdk.Managers;
using FrostySdk.ModsAndProjects.Projects;
using MahApps.Metro.Controls;
using Microsoft.Win32;
using Newtonsoft.Json;
Expand Down Expand Up @@ -473,44 +474,77 @@ private async void btnProjectSave_Click(object sender, RoutedEventArgs e)
await SaveProjectWithDialog();
}

private async Task<bool> SaveProjectWithDialog()
public virtual async Task<bool> SaveProjectWithDialog()
{
loadingDialog.Update("Saving Project", "Sweeping up debris", 0);
loadingDialog.UpdateAsync("Saving Project", "Sweeping up debris", 0);
//borderLoading.Visibility = Visibility.Visible;
//loadingDialog.Show();
await Task.Delay(100);
// ---------------------------------------------------------
// Remove chunks and actual unmodified files before writing
ChunkFileManager2022.CleanUpChunks();

loadingDialog.Update("", "");

//ChunkFileManager2022.CleanUpChunks();

await loadingDialog.UpdateAsync("", "");

SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Project files|*.fbproject";
saveFileDialog.Filter = "FMTProject files|*.fmtproj|FBProject files|*.fbproject|All Files (*.*)|*.*";
var result = saveFileDialog.ShowDialog();
if (result.HasValue && result.Value)
{
if (!string.IsNullOrEmpty(saveFileDialog.FileName))
{
loadingDialog.Update("Saving Project", "Saving project to file", 0);
//loadingDialog.Show();
await ProjectManagement.Project.SaveAsync(saveFileDialog.FileName, true);

Log("Saved project successfully to " + saveFileDialog.FileName);
if (!result.HasValue || !result.Value)
return false;

UpdateWindowTitle(saveFileDialog.FileName);
if (string.IsNullOrEmpty(saveFileDialog.FileName))
return false;

DiscordInterop.DiscordRpcClient.UpdateDetails("In Editor [" + GameInstanceSingleton.Instance.GAMEVERSION + "] - " + ProjectManagement.Project.DisplayName);
await loadingDialog.UpdateAsync("Saving Project", "Saving project to file");

// FMT Project file type
if (saveFileDialog.FileName.EndsWith(".fmtproj", StringComparison.OrdinalIgnoreCase))
{
//MessageBox.Show("FMTProj file type is EXPERIMENTAL. If concerned, use fbproject instead.");

// Same file -- Simple Update
if (ProjectManagement.Project is FMTProject fmtProj && fmtProj.Filename.Equals(saveFileDialog.FileName, StringComparison.OrdinalIgnoreCase))
fmtProj.Update();
// Different file -- Create new file and Update
else
{
var storedPreviousModSettings = ProjectManagement.Project.ModSettings.CloneJson();

ProjectManagement.Project = new FMTProject(saveFileDialog.FileName);
ProjectManagement.Project.ModSettings.UpdateFromOtherModSettings(storedPreviousModSettings);
((FMTProject)ProjectManagement.Project).Update();
}
}
loadingDialog.Update("", "");
// Legacy fbproject file type
else if (saveFileDialog.FileName.EndsWith(".fbproject", StringComparison.OrdinalIgnoreCase))
{
// Same file -- Simple Update
if (ProjectManagement.Project is FrostbiteProject fbProj)
await fbProj.SaveAsync(saveFileDialog.FileName, true);
// Different file -- Create new file and Update
else
{
ModSettings modSettings = ProjectManagement.Project.ModSettings.CloneJson();
ProjectManagement.Project = new FrostbiteProject();
ProjectManagement.Project.ModSettings.Author = modSettings.Author;
ProjectManagement.Project.ModSettings.Description = modSettings.Description;
ProjectManagement.Project.ModSettings.Title = modSettings.Title;
ProjectManagement.Project.ModSettings.Version = modSettings.Version;
await ProjectManagement.Project.SaveAsync(saveFileDialog.FileName, true);
}
}
// Unknown File
else
{
Log("Unknown file type detected. Project failed to save to " + saveFileDialog.FileName);
return false;
}

Log("Saved project successfully to " + saveFileDialog.FileName);
UpdateWindowTitle(saveFileDialog.FileName);

await loadingDialog.UpdateAsync("", "");

//loadingDialog.Close();
//loadingDialog = null;
return true;
}

Expand Down

0 comments on commit 9047c65

Please sign in to comment.