Flow.Launcher/Plugins/Flow.Launcher.Plugin.Program/Settings.cs

115 lines
4.1 KiB
C#
Raw Normal View History

2020-11-08 21:24:52 +00:00
using System;
2019-10-17 20:53:00 +00:00
using System.Collections.Generic;
2019-09-05 22:06:51 +00:00
using System.IO;
2022-10-23 09:29:37 +00:00
using System.Linq;
2022-10-23 10:50:38 +00:00
using System.Text.Json.Serialization;
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Plugin.Program
{
public class Settings
{
2019-10-17 21:16:07 +00:00
public DateTime LastIndexTime { get; set; }
2016-08-20 00:17:28 +00:00
public List<ProgramSource> ProgramSources { get; set; } = new List<ProgramSource>();
public List<DisabledProgramSource> DisabledProgramSources { get; set; } = new List<DisabledProgramSource>();
2022-10-23 12:01:18 +00:00
public string[] CustomSuffixes { get; set; } = Array.Empty<string>();
public string[] CustomProtocols { get; set; } = Array.Empty<string>();
2022-10-23 09:29:37 +00:00
2022-10-23 10:50:38 +00:00
[JsonIgnore]
2022-10-23 09:29:37 +00:00
public Dictionary<string, bool> BuiltinSuffixesStatus { get; set; } = new Dictionary<string, bool>{
{ "exe", true }, { "appref-ms", true }, { "lnk", true }
};
2022-10-23 12:01:18 +00:00
[JsonIgnore]
public Dictionary<string, bool> BuiltinProtocolsStatus { get; set; } = new Dictionary<string, bool>{
2022-10-23 14:09:22 +00:00
{ $"steam://run/{SuffixSeparator}steam://rungameid/", true }, { "com.epicgames.launcher://apps/", true }, { $"http://{SuffixSeparator}https://", false}
2022-10-23 12:01:18 +00:00
};
2022-10-23 14:09:22 +00:00
public bool UseCustomSuffixes { get; set; } = false;
public bool UseCustomProtocols { get; set; } = false;
2022-10-23 09:29:37 +00:00
2022-10-23 12:01:18 +00:00
public string[] GetSuffixes()
2022-10-23 09:29:37 +00:00
{
List<string> extensions = new List<string>();
foreach(var item in BuiltinSuffixesStatus)
{
if (item.Value)
{
extensions.Add(item.Key);
}
}
2022-10-23 12:01:18 +00:00
if (BuiltinProtocolsStatus.Values.Any(x => x == true) || UseCustomProtocols)
{
extensions.Add("url");
}
2022-10-23 10:50:38 +00:00
if (UseCustomSuffixes)
{
return extensions.Concat(CustomSuffixes).DistinctBy(x => x.ToLower()).ToArray();
}
else
{
2022-10-23 12:01:18 +00:00
return extensions.DistinctBy(x => x.ToLower()).ToArray();
2022-10-23 10:50:38 +00:00
}
2022-10-23 09:29:37 +00:00
}
2022-10-23 12:01:18 +00:00
public string[] GetProtocols()
{
List<string> protocols = new List<string>();
foreach (var item in BuiltinProtocolsStatus)
{
if (item.Value)
{
2022-10-23 14:09:22 +00:00
var tmp = item.Key.Split(SuffixSeparator, StringSplitOptions.RemoveEmptyEntries);
2022-10-23 12:01:18 +00:00
foreach(var p in tmp)
{
protocols.Add(p);
}
}
}
if (UseCustomProtocols)
{
return protocols.Concat(CustomProtocols).DistinctBy(x => x.ToLower()).ToArray();
}
else
{
return protocols.DistinctBy(x => x.ToLower()).ToArray();
}
}
2022-10-23 12:01:18 +00:00
public bool EnableStartMenuSource { get; set; } = true;
2021-11-27 20:05:25 +00:00
public bool EnableDescription { get; set; } = false;
public bool HideAppsPath { get; set; } = true;
public bool EnableRegistrySource { get; set; } = true;
2020-11-08 21:24:31 +00:00
public string CustomizedExplorer { get; set; } = Explorer;
2020-11-09 02:25:43 +00:00
public string CustomizedArgs { get; set; } = ExplorerArgs;
2016-08-19 19:34:20 +00:00
2022-10-23 14:09:22 +00:00
internal const char SuffixSeparator = ';';
2016-08-20 00:17:28 +00:00
2020-11-08 21:24:31 +00:00
internal const string Explorer = "explorer";
internal const string ExplorerArgs = "%s";
2020-11-09 02:25:43 +00:00
/// <summary>
/// Contains user added folder location contents as well as all user disabled applications
/// </summary>
/// <remarks>
2019-10-16 11:38:44 +00:00
/// <para>Win32 class applications set UniqueIdentifier using their full file path</para>
/// <para>UWP class applications set UniqueIdentifier using their Application User Model ID</para>
/// <para>Custom user added program sources set UniqueIdentifier using their location</para>
/// </remarks>
2016-08-20 00:17:28 +00:00
public class ProgramSource
{
2019-09-05 22:06:51 +00:00
private string name;
2016-08-20 00:17:28 +00:00
public string Location { get; set; }
2019-09-05 22:06:51 +00:00
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;
public string UniqueIdentifier { get; set; }
2016-08-20 00:17:28 +00:00
}
public class DisabledProgramSource : ProgramSource { }
}
}