Skip to content

Commit 31836a2

Browse files
committed
fix: 修复 7 个编译警告
- CA2022: QQPinyinQcelImporter 使用 ReadExactly 替代 Read - CS8604: SplitFileWindow/MergeWLWindow 添加 null 防护
1 parent edd1d99 commit 31836a2

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/ImeWlConverter.Formats/QQPinyinQcel/QQPinyinQcelImporter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ protected override IReadOnlyList<WordEntry> ParseBinary(Stream input, Cancellati
114114

115115
// Skip 2 bytes (unknown short) + 4 bytes (unknown int)
116116
var skip1 = new byte[2];
117-
fs.Read(skip1, 0, 2);
117+
fs.ReadExactly(skip1, 0, 2);
118118
var skip2 = new byte[4];
119-
fs.Read(skip2, 0, 4);
119+
fs.ReadExactly(skip2, 0, 4);
120120

121121
results.Add(new WordEntry
122122
{
@@ -128,7 +128,7 @@ protected override IReadOnlyList<WordEntry> ParseBinary(Stream input, Cancellati
128128

129129
// Skip trailing 6 bytes per entry
130130
var trailing = new byte[6];
131-
fs.Read(trailing, 0, 6);
131+
fs.ReadExactly(trailing, 0, 6);
132132
}
133133

134134
return results;

src/ImeWlConverterMac/Views/MergeWLWindow.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private async void BtnMergeWL_Click(object? sender, RoutedEventArgs e)
101101

102102
private async void PerformMerge()
103103
{
104-
var mainWL = FileOperationHelper.ReadFile(txbMainWLFile.Text);
104+
var mainWL = FileOperationHelper.ReadFile(txbMainWLFile.Text ?? "");
105105
var mainDict = ConvertTxt2Dictionary(mainWL);
106106
var userFiles = (txbUserWLFiles.Text ?? "").Split('|');
107107

src/ImeWlConverterMac/Views/SplitFileWindow.axaml.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ await Task.Run(() =>
8282

8383
private void SplitFileByLine(int maxLine)
8484
{
85-
var encoding = FileOperationHelper.GetEncodingType(txbFilePath.Text);
86-
var str = FileOperationHelper.ReadFile(txbFilePath.Text, encoding);
85+
var filePath = txbFilePath.Text ?? "";
86+
var encoding = FileOperationHelper.GetEncodingType(filePath);
87+
var str = FileOperationHelper.ReadFile(filePath, encoding);
8788

8889
var splitLineChar = "\r\n";
8990
if (str.IndexOf(splitLineChar) < 0)
@@ -127,7 +128,8 @@ private void SplitFileByLine(int maxLine)
127128

128129
private void SplitFileBySize(int maxSize)
129130
{
130-
var encoding = FileOperationHelper.GetEncodingType(txbFilePath.Text);
131+
var filePath = txbFilePath.Text ?? "";
132+
var encoding = FileOperationHelper.GetEncodingType(filePath);
131133
var fileIndex = 1;
132134
var size = (maxSize - 10) * 1024; // 10K的Buffer
133135

@@ -192,8 +194,9 @@ private bool ReadToNextLine(FileStream fs)
192194
private void SplitFileByLength(int length)
193195
{
194196
length = length - 100; // 100个字的Buffer
195-
var encoding = FileOperationHelper.GetEncodingType(txbFilePath.Text);
196-
var str = FileOperationHelper.ReadFile(txbFilePath.Text, encoding);
197+
var filePath = txbFilePath.Text ?? "";
198+
var encoding = FileOperationHelper.GetEncodingType(filePath);
199+
var str = FileOperationHelper.ReadFile(filePath, encoding);
197200
var fileIndex = 1;
198201

199202
do

0 commit comments

Comments
 (0)