private void AddUpdate(string path, bool showErrorDialog = true) { if (File.Exists(path)) { using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read)) { PartitionFileSystem nsp = new PartitionFileSystem(file.AsStorage()); try { (Nca patchNca, Nca controlNca) = ApplicationLoader.GetGameUpdateDataFromPartition(_virtualFileSystem, nsp, _titleId, 0); if (controlNca != null && patchNca != null) { ApplicationControlProperty controlData = new ApplicationControlProperty(); controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None).OpenFile(out IFile nacpFile, "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure(); nacpFile.Read(out _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None).ThrowIfFailure(); RadioButton radioButton = new RadioButton($"Version {controlData.DisplayVersion.ToString()} - {path}"); radioButton.JoinGroup(_noUpdateRadioButton); _availableUpdatesBox.Add(radioButton); _radioButtonToPathDictionary.Add(radioButton, path); radioButton.Show(); radioButton.Active = true; } else { GtkDialog.CreateErrorDialog("The specified file does not contain an update for the selected title!"); } } catch (InvalidDataException exception) { Logger.Error?.Print(LogClass.Application, $"{exception.Message}. Errored File: {path}"); if (showErrorDialog) { GtkDialog.CreateInfoDialog("Ryujinx - Error", "Add Update Failed!", "The NCA header content type check has failed. This is usually because the header key is incorrect or missing."); } } catch (MissingKeyException exception) { Logger.Error?.Print(LogClass.Application, $"Your key set is missing a key with the name: {exception.Name}. Errored File: {path}"); if (showErrorDialog) { GtkDialog.CreateInfoDialog("Ryujinx - Error", "Add Update Failed!", $"Your key set is missing a key with the name: {exception.Name}"); } } } } }
private Nca TryCreateNca(IStorage ncaStorage, string containerPath) { try { return(new Nca(_virtualFileSystem.KeySet, ncaStorage)); } catch (InvalidDataException exception) { Logger.Error?.Print(LogClass.Application, $"{exception.Message}. Errored File: {containerPath}"); GtkDialog.CreateInfoDialog("Ryujinx - Error", "Add DLC Failed!", "The NCA header content type check has failed. This is usually because the header key is incorrect or missing."); } catch (MissingKeyException exception) { Logger.Error?.Print(LogClass.Application, $"Your key set is missing a key with the name: {exception.Name}. Errored File: {containerPath}"); GtkDialog.CreateInfoDialog("Ryujinx - Error", "Add DLC Failed!", $"Your key set is missing a key with the name: {exception.Name}"); } return(null); }
public void LoadApplication(string path) { if (_gameLoaded) { GtkDialog.CreateInfoDialog("A game has already been loaded", "Please close it first and try again."); } else { PerformanceCheck(); Logger.RestartTime(); InitializeSwitchInstance(); UpdateGraphicsConfig(); SystemVersion firmwareVersion = _contentManager.GetCurrentFirmwareVersion(); bool isDirectory = Directory.Exists(path); if (!SetupValidator.CanStartApplication(_contentManager, path, out UserError userError)) { if (SetupValidator.CanFixStartApplication(_contentManager, path, userError, out firmwareVersion)) { if (userError == UserError.NoFirmware) { string message = $"Would you like to install the firmware embedded in this game? (Firmware {firmwareVersion.VersionString})"; ResponseType responseDialog = (ResponseType)GtkDialog.CreateConfirmationDialog("No Firmware Installed", message).Run(); if (responseDialog != ResponseType.Yes) { UserErrorDialog.CreateUserErrorDialog(userError); _emulationContext.Dispose(); return; } } if (!SetupValidator.TryFixStartApplication(_contentManager, path, userError, out _)) { UserErrorDialog.CreateUserErrorDialog(userError); _emulationContext.Dispose(); return; } // Tell the user that we installed a firmware for them. if (userError == UserError.NoFirmware) { firmwareVersion = _contentManager.GetCurrentFirmwareVersion(); RefreshFirmwareLabel(); string message = $"No installed firmware was found but Ryujinx was able to install firmware {firmwareVersion.VersionString} from the provided game.\nThe emulator will now start."; GtkDialog.CreateInfoDialog($"Firmware {firmwareVersion.VersionString} was installed", message); } } else { UserErrorDialog.CreateUserErrorDialog(userError); _emulationContext.Dispose(); return; } } Logger.Notice.Print(LogClass.Application, $"Using Firmware Version: {firmwareVersion?.VersionString}"); if (Directory.Exists(path)) { string[] romFsFiles = Directory.GetFiles(path, "*.istorage"); if (romFsFiles.Length == 0) { romFsFiles = Directory.GetFiles(path, "*.romfs"); } if (romFsFiles.Length > 0) { Logger.Info?.Print(LogClass.Application, "Loading as cart with RomFS."); _emulationContext.LoadCart(path, romFsFiles[0]); } else { Logger.Info?.Print(LogClass.Application, "Loading as cart WITHOUT RomFS."); _emulationContext.LoadCart(path); } } else if (File.Exists(path)) { switch (System.IO.Path.GetExtension(path).ToLowerInvariant()) { case ".xci": Logger.Info?.Print(LogClass.Application, "Loading as XCI."); _emulationContext.LoadXci(path); break; case ".nca": Logger.Info?.Print(LogClass.Application, "Loading as NCA."); _emulationContext.LoadNca(path); break; case ".nsp": case ".pfs0": Logger.Info?.Print(LogClass.Application, "Loading as NSP."); _emulationContext.LoadNsp(path); break; default: Logger.Info?.Print(LogClass.Application, "Loading as homebrew."); try { _emulationContext.LoadProgram(path); } catch (ArgumentOutOfRangeException) { Logger.Error?.Print(LogClass.Application, "The file which you have specified is unsupported by Ryujinx."); } break; } } else { Logger.Warning?.Print(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file."); _emulationContext.Dispose(); return; } _currentEmulatedGamePath = path; _deviceExitStatus.Reset(); Translator.IsReadyForTranslation.Reset(); #if MACOS_BUILD CreateGameWindow(); #else Thread windowThread = new Thread(() => { CreateGameWindow(); }) { Name = "GUI.WindowThread" }; windowThread.Start(); #endif _gameLoaded = true; _stopEmulation.Sensitive = true; _simulateWakeUpMessage.Sensitive = true; _firmwareInstallFile.Sensitive = false; _firmwareInstallDirectory.Sensitive = false; DiscordIntegrationModule.SwitchToPlayingState(_emulationContext.Application.TitleIdText, _emulationContext.Application.TitleName); _applicationLibrary.LoadAndSaveMetaData(_emulationContext.Application.TitleIdText, appMetadata => { appMetadata.LastPlayed = DateTime.UtcNow.ToString(); }); } }
private void HandleInstallerDialog(FileChooserDialog fileChooser) { if (fileChooser.Run() == (int)ResponseType.Accept) { try { string filename = fileChooser.Filename; fileChooser.Dispose(); SystemVersion firmwareVersion = _contentManager.VerifyFirmwarePackage(filename); string dialogTitle = $"Install Firmware {firmwareVersion.VersionString}"; if (firmwareVersion == null) { GtkDialog.CreateErrorDialog($"A valid system firmware was not found in {filename}."); return; } SystemVersion currentVersion = _contentManager.GetCurrentFirmwareVersion(); string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed."; if (currentVersion != null) { dialogMessage += $"\n\nThis will replace the current system version {currentVersion.VersionString}. "; } dialogMessage += "\n\nDo you want to continue?"; ResponseType responseInstallDialog = (ResponseType)GtkDialog.CreateConfirmationDialog(dialogTitle, dialogMessage).Run(); MessageDialog waitingDialog = GtkDialog.CreateWaitingDialog(dialogTitle, "Installing firmware..."); if (responseInstallDialog == ResponseType.Yes) { Logger.Info?.Print(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}"); Thread thread = new Thread(() => { Application.Invoke(delegate { waitingDialog.Run(); }); try { _contentManager.InstallFirmware(filename); Application.Invoke(delegate { waitingDialog.Dispose(); string message = $"System version {firmwareVersion.VersionString} successfully installed."; GtkDialog.CreateInfoDialog(dialogTitle, message); Logger.Info?.Print(LogClass.Application, message); }); } catch (Exception ex) { Application.Invoke(delegate { waitingDialog.Dispose(); GtkDialog.CreateErrorDialog(ex.Message); }); } finally { RefreshFirmwareLabel(); } }); thread.Name = "GUI.FirmwareInstallerThread"; thread.Start(); } } catch (LibHac.MissingKeyException ex) { Logger.Error?.Print(LogClass.Application, ex.ToString()); UserErrorDialog.CreateUserErrorDialog(UserError.NoKeys); } catch (Exception ex) { GtkDialog.CreateErrorDialog(ex.Message); } } else { fileChooser.Dispose(); } }
internal void LoadApplication(string path) { if (_gameLoaded) { GtkDialog.CreateInfoDialog("Ryujinx", "A game has already been loaded", "Please close it first and try again."); } else { if (ConfigurationState.Instance.Logger.EnableDebug.Value) { MessageDialog debugWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null) { Title = "Ryujinx - Warning", Text = "You have debug logging enabled, which is designed to be used by developers only.", SecondaryText = "For optimal performance, it's recommended to disable debug logging. Would you like to disable debug logging now?" }; if (debugWarningDialog.Run() == (int)ResponseType.Yes) { ConfigurationState.Instance.Logger.EnableDebug.Value = false; SaveConfig(); } debugWarningDialog.Dispose(); } if (!string.IsNullOrWhiteSpace(ConfigurationState.Instance.Graphics.ShadersDumpPath.Value)) { MessageDialog shadersDumpWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null) { Title = "Ryujinx - Warning", Text = "You have shader dumping enabled, which is designed to be used by developers only.", SecondaryText = "For optimal performance, it's recommended to disable shader dumping. Would you like to disable shader dumping now?" }; if (shadersDumpWarningDialog.Run() == (int)ResponseType.Yes) { ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = ""; SaveConfig(); } shadersDumpWarningDialog.Dispose(); } Logger.RestartTime(); HLE.Switch device = InitializeSwitchInstance(); UpdateGraphicsConfig(); Logger.Notice.Print(LogClass.Application, $"Using Firmware Version: {_contentManager.GetCurrentFirmwareVersion()?.VersionString}"); if (Directory.Exists(path)) { string[] romFsFiles = Directory.GetFiles(path, "*.istorage"); if (romFsFiles.Length == 0) { romFsFiles = Directory.GetFiles(path, "*.romfs"); } if (romFsFiles.Length > 0) { Logger.Info?.Print(LogClass.Application, "Loading as cart with RomFS."); device.LoadCart(path, romFsFiles[0]); } else { Logger.Info?.Print(LogClass.Application, "Loading as cart WITHOUT RomFS."); device.LoadCart(path); } } else if (File.Exists(path)) { switch (System.IO.Path.GetExtension(path).ToLowerInvariant()) { case ".xci": Logger.Info?.Print(LogClass.Application, "Loading as XCI."); device.LoadXci(path); break; case ".nca": Logger.Info?.Print(LogClass.Application, "Loading as NCA."); device.LoadNca(path); break; case ".nsp": case ".pfs0": Logger.Info?.Print(LogClass.Application, "Loading as NSP."); device.LoadNsp(path); break; default: Logger.Info?.Print(LogClass.Application, "Loading as homebrew."); try { device.LoadProgram(path); } catch (ArgumentOutOfRangeException) { Logger.Error?.Print(LogClass.Application, "The file which you have specified is unsupported by Ryujinx."); } break; } } else { Logger.Warning?.Print(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file."); device.Dispose(); return; } _emulationContext = device; _deviceExitStatus.Reset(); #if MACOS_BUILD CreateGameWindow(device); #else Thread windowThread = new Thread(() => { CreateGameWindow(device); }) { Name = "GUI.WindowThread" }; windowThread.Start(); #endif _gameLoaded = true; _stopEmulation.Sensitive = true; _firmwareInstallFile.Sensitive = false; _firmwareInstallDirectory.Sensitive = false; DiscordIntegrationModule.SwitchToPlayingState(device.Application.TitleIdText, device.Application.TitleName); ApplicationLibrary.LoadAndSaveMetaData(device.Application.TitleIdText, appMetadata => { appMetadata.LastPlayed = DateTime.UtcNow.ToString(); }); } }