Keep the GUI alive when closing a game (#888)

* Keep the GUI alive when closing a game

Make HLE.Switch init when starting a game and dispose it when closing
the GlScreen.

This also make HLE in charge of disposing the audio and gpu backend.

* Address Ac_k's comments

* Make sure to dispose the Discord module and use GTK quit method

Also update Discord Precense when closing a game.

* Make sure to dispose MainWindow

* Address gdk's comments
This commit is contained in:
Thog 2020-01-21 23:23:11 +01:00 committed by Ac_K
parent b4b2b8b162
commit d6b9babe1d
16 changed files with 284 additions and 215 deletions

View file

@ -1,3 +1,7 @@
using LibHac;
using LibHac.Fs;
using LibHac.FsService;
using LibHac.FsSystem;
using Ryujinx.HLE.FileSystem.Content;
using Ryujinx.HLE.HOS;
using System;
@ -16,6 +20,16 @@ namespace Ryujinx.HLE.FileSystem
public static string SystemNandPath = Path.Combine(NandPath, "system");
public static string UserNandPath = Path.Combine(NandPath, "user");
public Keyset KeySet { get; private set; }
public FileSystemServer FsServer { get; private set; }
public FileSystemClient FsClient { get; private set; }
public EmulatedGameCard GameCard { get; private set; }
public VirtualFileSystem()
{
Reload();
}
public Stream RomFs { get; private set; }
public void LoadRomFs(string fileName)
@ -183,6 +197,69 @@ namespace Ryujinx.HLE.FileSystem
return Path.Combine(appDataPath, BasePath);
}
public void Reload()
{
ReloadKeySet();
LocalFileSystem serverBaseFs = new LocalFileSystem(GetBasePath());
DefaultFsServerObjects fsServerObjects = DefaultFsServerObjects.GetDefaultEmulatedCreators(serverBaseFs, KeySet);
GameCard = fsServerObjects.GameCard;
FileSystemServerConfig fsServerConfig = new FileSystemServerConfig
{
FsCreators = fsServerObjects.FsCreators,
DeviceOperator = fsServerObjects.DeviceOperator,
ExternalKeySet = KeySet.ExternalKeySet
};
FsServer = new FileSystemServer(fsServerConfig);
FsClient = FsServer.CreateFileSystemClient();
}
private void ReloadKeySet()
{
string keyFile = null;
string titleKeyFile = null;
string consoleKeyFile = null;
string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
LoadSetAtPath(Path.Combine(home, ".switch"));
LoadSetAtPath(GetSystemPath());
void LoadSetAtPath(string basePath)
{
string localKeyFile = Path.Combine(basePath, "prod.keys");
string localTitleKeyFile = Path.Combine(basePath, "title.keys");
string localConsoleKeyFile = Path.Combine(basePath, "console.keys");
if (File.Exists(localKeyFile))
{
keyFile = localKeyFile;
}
if (File.Exists(localTitleKeyFile))
{
titleKeyFile = localTitleKeyFile;
}
if (File.Exists(localConsoleKeyFile))
{
consoleKeyFile = localConsoleKeyFile;
}
}
KeySet = ExternalKeyReader.ReadKeyFile(keyFile, titleKeyFile, consoleKeyFile);
}
public void Unload()
{
RomFs?.Dispose();
}
public void Dispose()
{
Dispose(true);
@ -192,7 +269,7 @@ namespace Ryujinx.HLE.FileSystem
{
if (disposing)
{
RomFs?.Dispose();
Unload();
}
}
}