add more resilience to MCDF export and loading

This commit is contained in:
rootdarkarchon
2023-12-07 09:43:43 +01:00
parent bd32a55ce5
commit 8a197e6387
3 changed files with 52 additions and 31 deletions

View File

@@ -15,6 +15,8 @@ public class GposeUi : WindowMediatorSubscriberBase
private readonly DalamudUtilService _dalamudUtil;
private readonly FileDialogManager _fileDialogManager;
private readonly MareCharaFileManager _mareCharaFileManager;
private Task<long>? _expectedLength;
private Task? _applicationTask;
public GposeUi(ILogger<GposeUi> logger, MareCharaFileManager mareCharaFileManager,
DalamudUtilService dalamudUtil, FileDialogManager fileDialogManager, MareConfigService configService,
@@ -51,21 +53,28 @@ public class GposeUi : WindowMediatorSubscriberBase
_configService.Current.ExportFolder = Path.GetDirectoryName(path) ?? string.Empty;
_configService.Save();
_ = Task.Run(() => _mareCharaFileManager.LoadMareCharaFile(path));
_expectedLength = Task.Run(() => _mareCharaFileManager.LoadMareCharaFile(path));
}, 1, Directory.Exists(_configService.Current.ExportFolder) ? _configService.Current.ExportFolder : null);
}
UiSharedService.AttachToolTip("Applies it to the currently selected GPose actor");
if (_mareCharaFileManager.LoadedCharaFile != null)
if (_mareCharaFileManager.LoadedCharaFile != null && _expectedLength != null)
{
UiSharedService.TextWrapped("Loaded file: " + _mareCharaFileManager.LoadedCharaFile.FilePath);
UiSharedService.TextWrapped("File Description: " + _mareCharaFileManager.LoadedCharaFile.CharaFileData.Description);
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.Check, "Apply loaded MCDF"))
{
_ = Task.Run(async () => await _mareCharaFileManager.ApplyMareCharaFile(_dalamudUtil.GposeTargetGameObject).ConfigureAwait(false));
_applicationTask = Task.Run(async () => await _mareCharaFileManager.ApplyMareCharaFile(_dalamudUtil.GposeTargetGameObject, _expectedLength!.GetAwaiter().GetResult()).ConfigureAwait(false));
}
UiSharedService.AttachToolTip("Applies it to the currently selected GPose actor");
UiSharedService.ColorTextWrapped("Warning: redrawing or changing the character will revert all applied mods.", ImGuiColors.DalamudYellow);
}
if (_applicationTask?.IsFaulted ?? false)
{
UiSharedService.ColorTextWrapped("Failure to read MCDF file. MCDF file is possibly corrupt. Re-export the MCDF file and try again.",
ImGuiColors.DalamudRed);
UiSharedService.ColorTextWrapped("Note: if this is your MCDF, try redrawing yourself, wait and re-export the file. " +
"If you received it from someone else have them do the same.", ImGuiColors.DalamudYellow);
}
}
else
{
@@ -77,6 +86,8 @@ public class GposeUi : WindowMediatorSubscriberBase
private void EndGpose()
{
IsOpen = false;
_applicationTask = null;
_expectedLength = null;
_mareCharaFileManager.ClearMareCharaFile();
}

View File

@@ -54,6 +54,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
private Task<List<FileCacheEntity>>? _validationTask;
private CancellationTokenSource? _validationCts;
private (int, int, FileCacheEntity) _currentProgress;
private Task? _exportTask;
public SettingsUi(ILogger<SettingsUi> logger,
UiSharedService uiShared, MareConfigService configService,
@@ -439,17 +440,11 @@ public class SettingsUi : WindowMediatorSubscriberBase
_configService.Current.ExportFolder = Path.GetDirectoryName(path) ?? string.Empty;
_configService.Save();
_ = Task.Run(() =>
_exportTask = Task.Run(() =>
{
try
{
_mareCharaFileManager.SaveMareCharaFile(LastCreatedCharacterData, _exportDescription, path);
_exportDescription = string.Empty;
}
catch (Exception ex)
{
_logger.LogCritical(ex, "Error saving data");
}
var desc = _exportDescription;
_exportDescription = string.Empty;
_mareCharaFileManager.SaveMareCharaFile(LastCreatedCharacterData, desc, path);
});
}, Directory.Exists(_configService.Current.ExportFolder) ? _configService.Current.ExportFolder : null);
}
@@ -461,6 +456,11 @@ public class SettingsUi : WindowMediatorSubscriberBase
UiSharedService.ColorTextWrapped("Export in progress", ImGuiColors.DalamudYellow);
}
if (_exportTask?.IsFaulted ?? false)
{
UiSharedService.ColorTextWrapped("Export failed, check /xllog for more details.", ImGuiColors.DalamudRed);
}
ImGui.Unindent();
}
bool openInGpose = _configService.Current.OpenGposeImportOnGposeStart;