Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not force loading additional dictionaries #687

Merged
merged 3 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions RetroBar/Extensions/ManagementExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.IO;

internal static class ManagementExtensions
{
public static string InLocalAppData(this string path1, string path2 = "")
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RetroBar", path1, path2);
}

public static void AddFrom(this List<string> list, string path, string extension, bool skipExisting = false)
{
if (!Directory.Exists(path))
{
return;
}

foreach (string file in Directory.GetFiles(path, $"*.{extension}"))
{
string fileName = Path.GetFileNameWithoutExtension(file);
if (skipExisting && list.Contains(fileName))
{
continue;
}
list.Add(fileName);
}
}
}
32 changes: 4 additions & 28 deletions RetroBar/Utilities/DictionaryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ private void SetDictionary(string dictionary, string dictFolder, string dictDefa
if (!File.Exists(dictFilePath))
{
// Installed dictionary in AppData directory
dictFilePath =
Path.ChangeExtension(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RetroBar", dictFolder, dictionary),
dictExtension);
dictFilePath = Path.ChangeExtension(dictFolder.InLocalAppData(dictionary), dictExtension);

if (!File.Exists(dictFilePath))
{
Expand Down Expand Up @@ -179,37 +177,15 @@ private List<string> GetDictionaries(string dictDefault, string dictFolder, stri
List<string> dictionaries = new List<string> { dictDefault };

// Built-in dictionaries
foreach (string subStr in Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dictFolder))
.Where(s => Path.GetExtension(s).Contains(dictExtension)))
{
dictionaries.Add(Path.GetFileNameWithoutExtension(subStr));
}
dictionaries.AddFrom(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dictFolder), dictExtension);

// Installed AppData dictionaries
string installedDictDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RetroBar", dictFolder);

if (Directory.Exists(installedDictDir))
{
foreach (string subStr in Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RetroBar", dictFolder))
.Where(s => Path.GetExtension(s).Contains(dictExtension)))
{
dictionaries.Add(Path.GetFileNameWithoutExtension(subStr));
}
}
dictionaries.AddFrom(dictFolder.InLocalAppData(), dictExtension);

// Same-folder dictionaries
// Because RetroBar is published as a single-file app, it gets extracted to a temp directory, so custom dictionaries won't be there.
// Get the executable path to find the custom dictionaries directory when not a debug build.
string customDictDir = Path.Combine(Path.GetDirectoryName(ExePath.GetExecutablePath()), dictFolder);

if (Directory.Exists(customDictDir))
{
foreach (string subStr in Directory.GetFiles(customDictDir)
.Where(s => Path.GetExtension(s).Contains(dictExtension) && !dictionaries.Contains(Path.GetFileNameWithoutExtension(s))))
{
dictionaries.Add(Path.GetFileNameWithoutExtension(subStr));
}
}
dictionaries.AddFrom(Path.Combine(Path.GetDirectoryName(ExePath.GetExecutablePath()), dictFolder), dictExtension, true);

return dictionaries;
}
Expand Down
2 changes: 1 addition & 1 deletion RetroBar/Utilities/ManagedShellLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RetroBar.Utilities
{
class ManagedShellLogger : IDisposable
{
private string _logPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RetroBar"), "Logs");
private string _logPath = "Logs".InLocalAppData();
private string _logName = DateTime.Now.ToString("yyyy-MM-dd_HHmmssfff");
private string _logExt = "log";
private TimeSpan _logRetention = new TimeSpan(7, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion RetroBar/Utilities/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static Settings Instance
}
}

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

Expand Down