EverythingPowerToys/Settings.cs

65 lines
2.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using NLog;
using Wox.Plugin.Logger;
using static Community.PowerToys.Run.Plugin.Everything.Interop.NativeMethods;
namespace Community.PowerToys.Run.Plugin.Everything
2023-01-07 02:20:22 +08:00
{
public class Settings
2022-12-11 02:20:09 +08:00
{
internal bool Is1_4 { get; set; }
2022-12-11 02:20:09 +08:00
// Settings from PTR settings
internal Sort Sort { get; set; } = Sort.NAME_ASCENDING;
internal uint Max { get; set; } = 10;
internal string Context { get; set; } = "01234568";
internal bool Copy { get; set; }
internal bool MatchPath { get; set; }
internal bool Preview { get; set; } = true;
internal bool QueryText { get; set; }
internal bool RegEx { get; set; }
internal bool EnvVar { get; set; }
internal bool Updates { get; set; } = true;
internal string Prefix { get; set; }
internal string EverythingPath { get; set; }
internal bool ShowMore { get; set; } = true;
internal string CustomProgram { get; set; } = "notepad.exe";
internal string CustomArg { get; set; } = "$P";
internal LogLevel LoggingLevel { get; set; } = LogLevel.Error;
2022-12-11 02:20:09 +08:00
// Get Filters from settings.toml
public Dictionary<string, string> Filters { get; } = [];
internal void Getfilters()
2022-12-11 02:20:09 +08:00
{
Is1_4 = true;
if (LoggingLevel <= LogLevel.Info)
Log.Info("User on Everything 1.4, GettingFilters...", GetType());
2022-12-11 02:20:09 +08:00
string[] strArr;
2022-12-17 22:53:28 +08:00
try { strArr = File.ReadAllLines(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "settings.toml")); }
2024-05-25 21:11:41 +08:00
catch (Exception e)
{
Log.Error($"Error reading settings.toml: {e.Message}", GetType());
2024-05-25 21:11:41 +08:00
return;
}
2022-12-11 02:20:09 +08:00
foreach (string str in strArr)
{
if (str.Length == 0 || str[0] == '#') continue;
2022-12-17 22:53:28 +08:00
string[] kv = str.Split('=', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
2022-12-11 02:20:09 +08:00
if (kv.Length != 2) continue;
if (kv[0].Contains(':'))
2024-05-25 21:11:41 +08:00
Filters.TryAdd(kv[0].ToLowerInvariant(), kv[1] + (kv[1].EndsWith(';') ? ' ' : string.Empty));
2022-12-11 02:20:09 +08:00
}
if (LoggingLevel <= LogLevel.Info)
Log.Info(LoggingLevel < LogLevel.Debug ? string.Join(Environment.NewLine, Filters) : " GettingFilters...Done", GetType());
2022-12-11 02:20:09 +08:00
}
}
}