diff --git a/src/AtlFieldExtractor/DumpCodingHistory.cs b/src/AtlFieldExtractor/DumpCodingHistory.cs index 415ed10..b187b52 100755 --- a/src/AtlFieldExtractor/DumpCodingHistory.cs +++ b/src/AtlFieldExtractor/DumpCodingHistory.cs @@ -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(" "); } diff --git a/src/AtlFieldExtractor/Program.cs b/src/AtlFieldExtractor/Program.cs index 4d5bcf2..78e136a 100755 --- a/src/AtlFieldExtractor/Program.cs +++ b/src/AtlFieldExtractor/Program.cs @@ -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 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}"); diff --git a/src/Core.Tests/DatabaseTests.cs b/src/Core.Tests/DatabaseTests.cs index 24f051a..934ddb3 100644 --- a/src/Core.Tests/DatabaseTests.cs +++ b/src/Core.Tests/DatabaseTests.cs @@ -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", }; } diff --git a/src/Core/Database.cs b/src/Core/Database.cs index a4c1281..9fa770f 100755 --- a/src/Core/Database.cs +++ b/src/Core/Database.cs @@ -298,7 +298,7 @@ public static class Database private static readonly HashSet AllowedSortColumns = new(StringComparer.OrdinalIgnoreCase) { "filename", "duration", "sample_rate", "channels", - "date_added", "rating", "type", "category", "id" + "date_added", "rating", "type", "category", "id", }; /// @@ -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(sql); - var allKeywords = new HashSet(StringComparer.OrdinalIgnoreCase); - foreach (var row in rows) + IEnumerable rows = connection.Query(sql); + HashSet 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); diff --git a/src/Core/PreferencesManager.cs b/src/Core/PreferencesManager.cs index bbfc9cf..02eadb3 100644 --- a/src/Core/PreferencesManager.cs +++ b/src/Core/PreferencesManager.cs @@ -28,7 +28,7 @@ public static class PreferencesManager // 文件不存在或反序列化失败 → 创建默认实例 CurrentPreferences = new Preferences { - DatabasePath = GetDefaultDatabasePath() + DatabasePath = GetDefaultDatabasePath(), }; // 立即落盘,确保下次启动能直接读取 diff --git a/src/GUI/Converters/ValueConverters.cs b/src/GUI/Converters/ValueConverters.cs index 1f18aa3..b255c5e 100644 --- a/src/GUI/Converters/ValueConverters.cs +++ b/src/GUI/Converters/ValueConverters.cs @@ -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"); } diff --git a/src/GUI/Services/SyncChannelManager.cs b/src/GUI/Services/SyncChannelManager.cs index 4fca06d..40eada7 100644 --- a/src/GUI/Services/SyncChannelManager.cs +++ b/src/GUI/Services/SyncChannelManager.cs @@ -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; diff --git a/src/GUI/ViewLocator.cs b/src/GUI/ViewLocator.cs index ba1c95d..0c494d0 100644 --- a/src/GUI/ViewLocator.cs +++ b/src/GUI/ViewLocator.cs @@ -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) { diff --git a/src/GUI/ViewModels/FileListViewModel.cs b/src/GUI/ViewModels/FileListViewModel.cs index 4f126a5..983cbfb 100644 --- a/src/GUI/ViewModels/FileListViewModel.cs +++ b/src/GUI/ViewModels/FileListViewModel.cs @@ -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 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)) { diff --git a/src/GUI/ViewModels/ScanProgressViewModel.cs b/src/GUI/ViewModels/ScanProgressViewModel.cs index d6151b3..0f60be9 100644 --- a/src/GUI/ViewModels/ScanProgressViewModel.cs +++ b/src/GUI/ViewModels/ScanProgressViewModel.cs @@ -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 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) { diff --git a/src/GUI/ViewModels/TagTreeViewModel.cs b/src/GUI/ViewModels/TagTreeViewModel.cs index 6e81a39..2a4eb29 100644 --- a/src/GUI/ViewModels/TagTreeViewModel.cs +++ b/src/GUI/ViewModels/TagTreeViewModel.cs @@ -28,14 +28,14 @@ public partial class TagTreeViewModel : ViewModelBase CategoryNodes.Clear(); KeywordNodes.Clear(); - var categories = Database.GetAllCategories(); - foreach (var cat in categories) + IEnumerable 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 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, } diff --git a/src/GUI/Views/MainWindow.axaml.cs b/src/GUI/Views/MainWindow.axaml.cs index 48f9061..edd9665 100644 --- a/src/GUI/Views/MainWindow.axaml.cs +++ b/src/GUI/Views/MainWindow.axaml.cs @@ -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 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); } } diff --git a/src/Resonance.sln.DotSettings.user b/src/Resonance.sln.DotSettings.user index 0023a56..9c6f2d2 100755 --- a/src/Resonance.sln.DotSettings.user +++ b/src/Resonance.sln.DotSettings.user @@ -1,6 +1,9 @@  ForceIncluded + ForceIncluded + ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded