chore: 统一代码风格

This commit is contained in:
2026-05-28 19:23:28 +08:00
parent 87afe57bfa
commit 4ff375d132
13 changed files with 51 additions and 47 deletions
+6 -6
View File
@@ -41,10 +41,10 @@ class DumpCodingHistory
{
Console.WriteLine($"处理: {wavFilePath}");
var track = new Track(wavFilePath);
Track track = new(wavFilePath);
if (track.AdditionalFields == null ||
!track.AdditionalFields.TryGetValue("bext.codingHistory", out var codingHistory))
!track.AdditionalFields.TryGetValue("bext.codingHistory", out string? codingHistory))
{
Console.WriteLine(" -> 无 bext.codingHistory 字段");
return;
@@ -53,8 +53,8 @@ class DumpCodingHistory
Console.WriteLine($" -> 字符串长度: {codingHistory.Length}");
// 用 Latin-1 编码转回字节(Latin-1 把 Unicode 0x00-0xFF 直接映射为 byte 0x00-0xFF
var bytes = System.Text.Encoding.Latin1.GetBytes(codingHistory);
var outputPath = Path.Combine(
byte[] bytes = System.Text.Encoding.Latin1.GetBytes(codingHistory);
string outputPath = Path.Combine(
Path.GetDirectoryName(wavFilePath)!,
Path.GetFileNameWithoutExtension(wavFilePath) + ".codingHistory.bin"
);
@@ -64,7 +64,7 @@ class DumpCodingHistory
Console.WriteLine($" -> 字节数: {bytes.Length}");
// 打印前 64 个字节的 hex
var hexPreview = Math.Min(64, bytes.Length);
int hexPreview = Math.Min(64, bytes.Length);
Console.Write(" -> Hex 前 64 字节: ");
for (int i = 0; i < hexPreview; i++)
{
@@ -77,7 +77,7 @@ class DumpCodingHistory
Console.Write(" -> ASCII 前 64 字节: ");
for (int i = 0; i < hexPreview; i++)
{
var c = (char)bytes[i];
char c = (char)bytes[i];
Console.Write(c >= 32 && c < 127 ? c : '.');
if ((i + 1) % 16 == 0) Console.Write(" ");
}
+8 -8
View File
@@ -20,11 +20,11 @@ class Program
}
// 查找所有 WAV 文件
var wavFiles = Directory.GetFiles(sourceDir, "*.wav", SearchOption.AllDirectories);
string[] wavFiles = Directory.GetFiles(sourceDir, "*.wav", SearchOption.AllDirectories);
Console.WriteLine($"找到 {wavFiles.Length} 个 WAV 文件");
foreach (var wavFile in wavFiles)
foreach (string wavFile in wavFiles)
{
try
{
@@ -44,10 +44,10 @@ class Program
{
Console.WriteLine($"处理: {wavFilePath}");
var track = new Track(wavFilePath);
var outputPath = Path.ChangeExtension(wavFilePath, ".atl.txt");
Track track = new(wavFilePath);
string outputPath = Path.ChangeExtension(wavFilePath, ".atl.txt");
using var writer = new StreamWriter(outputPath);
using StreamWriter writer = new(outputPath);
writer.WriteLine("=== ATL Track 基础属性 ===");
writer.WriteLine();
@@ -91,7 +91,7 @@ class Program
// 打印所有附加字段
if (track.AdditionalFields != null && track.AdditionalFields.Count > 0)
{
foreach (var field in track.AdditionalFields.OrderBy(f => f.Key))
foreach (KeyValuePair<string, string> field in track.AdditionalFields.OrderBy(f => f.Key))
{
writer.WriteLine($"[{field.Key}] = {field.Value}");
}
@@ -108,7 +108,7 @@ class Program
// 打印图片信息
if (track.EmbeddedPictures != null && track.EmbeddedPictures.Count > 0)
{
foreach (var pic in track.EmbeddedPictures)
foreach (PictureInfo? pic in track.EmbeddedPictures)
{
writer.WriteLine($"PictureType: {pic.PicType}");
writer.WriteLine($"Description: {pic.Description}");
@@ -129,7 +129,7 @@ class Program
// 打印章节信息
if (track.Chapters != null && track.Chapters.Count > 0)
{
foreach (var chapter in track.Chapters)
foreach (ChapterInfo? chapter in track.Chapters)
{
writer.WriteLine($"Title: {chapter.Title}");
writer.WriteLine($"StartTime: {chapter.StartTime}");
+1 -1
View File
@@ -110,7 +110,7 @@ public class DatabaseTests
Description = "Test explosion sound",
Category = "SFX",
Keywords = "test,boom,explosion",
FxName = "Test Explosion Boom"
FxName = "Test Explosion Boom",
};
}
+5 -5
View File
@@ -298,7 +298,7 @@ public static class Database
private static readonly HashSet<string> AllowedSortColumns = new(StringComparer.OrdinalIgnoreCase)
{
"filename", "duration", "sample_rate", "channels",
"date_added", "rating", "type", "category", "id"
"date_added", "rating", "type", "category", "id",
};
/// <summary>
@@ -483,12 +483,12 @@ public static class Database
using IDbConnection connection = GetConnection();
connection.Open();
const string sql = "SELECT keywords FROM audio_files WHERE keywords IS NOT NULL AND keywords != '';";
var rows = connection.Query<string>(sql);
var allKeywords = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var row in rows)
IEnumerable<string> rows = connection.Query<string>(sql);
HashSet<string> allKeywords = new(StringComparer.OrdinalIgnoreCase);
foreach (string row in rows)
{
if (string.IsNullOrWhiteSpace(row)) continue;
foreach (var part in row.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
foreach (string part in row.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
{
if (!string.IsNullOrWhiteSpace(part))
allKeywords.Add(part);
+1 -1
View File
@@ -28,7 +28,7 @@ public static class PreferencesManager
// 文件不存在或反序列化失败 → 创建默认实例
CurrentPreferences = new Preferences
{
DatabasePath = GetDefaultDatabasePath()
DatabasePath = GetDefaultDatabasePath(),
};
// 立即落盘,确保下次启动能直接读取
+3 -3
View File
@@ -8,7 +8,7 @@ public class DurationFormatConverter : IValueConverter
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not double duration) return "--:--";
var ts = TimeSpan.FromSeconds(duration);
TimeSpan ts = TimeSpan.FromSeconds(duration);
if (ts.TotalHours >= 1)
return ts.ToString(@"h\:mm\:ss\.ff");
return ts.ToString(@"m\:ss\.ff");
@@ -40,7 +40,7 @@ public class ChannelsFormatConverter : IValueConverter
int ch when ch == 2 => "Stereo",
null => "--",
int ch => $"{ch}ch",
_ => "--"
_ => "--",
};
}
@@ -77,7 +77,7 @@ public class PositionFormatConverter : IValueConverter
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not double pos) return "0:00";
var ts = TimeSpan.FromSeconds(pos);
TimeSpan ts = TimeSpan.FromSeconds(pos);
return ts.ToString(@"m\:ss");
}
+1 -1
View File
@@ -6,7 +6,7 @@ public class SyncChannelManager
public SyncChannel GetOrCreate(string id)
{
if (!_channels.TryGetValue(id, out var channel))
if (!_channels.TryGetValue(id, out SyncChannel? channel))
{
channel = new SyncChannel(id);
_channels[id] = channel;
+2 -2
View File
@@ -19,8 +19,8 @@ public class ViewLocator : IDataTemplate
if (param is null)
return null;
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
var type = Type.GetType(name);
string name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
Type? type = Type.GetType(name);
if (type != null)
{
+3 -3
View File
@@ -28,7 +28,7 @@ public partial class FileListViewModel : ViewModelBase
public string[] SortOptions { get; } =
[
"date_added", "filename", "duration", "sample_rate", "channels", "rating", "type", "category"
"date_added", "filename", "duration", "sample_rate", "channels", "rating", "type", "category",
];
public FileListViewModel(SyncChannel channel)
@@ -60,7 +60,7 @@ public partial class FileListViewModel : ViewModelBase
IsLoading = true;
Files.Clear();
var entries = Database.QueryEntries(
IEnumerable<AudioFileMeta> entries = Database.QueryEntries(
searchText: string.IsNullOrWhiteSpace(_channel.SearchText) ? null : _channel.SearchText,
category: _channel.FilterCategory,
sortBy: SelectedSortBy,
@@ -73,7 +73,7 @@ public partial class FileListViewModel : ViewModelBase
);
// 如果有 FilterKeyword,在客户端过滤(Keywords 字段 LIKE 搜索)
foreach (var entry in entries)
foreach (AudioFileMeta entry in entries)
{
if (!string.IsNullOrWhiteSpace(_channel.FilterKeyword))
{
+8 -8
View File
@@ -34,11 +34,11 @@ public partial class ScanProgressViewModel : ViewModelBase
Database.InitializeDatabase();
var scanner = new AudioFileScanner();
var reader = new AudioMetadataReader();
var validator = new AudioFileMetaValidator();
AudioFileScanner scanner = new();
AudioMetadataReader reader = new();
AudioFileMetaValidator validator = new();
var files = scanner.ScanDirectory(directory, recursive: true).ToList();
List<string> files = scanner.ScanDirectory(directory, recursive: true).ToList();
TotalFiles = files.Count;
ProcessedFiles = 0;
AddedFiles = 0;
@@ -47,15 +47,15 @@ public partial class ScanProgressViewModel : ViewModelBase
StatusText = $"发现 {TotalFiles} 个文件,正在解析元数据...";
foreach (var filePath in files)
foreach (string filePath in files)
{
CurrentFile = System.IO.Path.GetFileName(filePath);
CurrentFile = Path.GetFileName(filePath);
ProcessedFiles++;
try
{
var fileInfo = new FileInfo(filePath);
var meta = reader.ReadMetadata(fileInfo);
FileInfo fileInfo = new(filePath);
AudioFileMeta? meta = reader.ReadMetadata(fileInfo);
if (meta == null)
{
+5 -5
View File
@@ -28,14 +28,14 @@ public partial class TagTreeViewModel : ViewModelBase
CategoryNodes.Clear();
KeywordNodes.Clear();
var categories = Database.GetAllCategories();
foreach (var cat in categories)
IEnumerable<string> categories = Database.GetAllCategories();
foreach (string cat in categories)
{
CategoryNodes.Add(new TagTreeNode { Name = cat, Type = TagTreeNodeType.Category });
}
var keywords = Database.GetAllKeywords();
foreach (var kw in keywords)
IEnumerable<string> keywords = Database.GetAllKeywords();
foreach (string kw in keywords)
{
KeywordNodes.Add(new TagTreeNode { Name = kw, Type = TagTreeNodeType.Keyword });
}
@@ -88,5 +88,5 @@ public partial class TagTreeNode : ObservableObject
public enum TagTreeNodeType
{
Category,
Keyword
Keyword,
}
+5 -4
View File
@@ -1,5 +1,6 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using GUI.ViewModels;
namespace GUI.Views;
@@ -9,22 +10,22 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
ScanButton.Click += OnScanButtonClick;
this.ScanButton.Click += OnScanButtonClick;
}
private async void OnScanButtonClick(object? sender, RoutedEventArgs e)
{
if (DataContext is not MainWindowViewModel vm) return;
var folders = await StorageProvider.OpenFolderPickerAsync(new Avalonia.Platform.Storage.FolderPickerOpenOptions
IReadOnlyList<IStorageFolder> folders = await StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
{
Title = "选择音频目录",
AllowMultiple = false
AllowMultiple = false,
});
if (folders.Count > 0)
{
var path = folders[0].Path.LocalPath;
string path = folders[0].Path.LocalPath;
vm.RequestScan(path);
}
}
+3
View File
@@ -1,6 +1,9 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFormat_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fe2d95a1d7b987bbb7785b2ad7e2e3e29075ba79cdf7619dd26c10d266c5_003FFormat_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGUI_002EViewModels_002EScanProgressViewModel_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fbb74b3c6eaaeb5d783f31310eae5345eba75596a_003FGUI_002EViewModels_002EScanProgressViewModel_002Eg_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGUI_002EViewModels_002EScanProgressViewModel_002EStartScan_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003F1a6f588df342309187674fcc524512a9a4a46540_003FGUI_002EViewModels_002EScanProgressViewModel_002EStartScan_002Eg_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIDbConnection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F01c4805efedf4381865d701be69b5ce5314910_003F77_003Ffb273e4d_003FIDbConnection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIRelayCommand_007BT_007D_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003F49f2a292ecb417be1f61c426de242e503b4371a346bf5b68a843b462337e62_003FIRelayCommand_007BT_007D_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AOSPlatform_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003F9e988c941e6515999ebab7336243c87df16e340b8faeb57b5f562d2b8a7c2c_003FOSPlatform_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATrack_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003F872a20b9878a835418db772627eab53c29e04a65284443b02d35345255649a3a_003FTrack_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>