新增应用程序图标并优化界面与匹配逻辑
- 增加 复制.ico 作为应用图标,并在项目文件中配置 ApplicationIcon。 - 修正 MatchFolderName 数字编号截取索引,保证匹配准确。 - 调整主窗口高度为 645,优化界面体验。 - LogTextBox 允许编辑(去除 IsReadOnly)。 - 处理单个料号时回车后自动聚焦输入框,提升操作流畅度。 - 代码格式优化,提升可读性。
This commit is contained in:
@@ -8,6 +8,11 @@
|
|||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<Platforms>AnyCPU;x86</Platforms>
|
<Platforms>AnyCPU;x86</Platforms>
|
||||||
|
<ApplicationIcon>复制.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="复制.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -10,25 +10,25 @@ namespace CopyRou
|
|||||||
{
|
{
|
||||||
public bool MatchFolderName(string folderName, string numPart, string versionPart)
|
public bool MatchFolderName(string folderName, string numPart, string versionPart)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(folderName) ||
|
if (string.IsNullOrEmpty(folderName) ||
|
||||||
string.IsNullOrEmpty(numPart) ||
|
string.IsNullOrEmpty(numPart) ||
|
||||||
string.IsNullOrEmpty(versionPart))
|
string.IsNullOrEmpty(versionPart))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var folderNameLower = folderName.ToLower();
|
var folderNameLower = folderName.ToLower();
|
||||||
var numLength = numPart.Length;
|
var numLength = numPart.Length;
|
||||||
|
|
||||||
// 检查文件夹名长度是否足够
|
// 检查文件夹名长度是否足够
|
||||||
if (folderNameLower.Length < 3 + numLength)
|
if (folderNameLower.Length < 3 + numLength)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 从第4个字符开始匹配数字编号(索引3)
|
// 从第4个字符开始匹配数字编号(索引3)
|
||||||
var numInName = folderNameLower.Substring(3, numLength);
|
var numInName = folderNameLower.Substring(4, numLength);
|
||||||
if (numInName != numPart.ToLower())
|
if (numInName != numPart.ToLower())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 检查版本部分
|
// 检查版本部分
|
||||||
var versionInName = folderNameLower.Substring(3 + numLength);
|
var versionInName = folderNameLower.Substring(4 + numLength);
|
||||||
return versionInName.StartsWith(versionPart.ToLower());
|
return versionInName.StartsWith(versionPart.ToLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,38 +37,38 @@ namespace CopyRou
|
|||||||
var copiedFiles = new List<string>();
|
var copiedFiles = new List<string>();
|
||||||
var edFoldersFound = 0;
|
var edFoldersFound = 0;
|
||||||
var rouExtensions = new[] { ".rou", ".rou1", ".rou2", ".rou3" };
|
var rouExtensions = new[] { ".rou", ".rou1", ".rou2", ".rou3" };
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 确保目标目录存在
|
// 确保目标目录存在
|
||||||
Directory.CreateDirectory(destPath);
|
Directory.CreateDirectory(destPath);
|
||||||
|
|
||||||
foreach (var item in Directory.GetDirectories(sourceFolder))
|
foreach (var item in Directory.GetDirectories(sourceFolder))
|
||||||
{
|
{
|
||||||
var folderName = Path.GetFileName(item);
|
var folderName = Path.GetFileName(item);
|
||||||
if (folderName.StartsWith("ED", StringComparison.OrdinalIgnoreCase) ||
|
if (folderName.StartsWith("ED", StringComparison.OrdinalIgnoreCase) ||
|
||||||
folderName.StartsWith("ROU", StringComparison.OrdinalIgnoreCase))
|
folderName.StartsWith("ROU", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
edFoldersFound++;
|
edFoldersFound++;
|
||||||
logger?.Log($"正在处理ED文件夹: {folderName}");
|
logger?.Log($"正在处理ED文件夹: {folderName}");
|
||||||
|
|
||||||
// 递归查找所有.rou文件
|
// 递归查找所有.rou文件
|
||||||
var rouFiles = Directory.GetFiles(item, "*.*", SearchOption.AllDirectories)
|
var rouFiles = Directory.GetFiles(item, "*.*", SearchOption.AllDirectories)
|
||||||
.Where(file => rouExtensions.Contains(Path.GetExtension(file).ToLower()))
|
.Where(file => rouExtensions.Contains(Path.GetExtension(file).ToLower()))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
foreach (var srcFile in rouFiles)
|
foreach (var srcFile in rouFiles)
|
||||||
{
|
{
|
||||||
var fileName = Path.GetFileName(srcFile);
|
var fileName = Path.GetFileName(srcFile);
|
||||||
var baseName = $"{number}_{folderName}_{fileName}";
|
var baseName = $"{number}_{folderName}_{fileName}";
|
||||||
var destFile = Path.Combine(destPath, baseName);
|
var destFile = Path.Combine(destPath, baseName);
|
||||||
|
|
||||||
File.Copy(srcFile, destFile, true);
|
File.Copy(srcFile, destFile, true);
|
||||||
copiedFiles.Add(baseName);
|
copiedFiles.Add(baseName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edFoldersFound == 0)
|
if (edFoldersFound == 0)
|
||||||
{
|
{
|
||||||
logger?.LogWarning("未找到任何以ED或ROU开头的文件夹");
|
logger?.LogWarning("未找到任何以ED或ROU开头的文件夹");
|
||||||
@@ -86,35 +86,35 @@ namespace CopyRou
|
|||||||
{
|
{
|
||||||
logger?.LogError($"复制文件时发生错误: {ex.Message}");
|
logger?.LogError($"复制文件时发生错误: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return copiedFiles;
|
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)
|
IProgress<int> progress, ILogger logger)
|
||||||
{
|
{
|
||||||
var totalCodes = codes.Count;
|
var totalCodes = codes.Count;
|
||||||
var processedCodes = 0;
|
var processedCodes = 0;
|
||||||
|
|
||||||
foreach (var code in codes)
|
foreach (var code in codes)
|
||||||
{
|
{
|
||||||
var trimmedCode = code.Trim();
|
var trimmedCode = code.Trim();
|
||||||
if (string.IsNullOrEmpty(trimmedCode))
|
if (string.IsNullOrEmpty(trimmedCode))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
logger?.Log($"\n处理编号: {trimmedCode}");
|
logger?.Log($"\n处理编号: {trimmedCode}");
|
||||||
|
|
||||||
var numPart = trimmedCode.Length >= 5 ? trimmedCode.Substring(0, 5) : trimmedCode;
|
var numPart = trimmedCode.Length >= 5 ? trimmedCode.Substring(0, 5) : trimmedCode;
|
||||||
var versionPart = trimmedCode.Length > 5 ? trimmedCode.Substring(5) : "";
|
var versionPart = trimmedCode.Length > 5 ? trimmedCode.Substring(5) : "";
|
||||||
|
|
||||||
var found = false;
|
var found = false;
|
||||||
|
|
||||||
foreach (var sourceRoot in sourcePaths)
|
foreach (var sourceRoot in sourcePaths)
|
||||||
{
|
{
|
||||||
var numFolder = Path.Combine(sourceRoot, numPart);
|
var numFolder = Path.Combine(sourceRoot, numPart);
|
||||||
if (!Directory.Exists(numFolder))
|
if (!Directory.Exists(numFolder))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var folders = Directory.GetDirectories(numFolder);
|
var folders = Directory.GetDirectories(numFolder);
|
||||||
@@ -134,15 +134,15 @@ namespace CopyRou
|
|||||||
logger?.LogError($"访问文件夹 {numFolder} 时发生错误: {ex.Message}");
|
logger?.LogError($"访问文件夹 {numFolder} 时发生错误: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
logger?.Log("未找到匹配的文件夹");
|
logger?.Log("未找到匹配的文件夹");
|
||||||
}
|
}
|
||||||
|
|
||||||
processedCodes++;
|
processedCodes++;
|
||||||
progress?.Report((int)((double)processedCodes / totalCodes * 100));
|
progress?.Report((int)((double)processedCodes / totalCodes * 100));
|
||||||
|
|
||||||
// 添加小延迟以避免UI阻塞
|
// 添加小延迟以避免UI阻塞
|
||||||
await Task.Delay(10);
|
await Task.Delay(10);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
Title="ROU文件复制工具"
|
Title="ROU文件复制工具"
|
||||||
Width="586"
|
Width="586"
|
||||||
Height="631"
|
Height="645"
|
||||||
MinWidth="586"
|
MinWidth="586"
|
||||||
MinHeight="631"
|
MinHeight="645"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Grid Margin="10">
|
<Grid Margin="10">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
@@ -50,7 +50,6 @@
|
|||||||
Height="60"
|
Height="60"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
AcceptsReturn="True"
|
AcceptsReturn="True"
|
||||||
IsReadOnly="True"
|
|
||||||
TextWrapping="Wrap"
|
TextWrapping="Wrap"
|
||||||
VerticalScrollBarVisibility="Auto" />
|
VerticalScrollBarVisibility="Auto" />
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace CopyRou
|
|||||||
_fileService = new FileService();
|
_fileService = new FileService();
|
||||||
_logger = new Logger();
|
_logger = new Logger();
|
||||||
_config = AppConfig.Load();
|
_config = AppConfig.Load();
|
||||||
|
|
||||||
InitializeUI();
|
InitializeUI();
|
||||||
SubscribeToEvents();
|
SubscribeToEvents();
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ namespace CopyRou
|
|||||||
// 加载配置到UI
|
// 加载配置到UI
|
||||||
SourcePathsTextBox.Text = _config.GetSourcePathsText();
|
SourcePathsTextBox.Text = _config.GetSourcePathsText();
|
||||||
DestPathTextBox.Text = _config.DestPath;
|
DestPathTextBox.Text = _config.DestPath;
|
||||||
|
|
||||||
// 设置初始状态
|
// 设置初始状态
|
||||||
StartButton.IsEnabled = true;
|
StartButton.IsEnabled = true;
|
||||||
ProgressBar.Value = 0;
|
ProgressBar.Value = 0;
|
||||||
@@ -102,7 +102,7 @@ namespace CopyRou
|
|||||||
});
|
});
|
||||||
|
|
||||||
await _fileService.ProcessCodes(materialNumbers, sourcePaths, destPath, progress, _logger);
|
await _fileService.ProcessCodes(materialNumbers, sourcePaths, destPath, progress, _logger);
|
||||||
|
|
||||||
_logger.Log("=== 处理完成 ===");
|
_logger.Log("=== 处理完成 ===");
|
||||||
System.Windows.MessageBox.Show("处理完成!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
System.Windows.MessageBox.Show("处理完成!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ namespace CopyRou
|
|||||||
_config.SetSourcePathsFromText(SourcePathsTextBox.Text);
|
_config.SetSourcePathsFromText(SourcePathsTextBox.Text);
|
||||||
_config.DestPath = DestPathTextBox.Text;
|
_config.DestPath = DestPathTextBox.Text;
|
||||||
_config.Save();
|
_config.Save();
|
||||||
|
|
||||||
System.Windows.MessageBox.Show("配置已保存", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
System.Windows.MessageBox.Show("配置已保存", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ namespace CopyRou
|
|||||||
{
|
{
|
||||||
var dialog = new System.Windows.Forms.FolderBrowserDialog();
|
var dialog = new System.Windows.Forms.FolderBrowserDialog();
|
||||||
dialog.Description = "选择源路径";
|
dialog.Description = "选择源路径";
|
||||||
|
|
||||||
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||||
{
|
{
|
||||||
var currentPaths = GetSourcePaths();
|
var currentPaths = GetSourcePaths();
|
||||||
@@ -154,7 +154,7 @@ namespace CopyRou
|
|||||||
{
|
{
|
||||||
var dialog = new System.Windows.Forms.FolderBrowserDialog();
|
var dialog = new System.Windows.Forms.FolderBrowserDialog();
|
||||||
dialog.Description = "选择目标路径";
|
dialog.Description = "选择目标路径";
|
||||||
|
|
||||||
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||||
{
|
{
|
||||||
DestPathTextBox.Text = dialog.SelectedPath;
|
DestPathTextBox.Text = dialog.SelectedPath;
|
||||||
@@ -179,6 +179,7 @@ namespace CopyRou
|
|||||||
if (e.Key == System.Windows.Input.Key.Enter)
|
if (e.Key == System.Windows.Input.Key.Enter)
|
||||||
{
|
{
|
||||||
ProcessSingleCode();
|
ProcessSingleCode();
|
||||||
|
SingleCodeTextBox.Focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,12 +250,12 @@ namespace CopyRou
|
|||||||
});
|
});
|
||||||
|
|
||||||
await _fileService.ProcessCodes(materialNumbers, sourcePaths, destPath, progress, _logger);
|
await _fileService.ProcessCodes(materialNumbers, sourcePaths, destPath, progress, _logger);
|
||||||
|
|
||||||
_logger.Log("=== 单个料号处理完成 ===");
|
_logger.Log("=== 单个料号处理完成 ===");
|
||||||
|
|
||||||
// 清空输入框
|
// 清空输入框
|
||||||
SingleCodeTextBox.Clear();
|
SingleCodeTextBox.Clear();
|
||||||
|
|
||||||
// 将焦点返回到输入框,方便继续输入
|
// 将焦点返回到输入框,方便继续输入
|
||||||
SingleCodeTextBox.Focus();
|
SingleCodeTextBox.Focus();
|
||||||
}
|
}
|
||||||
@@ -277,7 +278,7 @@ namespace CopyRou
|
|||||||
_config.SetSourcePathsFromText(SourcePathsTextBox.Text);
|
_config.SetSourcePathsFromText(SourcePathsTextBox.Text);
|
||||||
_config.DestPath = DestPathTextBox.Text;
|
_config.DestPath = DestPathTextBox.Text;
|
||||||
_config.Save();
|
_config.Save();
|
||||||
|
|
||||||
base.OnClosed(e);
|
base.OnClosed(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user