diff --git a/Ryujinx.Ava/Program.cs b/Ryujinx.Ava/Program.cs index 6fa9a2f4f..ed256d919 100644 --- a/Ryujinx.Ava/Program.cs +++ b/Ryujinx.Ava/Program.cs @@ -43,16 +43,37 @@ namespace Ryujinx.Ava return; } - if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share", "mime", "packages", "Ryujinx.xml"))) + string mimeDbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share", "mime"); + + if (!File.Exists(Path.Combine(mimeDbPath, "packages", "Ryujinx.xml"))) { string mimeTypesFile = Path.Combine(ReleaseInformation.GetBaseApplicationDirectory(), "mime", "Ryujinx.xml"); using Process mimeProcess = new(); mimeProcess.StartInfo.FileName = "xdg-mime"; - mimeProcess.StartInfo.Arguments = $"install --mode user {mimeTypesFile}"; + mimeProcess.StartInfo.Arguments = $"install --novendor --mode user {mimeTypesFile}"; mimeProcess.Start(); mimeProcess.WaitForExit(); + + if (mimeProcess.ExitCode != 0) + { + Logger.Error?.PrintMsg(LogClass.Application, $"Unable to install mime types. Make sure xdg-utils is installed. Process exited with code: {mimeProcess.ExitCode}"); + return; + } + + using Process updateMimeProcess = new(); + + updateMimeProcess.StartInfo.FileName = "update-mime-database"; + updateMimeProcess.StartInfo.Arguments = mimeDbPath; + + updateMimeProcess.Start(); + updateMimeProcess.WaitForExit(); + + if (updateMimeProcess.ExitCode != 0) + { + Logger.Error?.PrintMsg(LogClass.Application, $"Could not update local mime database. Process exited with code: {updateMimeProcess.ExitCode}"); + } } } @@ -60,11 +81,6 @@ namespace Ryujinx.Ava { Version = ReleaseInformation.GetVersion(); - if (OperatingSystem.IsLinux()) - { - RegisterMimeTypes(); - } - if (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134)) { _ = MessageBoxA(IntPtr.Zero, "You are running an outdated version of Windows.\n\nStarting on June 1st 2022, Ryujinx will only support Windows 10 1803 and newer.\n", $"Ryujinx {Version}", MB_ICONWARNING); @@ -122,6 +138,12 @@ namespace Ryujinx.Ava // Initialize the logger system. LoggerModule.Initialize(); + // Register mime types on linux. + if (OperatingSystem.IsLinux()) + { + RegisterMimeTypes(); + } + // Initialize Discord integration. DiscordIntegrationModule.Initialize(); diff --git a/Ryujinx/Program.cs b/Ryujinx/Program.cs index 8b47e69aa..336fa9d8a 100644 --- a/Ryujinx/Program.cs +++ b/Ryujinx/Program.cs @@ -82,16 +82,37 @@ namespace Ryujinx return; } - if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share", "mime", "packages", "Ryujinx.xml"))) + string mimeDbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share", "mime"); + + if (!File.Exists(Path.Combine(mimeDbPath, "packages", "Ryujinx.xml"))) { string mimeTypesFile = Path.Combine(ReleaseInformation.GetBaseApplicationDirectory(), "mime", "Ryujinx.xml"); using Process mimeProcess = new(); mimeProcess.StartInfo.FileName = "xdg-mime"; - mimeProcess.StartInfo.Arguments = $"install --mode user {mimeTypesFile}"; + mimeProcess.StartInfo.Arguments = $"install --novendor --mode user {mimeTypesFile}"; mimeProcess.Start(); mimeProcess.WaitForExit(); + + if (mimeProcess.ExitCode != 0) + { + Logger.Error?.PrintMsg(LogClass.Application, $"Unable to install mime types. Make sure xdg-utils is installed. Process exited with code: {mimeProcess.ExitCode}"); + return; + } + + using Process updateMimeProcess = new(); + + updateMimeProcess.StartInfo.FileName = "update-mime-database"; + updateMimeProcess.StartInfo.Arguments = mimeDbPath; + + updateMimeProcess.Start(); + updateMimeProcess.WaitForExit(); + + if (updateMimeProcess.ExitCode != 0) + { + Logger.Error?.PrintMsg(LogClass.Application, $"Could not update local mime database. Process exited with code: {updateMimeProcess.ExitCode}"); + } } } @@ -123,8 +144,6 @@ namespace Ryujinx // This ends up causing race condition and abort of XCB when a context is created by SPB (even if SPB do call XInitThreads). if (OperatingSystem.IsLinux()) { - RegisterMimeTypes(); - XInitThreads(); Environment.SetEnvironmentVariable("GDK_BACKEND", "x11"); setenv("GDK_BACKEND", "x11", 1); @@ -171,6 +190,12 @@ namespace Ryujinx // Initialize the logger system. LoggerModule.Initialize(); + // Register mime types on linux. + if (OperatingSystem.IsLinux()) + { + RegisterMimeTypes(); + } + // Initialize Discord integration. DiscordIntegrationModule.Initialize();