mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-01-14 22:18:43 +00:00
Implement Database List with Tag filter, escape name
This commit is contained in:
parent
f999ef6f8c
commit
405e85f30f
@ -17,6 +17,8 @@ namespace MpcNET.Commands.Database
|
|||||||
public class ListCommand : IMpcCommand<List<string>>
|
public class ListCommand : IMpcCommand<List<string>>
|
||||||
{
|
{
|
||||||
private readonly ITag tag;
|
private readonly ITag tag;
|
||||||
|
private readonly ITag filterTag;
|
||||||
|
private readonly string filterValue;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ListCommand"/> class.
|
/// Initializes a new instance of the <see cref="ListCommand"/> class.
|
||||||
@ -27,13 +29,32 @@ namespace MpcNET.Commands.Database
|
|||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ListCommand"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tag">The tag.</param>
|
||||||
|
/// <param name="filterTag">The filter tag.</param>
|
||||||
|
/// <param name="filterValue">Filter value.</param>
|
||||||
|
public ListCommand(ITag tag, ITag filterTag, string filterValue)
|
||||||
|
{
|
||||||
|
this.tag = tag;
|
||||||
|
this.filterTag = filterTag;
|
||||||
|
this.filterValue = filterValue;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes the command.
|
/// Serializes the command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// The serialize command.
|
/// The serialize command.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public string Serialize() => string.Join(" ", "list", this.tag.Value);
|
public string Serialize()
|
||||||
|
{
|
||||||
|
if (this.filterTag == null)
|
||||||
|
return string.Join(" ", "list", this.tag.Value);
|
||||||
|
|
||||||
|
return string.Join(" ", "list", this.tag.Value, this.filterTag.Value, escape(this.filterValue));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes the specified response text pairs.
|
/// Deserializes the specified response text pairs.
|
||||||
@ -46,6 +67,8 @@ namespace MpcNET.Commands.Database
|
|||||||
{
|
{
|
||||||
return response.Select(x => x.Value).ToList();
|
return response.Select(x => x.Value).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string escape(string value) => string.Format("\"{0}\"", value.Replace("\\", "\\\\").Replace("\"", "\\\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rescan
|
// TODO: rescan
|
||||||
|
Loading…
Reference in New Issue
Block a user