Skip to content

Commit

Permalink
Better error message for unsupported files
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkey85 committed Dec 30, 2023
1 parent 3e8428d commit 7fd0f67
Showing 1 changed file with 69 additions and 3 deletions.
72 changes: 69 additions & 3 deletions Pkmds.Web/Layout/MainLayout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,80 @@ private async Task ExportSaveFileAsync()
{
return;
}
switch ((GameVersion)AppState.SaveFile.Game)
{
case GameVersion.BD:
case GameVersion.SP:
case GameVersion.BDSP:
await ExportBdsp();
break;
case GameVersion.SN:
case GameVersion.MN:
case GameVersion.SM:
case GameVersion.US:
case GameVersion.UM:
case GameVersion.USUM:
await ExportSmUsUm();
break;
default:
await ExportSupportedSaveFile();
break;
};
}

private async Task ExportSupportedSaveFile()
{
if (AppState.SaveFile is null)
{
return;
}
AppState.ShowProgressIndicator = true;

await WriteFile(AppState.SaveFile.Write(), browserLoadSaveFile?.Name ?? "save.sav");

AppState.ShowProgressIndicator = false;
}

private bool IsWebAssembly() => JSRuntime is IJSInProcessRuntime;

private const string UnsupportedSaveFileExportMessage =
"Save export not supported for BDSP, Sun / Moon, or Ultra Sun / Moon at this time. " +
"See: https://github.com/codemonkey85/PKMDS-Blazor/issues/12#issuecomment-1872579636";

private async Task ExportSmUsUm()
{
if (AppState.SaveFile is null)
{
return;
}

if (!IsWebAssembly())
{
await ExportSupportedSaveFile();
return;
}

await DialogService.ShowMessageBox(
"Unsupported File",
UnsupportedSaveFileExportMessage);
}

private async Task ExportBdsp()
{
if (AppState.SaveFile is null)
{
return;
}

if (!IsWebAssembly())
{
await ExportSupportedSaveFile();
return;
}

await DialogService.ShowMessageBox(
"Unsupported File",
UnsupportedSaveFileExportMessage);
}

private async Task ExportSelectedPokemonAsync()
{
if (AppService.EditFormPokemon is null)
Expand Down Expand Up @@ -114,7 +180,7 @@ private async Task WriteFile(byte[] data, string fileName)
try
{
await using var fileHandle = await FileSystemAccessService.ShowSaveFilePickerAsync(
new KristofferStrube.Blazor.FileSystemAccess.SaveFilePickerOptionsStartInFileSystemHandle
new SaveFilePickerOptionsStartInFileSystemHandle
{
SuggestedName = fileName,
});
Expand Down

1 comment on commit 7fd0f67

@codemonkey85
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to help address #12. Not a solution, but a better error message anyway.

Please sign in to comment.