From 0a534e7e088694276f2abacef773e1abc84b0f39 Mon Sep 17 00:00:00 2001
From: "Mr.Xia" <1424473282@qq.com>
Date: Mon, 29 Dec 2025 16:41:44 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BA=94=E7=94=A8=E7=A8=8B?=
=?UTF-8?q?=E5=BA=8F=E5=9B=BE=E6=A0=87=E5=B9=B6=E4=BC=98=E5=8C=96=E7=95=8C?=
=?UTF-8?q?=E9=9D=A2=E4=B8=8E=E5=8C=B9=E9=85=8D=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 增加 复制.ico 作为应用图标,并在项目文件中配置 ApplicationIcon。
- 修正 MatchFolderName 数字编号截取索引,保证匹配准确。
- 调整主窗口高度为 645,优化界面体验。
- LogTextBox 允许编辑(去除 IsReadOnly)。
- 处理单个料号时回车后自动聚焦输入框,提升操作流畅度。
- 代码格式优化,提升可读性。
---
CopyRou.csproj | 5 +++++
FileService.cs | 52 ++++++++++++++++++++++-----------------------
MainWindow.xaml | 5 ++---
MainWindow.xaml.cs | 21 +++++++++---------
复制.ico | Bin 0 -> 16958 bytes
5 files changed, 44 insertions(+), 39 deletions(-)
create mode 100644 复制.ico
diff --git a/CopyRou.csproj b/CopyRou.csproj
index efbaa4d..1a08877 100644
--- a/CopyRou.csproj
+++ b/CopyRou.csproj
@@ -8,6 +8,11 @@
true
true
AnyCPU;x86
+ 复制.ico
+
+
+
+
diff --git a/FileService.cs b/FileService.cs
index 9f965ec..0dc0169 100644
--- a/FileService.cs
+++ b/FileService.cs
@@ -10,25 +10,25 @@ namespace CopyRou
{
public bool MatchFolderName(string folderName, string numPart, string versionPart)
{
- if (string.IsNullOrEmpty(folderName) ||
- string.IsNullOrEmpty(numPart) ||
+ if (string.IsNullOrEmpty(folderName) ||
+ string.IsNullOrEmpty(numPart) ||
string.IsNullOrEmpty(versionPart))
return false;
-
+
var folderNameLower = folderName.ToLower();
var numLength = numPart.Length;
-
+
// 检查文件夹名长度是否足够
if (folderNameLower.Length < 3 + numLength)
return false;
-
+
// 从第4个字符开始匹配数字编号(索引3)
- var numInName = folderNameLower.Substring(3, numLength);
+ var numInName = folderNameLower.Substring(4, numLength);
if (numInName != numPart.ToLower())
return false;
-
+
// 检查版本部分
- var versionInName = folderNameLower.Substring(3 + numLength);
+ var versionInName = folderNameLower.Substring(4 + numLength);
return versionInName.StartsWith(versionPart.ToLower());
}
@@ -37,38 +37,38 @@ namespace CopyRou
var copiedFiles = new List();
var edFoldersFound = 0;
var rouExtensions = new[] { ".rou", ".rou1", ".rou2", ".rou3" };
-
+
try
{
// 确保目标目录存在
Directory.CreateDirectory(destPath);
-
+
foreach (var item in Directory.GetDirectories(sourceFolder))
{
var folderName = Path.GetFileName(item);
- if (folderName.StartsWith("ED", StringComparison.OrdinalIgnoreCase) ||
+ if (folderName.StartsWith("ED", StringComparison.OrdinalIgnoreCase) ||
folderName.StartsWith("ROU", StringComparison.OrdinalIgnoreCase))
{
edFoldersFound++;
logger?.Log($"正在处理ED文件夹: {folderName}");
-
+
// 递归查找所有.rou文件
var rouFiles = Directory.GetFiles(item, "*.*", SearchOption.AllDirectories)
.Where(file => rouExtensions.Contains(Path.GetExtension(file).ToLower()))
.ToList();
-
+
foreach (var srcFile in rouFiles)
{
var fileName = Path.GetFileName(srcFile);
var baseName = $"{number}_{folderName}_{fileName}";
var destFile = Path.Combine(destPath, baseName);
-
+
File.Copy(srcFile, destFile, true);
copiedFiles.Add(baseName);
}
}
}
-
+
if (edFoldersFound == 0)
{
logger?.LogWarning("未找到任何以ED或ROU开头的文件夹");
@@ -86,35 +86,35 @@ namespace CopyRou
{
logger?.LogError($"复制文件时发生错误: {ex.Message}");
}
-
+
return copiedFiles;
}
- public async Task ProcessCodes(List codes, List sourcePaths, string destPath,
+ public async Task ProcessCodes(List codes, List sourcePaths, string destPath,
IProgress progress, ILogger logger)
{
var totalCodes = codes.Count;
var processedCodes = 0;
-
+
foreach (var code in codes)
{
var trimmedCode = code.Trim();
if (string.IsNullOrEmpty(trimmedCode))
continue;
-
+
logger?.Log($"\n处理编号: {trimmedCode}");
-
+
var numPart = trimmedCode.Length >= 5 ? trimmedCode.Substring(0, 5) : trimmedCode;
var versionPart = trimmedCode.Length > 5 ? trimmedCode.Substring(5) : "";
-
+
var found = false;
-
+
foreach (var sourceRoot in sourcePaths)
{
var numFolder = Path.Combine(sourceRoot, numPart);
if (!Directory.Exists(numFolder))
continue;
-
+
try
{
var folders = Directory.GetDirectories(numFolder);
@@ -134,15 +134,15 @@ namespace CopyRou
logger?.LogError($"访问文件夹 {numFolder} 时发生错误: {ex.Message}");
}
}
-
+
if (!found)
{
logger?.Log("未找到匹配的文件夹");
}
-
+
processedCodes++;
progress?.Report((int)((double)processedCodes / totalCodes * 100));
-
+
// 添加小延迟以避免UI阻塞
await Task.Delay(10);
}
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 354a9c2..807d4a1 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -7,9 +7,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="ROU文件复制工具"
Width="586"
- Height="631"
+ Height="645"
MinWidth="586"
- MinHeight="631"
+ MinHeight="645"
mc:Ignorable="d">
@@ -50,7 +50,6 @@
Height="60"
Margin="5"
AcceptsReturn="True"
- IsReadOnly="True"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto" />