Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91c4ec1

Browse files
authored
Merge pull request #33 from dotnet-campus/t/lindexi/WhelqedilebakiCehafukoniku
修复找不到资源
2 parents d5d5cc7 + 40d5d00 commit 91c4ec1

File tree

9 files changed

+66
-288
lines changed

9 files changed

+66
-288
lines changed

EncodingNormalior.WPF/ViewModel/Account.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using System.Text;
55
using EncodingNormalior.Model;
6-
using EncodingNormalior.Resource;
76
using Newtonsoft.Json;
87

98
namespace EncodingNormalizerVsx.ViewModel
@@ -109,7 +108,7 @@ public static Account ReadAccount()
109108
catch (Exception)
110109
{
111110
//默认配置
112-
var whiteList = TextFileSuffix.WhiteList;
111+
var whiteList = EncodingNormaliorContext.WhiteList;
113112
var fileInclude = IncludeFileSetting.TextFileSuffix.Aggregate("",
114113
(current, temp) => current + temp + "\r\n");
115114
//EncodingNormalior.Resource.TextFileSuffix.textFileSuffix;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace EncodingNormalior.Model
2+
{
3+
public class EncodingNormaliorContext
4+
{
5+
/// <summary>
6+
/// 白名单的文件后缀名,这部分的文件忽略文件编码
7+
/// </summary>
8+
public const string WhiteList =
9+
@".git\
10+
.vs\
11+
obj\
12+
bin\
13+
packages\
14+
*.png
15+
*.jpg
16+
*.tmp
17+
*.exe
18+
*.mp4
19+
*.snk
20+
*.pfx
21+
*.zip
22+
*.rar
23+
*.7z
24+
*.cer";
25+
26+
/// <summary>
27+
/// 常用文本后缀
28+
/// </summary>
29+
public const string TextFileSuffix = @"txt
30+
cs
31+
java
32+
c
33+
cpp
34+
md
35+
csproj
36+
json
37+
asp
38+
bat
39+
vbs
40+
cmd
41+
html
42+
htm
43+
csv
44+
ini
45+
log
46+
xaml
47+
xml";
48+
}
49+
}

EncodingNormalior/Model/IncludeFileSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private static void ReadFileSuffix()
104104
string[] textFileSuffix;
105105
if (!File.Exists(file))
106106
{
107-
textFileSuffix = Resource.TextFileSuffix.textFileSuffix.Split('\n');
107+
textFileSuffix = EncodingNormaliorContext.TextFileSuffix.Split('\n');
108108
}
109109
else
110110
{

EncodingNormalior/Model/InspectFileWhiteListSetting.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using System.Text.RegularExpressions;
66
using EncodingNormalior.Annotations;
7-
using EncodingNormalior.Resource;
87

98
namespace EncodingNormalior.Model
109
{
@@ -56,13 +55,13 @@ static InspectFileWhiteListSetting()
5655

5756
public InspectFileWhiteListSetting([NotNull] List<string> whiteList)
5857
{
59-
foreach (var temp in whiteList.Where(temp=>!string.IsNullOrEmpty(temp)))
58+
foreach (var temp in whiteList.Where(temp => !string.IsNullOrEmpty(temp)))
6059
{
6160
Parse(temp);
6261
}
6362
}
6463

65-
private static Regex _folderRegex = new Regex("\\w+[\\\\|/]");
64+
private static readonly Regex FolderRegex = new Regex("\\w+[\\\\|/]");
6665

6766
public static List<string> DefaultWhiteList { set; get; }
6867

@@ -81,9 +80,9 @@ public static InspectFileWhiteListSetting ReadWhiteListSetting(string file)
8180
{
8281
throw new ArgumentException("文件不存在" + file);
8382
}
83+
8484
var whiteList = new List<string>();
85-
using (StreamReader stream = new StreamReader(
86-
new FileStream(file, FileMode.Open)))
85+
using (StreamReader stream = new StreamReader(new FileStream(file, FileMode.Open)))
8786
{
8887
whiteList.AddRange(stream.ReadToEnd().Split('\n').Select(temp => temp.Replace("\r", "").Trim()));
8988
}
@@ -97,15 +96,14 @@ private static IEnumerable<string> ReadWhiteList(string file)
9796
string[] whiteList;
9897
if (File.Exists(file))
9998
{
100-
using (StreamReader stream = new StreamReader(
101-
new FileStream(file, FileMode.Open)))
99+
using (StreamReader stream = new StreamReader(new FileStream(file, FileMode.Open)))
102100
{
103101
whiteList = stream.ReadToEnd().Split('\n');
104102
}
105103
}
106104
else
107105
{
108-
whiteList = TextFileSuffix.WhiteList.Split('\n');
106+
whiteList = EncodingNormaliorContext.WhiteList.Split('\n');
109107
}
110108

111109
var fileSuffix = whiteList.Select(temp => temp.Replace("\r", "").Trim());
@@ -119,10 +117,10 @@ public void Add(string whiteList)
119117

120118
public void Remove(string whiteList)
121119
{
122-
var folderWhiteList = ((List<string>)FolderWhiteList);
120+
var folderWhiteList = ((List<string>) FolderWhiteList);
123121

124122
Remove(whiteList, folderWhiteList);
125-
folderWhiteList = (List<string>)FileWhiteList;
123+
folderWhiteList = (List<string>) FileWhiteList;
126124
Remove(whiteList, folderWhiteList);
127125
}
128126

@@ -147,20 +145,19 @@ public void Add(List<string> whiteList)
147145

148146
private void Parse(string whiteList)
149147
{
150-
_folderRegex = new Regex("\\w+[\\\\|/]$");
151-
152-
if (_folderRegex.IsMatch(whiteList))
148+
if (FolderRegex.IsMatch(whiteList))
153149
{
154-
((List<string>)FolderWhiteList).Add(whiteList.Substring(0, whiteList.Length - 1));
150+
((List<string>) FolderWhiteList).Add(whiteList.Substring(0, whiteList.Length - 1));
155151
}
156152
else
157153
{
158154
if (whiteList.Contains("\\") || whiteList.Contains("/"))
159155
{
160156
throw new ArgumentException("不支持指定文件夹中的文件\r\n" + whiteList + " 错误");
161157
}
162-
((List<string>)FileWhiteList).Add(whiteList);
163-
((List<Regex>)FileRegexWhiteList).Add(new Regex(GetWildcardRegexString(whiteList),
158+
159+
((List<string>) FileWhiteList).Add(whiteList);
160+
((List<Regex>) FileRegexWhiteList).Add(new Regex(GetWildcardRegexString(whiteList),
164161
RegexOptions.IgnoreCase));
165162
}
166163
}
@@ -182,6 +179,7 @@ public bool ConformWhiteList(string whiteList)
182179
{
183180
return false;
184181
}
182+
185183
return true;
186184
}
187185

EncodingNormalior/Resource/TextFileSuffix.Designer.cs

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)