Flow.Launcher/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs

90 lines
2.8 KiB
C#
Raw Normal View History

2022-10-20 08:15:56 +00:00
using System;
using System.IO;
using System.Text.Json.Serialization;
2022-10-20 08:15:56 +00:00
using Flow.Launcher.Plugin.Program.Programs;
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Plugin.Program.Views.Models
2019-09-08 12:18:55 +00:00
{
2022-10-20 08:15:56 +00:00
/// <summary>
/// Contains user added folder location contents as well as all user disabled applications
/// </summary>
/// <remarks>
/// <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>
public class ProgramSource
{
2022-11-14 16:43:37 +00:00
private string name = string.Empty;
2022-11-14 16:07:12 +00:00
private string loc = string.Empty;
private string uniqueIdentifier = string.Empty;
2022-10-20 08:15:56 +00:00
2022-10-28 12:00:38 +00:00
public string Location
{
get => loc;
set
{
2022-11-14 16:07:12 +00:00
loc = value ?? string.Empty;
UniqueIdentifier = value;
2022-10-28 12:00:38 +00:00
}
}
2022-11-14 16:07:12 +00:00
2022-11-14 16:48:24 +00:00
public string Name { get => name; set => name = value ?? string.Empty; }
2022-10-20 08:15:56 +00:00
public bool Enabled { get; set; } = true;
2022-11-14 16:48:24 +00:00
public string UniqueIdentifier
{
get => uniqueIdentifier;
2022-11-14 16:07:12 +00:00
private set
{
uniqueIdentifier = value == null ? string.Empty : value.ToLowerInvariant();
2022-11-14 16:48:24 +00:00
}
2022-11-14 16:07:12 +00:00
}
2022-10-20 08:15:56 +00:00
[JsonConstructor]
public ProgramSource(string name, string location, bool enabled, string uniqueIdentifier)
{
2022-11-14 16:07:12 +00:00
loc = location ?? string.Empty;
2022-11-14 16:43:37 +00:00
Name = name;
Enabled = enabled;
2022-11-14 16:07:12 +00:00
UniqueIdentifier = uniqueIdentifier;
}
2022-10-20 08:15:56 +00:00
/// <summary>
2022-10-20 10:16:46 +00:00
/// Add source by location
2022-10-20 08:15:56 +00:00
/// </summary>
2022-10-20 10:16:46 +00:00
/// <param name="location">location of program source</param>
/// <param name="enabled">enabled</param>
2022-10-28 12:00:38 +00:00
public ProgramSource(string location, bool enabled = true)
2022-10-20 08:15:56 +00:00
{
2022-11-14 16:07:12 +00:00
loc = location ?? string.Empty;
2022-10-20 08:15:56 +00:00
Enabled = enabled;
2022-11-14 16:07:12 +00:00
UniqueIdentifier = location; // For path comparison
2022-11-14 16:43:37 +00:00
Name = new DirectoryInfo(Location).Name;
2022-10-20 08:15:56 +00:00
}
public ProgramSource(IProgram source)
{
2022-11-14 16:43:37 +00:00
loc = source.Location ?? string.Empty;
2022-10-20 08:15:56 +00:00
Name = source.Name;
Enabled = source.Enabled;
UniqueIdentifier = source.UniqueIdentifier;
}
public override bool Equals(object obj)
{
return obj is ProgramSource other && other.UniqueIdentifier == this.UniqueIdentifier;
}
public bool Equals(IProgram program)
{
return program != null && program.UniqueIdentifier == this.UniqueIdentifier;
}
public override int GetHashCode()
{
2022-12-06 14:47:27 +00:00
return uniqueIdentifier.GetHashCode();
}
2022-10-20 08:15:56 +00:00
}
2019-09-08 12:18:55 +00:00
}