Implement friendlier portable mode (#1885)

* Implement friendlier portable mode

* Remove first run dialog

* Disable updates in portable mode for now

* Convert relative custom paths to absolute ones

Also, fix a regression when custom path doesn't exist
This commit is contained in:
mageven 2021-03-16 02:40:36 +05:30 committed by GitHub
parent 88d0708061
commit e44850fed4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 18 deletions

View file

@ -6,21 +6,28 @@ namespace Ryujinx.Common.Configuration
{ {
public static class AppDataManager public static class AppDataManager
{ {
private static readonly string _defaultBaseDirPath; public const string DefaultBaseDir = "Ryujinx";
public const string DefaultPortableDir = "portable";
private const string DefaultBaseDir = "Ryujinx";
// The following 3 are always part of Base Directory // The following 3 are always part of Base Directory
private const string GamesDir = "games"; private const string GamesDir = "games";
private const string ProfilesDir = "profiles"; private const string ProfilesDir = "profiles";
private const string KeysDir = "system"; private const string KeysDir = "system";
public static bool IsCustomBasePath { get; private set; } public enum LaunchMode
{
UserProfile,
Portable,
Custom
}
public static LaunchMode Mode { get; private set; }
public static string BaseDirPath { get; private set; } public static string BaseDirPath { get; private set; }
public static string GamesDirPath { get; private set; } public static string GamesDirPath { get; private set; }
public static string ProfilesDirPath { get; private set; } public static string ProfilesDirPath { get; private set; }
public static string KeysDirPath { get; private set; } public static string KeysDirPath { get; private set; }
public static string KeysDirPathAlt { get; } public static string KeysDirPathUser { get; }
public const string DefaultNandDir = "bis"; public const string DefaultNandDir = "bis";
public const string DefaultSdcardDir = "sdcard"; public const string DefaultSdcardDir = "sdcard";
@ -32,27 +39,40 @@ namespace Ryujinx.Common.Configuration
static AppDataManager() static AppDataManager()
{ {
_defaultBaseDirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), DefaultBaseDir); KeysDirPathUser = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".switch");
KeysDirPathAlt = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".switch");
} }
public static void Initialize(string baseDirPath) public static void Initialize(string baseDirPath)
{ {
BaseDirPath = _defaultBaseDirPath; string userProfilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), DefaultBaseDir);
string portablePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DefaultPortableDir);
if (baseDirPath != null && baseDirPath != _defaultBaseDirPath) if (Directory.Exists(portablePath))
{
BaseDirPath = portablePath;
Mode = LaunchMode.Portable;
}
else
{
BaseDirPath = userProfilePath;
Mode = LaunchMode.UserProfile;
}
if (baseDirPath != null && baseDirPath != userProfilePath)
{ {
if (!Directory.Exists(baseDirPath)) if (!Directory.Exists(baseDirPath))
{ {
Logger.Error?.Print(LogClass.Application, $"Custom Data Directory '{baseDirPath}' does not exist. Using defaults..."); Logger.Error?.Print(LogClass.Application, $"Custom Data Directory '{baseDirPath}' does not exist. Falling back to {Mode}...");
} }
else else
{ {
BaseDirPath = baseDirPath; BaseDirPath = baseDirPath;
IsCustomBasePath = true; Mode = LaunchMode.Custom;
} }
} }
BaseDirPath = Path.GetFullPath(BaseDirPath); // convert relative paths
SetupBasePaths(); SetupBasePaths();
} }

View file

@ -227,9 +227,9 @@ namespace Ryujinx.HLE.FileSystem
string titleKeyFile = null; string titleKeyFile = null;
string consoleKeyFile = null; string consoleKeyFile = null;
if (!AppDataManager.IsCustomBasePath) if (AppDataManager.Mode == AppDataManager.LaunchMode.UserProfile)
{ {
LoadSetAtPath(AppDataManager.KeysDirPathAlt); LoadSetAtPath(AppDataManager.KeysDirPathUser);
} }
LoadSetAtPath(AppDataManager.KeysDirPath); LoadSetAtPath(AppDataManager.KeysDirPath);

View file

@ -4,6 +4,7 @@ using ICSharpCode.SharpZipLib.Tar;
using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Zip;
using Mono.Unix; using Mono.Unix;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Ui; using Ryujinx.Ui;
using Ryujinx.Ui.Widgets; using Ryujinx.Ui.Widgets;
@ -490,6 +491,16 @@ namespace Ryujinx.Modules
return false; return false;
} }
if (AppDataManager.Mode == AppDataManager.LaunchMode.Portable)
{
if (showWarnings)
{
GtkDialog.CreateWarningDialog("You cannot update a portable version of Ryujinx!", "Please use a non-portable configuration to enable updates.");
}
return false;
}
if (Program.Version.Contains("dirty")) if (Program.Version.Contains("dirty"))
{ {
if (showWarnings) if (showWarnings)

View file

@ -135,9 +135,9 @@ namespace Ryujinx
Application.Init(); Application.Init();
// Check if keys exists. // Check if keys exists.
bool hasGlobalProdKeys = File.Exists(Path.Combine(AppDataManager.KeysDirPath, "prod.keys")); bool hasSystemProdKeys = File.Exists(Path.Combine(AppDataManager.KeysDirPath, "prod.keys"));
bool hasAltProdKeys = !AppDataManager.IsCustomBasePath && File.Exists(Path.Combine(AppDataManager.KeysDirPathAlt, "prod.keys")); bool hasCommonProdKeys = AppDataManager.Mode == AppDataManager.LaunchMode.UserProfile && File.Exists(Path.Combine(AppDataManager.KeysDirPathUser, "prod.keys"));
if (!hasGlobalProdKeys && !hasAltProdKeys) if (!hasSystemProdKeys && !hasCommonProdKeys)
{ {
UserErrorDialog.CreateUserErrorDialog(UserError.NoKeys); UserErrorDialog.CreateUserErrorDialog(UserError.NoKeys);
} }
@ -173,9 +173,13 @@ namespace Ryujinx
var enabledLogs = Logger.GetEnabledLevels(); var enabledLogs = Logger.GetEnabledLevels();
Logger.Notice.Print(LogClass.Application, $"Logs Enabled: {(enabledLogs.Count == 0 ? "<None>" : string.Join(", ", enabledLogs))}"); Logger.Notice.Print(LogClass.Application, $"Logs Enabled: {(enabledLogs.Count == 0 ? "<None>" : string.Join(", ", enabledLogs))}");
if (AppDataManager.IsCustomBasePath) if (AppDataManager.Mode == AppDataManager.LaunchMode.Custom)
{ {
Logger.Notice.Print(LogClass.Application, $"Custom Data Directory: {AppDataManager.BaseDirPath}"); Logger.Notice.Print(LogClass.Application, $"Launch Mode: Custom Path {AppDataManager.BaseDirPath}");
}
else
{
Logger.Notice.Print(LogClass.Application, $"Launch Mode: {AppDataManager.Mode}");
} }
} }