From c82a22bf31500ca83ee16aa7eed7dbd6e967f365 Mon Sep 17 00:00:00 2001 From: limil Date: Fri, 16 Jan 2026 11:40:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A7=BB=E5=8A=A8=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Component/MainTreePanel.cs | 2 +- Config/AppConfig.cs | 2 ++ FileMover.cs | 28 +++++++++++++++++++++++----- Main.cs | 14 +++++++++++--- MediaTreeEditor.tscn | 9 ++++++++- project.godot | 2 ++ 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Component/MainTreePanel.cs b/Component/MainTreePanel.cs index 9a71914..1a9d890 100644 --- a/Component/MainTreePanel.cs +++ b/Component/MainTreePanel.cs @@ -38,7 +38,7 @@ public partial class MainTreePanel : Tree SetColumnTitlesVisible(true); SetColumnTitle(0, "文件名"); - SetColumnCustomMinimumWidth(0, 800); + SetColumnCustomMinimumWidth(0, 400); SetColumnExpand(0, true); MultiSelected += OnMultiSelected; diff --git a/Config/AppConfig.cs b/Config/AppConfig.cs index cea4e42..36bcd22 100644 --- a/Config/AppConfig.cs +++ b/Config/AppConfig.cs @@ -6,4 +6,6 @@ namespace Learn.Config; public class AppConfig : IConfigItem { public string ScanPath { get; set; } = ""; + + public string TargetPath { get; set; } = ""; } \ No newline at end of file diff --git a/FileMover.cs b/FileMover.cs index 0c7aa08..0c634b1 100644 --- a/FileMover.cs +++ b/FileMover.cs @@ -6,7 +6,7 @@ using Learn.Parsers; namespace Learn; -public class FileMover(string targetPath) +public class FileMover(string targetPath, bool preview) { private readonly HashSet _visited = new (); @@ -77,8 +77,8 @@ public class FileMover(string targetPath) var filename = string.Join(" ", string.Join(" ", filenameParts), string.Join("", metaParts.Select(part => $"[{part}]"))); filename += Path.GetExtension(path); - var filePath = string.Join("/", targetPath, relativePath, filename); - node.Info.Info["TargetPath"] = filePath; + var target = string.Join("/", targetPath, relativePath, filename); + MoveIt(node, target); } private void MoveExtra(TreeNode node) @@ -87,8 +87,26 @@ public class FileMover(string targetPath) var path = node.Info.MainInfo[ItemFields.MainKey_Path]; var name = Path.GetFileName(path); - var target = string.Join("/", targetPath, relativePath, name); - node.Info.Info["TargetPath"] = target; + var target = string.Join("/", targetPath, relativePath, "Extra", name); + MoveIt(node, target); + } + + private void MoveIt(TreeNode node, string targetPath) + { + node.Info.Info["TargetPath"] = targetPath; + if (preview) return; + var path = node.Info.MainInfo[ItemFields.MainKey_Path]; + if (File.Exists(targetPath)) return; + if (Directory.Exists(path)) + { + Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); + Directory.Move(path, targetPath); + } + else + { + Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); + File.Move(path, targetPath); + } } public void DoMove(TreeNode node) diff --git a/Main.cs b/Main.cs index ab023c3..ba2661c 100644 --- a/Main.cs +++ b/Main.cs @@ -22,6 +22,7 @@ public partial class Main : Node [Export] private Button _doParseButton; [Export] private Button _doTMDBParseButton; [Export] private Button _doMoveButton; + [Export] private Button _startMoveButton; [Export] private Button _saveButton; [Export] private Button _resetButton; [Export] private Button _loadButton; @@ -83,7 +84,8 @@ public partial class Main : Node _doParseButton.Pressed += DoParse; _doTMDBParseButton.Pressed += DoTMDBParse; _saveButton.Pressed += DoSave; - _doMoveButton.Pressed += DoMove; + _doMoveButton.Pressed += () => DoMove(true); + _startMoveButton.Pressed += () => DoMove(false); _resetButton.Pressed += DoReset; _loadButton.Pressed += LoadData; _reloadConfigButton.Pressed += ReloadConfig; @@ -216,9 +218,9 @@ public partial class Main : Node private const string DataPath = "data.json"; - private void DoMove() + private void DoMove(bool preview) { - var mover = new FileMover(""); + var mover = new FileMover(_configs.Get().TargetPath, preview); foreach (var node in _mainTreePanel.SelectingNodes) { @@ -226,6 +228,12 @@ public partial class Main : Node } _mainTreePanel.UpdateColumns(); + DoSave(); + + if (!preview) + { + ScanDir(); + } } private void DoSave() diff --git a/MediaTreeEditor.tscn b/MediaTreeEditor.tscn index 3a2913f..1474d19 100644 --- a/MediaTreeEditor.tscn +++ b/MediaTreeEditor.tscn @@ -17,13 +17,14 @@ 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", "_doMoveButton", "_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", "_startMoveButton", "_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") +_startMoveButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/StartMove") _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") @@ -61,6 +62,8 @@ layout_mode = 2 layout_mode = 2 size_flags_horizontal = 3 size_flags_stretch_ratio = 7.0 +theme_override_font_sizes/font_size = 8 +theme_override_font_sizes/title_button_font_size = 12 allow_search = false hide_root = true select_mode = 2 @@ -114,6 +117,10 @@ layout_mode = 2 text = "整理选中部分 " +[node name="StartMove" 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 diff --git a/project.godot b/project.godot index 6bc9f78..c75b4ad 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,8 @@ config/icon="res://icon.svg" window/size/viewport_width=1600 window/size/viewport_height=900 +window/stretch/mode="canvas_items" +window/stretch/aspect="expand" [dotnet]