XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension

【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension

修改配置文件位置

264bea3
XFE工作室室长 <xfe18827675401@126.com>
提交于

代码差异

10 个文件 +85 -52
Modified XFE各类拓展.NetCore/FileExtension/XFEFileWatcher.cs +6 -4
@@ -69,8 +69,10 @@ public class XFEFileWatcher
69 69 {
70 70 try
71 71 {
72 FileSystemWatcher subdirectoryWatcher = new FileSystemWatcher(subdirectory);
73 subdirectoryWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
72 FileSystemWatcher subdirectoryWatcher = new(subdirectory)
73 {
74 NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName
75 };
74 76 watchers.Add(subdirectoryWatcher);
75 77 subdirectoryWatcher.Changed += OnFileChanged;
76 78 subdirectoryWatcher.Created += OnFileChanged;
@@ -101,7 +103,7 @@ public class XFEFileWatcher
101 103 {
102 104 await new Action(() => { MonitorSubdirectories(Path); }).StartNewTask();
103 105 }
104 FileSystemWatcher rootWatcher = new FileSystemWatcher(Path);
106 FileSystemWatcher rootWatcher = new(Path);
105 107 watchers.Add(rootWatcher);
106 108 rootWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
107 109 rootWatcher.Changed += OnFileChanged;
@@ -134,7 +136,7 @@ public class XFEFileWatcher
134 136 {
135 137 MonitorSubdirectories(Path);
136 138 }
137 FileSystemWatcher rootWatcher = new FileSystemWatcher(Path);
139 FileSystemWatcher rootWatcher = new(Path);
138 140 watchers.Add(rootWatcher);
139 141 rootWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
140 142 rootWatcher.Changed += OnFileChanged;
Modified XFE各类拓展.NetCore/FormatExtension/XFEDictionary.cs +6 -0
@@ -5,7 +5,13 @@
5 5 /// </summary>
6 6 public class XFEDictionary : ICollection<XFEEntry>
7 7 {
8 /// <summary>
9 /// 字典分隔符
10 /// </summary>
8 11 public static string[] DictionarySeparator { get; } = ["|{+-", "-+}|"];
12 /// <summary>
13 /// 条目分隔符
14 /// </summary>
9 15 public static string[] EntrySeparator { get; } = ["[+-", "-+]"];
10 16 private List<XFEEntry> xFEDictionaryList = [];
11 17 /// <summary>
Modified XFE各类拓展.NetCore/FormatExtension/XFEMultiDictionary.cs +1 -1
@@ -33,7 +33,7 @@ public class XFEMultiDictionary : ICollection<XFEEntry>
33 33 /// <summary>
34 34 /// 追加条目
35 35 /// </summary>
36 /// <param name="EntryString">条目字符串</param>
36 /// <param name="entryString">条目字符串</param>
37 37 public void Add(string entryString)
38 38 {
39 39 var entry = XFEEntry.ToEntry(entryString);
Modified XFE各类拓展.NetCore/WebExtension/FileDownloadedEventArgs.cs +1 -1
@@ -22,4 +22,4 @@ public class FileDownloadedEventArgs(byte[] currentBuffer, long downloadedBuffer
22 22 /// 是否下载完成
23 23 /// </summary>
24 24 public bool Downloaded { get; } = downloaded;
25 }
25 }
Modified XFE各类拓展.NetCore/XFE各类拓展.NetCore.csproj +9 -5
@@ -13,7 +13,7 @@
13 13 <SignAssembly>True</SignAssembly>
14 14 <Copyright>XFE工作室版权所有</Copyright>
15 15 <PackageProjectUrl>https://github.com/XFEstudio/XFEExtension</PackageProjectUrl>
16 <PackageIcon>寰宇朽力定稿版_透明图标.png</PackageIcon>
16 <PackageIcon>logoIcon.png</PackageIcon>
17 17 <Description>XFE各类拓展为代码拓展</Description>
18 18 <PackageReadmeFile>README.md</PackageReadmeFile>
19 19 <PackageTags>XFE;XFEExtension;XFE各类拓展</PackageTags>
@@ -21,7 +21,7 @@
21 21 <NeutralLanguage>zh-CN</NeutralLanguage>
22 22 <PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
23 23 <PackageLicenseFile>LICENSE</PackageLicenseFile>
24 <AssemblyOriginatorKeyFile>C:\Users\XFEstudio\Desktop\work\C#\OtherProject\XFE各类拓展\XFE各类拓展\XFEstudio.pfx</AssemblyOriginatorKeyFile>
24 <AssemblyOriginatorKeyFile>..\XFEstudio.pfx</AssemblyOriginatorKeyFile>
25 25 <AssemblyVersion>1.1.2.0</AssemblyVersion>
26 26 <FileVersion>1.1.2.0</FileVersion>
27 27 <Version>1.1.0</Version>
@@ -37,15 +37,19 @@
37 37 </PropertyGroup>
38 38
39 39 <ItemGroup>
40 <None Include="..\..\..\..\LOGO\寰宇朽力定稿版_透明图标.png">
40 <None Include="..\LICENSE">
41 41 <Pack>True</Pack>
42 42 <PackagePath>\</PackagePath>
43 43 </None>
44 <None Include="..\LICENSE">
44 <None Include="..\README.md">
45 45 <Pack>True</Pack>
46 46 <PackagePath>\</PackagePath>
47 47 </None>
48 <None Include="..\README.md">
48 <None Include="..\XFEstudio.pfx">
49 <Pack>True</Pack>
50 <PackagePath>\</PackagePath>
51 </None>
52 <None Include="..\logoIcon.png">
49 53 <Pack>True</Pack>
50 54 <PackagePath>\</PackagePath>
51 55 </None>
Modified XFE各类拓展/ArrayExtension.cs +0 -1
@@ -1,5 +1,4 @@
1 1 using System;
2 using System.Collections.Generic;
3 2
4 3 namespace XFE各类拓展.ArrayExtension
5 4 {
Modified XFE各类拓展/ObjectExtension.cs +2 -2
@@ -56,12 +56,12 @@ namespace XFE各类拓展.ObjectExtension
56 56 /// <returns></returns>
57 57 public static bool AboutEqual<T>(this T obj1, T obj2)
58 58 {
59 if (obj1 is null && obj2 is null)
59 if (obj1 == null && obj2 == null)
60 60 {
61 61 return true;
62 62 }
63 63
64 if (obj1 is null || obj2 is null)
64 if (obj1 == null || obj2 == null)
65 65 {
66 66 return false;
67 67 }
Modified XFE各类拓展/WebExtension.cs +58 -36
@@ -3,6 +3,7 @@ using System.IO;
3 3 using System.Net.Http;
4 4 using System.Text;
5 5 using System.Threading.Tasks;
6 using XFE各类拓展.DelegateExtension;
6 7 using XFE各类拓展.TaskExtension;
7 8
8 9 namespace XFE各类拓展.WebExtension
@@ -145,53 +146,55 @@ namespace XFE各类拓展.WebExtension
145 146 public class XFEDownloader
146 147 {
147 148 /// <summary>
148 /// 下载事件
149 /// 字节下载事件
149 150 /// </summary>
150 public event EventHandler<FileDownloadedEventArgs> BufferDownloaded;
151 public event XFEEventHandler<XFEDownloader, FileDownloadedEventArgs> BufferDownloaded;
151 152 /// <summary>
152 /// 下载文件目标URL
153 /// 目标下载地址
153 154 /// </summary>
154 155 public string DownloadUrl { get; set; }
155 156 /// <summary>
156 /// 文件储存位置
157 /// 储存位置
157 158 /// </summary>
158 159 public string SavePath { get; set; }
159 160 /// <summary>
161 /// 已下载
162 /// </summary>
163 public bool Downloaded { get; }
164 /// <summary>
160 165 /// 开始下载
161 166 /// </summary>
167 /// <param name="continueFromLastDownload"></param>
162 168 /// <returns></returns>
163 public async Task Download()
169 public async Task Download(bool continueFromLastDownload = true)
164 170 {
165 using (HttpClient client = new HttpClient())
171 using (var client = new HttpClient())
166 172 {
167 using (HttpResponseMessage response = await client.GetAsync(DownloadUrl, HttpCompletionOption.ResponseHeadersRead))
173 var continueDownload = continueFromLastDownload && File.Exists(SavePath);
174 using (var fileStream = new FileStream(SavePath, continueDownload ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.None, 8192, true))
168 175 {
169 response.EnsureSuccessStatusCode();
170
171 long? totalFileSize = response.Content.Headers.ContentLength;
172
173 using (Stream contentStream = await response.Content.ReadAsStreamAsync())
176 long totalRead = 0;
177 long lastBufferDownloadSize = fileStream.Length;
178 if (continueDownload)
174 179 {
175 using (FileStream fileStream = new FileStream(SavePath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true))
180 client.DefaultRequestHeaders.Range = new System.Net.Http.Headers.RangeHeaderValue(lastBufferDownloadSize, null);
181 totalRead = lastBufferDownloadSize;
182 }
183 using (var response = await client.GetAsync(DownloadUrl, HttpCompletionOption.ResponseHeadersRead))
184 {
185 response.EnsureSuccessStatusCode();
186 long? totalFileSize = response.Content.Headers.ContentLength + lastBufferDownloadSize;
187 using (var contentStream = await response.Content.ReadAsStreamAsync())
176 188 {
177 189 byte[] buffer = new byte[8192];
178 long totalRead = 0;
179 int read;
180
181 while ((read = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
190 int currentRead;
191 while ((currentRead = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
182 192 {
183 await fileStream.WriteAsync(buffer, 0, read);
184 totalRead += read;
185
186 if (totalFileSize.HasValue)
187 {
188 double percentage = ((double)totalRead / totalFileSize.Value) * 100;
189 Console.WriteLine($"Downloaded {totalRead}/{totalFileSize} bytes ({percentage:F2}%)");
190 }
191 else
192 {
193 Console.WriteLine($"Downloaded {totalRead} bytes");
194 }
193 await fileStream.WriteAsync(buffer, 0, currentRead);
194 totalRead += currentRead;
195 var bufferCopy = new byte[8192];
196 bufferCopy.CopyTo(buffer, 0);
197 BufferDownloaded?.Invoke(this, new FileDownloadedEventArgs(bufferCopy, totalRead, totalFileSize, currentRead != 8192));
195 198 }
196 199 }
197 200 }
@@ -199,22 +202,41 @@ namespace XFE各类拓展.WebExtension
199 202 }
200 203 }
201 204 }
205
202 206 /// <summary>
203 /// 文件下载事件
207 /// 字符下载事件
204 208 /// </summary>
205 209 public class FileDownloadedEventArgs : EventArgs
206 210 {
207 211 /// <summary>
208 /// 当前下载的字节大小
212 /// 当前下载到的字节
209 213 /// </summary>
210 public long CurrentBufferSize { get; set; }
214 public byte[] CurrentBuffer { get; }
211 215 /// <summary>
212 /// 总计下载的字节大小
216 /// 总计下载的字节长度
213 217 /// </summary>
214 public long DownloadedBufferSize { get; set; }
218 public long DownloadedBufferSize { get; }
215 219 /// <summary>
216 220 /// 总共需要下载的字节大小
217 221 /// </summary>
218 public long TotalBufferSize { get; set; }
222 public long? TotalBufferSize { get; }
223 /// <summary>
224 /// 是否下载完成
225 /// </summary>
226 public bool Downloaded { get; }
227 /// <summary>
228 /// 字符下载事件
229 /// </summary>
230 /// <param name="currentBuffer">当前下载的字符</param>
231 /// <param name="downloadedBufferSize">已下载的字节大小</param>
232 /// <param name="totalBufferSize">总计需要下载的字节大小</param>
233 /// <param name="downloaded">是否已经下载完成</param>
234 public FileDownloadedEventArgs(byte[] currentBuffer, long downloadedBufferSize, long? totalBufferSize, bool downloaded)
235 {
236 this.CurrentBuffer = currentBuffer;
237 this.DownloadedBufferSize = downloadedBufferSize;
238 this.TotalBufferSize = totalBufferSize;
239 this.Downloaded = downloaded;
240 }
219 241 }
220 }
242 }
Modified XFE各类拓展/XFE各类拓展.csproj +2 -2
@@ -40,7 +40,8 @@
40 40 <SignAssembly>true</SignAssembly>
41 41 </PropertyGroup>
42 42 <PropertyGroup>
43 <AssemblyOriginatorKeyFile>XFEstudio.pfx</AssemblyOriginatorKeyFile>
43 <AssemblyOriginatorKeyFile>
44 </AssemblyOriginatorKeyFile>
44 45 </PropertyGroup>
45 46 <ItemGroup>
46 47 <Reference Include="System" />
@@ -80,7 +81,6 @@
80 81 <None Include="..\.editorconfig">
81 82 <Link>.editorconfig</Link>
82 83 </None>
83 <None Include="XFEstudio.pfx" />
84 84 </ItemGroup>
85 85 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
86 86 </Project>
Added logoIcon.png +0 -0
二进制文件已变更,无法进行逐行预览。