Skip to content

Commit

Permalink
Merge pull request #669 from dremin/misc-updates
Browse files Browse the repository at this point in the history
Misc updates
  • Loading branch information
dremin authored Aug 30, 2023
2 parents e6dd912 + 575ff87 commit 2a213ee
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ RetroBar is based on the [ManagedShell](https://github.com/cairoshell/ManagedShe
- Korean (한국어)
- Latvian (latviešu)
- Lithuanian (lietuvių)
- Luxembourgish (Lëtzebuergesch)
- Malay (Melayu)
- Persian (فارسی)
- Polish (polski)
Expand Down
2 changes: 1 addition & 1 deletion RetroBar/RetroBar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<ItemGroup>
<PackageReference Include="gong-wpf-dragdrop" Version="3.1.1" />
<PackageReference Include="ManagedShell" Version="0.0.212" />
<PackageReference Include="ManagedShell" Version="0.0.223" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
</ItemGroup>

Expand Down
6 changes: 6 additions & 0 deletions RetroBar/Utilities/ManagedShellLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ private void DeleteOldLogFiles()
{
try
{
if (!Directory.Exists(_logPath))
{
// Nothing to delete
return;
}

// look for all of the log files
DirectoryInfo info = new DirectoryInfo(_logPath);
FileInfo[] files = info.GetFiles($"*.{_logExt}", SearchOption.TopDirectoryOnly);
Expand Down
5 changes: 4 additions & 1 deletion RetroBar/Utilities/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using ManagedShell.AppBar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;

namespace RetroBar.Utilities
Expand All @@ -23,8 +25,9 @@ public static Settings Instance
}
}

private static string _settingsPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RetroBar"), "settings.json");
private static bool _isInitializing = true;
private static SettingsManager<Settings> _settingsManager = new SettingsManager<Settings>(new Settings());
private static SettingsManager<Settings> _settingsManager = new SettingsManager<Settings>(_settingsPath, new Settings());

public event PropertyChangedEventHandler PropertyChanged;

Expand Down
12 changes: 9 additions & 3 deletions RetroBar/Utilities/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace RetroBar.Utilities
{
public class SettingsManager<T> : INotifyPropertyChanged
{
private string _fileName = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\RetroBar\\settings.json";

public event PropertyChangedEventHandler PropertyChanged;

private string _fileName;

private T _settings;
public T Settings
{
Expand All @@ -27,8 +27,9 @@ public T Settings
}
}

public SettingsManager(T defaultSettings)
public SettingsManager(string fileName, T defaultSettings)
{
_fileName = fileName;
_settings = defaultSettings;

if (!loadFromFile())
Expand Down Expand Up @@ -67,6 +68,11 @@ private void saveToFile()

try
{
if (!Directory.Exists(Path.GetDirectoryName(_fileName)))
{
Directory.CreateDirectory(Path.GetDirectoryName(_fileName));
}

string jsonString = JsonSerializer.Serialize(Settings, options);
File.WriteAllText(_fileName, jsonString);
}
Expand Down

0 comments on commit 2a213ee

Please sign in to comment.