Skip to content

Commit

Permalink
reset
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed May 20, 2024
1 parent a44ef7b commit 48f35d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
10 changes: 8 additions & 2 deletions OneMore/Commands/Styles/LoadStylesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Styles;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Resx = Properties.Resources;
Expand Down Expand Up @@ -40,8 +41,13 @@ public override async Task Execute(params object[] args)

public Theme LoadTheme()
{
var path = Path.Combine(PathHelper.GetAppDataPath(), Resx.ThemesFolder);
PathHelper.EnsurePathExists(path);
var path = ThemeProvider.GetCustomThemeDirectory();
if (!Directory.Exists(path) ||
!Directory.EnumerateFiles(path, "*.xml").Any())
{
path = ThemeProvider.GetThemeDirectory();
PathHelper.EnsurePathExists(path);
}

using var dialog = new OpenFileDialog
{
Expand Down
20 changes: 15 additions & 5 deletions OneMore/Styles/ThemeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ private Theme Load(string key)
key = Path.GetFileNameWithoutExtension(key);

// appdata\Roaming\OneMore\Themes\key-edited.xml
root = LoadFromFile(Path.Combine(
PathHelper.GetAppDataPath(), Resx.ThemesFolder, CustomFolder, $"{key}.xml"));
root = LoadFromFile(Path.Combine(GetCustomThemeDirectory(), $"{key}.xml"));

// appdata\Roaming\OneMore\Themes\key.xml
root ??= LoadFromFile(Path.Combine(
PathHelper.GetAppDataPath(), Resx.ThemesFolder, $"{key}.xml"));
root ??= LoadFromFile(Path.Combine(GetThemeDirectory(), $"{key}.xml"));

if (root is null)
{
Expand Down Expand Up @@ -148,6 +146,18 @@ private XElement LoadFromFile(string path)
}


public static string GetThemeDirectory()
{
return Path.Combine(PathHelper.GetAppDataPath(), Resx.ThemesFolder);
}


public static string GetCustomThemeDirectory()
{
return Path.Combine(PathHelper.GetAppDataPath(), Resx.ThemesFolder, CustomFolder);
}


public static void RecordTheme(string key)
{
var setprovider = new SettingsProvider();
Expand All @@ -162,7 +172,7 @@ public static void RecordTheme(string key)

public Theme ResetPredefinedTheme(string key)
{
var prefix = Path.Combine(PathHelper.GetAppDataPath(), Resx.ThemesFolder);
var prefix = GetThemeDirectory();

var source = Path.Combine(prefix, $"{key}.xml");
if (File.Exists(source))
Expand Down

0 comments on commit 48f35d3

Please sign in to comment.