Skip to content

Commit

Permalink
GameDriver: Improve FFNx configuration management
Browse files Browse the repository at this point in the history
- Make a backup of the vanilla configuration file everytime the user installs/updates FFNx via 7th
- Restore a vanilla backup for the configuration file ( with 7th defaults applied ) everytime the user click on Reset to Default on the Game Driver window
- Move the backup file inside the 7thWorkshop folder so users won't mistakenly delete it
  • Loading branch information
julianxhokaxhiu committed Jul 3, 2022
1 parent 32770a2 commit ca14de4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 7thHeaven.Code/FFNxConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Iros._7th.Workshop.ConfigSettings
public class FFNxConfigManager
{
private string _pathToFFNxToml = Sys.PathToFFNxToml;
private string _pathToFFNxTomlBak = Sys.PathToFFNxToml + ".bak";
private string _pathToFFNxTomlBak = Path.Combine(Sys.PathToGameDriverFolder, "FFNx.toml.bak");
private Exception _lastException = null;

private TomlTable _toml = null;
Expand Down Expand Up @@ -274,7 +274,7 @@ public void RestoreBackup()
if (File.Exists(_pathToFFNxTomlBak))
{
File.Delete(_pathToFFNxToml);
File.Move(_pathToFFNxTomlBak, _pathToFFNxToml);
File.Copy(_pathToFFNxTomlBak, _pathToFFNxToml);
Reload();
}
}
Expand Down
1 change: 1 addition & 0 deletions SeventhHeavenUI/Classes/FFNxDriverUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ private void DownloadAndExtract(string url, string version)
}
SwitchToModPanel();
Sys.FFNxConfig.Backup();
Sys.FFNxConfig.Reload();
Sys.FFNxConfig.ResetTo7thHeavenDefaults();
Sys.FFNxConfig.OverrideInternalKeys();
Expand Down
3 changes: 3 additions & 0 deletions SeventhHeavenUI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,9 @@ public void InitViewModel()
DS4ControllerService.Instance.StartService();
}

// Ensure game driver directory exists
Directory.CreateDirectory(Sys.PathToGameDriverFolder);

// Ensure temp directory exists
Directory.CreateDirectory(Sys.PathToTempFolder);

Expand Down
4 changes: 4 additions & 0 deletions SeventhHeavenUI/Windows/ConfigureGLWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ private void btnSave_Click(object sender, RoutedEventArgs e)

private void btnReset_Click(object sender, RoutedEventArgs e)
{
Sys.FFNxConfig.RestoreBackup();
Sys.FFNxConfig.ResetTo7thHeavenDefaults();
Sys.FFNxConfig.Save();

foreach (var item in ViewModels)
{
item.ResetToDefault(_settings);
Expand Down

0 comments on commit ca14de4

Please sign in to comment.