0
0
Fork 0

Make Device Location Name configuration (custom TZ) (#1031)

This permit to use arbitrary timezone (instead of UTC).

Useful for games like ACNH.
This commit is contained in:
Thog 2020-03-25 23:23:21 +01:00 committed by GitHub
parent 82c3df83c4
commit 0dd38028cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 148 additions and 27 deletions

View file

@ -16,6 +16,11 @@ namespace Ryujinx.Configuration
{ {
public class ConfigurationFileFormat public class ConfigurationFileFormat
{ {
/// <summary>
/// The current version of the file format
/// </summary>
public const int CurrentVersion = 3;
public int Version { get; set; } public int Version { get; set; }
/// <summary> /// <summary>
@ -78,6 +83,11 @@ namespace Ryujinx.Configuration
/// </summary> /// </summary>
public Region SystemRegion { get; set; } public Region SystemRegion { get; set; }
/// <summary>
/// Change System TimeZone
/// </summary>
public string SystemTimeZone { get; set; }
/// <summary> /// <summary>
/// Enables or disables Docked Mode /// Enables or disables Docked Mode
/// </summary> /// </summary>

View file

@ -153,6 +153,11 @@ namespace Ryujinx.Configuration
/// </summary> /// </summary>
public ReactiveObject<Region> Region { get; private set; } public ReactiveObject<Region> Region { get; private set; }
/// <summary>
/// Change System TimeZone
/// </summary>
public ReactiveObject<string> TimeZone { get; private set; }
/// <summary> /// <summary>
/// Enables or disables Docked Mode /// Enables or disables Docked Mode
/// </summary> /// </summary>
@ -182,6 +187,7 @@ namespace Ryujinx.Configuration
{ {
Language = new ReactiveObject<Language>(); Language = new ReactiveObject<Language>();
Region = new ReactiveObject<Region>(); Region = new ReactiveObject<Region>();
TimeZone = new ReactiveObject<string>();
EnableDockedMode = new ReactiveObject<bool>(); EnableDockedMode = new ReactiveObject<bool>();
EnableMulticoreScheduling = new ReactiveObject<bool>(); EnableMulticoreScheduling = new ReactiveObject<bool>();
EnableFsIntegrityChecks = new ReactiveObject<bool>(); EnableFsIntegrityChecks = new ReactiveObject<bool>();
@ -295,7 +301,7 @@ namespace Ryujinx.Configuration
{ {
ConfigurationFileFormat configurationFile = new ConfigurationFileFormat ConfigurationFileFormat configurationFile = new ConfigurationFileFormat
{ {
Version = 2, Version = ConfigurationFileFormat.CurrentVersion,
GraphicsShadersDumpPath = Graphics.ShadersDumpPath, GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
LoggingEnableDebug = Logger.EnableDebug, LoggingEnableDebug = Logger.EnableDebug,
LoggingEnableStub = Logger.EnableStub, LoggingEnableStub = Logger.EnableStub,
@ -308,6 +314,7 @@ namespace Ryujinx.Configuration
EnableFileLog = Logger.EnableFileLog, EnableFileLog = Logger.EnableFileLog,
SystemLanguage = System.Language, SystemLanguage = System.Language,
SystemRegion = System.Region, SystemRegion = System.Region,
SystemTimeZone = System.TimeZone,
DockedMode = System.EnableDockedMode, DockedMode = System.EnableDockedMode,
EnableDiscordIntegration = EnableDiscordIntegration, EnableDiscordIntegration = EnableDiscordIntegration,
EnableVsync = Graphics.EnableVsync, EnableVsync = Graphics.EnableVsync,
@ -354,6 +361,7 @@ namespace Ryujinx.Configuration
Logger.EnableFileLog.Value = true; Logger.EnableFileLog.Value = true;
System.Language.Value = Language.AmericanEnglish; System.Language.Value = Language.AmericanEnglish;
System.Region.Value = Region.USA; System.Region.Value = Region.USA;
System.TimeZone.Value = "UTC";
System.EnableDockedMode.Value = false; System.EnableDockedMode.Value = false;
EnableDiscordIntegration.Value = true; EnableDiscordIntegration.Value = true;
Graphics.EnableVsync.Value = true; Graphics.EnableVsync.Value = true;
@ -452,7 +460,7 @@ namespace Ryujinx.Configuration
{ {
bool configurationFileUpdated = false; bool configurationFileUpdated = false;
if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > 2) if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion)
{ {
Common.Logging.Logger.PrintWarning(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default."); Common.Logging.Logger.PrintWarning(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");
@ -463,13 +471,22 @@ namespace Ryujinx.Configuration
if (configurationFileFormat.Version < 2) if (configurationFileFormat.Version < 2)
{ {
Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, needs to be updated."); Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 2.");
configurationFileFormat.SystemRegion = Region.USA; configurationFileFormat.SystemRegion = Region.USA;
configurationFileUpdated = true; configurationFileUpdated = true;
} }
if (configurationFileFormat.Version < 3)
{
Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 3.");
configurationFileFormat.SystemTimeZone = "UTC";
configurationFileUpdated = true;
}
Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath; Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug; Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub; Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;
@ -482,6 +499,7 @@ namespace Ryujinx.Configuration
Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog; Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
System.Language.Value = configurationFileFormat.SystemLanguage; System.Language.Value = configurationFileFormat.SystemLanguage;
System.Region.Value = configurationFileFormat.SystemRegion; System.Region.Value = configurationFileFormat.SystemRegion;
System.TimeZone.Value = configurationFileFormat.SystemTimeZone;
System.EnableDockedMode.Value = configurationFileFormat.DockedMode; System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
System.EnableDockedMode.Value = configurationFileFormat.DockedMode; System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration; EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration;

View file

@ -4,8 +4,10 @@ using LibHac.Fs;
using LibHac.FsSystem; using LibHac.FsSystem;
using LibHac.FsSystem.NcaUtils; using LibHac.FsSystem.NcaUtils;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Configuration;
using Ryujinx.HLE.Exceptions; using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.FileSystem; using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.FileSystem.Content;
using Ryujinx.HLE.HOS.Services.Time.Clock; using Ryujinx.HLE.HOS.Services.Time.Clock;
using Ryujinx.HLE.Utilities; using Ryujinx.HLE.Utilities;
using System.Collections.Generic; using System.Collections.Generic;
@ -15,34 +17,62 @@ using static Ryujinx.HLE.HOS.Services.Time.TimeZone.TimeZoneRule;
namespace Ryujinx.HLE.HOS.Services.Time.TimeZone namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
{ {
class TimeZoneContentManager public class TimeZoneContentManager
{ {
private const long TimeZoneBinaryTitleId = 0x010000000000080E; private const long TimeZoneBinaryTitleId = 0x010000000000080E;
private Switch _device; private VirtualFileSystem _virtualFileSystem;
private string[] _locationNameCache; private IntegrityCheckLevel _fsIntegrityCheckLevel;
private ContentManager _contentManager;
public TimeZoneManager Manager { get; private set; } public string[] LocationNameCache { get; private set; }
internal TimeZoneManager Manager { get; private set; }
public TimeZoneContentManager() public TimeZoneContentManager()
{ {
Manager = new TimeZoneManager(); Manager = new TimeZoneManager();
} }
internal void Initialize(TimeManager timeManager, Switch device) public void InitializeInstance(VirtualFileSystem virtualFileSystem, ContentManager contentManager, IntegrityCheckLevel fsIntegrityCheckLevel)
{ {
_device = device; _virtualFileSystem = virtualFileSystem;
_contentManager = contentManager;
_fsIntegrityCheckLevel = fsIntegrityCheckLevel;
InitializeLocationNameCache(); InitializeLocationNameCache();
}
public string SanityCheckDeviceLocationName()
{
string locationName = ConfigurationState.Instance.System.TimeZone;
if (IsLocationNameValid(locationName))
{
return locationName;
}
Logger.PrintWarning(LogClass.ServiceTime, $"Invalid device TimeZone {locationName}, switching back to UTC");
ConfigurationState.Instance.System.TimeZone.Value = "UTC";
return "UTC";
}
internal void Initialize(TimeManager timeManager, Switch device)
{
InitializeInstance(device.FileSystem, device.System.ContentManager, device.System.FsIntegrityCheckLevel);
SteadyClockTimePoint timeZoneUpdatedTimePoint = timeManager.StandardSteadyClock.GetCurrentTimePoint(null); SteadyClockTimePoint timeZoneUpdatedTimePoint = timeManager.StandardSteadyClock.GetCurrentTimePoint(null);
ResultCode result = GetTimeZoneBinary("UTC", out Stream timeZoneBinaryStream, out LocalStorage ncaFile); string deviceLocationName = SanityCheckDeviceLocationName();
ResultCode result = GetTimeZoneBinary(deviceLocationName, out Stream timeZoneBinaryStream, out LocalStorage ncaFile);
if (result == ResultCode.Success) if (result == ResultCode.Success)
{ {
// TODO: Read TimeZoneVersion from sysarchive. // TODO: Read TimeZoneVersion from sysarchive.
timeManager.SetupTimeZoneManager("UTC", timeZoneUpdatedTimePoint, (uint)_locationNameCache.Length, new UInt128(), timeZoneBinaryStream); timeManager.SetupTimeZoneManager(deviceLocationName, timeZoneUpdatedTimePoint, (uint)LocationNameCache.Length, new UInt128(), timeZoneBinaryStream);
ncaFile.Dispose(); ncaFile.Dispose();
} }
@ -57,10 +87,10 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
{ {
if (HasTimeZoneBinaryTitle()) if (HasTimeZoneBinaryTitle())
{ {
using (IStorage ncaFileStream = new LocalStorage(_device.FileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open)) using (IStorage ncaFileStream = new LocalStorage(_virtualFileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open))
{ {
Nca nca = new Nca(_device.System.KeySet, ncaFileStream); Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFileStream);
IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel); IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel);
romfs.OpenFile(out IFile binaryListFile, "/binaryList.txt".ToU8Span(), OpenMode.Read).ThrowIfFailure(); romfs.OpenFile(out IFile binaryListFile, "/binaryList.txt".ToU8Span(), OpenMode.Read).ThrowIfFailure();
@ -74,12 +104,12 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
locationNameList.Add(locationName); locationNameList.Add(locationName);
} }
_locationNameCache = locationNameList.ToArray(); LocationNameCache = locationNameList.ToArray();
} }
} }
else else
{ {
_locationNameCache = new string[0]; LocationNameCache = new string[] { "UTC" };
Logger.PrintWarning(LogClass.ServiceTime, "TimeZoneBinary system title not found! TimeZone conversions will not work, provide the system archive to fix this warning. (See https://github.com/Ryujinx/Ryujinx#requirements for more informations)"); Logger.PrintWarning(LogClass.ServiceTime, "TimeZoneBinary system title not found! TimeZone conversions will not work, provide the system archive to fix this warning. (See https://github.com/Ryujinx/Ryujinx#requirements for more informations)");
} }
@ -87,7 +117,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
private bool IsLocationNameValid(string locationName) private bool IsLocationNameValid(string locationName)
{ {
foreach (string cachedLocationName in _locationNameCache) foreach (string cachedLocationName in LocationNameCache)
{ {
if (cachedLocationName.Equals(locationName)) if (cachedLocationName.Equals(locationName))
{ {
@ -116,14 +146,14 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
{ {
List<string> locationNameList = new List<string>(); List<string> locationNameList = new List<string>();
for (int i = 0; i < _locationNameCache.Length && i < maxLength; i++) for (int i = 0; i < LocationNameCache.Length && i < maxLength; i++)
{ {
if (i < index) if (i < index)
{ {
continue; continue;
} }
string locationName = _locationNameCache[i]; string locationName = LocationNameCache[i];
// If the location name is too long, error out. // If the location name is too long, error out.
if (locationName.Length > 0x24) if (locationName.Length > 0x24)
@ -143,7 +173,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
public string GetTimeZoneBinaryTitleContentPath() public string GetTimeZoneBinaryTitleContentPath()
{ {
return _device.System.ContentManager.GetInstalledContentPath(TimeZoneBinaryTitleId, StorageId.NandSystem, NcaContentType.Data); return _contentManager.GetInstalledContentPath(TimeZoneBinaryTitleId, StorageId.NandSystem, NcaContentType.Data);
} }
public bool HasTimeZoneBinaryTitle() public bool HasTimeZoneBinaryTitle()
@ -161,10 +191,10 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
return ResultCode.TimeZoneNotFound; return ResultCode.TimeZoneNotFound;
} }
ncaFile = new LocalStorage(_device.FileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open); ncaFile = new LocalStorage(_virtualFileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open);
Nca nca = new Nca(_device.System.KeySet, ncaFile); Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile);
IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel); IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel);
Result result = romfs.OpenFile(out IFile timeZoneBinaryFile, $"/zoneinfo/{locationName}".ToU8Span(), OpenMode.Read); Result result = romfs.OpenFile(out IFile timeZoneBinaryFile, $"/zoneinfo/{locationName}".ToU8Span(), OpenMode.Read);

View file

@ -935,7 +935,7 @@ namespace Ryujinx.Ui
private void Settings_Pressed(object sender, EventArgs args) private void Settings_Pressed(object sender, EventArgs args)
{ {
SwitchSettings settingsWin = new SwitchSettings(); SwitchSettings settingsWin = new SwitchSettings(_virtualFileSystem, _contentManager);
settingsWin.Show(); settingsWin.Show();
} }

View file

@ -2,6 +2,7 @@
using Ryujinx.Configuration; using Ryujinx.Configuration;
using Ryujinx.Configuration.Hid; using Ryujinx.Configuration.Hid;
using Ryujinx.Configuration.System; using Ryujinx.Configuration.System;
using Ryujinx.HLE.HOS.Services.Time.TimeZone;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -40,6 +41,7 @@ namespace Ryujinx.Ui
[GUI] CheckButton _directKeyboardAccess; [GUI] CheckButton _directKeyboardAccess;
[GUI] ComboBoxText _systemLanguageSelect; [GUI] ComboBoxText _systemLanguageSelect;
[GUI] ComboBoxText _systemRegionSelect; [GUI] ComboBoxText _systemRegionSelect;
[GUI] ComboBoxText _systemTimeZoneSelect;
[GUI] CheckButton _custThemeToggle; [GUI] CheckButton _custThemeToggle;
[GUI] Entry _custThemePath; [GUI] Entry _custThemePath;
[GUI] ToggleButton _browseThemePath; [GUI] ToggleButton _browseThemePath;
@ -80,9 +82,9 @@ namespace Ryujinx.Ui
#pragma warning restore CS0649 #pragma warning restore CS0649
#pragma warning restore IDE0044 #pragma warning restore IDE0044
public SwitchSettings() : this(new Builder("Ryujinx.Ui.SwitchSettings.glade")) { } public SwitchSettings(HLE.FileSystem.VirtualFileSystem virtualFileSystem, HLE.FileSystem.Content.ContentManager contentManager) : this(new Builder("Ryujinx.Ui.SwitchSettings.glade"), virtualFileSystem, contentManager) { }
private SwitchSettings(Builder builder) : base(builder.GetObject("_settingsWin").Handle) private SwitchSettings(Builder builder, HLE.FileSystem.VirtualFileSystem virtualFileSystem, HLE.FileSystem.Content.ContentManager contentManager) : base(builder.GetObject("_settingsWin").Handle)
{ {
builder.Autoconnect(this); builder.Autoconnect(this);
@ -197,8 +199,22 @@ namespace Ryujinx.Ui
_custThemeToggle.Click(); _custThemeToggle.Click();
} }
TimeZoneContentManager timeZoneContentManager = new TimeZoneContentManager();
timeZoneContentManager.InitializeInstance(virtualFileSystem, contentManager, LibHac.FsSystem.IntegrityCheckLevel.None);
List<string> locationNames = timeZoneContentManager.LocationNameCache.ToList();
locationNames.Sort();
foreach (string locationName in locationNames)
{
_systemTimeZoneSelect.Append(locationName, locationName);
}
_systemLanguageSelect.SetActiveId(ConfigurationState.Instance.System.Language.Value.ToString()); _systemLanguageSelect.SetActiveId(ConfigurationState.Instance.System.Language.Value.ToString());
_systemRegionSelect .SetActiveId(ConfigurationState.Instance.System.Region.Value.ToString()); _systemRegionSelect .SetActiveId(ConfigurationState.Instance.System.Region.Value.ToString());
_systemTimeZoneSelect.SetActiveId(timeZoneContentManager.SanityCheckDeviceLocationName());
_controller1Type .SetActiveId(ConfigurationState.Instance.Hid.ControllerType.Value.ToString()); _controller1Type .SetActiveId(ConfigurationState.Instance.Hid.ControllerType.Value.ToString());
Controller_Changed(null, null, _controller1Type.ActiveId, _controller1Image); Controller_Changed(null, null, _controller1Type.ActiveId, _controller1Image);
@ -448,6 +464,8 @@ namespace Ryujinx.Ui
ConfigurationState.Instance.Ui.GameDirs.Value = gameDirs; ConfigurationState.Instance.Ui.GameDirs.Value = gameDirs;
ConfigurationState.Instance.System.FsGlobalAccessLogMode.Value = (int)_fsLogSpinAdjustment.Value; ConfigurationState.Instance.System.FsGlobalAccessLogMode.Value = (int)_fsLogSpinAdjustment.Value;
ConfigurationState.Instance.System.TimeZone.Value = _systemTimeZoneSelect.ActiveId;
MainWindow.SaveConfig(); MainWindow.SaveConfig();
MainWindow.ApplyTheme(); MainWindow.ApplyTheme();
MainWindow.UpdateGameTable(); MainWindow.UpdateGameTable();

View file

@ -210,6 +210,51 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Change System TimeZone</property>
<property name="halign">end</property>
<property name="label" translatable="yes">System TimeZone:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="_systemTimeZoneSelect">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Change System TimeZone</property>
<property name="margin_left">5</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child> <child>
<object class="GtkCheckButton" id="_discordToggle"> <object class="GtkCheckButton" id="_discordToggle">
<property name="label" translatable="yes">Enable Discord Rich Presence</property> <property name="label" translatable="yes">Enable Discord Rich Presence</property>
@ -224,7 +269,7 @@
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="padding">5</property> <property name="padding">5</property>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</object> </object>