不显示空白文件夹
This commit is contained in:
parent
5ffdccdfef
commit
3d1ebec4db
@ -103,6 +103,7 @@ public partial class MainTreePanel : Tree
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnMultiSelected(TreeItem item, long column, bool selected)
|
||||
@ -189,6 +190,7 @@ public partial class MainTreePanel : Tree
|
||||
_selectingNodes.Clear();
|
||||
|
||||
TreeItem root = CreateItem();
|
||||
_mapper[root] = new TreeNode(null);
|
||||
BuildTree(root, path);
|
||||
}
|
||||
|
||||
@ -197,35 +199,39 @@ public partial class MainTreePanel : Tree
|
||||
return _mapper.TryGetValue(item, out node);
|
||||
}
|
||||
|
||||
private void BuildTree(TreeItem root, string path)
|
||||
private bool BuildTree(TreeItem current, string path)
|
||||
{
|
||||
var nodes = new Stack<(TreeItem node, string path)>();
|
||||
_mapper[root] = new TreeNode(null);
|
||||
nodes.Push((root, path));
|
||||
while (nodes.Count > 0)
|
||||
var isEmpty = true;
|
||||
var node = _mapper[current];
|
||||
|
||||
foreach (var filePath in Directory.GetFiles(path))
|
||||
{
|
||||
var node = nodes.Pop();
|
||||
var father = node.node;
|
||||
var fatherNode = _mapper[father];
|
||||
isEmpty = false;
|
||||
var item = InitItem(filePath, false);
|
||||
var childNode = new TreeNode(item);
|
||||
node.AddNode(childNode);
|
||||
var child = CreateNode(current, item);
|
||||
_mapper[child] = childNode;
|
||||
}
|
||||
|
||||
foreach (var filePath in Directory.GetFiles(node.path))
|
||||
foreach (var subDirPath in Directory.GetDirectories(path))
|
||||
{
|
||||
var item = InitItem(subDirPath, true);
|
||||
var childNode = new TreeNode(item);
|
||||
node.AddNode(childNode);
|
||||
var child = CreateNode(current, item);
|
||||
_mapper[child] = childNode;
|
||||
if (BuildTree(child, subDirPath))
|
||||
{
|
||||
var item = InitItem(filePath, false);
|
||||
var childNode = new TreeNode(item);
|
||||
fatherNode.AddNode(childNode);
|
||||
var child = CreateNode(father, item);
|
||||
_mapper[child] = childNode;
|
||||
_mapper.Remove(child);
|
||||
child.Free();
|
||||
}
|
||||
|
||||
foreach (var subDirPath in Directory.GetDirectories(node.path))
|
||||
else
|
||||
{
|
||||
var item = InitItem(subDirPath, true);
|
||||
var childNode = new TreeNode(item);
|
||||
fatherNode.AddNode(childNode);
|
||||
var child = CreateNode(father, item);
|
||||
_mapper[child] = childNode;
|
||||
nodes.Push((child, subDirPath));
|
||||
isEmpty = false;
|
||||
}
|
||||
}
|
||||
|
||||
return isEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
21
FileMover.cs
Normal file
21
FileMover.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using Learn.Models;
|
||||
using Learn.Parsers;
|
||||
|
||||
namespace Learn;
|
||||
|
||||
public class FileMover(string targetPath)
|
||||
{
|
||||
private readonly HashSet<string> _visited = new ();
|
||||
|
||||
public void DoMove(TreeNode node)
|
||||
{
|
||||
if (!node.Info.IsFolder())
|
||||
{
|
||||
var path = ItemFields.MainKey_Path;
|
||||
if (_visited.Contains(path)) return;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
FileMover.cs.uid
Normal file
1
FileMover.cs.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://cbo6d0l8ax518
|
||||
47
Main.cs
47
Main.cs
@ -5,8 +5,10 @@ using System.IO;
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Learn;
|
||||
using Learn.Component;
|
||||
using Learn.Config;
|
||||
using Learn.Models;
|
||||
using Learn.Parsers;
|
||||
using Learn.Utils;
|
||||
|
||||
@ -19,6 +21,7 @@ public partial class Main : Node
|
||||
[Export] private Button _openDirButton;
|
||||
[Export] private Button _doParseButton;
|
||||
[Export] private Button _doTMDBParseButton;
|
||||
[Export] private Button _doMoveButton;
|
||||
[Export] private Button _saveButton;
|
||||
[Export] private Button _resetButton;
|
||||
[Export] private Button _loadButton;
|
||||
@ -59,9 +62,18 @@ public partial class Main : Node
|
||||
_mainTreePanel.AddColumn(_columnText.Text,
|
||||
int.TryParse(_columnIndexText.Text, out var index) ? index : -1,
|
||||
int.TryParse(_columnWidthText.Text, out var width) ? width : -1);
|
||||
DoSave();
|
||||
};
|
||||
_removeColumnButton.Pressed += () =>
|
||||
{
|
||||
_mainTreePanel.RemoveColumn(_columnText.Text);
|
||||
DoSave();
|
||||
};
|
||||
_clearColumnButton.Pressed += () =>
|
||||
{
|
||||
_mainTreePanel.ClearColumns();
|
||||
DoSave();
|
||||
};
|
||||
_removeColumnButton.Pressed += () => _mainTreePanel.RemoveColumn(_columnText.Text);
|
||||
_clearColumnButton.Pressed += () => _mainTreePanel.ClearColumns();
|
||||
|
||||
_expandAllButton.Pressed += ExpandAll;
|
||||
_foldAllButton.Pressed += FoldAll;
|
||||
@ -71,6 +83,7 @@ public partial class Main : Node
|
||||
_doParseButton.Pressed += DoParse;
|
||||
_doTMDBParseButton.Pressed += DoTMDBParse;
|
||||
_saveButton.Pressed += DoSave;
|
||||
_doMoveButton.Pressed += DoMove;
|
||||
_resetButton.Pressed += DoReset;
|
||||
_loadButton.Pressed += LoadData;
|
||||
_reloadConfigButton.Pressed += ReloadConfig;
|
||||
@ -159,7 +172,14 @@ public partial class Main : Node
|
||||
|
||||
foreach (var node in _mainTreePanel.SelectingNodes)
|
||||
{
|
||||
await parser.Parse(node);
|
||||
try
|
||||
{
|
||||
await parser.Parse(node);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GD.Print(ex);
|
||||
}
|
||||
}
|
||||
|
||||
_doTMDBParseButton.Disabled = false;
|
||||
@ -178,7 +198,14 @@ public partial class Main : Node
|
||||
|
||||
if (_mainTreePanel.Query(root, out var node))
|
||||
{
|
||||
await parser.Parse(node);
|
||||
try
|
||||
{
|
||||
await parser.Parse(node);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GD.Print(ex);
|
||||
}
|
||||
}
|
||||
|
||||
_doParseButton.Disabled = false;
|
||||
@ -189,6 +216,18 @@ public partial class Main : Node
|
||||
|
||||
private const string DataPath = "data.json";
|
||||
|
||||
private void DoMove()
|
||||
{
|
||||
var mover = new FileMover("");
|
||||
|
||||
foreach (var node in _mainTreePanel.SelectingNodes)
|
||||
{
|
||||
mover.DoMove(node);
|
||||
}
|
||||
|
||||
ScanDir();
|
||||
}
|
||||
|
||||
private void DoSave()
|
||||
{
|
||||
_mainTreePanel.SaveData(DataPath);
|
||||
|
||||
@ -17,12 +17,13 @@ grow_vertical = 2
|
||||
[node name="FileDirDialog" type="FileDialog" parent="."]
|
||||
script = ExtResource("1_d2g23")
|
||||
|
||||
[node name="Main" type="Node" parent="." node_paths=PackedStringArray("_dirSelector", "_openDirButton", "_doParseButton", "_doTMDBParseButton", "_saveButton", "_resetButton", "_loadButton", "_reloadConfigButton", "_nodeInfoEditPanel", "_addKeyButton", "_removeKeyButton", "_inspectorPanel", "_mainTreePanel", "_columnIndexText", "_columnWidthText", "_columnText", "_addColumnButton", "_removeColumnButton", "_clearColumnButton", "_expandAllButton", "_foldAllButton")]
|
||||
[node name="Main" type="Node" parent="." node_paths=PackedStringArray("_dirSelector", "_openDirButton", "_doParseButton", "_doTMDBParseButton", "_doMoveButton", "_saveButton", "_resetButton", "_loadButton", "_reloadConfigButton", "_nodeInfoEditPanel", "_addKeyButton", "_removeKeyButton", "_inspectorPanel", "_mainTreePanel", "_columnIndexText", "_columnWidthText", "_columnText", "_addColumnButton", "_removeColumnButton", "_clearColumnButton", "_expandAllButton", "_foldAllButton")]
|
||||
script = ExtResource("2_0727o")
|
||||
_dirSelector = NodePath("../FileDirDialog")
|
||||
_openDirButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/ScanDir")
|
||||
_doParseButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoParse")
|
||||
_doTMDBParseButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoTMDBParse")
|
||||
_doMoveButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoMove")
|
||||
_saveButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Save")
|
||||
_resetButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Reset")
|
||||
_loadButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Load")
|
||||
@ -108,6 +109,11 @@ layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
text = "搜刮选中部分"
|
||||
|
||||
[node name="DoMove" type="Button" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作"]
|
||||
layout_mode = 2
|
||||
text = "整理选中部分
|
||||
"
|
||||
|
||||
[node name="保存操作" type="VBoxContainer" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
@ -47,6 +47,9 @@ public static class ItemFields
|
||||
|
||||
public static string Key_TMDBID => "TMDBID";
|
||||
|
||||
public static string Key_Offset => "EpisodeOffset";
|
||||
|
||||
|
||||
public static ItemType Type(this Item item)
|
||||
{
|
||||
if (item.Info.TryGetValue(Key_Type, out var typeName))
|
||||
|
||||
@ -86,12 +86,20 @@ public class TMDBParser(Configs configs) : ItemParser
|
||||
return;
|
||||
}
|
||||
|
||||
var showInfo = await _client.GetTvShowAsync(result.Id, language: "zh-CN");
|
||||
|
||||
if (result.FirstAirDate != null)
|
||||
{
|
||||
node.Info.Info[ItemFields.Key_Year] = result.FirstAirDate.Value.Year.ToString();
|
||||
node.Info.Info[ItemFields.Key_Year] = showInfo.FirstAirDate.Value.Year.ToString();
|
||||
}
|
||||
|
||||
node.Info.Info[ItemFields.Key_Title] = result.Name;
|
||||
node.Info.Info[ItemFields.Key_TMDBID] = result.Id.ToString();
|
||||
node.Info.Info[ItemFields.Key_Title] = showInfo.Name;
|
||||
node.Info.Info[ItemFields.Key_TMDBID] = showInfo.Id.ToString();
|
||||
node.Info.Info["SeasonInfo"] = string.Join(", ", showInfo.Seasons.Select(season => season.Name));
|
||||
|
||||
if (showInfo.Seasons.Count == 1)
|
||||
{
|
||||
node.Info.Info.TryAdd(ItemFields.Key_Season, "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,8 @@
|
||||
## TODO
|
||||
|
||||
- [ ] 添加匹配Season功能
|
||||
- [ ] 添加剧集偏移功能
|
||||
- [ ] 解析操作添加异常保护
|
||||
- [ ] 实现Popout提示功能
|
||||
- [x] 添加匹配Season功能
|
||||
- [x] 添加剧集偏移功能
|
||||
- [x] 解析操作添加异常保护
|
||||
- [ ] 添加检查是否完全解析完成
|
||||
- 添加一个字段,如果是文件夹,就是文件夹下剩余未完全解析的数量;如果是文件,就是文件是否已经完全解析
|
||||
- 完全解析是指已经包含:Title、Episode、Season、TMDBID的剧集
|
||||
- [ ] 添加转移选中的项目,转移完成添加一个标记。有这个标记的被隐藏起来
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user