新增应用程序图标并优化界面与匹配逻辑
- 增加 复制.ico 作为应用图标,并在项目文件中配置 ApplicationIcon。 - 修正 MatchFolderName 数字编号截取索引,保证匹配准确。 - 调整主窗口高度为 645,优化界面体验。 - LogTextBox 允许编辑(去除 IsReadOnly)。 - 处理单个料号时回车后自动聚焦输入框,提升操作流畅度。 - 代码格式优化,提升可读性。
This commit is contained in:
@@ -8,6 +8,11 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<Platforms>AnyCPU;x86</Platforms>
|
||||
<ApplicationIcon>复制.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="复制.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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<string>();
|
||||
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<string> codes, List<string> sourcePaths, string destPath,
|
||||
public async Task ProcessCodes(List<string> codes, List<string> sourcePaths, string destPath,
|
||||
IProgress<int> 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);
|
||||
}
|
||||
|
||||
@@ -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">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
@@ -50,7 +50,6 @@
|
||||
Height="60"
|
||||
Margin="5"
|
||||
AcceptsReturn="True"
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
VerticalScrollBarVisibility="Auto" />
|
||||
<Button
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace CopyRou
|
||||
_fileService = new FileService();
|
||||
_logger = new Logger();
|
||||
_config = AppConfig.Load();
|
||||
|
||||
|
||||
InitializeUI();
|
||||
SubscribeToEvents();
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace CopyRou
|
||||
// 加载配置到UI
|
||||
SourcePathsTextBox.Text = _config.GetSourcePathsText();
|
||||
DestPathTextBox.Text = _config.DestPath;
|
||||
|
||||
|
||||
// 设置初始状态
|
||||
StartButton.IsEnabled = true;
|
||||
ProgressBar.Value = 0;
|
||||
@@ -102,7 +102,7 @@ namespace CopyRou
|
||||
});
|
||||
|
||||
await _fileService.ProcessCodes(materialNumbers, sourcePaths, destPath, progress, _logger);
|
||||
|
||||
|
||||
_logger.Log("=== 处理完成 ===");
|
||||
System.Windows.MessageBox.Show("处理完成!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ namespace CopyRou
|
||||
_config.SetSourcePathsFromText(SourcePathsTextBox.Text);
|
||||
_config.DestPath = DestPathTextBox.Text;
|
||||
_config.Save();
|
||||
|
||||
|
||||
System.Windows.MessageBox.Show("配置已保存", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace CopyRou
|
||||
{
|
||||
var dialog = new System.Windows.Forms.FolderBrowserDialog();
|
||||
dialog.Description = "选择源路径";
|
||||
|
||||
|
||||
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
var currentPaths = GetSourcePaths();
|
||||
@@ -154,7 +154,7 @@ namespace CopyRou
|
||||
{
|
||||
var dialog = new System.Windows.Forms.FolderBrowserDialog();
|
||||
dialog.Description = "选择目标路径";
|
||||
|
||||
|
||||
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
DestPathTextBox.Text = dialog.SelectedPath;
|
||||
@@ -179,6 +179,7 @@ namespace CopyRou
|
||||
if (e.Key == System.Windows.Input.Key.Enter)
|
||||
{
|
||||
ProcessSingleCode();
|
||||
SingleCodeTextBox.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,12 +250,12 @@ namespace CopyRou
|
||||
});
|
||||
|
||||
await _fileService.ProcessCodes(materialNumbers, sourcePaths, destPath, progress, _logger);
|
||||
|
||||
|
||||
_logger.Log("=== 单个料号处理完成 ===");
|
||||
|
||||
|
||||
// 清空输入框
|
||||
SingleCodeTextBox.Clear();
|
||||
|
||||
|
||||
// 将焦点返回到输入框,方便继续输入
|
||||
SingleCodeTextBox.Focus();
|
||||
}
|
||||
@@ -277,7 +278,7 @@ namespace CopyRou
|
||||
_config.SetSourcePathsFromText(SourcePathsTextBox.Text);
|
||||
_config.DestPath = DestPathTextBox.Text;
|
||||
_config.Save();
|
||||
|
||||
|
||||
base.OnClosed(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user