mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-12-16 12:09:51 +00:00
Preserve and rename the configuration file when it is deemed invalid (ryubing/ryujinx!216)
See merge request ryubing/ryujinx!216
This commit is contained in:
parent
e8225ce7aa
commit
1baaa1c365
@ -233,6 +233,8 @@ namespace Ryujinx.Ava
|
||||
{
|
||||
Logger.Warning?.PrintMsg(LogClass.Application, $"Failed to load config! Loading the default config instead.\nFailed config location: {ConfigurationPath}");
|
||||
|
||||
ConfigurationFileFormat.RenameInvalidConfigFile(ConfigurationPath);
|
||||
|
||||
ConfigurationState.Instance.LoadDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,9 @@ using Ryujinx.Common.Configuration.Multiplayer;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.HLE;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Ryujinx.Ava.Systems.Configuration
|
||||
{
|
||||
@ -510,6 +512,43 @@ namespace Ryujinx.Ava.Systems.Configuration
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renames the configuration file when it is deemed invalid
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the invalid JSON configuration file</param>
|
||||
/// <returns>The path of the renamed invalid JSON configuration file, or null if the rename failed</returns>
|
||||
public static string RenameInvalidConfigFile(string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path) || !File.Exists(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string directory = Path.GetDirectoryName(path) ?? string.Empty;
|
||||
string originalFileName = Path.GetFileName(path);
|
||||
if (string.IsNullOrWhiteSpace(originalFileName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string renamedFileName = $"{originalFileName}.{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.invalid";
|
||||
string renamedPath = string.IsNullOrEmpty(directory) ? renamedFileName : Path.Combine(directory, renamedFileName);
|
||||
|
||||
File.Move(path, renamedPath, overwrite: false);
|
||||
|
||||
Logger.Warning?.PrintMsg(LogClass.Application, $"Invalid configuration renamed to: {renamedPath}");
|
||||
|
||||
return renamedPath;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error?.PrintMsg(LogClass.Application, $"Failed to rename invalid configuration file \"{path}\": {ex}");
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save a configuration file to disk
|
||||
/// </summary>
|
||||
|
||||
@ -28,6 +28,8 @@ namespace Ryujinx.Ava.Systems.Configuration
|
||||
{
|
||||
RyuLogger.Warning?.Print(LogClass.Application, $"Unsupported configuration version {cff.Version}, loading default.");
|
||||
|
||||
ConfigurationFileFormat.RenameInvalidConfigFile(configurationFilePath);
|
||||
|
||||
LoadDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user