From ac21abbb9d23432879b1026eb5bc48ad3d4583d8 Mon Sep 17 00:00:00 2001 From: Mary Date: Fri, 4 Mar 2022 18:03:16 +0100 Subject: [PATCH] Preparation for initial Flatpack and FlatHub integration (#3173) * Preparation for initial Flatpack and FlatHub integration This integrate some initial changes required for Flatpack and distribution from FlatHub. Also added some resources that will be used for packaging on Linux. * Address gdkchan comment --- Ryujinx.Common/ReleaseInformations.cs | 21 ++++++++++++++++++++- Ryujinx.Headless.SDL2/Program.cs | 4 ++-- Ryujinx.SDL2.Common/SDL2Driver.cs | 5 +++-- Ryujinx/Configuration/LoggerModule.cs | 2 +- Ryujinx/Modules/Updater/Updater.cs | 15 +++++++++++---- Ryujinx/Ui/MainWindow.cs | 2 +- distribution/linux/ryujinx-logo.svg | 1 + distribution/linux/ryujinx-mime.xml | 23 +++++++++++++++++++++++ distribution/linux/ryujinx.desktop | 14 ++++++++++++++ 9 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 distribution/linux/ryujinx-logo.svg create mode 100644 distribution/linux/ryujinx-mime.xml create mode 100644 distribution/linux/ryujinx.desktop diff --git a/Ryujinx.Common/ReleaseInformations.cs b/Ryujinx.Common/ReleaseInformations.cs index 32a019480..35890406e 100644 --- a/Ryujinx.Common/ReleaseInformations.cs +++ b/Ryujinx.Common/ReleaseInformations.cs @@ -1,10 +1,14 @@ -using System.Reflection; +using Ryujinx.Common.Configuration; +using System; +using System.Reflection; namespace Ryujinx.Common { // DO NOT EDIT, filled by CI public static class ReleaseInformations { + private const string FlatHubChannelOwner = "flathub"; + public static string BuildVersion = "%%RYUJINX_BUILD_VERSION%%"; public static string BuildGitHash = "%%RYUJINX_BUILD_GIT_HASH%%"; public static string ReleaseChannelName = "%%RYUJINX_TARGET_RELEASE_CHANNEL_NAME%%"; @@ -19,6 +23,11 @@ namespace Ryujinx.Common !ReleaseChannelRepo.StartsWith("%%"); } + public static bool IsFlatHubBuild() + { + return IsValid() && ReleaseChannelOwner.Equals(FlatHubChannelOwner); + } + public static string GetVersion() { if (IsValid()) @@ -30,5 +39,15 @@ namespace Ryujinx.Common return Assembly.GetEntryAssembly().GetCustomAttribute().InformationalVersion; } } + + public static string GetBaseApplicationDirectory() + { + if (IsFlatHubBuild()) + { + return AppDataManager.BaseDirPath; + } + + return AppDomain.CurrentDomain.BaseDirectory; + } } } diff --git a/Ryujinx.Headless.SDL2/Program.cs b/Ryujinx.Headless.SDL2/Program.cs index 973b4f5e4..4daf6084c 100644 --- a/Ryujinx.Headless.SDL2/Program.cs +++ b/Ryujinx.Headless.SDL2/Program.cs @@ -310,7 +310,7 @@ namespace Ryujinx.Headless.SDL2 { controllerConfig.RangeLeft = 1.0f; controllerConfig.RangeRight = 1.0f; - + Logger.Info?.Print(LogClass.Application, $"{config.PlayerIndex} stick range reset. Save the profile now to update your configuration"); } } @@ -396,7 +396,7 @@ namespace Ryujinx.Headless.SDL2 if ((bool)option.EnableFileLog) { Logger.AddTarget(new AsyncLogTargetWrapper( - new FileLogTarget(AppDomain.CurrentDomain.BaseDirectory, "file"), + new FileLogTarget(ReleaseInformations.GetBaseApplicationDirectory(), "file"), 1000, AsyncLogTargetOverflowAction.Block )); diff --git a/Ryujinx.SDL2.Common/SDL2Driver.cs b/Ryujinx.SDL2.Common/SDL2Driver.cs index 944f8e57e..fbf2b64ab 100644 --- a/Ryujinx.SDL2.Common/SDL2Driver.cs +++ b/Ryujinx.SDL2.Common/SDL2Driver.cs @@ -1,4 +1,5 @@ -using Ryujinx.Common.Logging; +using Ryujinx.Common; +using Ryujinx.Common.Logging; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -81,7 +82,7 @@ namespace Ryujinx.SDL2.Common SDL_EventState(SDL_EventType.SDL_CONTROLLERSENSORUPDATE, SDL_DISABLE); - string gamepadDbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SDL_GameControllerDB.txt"); + string gamepadDbPath = Path.Combine(ReleaseInformations.GetBaseApplicationDirectory(), "SDL_GameControllerDB.txt"); if (File.Exists(gamepadDbPath)) { diff --git a/Ryujinx/Configuration/LoggerModule.cs b/Ryujinx/Configuration/LoggerModule.cs index 9e81f7256..cf873e561 100644 --- a/Ryujinx/Configuration/LoggerModule.cs +++ b/Ryujinx/Configuration/LoggerModule.cs @@ -80,7 +80,7 @@ namespace Ryujinx.Configuration if (e.NewValue) { Logger.AddTarget(new AsyncLogTargetWrapper( - new FileLogTarget(AppDomain.CurrentDomain.BaseDirectory, "file"), + new FileLogTarget(ReleaseInformations.GetBaseApplicationDirectory(), "file"), 1000, AsyncLogTargetOverflowAction.Block )); diff --git a/Ryujinx/Modules/Updater/Updater.cs b/Ryujinx/Modules/Updater/Updater.cs index f3a250158..bf5f54ed3 100644 --- a/Ryujinx/Modules/Updater/Updater.cs +++ b/Ryujinx/Modules/Updater/Updater.cs @@ -311,7 +311,7 @@ namespace Ryujinx.Modules catch (Exception e) { Logger.Warning?.Print(LogClass.Application, e.Message); - Logger.Warning?.Print(LogClass.Application, $"Multi-Threaded update failed, falling back to single-threaded updater."); + Logger.Warning?.Print(LogClass.Application, "Multi-Threaded update failed, falling back to single-threaded updater."); DoUpdateWithSingleThread(updateDialog, downloadUrl, updateFile); @@ -327,8 +327,8 @@ namespace Ryujinx.Modules catch (WebException ex) { Logger.Warning?.Print(LogClass.Application, ex.Message); - Logger.Warning?.Print(LogClass.Application, $"Multi-Threaded update failed, falling back to single-threaded updater."); - + Logger.Warning?.Print(LogClass.Application, "Multi-Threaded update failed, falling back to single-threaded updater."); + for (int j = 0; j < webClients.Count; j++) { webClients[j].CancelAsync(); @@ -567,7 +567,14 @@ namespace Ryujinx.Modules #else if (showWarnings) { - GtkDialog.CreateWarningDialog("Updater Disabled!", "Please download Ryujinx at https://ryujinx.org/ if you are looking for a supported version."); + if (ReleaseInformations.IsFlatHubBuild()) + { + GtkDialog.CreateWarningDialog("Updater Disabled!", "Please update Ryujinx via FlatHub."); + } + else + { + GtkDialog.CreateWarningDialog("Updater Disabled!", "Please download Ryujinx at https://ryujinx.org/ if you are looking for a supported version."); + } } return false; diff --git a/Ryujinx/Ui/MainWindow.cs b/Ryujinx/Ui/MainWindow.cs index 0c94fc673..5ab3cf61a 100644 --- a/Ryujinx/Ui/MainWindow.cs +++ b/Ryujinx/Ui/MainWindow.cs @@ -1291,7 +1291,7 @@ namespace Ryujinx.Ui private void OpenLogsFolder_Pressed(object sender, EventArgs args) { - string logPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"); + string logPath = System.IO.Path.Combine(ReleaseInformations.GetBaseApplicationDirectory(), "Logs"); new DirectoryInfo(logPath).Create(); diff --git a/distribution/linux/ryujinx-logo.svg b/distribution/linux/ryujinx-logo.svg new file mode 100644 index 000000000..d6a76312a --- /dev/null +++ b/distribution/linux/ryujinx-logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/distribution/linux/ryujinx-mime.xml b/distribution/linux/ryujinx-mime.xml new file mode 100644 index 000000000..6ec35c848 --- /dev/null +++ b/distribution/linux/ryujinx-mime.xml @@ -0,0 +1,23 @@ + + + + Nintendo Content Archive + + + + Nintendo Relocatable Object + + + + Nintendo Shared Object + + + + Nintendo Submission Package + + + + Nintendo Switch Cartridge + + + diff --git a/distribution/linux/ryujinx.desktop b/distribution/linux/ryujinx.desktop new file mode 100644 index 000000000..dbfc43e41 --- /dev/null +++ b/distribution/linux/ryujinx.desktop @@ -0,0 +1,14 @@ +[Desktop Entry] +Version=1.0 +Name=Ryujinx +Comment=A Nintendo Switch Emulator +Type=Application +GenericName=Nintendo Switch Emulator +Icon=ryujinx +Terminal=false +Exec=Ryujinx %f +Categories=Game;Emulator;GTK; +MimeType=application/x-nx-nca;application/x-nx-nro;application/x-nx-nso;application/x-nx-nsp;application/x-nx-xci; +Keywords=Switch;Nintendo;Emulator; +StartupWMClass=Ryujinx +PrefersNonDefaultGPU=true