代码清理

This commit is contained in:
PrefacedCorg
2025-08-03 16:46:33 +08:00
parent 745b798d89
commit 11a5a7fdbe
73 changed files with 5733 additions and 3857 deletions
@@ -1,8 +1,8 @@
using Microsoft.Win32;
using System;
using System.IO;
using System.Windows;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
namespace Ink_Canvas
{
@@ -20,7 +20,7 @@ namespace Ink_Canvas
InitializeComponent();
mainWindow = owner;
IsSuccess = false;
// 添加TextBox内容变化事件以检查是否可以保存
BackgroundNameTextBox.TextChanged += (s, e) => ValidateSaveButton();
}
@@ -37,7 +37,7 @@ namespace Ink_Canvas
{
selectedFilePath = openFileDialog.FileName;
BackgroundPathTextBox.Text = selectedFilePath;
// 显示预览
try
{
@@ -52,15 +52,15 @@ namespace Ink_Canvas
{
MessageBox.Show($"无法加载图像: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
// 自动填充名称建议(文件名,不包括扩展名)
string suggestedName = Path.GetFileNameWithoutExtension(selectedFilePath);
BackgroundNameTextBox.Text = suggestedName;
ValidateSaveButton();
}
}
private void ValidateSaveButton()
{
SaveButton.IsEnabled = !string.IsNullOrWhiteSpace(BackgroundNameTextBox.Text) && !string.IsNullOrEmpty(selectedFilePath);
@@ -78,37 +78,37 @@ namespace Ink_Canvas
// 创建pictures/picknamebackgrounds文件夹结构(如果不存在)
string picturesFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pictures");
string backgroundsFolder = Path.Combine(picturesFolder, "picknamebackgrounds");
if (!Directory.Exists(picturesFolder))
{
Directory.CreateDirectory(picturesFolder);
}
if (!Directory.Exists(backgroundsFolder))
{
Directory.CreateDirectory(backgroundsFolder);
}
// 生成一个唯一的文件名(使用GUID)
string extension = Path.GetExtension(selectedFilePath);
string newFileName = $"{Guid.NewGuid()}{extension}";
string destPath = Path.Combine(backgroundsFolder, newFileName);
// 复制文件到pictures/picknamebackgrounds文件夹
File.Copy(selectedFilePath, destPath);
// 创建新的自定义背景对象
var customBackground = new CustomPickNameBackground(BackgroundNameTextBox.Text, destPath);
// 添加到主窗口的设置中
MainWindow.Settings.RandSettings.CustomPickNameBackgrounds.Add(customBackground);
// 更新ComboBox
mainWindow.UpdatePickNameBackgroundsInComboBox();
// 保存设置
MainWindow.SaveSettingsToFile();
IsSuccess = true;
Close();
}
@@ -118,4 +118,4 @@ namespace Ink_Canvas
}
}
}
}
}