Skip to content

Commit

Permalink
input text support dir path #27 #93
Browse files Browse the repository at this point in the history
  • Loading branch information
jitwxs committed May 28, 2022
1 parent 04d829f commit e8c44bb
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions MusicLyricApp/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ private void TrySetHighDPIFont(string fontName)
/// </summary>
private void ReloadConfig()
{
var ids = Search_Text.Text.Trim().Split(',');
_globalSearchInfo.InputIds = new string[ids.Length];
for (var i = 0; i < ids.Length; i++)
{
_globalSearchInfo.InputIds[i] = ids[i].Trim();
}
ReloadInputIdText();

_globalSearchInfo.SongIds.Clear();

Expand All @@ -150,6 +145,52 @@ private void ReloadConfig()
}
}

private void ReloadInputIdText()
{
var inputText = Search_Text.Text.Trim();

// 判断是否是目录
if (Directory.Exists(inputText))
{
var subFileNameList = new List<string>();

var directoryInfo = new DirectoryInfo(inputText);
foreach (var info in directoryInfo.GetFileSystemInfos())
{
if (info is DirectoryInfo)
{
// 文件夹,跳过处理,不做递归
continue;
}
else
{
var name = info.Name;

if (name.EndsWith(info.Extension))
{
name = name.Remove(name.Length - info.Extension.Length);
}

name = name.Trim();

subFileNameList.Add(name);
}
}

_globalSearchInfo.InputIds = subFileNameList.ToArray();
}
else
{
// 不是目录,认为是实际的 ID
var ids = Search_Text.Text.Trim().Split(',');
_globalSearchInfo.InputIds = new string[ids.Length];
for (var i = 0; i < ids.Length; i++)
{
_globalSearchInfo.InputIds[i] = ids[i].Trim();
}
}
}

/// <summary>
/// 根据歌曲ID查询
/// </summary>
Expand Down

0 comments on commit e8c44bb

Please sign in to comment.