using System;
using System.IO;
using Flow.Launcher.Plugin.Program.Programs;
namespace Flow.Launcher.Plugin.Program.Views.Models
{
///
/// Contains user added folder location contents as well as all user disabled applications
///
///
/// Win32 class applications set UniqueIdentifier using their full file path
/// UWP class applications set UniqueIdentifier using their Application User Model ID
/// Custom user added program sources set UniqueIdentifier using their location
///
public class ProgramSource
{
private string name;
public string Location;
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;
private string uid { get; set; }
///
/// Guranteed lowercase.
///
public string UniqueIdentifier { get => uid; set => uid = value.ToLowerInvariant(); }
public ProgramSource()
{
} // TODO Remove
///
/// Custom user added source.
///
///
///
public ProgramSource(string location, bool enabled)
{
Location = location;
Enabled = enabled;
UniqueIdentifier = location;
}
public ProgramSource(ProgramSource source)
{
Location = source.Location;
Name = source.Name;
Enabled = source.Enabled;
UniqueIdentifier = source.UniqueIdentifier;
}
public ProgramSource(IProgram source)
{
Location = source.Location;
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()
{
return HashCode.Combine(uid);
}
}
public class DisabledProgramSource : ProgramSource
{
//public DisabledProgramSource() { }
public DisabledProgramSource(string location) : base(location, false) { }
public DisabledProgramSource(ProgramSource source) : base(source)
{
Enabled = false;
}
public DisabledProgramSource(IProgram program) : base(program)
{
Enabled = false;
}
}
}