SetupValidator.cs
1 using Ryujinx.Common.Logging; 2 using Ryujinx.HLE.FileSystem; 3 using System; 4 using System.IO; 5 6 namespace Ryujinx.UI.Common.Helper 7 { 8 /// <summary> 9 /// Ensure installation validity 10 /// </summary> 11 public static class SetupValidator 12 { 13 public static bool IsFirmwareValid(ContentManager contentManager, out UserError error) 14 { 15 bool hasFirmware = contentManager.GetCurrentFirmwareVersion() != null; 16 17 if (hasFirmware) 18 { 19 error = UserError.Success; 20 21 return true; 22 } 23 24 error = UserError.NoFirmware; 25 26 return false; 27 } 28 29 public static bool CanFixStartApplication(ContentManager contentManager, string baseApplicationPath, UserError error, out SystemVersion firmwareVersion) 30 { 31 try 32 { 33 firmwareVersion = contentManager.VerifyFirmwarePackage(baseApplicationPath); 34 } 35 catch (Exception) 36 { 37 firmwareVersion = null; 38 } 39 40 return error == UserError.NoFirmware && Path.GetExtension(baseApplicationPath).ToLowerInvariant() == ".xci" && firmwareVersion != null; 41 } 42 43 public static bool TryFixStartApplication(ContentManager contentManager, string baseApplicationPath, UserError error, out UserError outError) 44 { 45 if (error == UserError.NoFirmware) 46 { 47 string baseApplicationExtension = Path.GetExtension(baseApplicationPath).ToLowerInvariant(); 48 49 // If the target app to start is a XCI, try to install firmware from it 50 if (baseApplicationExtension == ".xci") 51 { 52 SystemVersion firmwareVersion; 53 54 try 55 { 56 firmwareVersion = contentManager.VerifyFirmwarePackage(baseApplicationPath); 57 } 58 catch (Exception) 59 { 60 firmwareVersion = null; 61 } 62 63 // The XCI is a valid firmware package, try to install the firmware from it! 64 if (firmwareVersion != null) 65 { 66 try 67 { 68 Logger.Info?.Print(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}"); 69 70 contentManager.InstallFirmware(baseApplicationPath); 71 72 Logger.Info?.Print(LogClass.Application, $"System version {firmwareVersion.VersionString} successfully installed."); 73 74 outError = UserError.Success; 75 76 return true; 77 } 78 catch (Exception) { } 79 } 80 81 outError = error; 82 83 return false; 84 } 85 } 86 87 outError = error; 88 89 return false; 90 } 91 92 public static bool CanStartApplication(ContentManager contentManager, string baseApplicationPath, out UserError error) 93 { 94 if (Directory.Exists(baseApplicationPath) || File.Exists(baseApplicationPath)) 95 { 96 string baseApplicationExtension = Path.GetExtension(baseApplicationPath).ToLowerInvariant(); 97 98 // NOTE: We don't force homebrew developers to install a system firmware. 99 if (baseApplicationExtension == ".nro" || baseApplicationExtension == ".nso") 100 { 101 error = UserError.Success; 102 103 return true; 104 } 105 106 return IsFirmwareValid(contentManager, out error); 107 } 108 109 error = UserError.ApplicationNotFound; 110 111 return false; 112 } 113 } 114 }