Clean the SD card save directory when opening the emulator (#2564)

Cleans "sdcard:/Nintendo/save" and deletes "sdcard:/save" when opening the emulator.

Works around invalid encryption when keys or the SD card encryption seed are changed.
This commit is contained in:
Alex Barney 2021-08-20 13:36:14 -07:00 committed by GitHub
parent 97aedc030d
commit e0af248e6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 34 deletions

View file

@ -9,8 +9,6 @@ namespace Ryujinx.HLE.FileSystem
{
public class EncryptedFileSystemCreator : IEncryptedFileSystemCreator
{
public EncryptedFileSystemCreator() { }
public Result Create(out ReferenceCountedDisposable<IFileSystem> encryptedFileSystem, ReferenceCountedDisposable<IFileSystem> baseFileSystem,
EncryptedFsKeyId keyId, in EncryptionSeed encryptionSeed)
{
@ -23,40 +21,9 @@ namespace Ryujinx.HLE.FileSystem
// Force all-zero keys for now since people can open the emulator with different keys or sd seeds sometimes
var fs = new AesXtsFileSystem(baseFileSystem, new byte[0x32], 0x4000);
var aesFileSystem = new ReferenceCountedDisposable<IFileSystem>(fs);
// This wrapper will handle deleting files that were created with different keys
var wrappedFs = new ChangedEncryptionHandlingFileSystem(aesFileSystem);
encryptedFileSystem = new ReferenceCountedDisposable<IFileSystem>(wrappedFs);
encryptedFileSystem = new ReferenceCountedDisposable<IFileSystem>(fs);
return Result.Success;
}
}
public class ChangedEncryptionHandlingFileSystem : ForwardingFileSystem
{
public ChangedEncryptionHandlingFileSystem(ReferenceCountedDisposable<IFileSystem> baseFileSystem) : base(baseFileSystem) { }
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
{
UnsafeHelpers.SkipParamInit(out file);
try
{
return base.DoOpenFile(out file, path, mode);
}
catch (HorizonResultException ex)
{
if (ResultFs.AesXtsFileHeaderInvalidKeys.Includes(ex.ResultValue))
{
Result rc = DeleteFile(path);
if (rc.IsFailure()) return rc;
return base.DoOpenFile(out file, path, mode);
}
throw;
}
}
}
}