-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Settings.cs
77 lines (73 loc) · 2.68 KB
/
Settings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Wox.Plugin.Logger;
using static Community.PowerToys.Run.Plugin.Everything.Interop.NativeMethods;
namespace Community.PowerToys.Run.Plugin.Everything
{
public class Settings
{
// Settings from PTR settings
public Sort Sort { get; set; } = Sort.NAME_ASCENDING;
public uint Max { get; set; } = 10;
public string Context { get; set; } = "0123456";
public bool Copy { get; set; }
public bool MatchPath { get; set; }
public bool Preview { get; set; } = true;
public bool QueryText { get; set; }
public bool RegEx { get; set; }
public bool EnvVar { get; set; }
public bool Updates { get; set; } = true;
public string Skip { get; set; }
public string Prefix { get; set; }
public string EverythingPath { get; set; }
public bool ShowMore { get; set; } = true;
public string CustomProgram { get; set; } = "notepad.exe";
public string CustomArg { get; set; } = "$P";
#if DEBUG
public LogLevel Log { get; set; } = LogLevel.None;
#endif
// Get Filters from settings.toml
public Dictionary<string, string> Filters { get; } = [];
internal void Getfilters()
{
Log.Info("User on Everything 1.4", GetType());
#if DEBUG
if (Log > LogLevel.None)
Debugger.Write("2.Getting Filters...");
#endif
string[] strArr;
try { strArr = File.ReadAllLines(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "settings.toml")); }
catch (Exception e)
{
#if DEBUG
if (Log > LogLevel.None)
Debugger.Write($"\r\nERROR: {e.Message}\r\n");
#endif
Log.Error($"Error reading settings.toml: {e.Message}", GetType());
return;
}
foreach (string str in strArr)
{
if (str.Length == 0 || str[0] == '#') continue;
string[] kv = str.Split('=', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (kv.Length != 2) continue;
if (kv[0].Contains(':'))
Filters.TryAdd(kv[0].ToLowerInvariant(), kv[1] + (kv[1].EndsWith(';') ? ' ' : string.Empty));
}
#if DEBUG
if (Log > LogLevel.None)
Debugger.Write(Log > LogLevel.Debug ? string.Join(Environment.NewLine, Filters) + "\r\n" : string.Empty + " GettingFilters...Done");
#endif
}
}
#if DEBUG
public enum LogLevel
{
None,
Debug,
Verbose,
}
#endif
}