Browse Source

增加内核下载功能

master
С·æ 4 years ago
parent
commit
88f63ca665
  1. 1
      JdShopListener/JdShopListener/JdShopListener.csproj
  2. 56
      JdShopListener/JdShopListener/MainWindowViewModel.cs
  3. 2
      JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user

1
JdShopListener/JdShopListener/JdShopListener.csproj

@ -18,6 +18,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetZip" Version="1.15.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5">
<PrivateAssets>all</PrivateAssets>

56
JdShopListener/JdShopListener/MainWindowViewModel.cs

@ -13,6 +13,9 @@ using System.Threading;
using Newtonsoft.Json.Linq;
using PuppeteerSharp;
using Utils;
using System.Threading.Tasks;
using System.IO;
using Ionic.Zip;
namespace JdShopListener
{
@ -46,6 +49,8 @@ namespace JdShopListener
public string JDCookie { get; set; }
public MainWindowViewModel() {
ProList = new System.Collections.ObjectModel.ObservableCollection<ProModel>() {
new ProModel(){ Name="价格" , Type= ProType.Price},
new ProModel(){ Name="活动" , Type= ProType.Active},
@ -88,7 +93,13 @@ namespace JdShopListener
}
LoadHYItems();
Task.Factory.StartNew(() =>
{
InitWeb();
}).ContinueWith((state) => {
LoadHYItems();
});
}
private string _InitText= "正在加载慧眼竞品商品数据, 请稍后...";
@ -99,6 +110,49 @@ namespace JdShopListener
set { Set(ref _InitText, value); }
}
/// <summary>
/// 初始化内核
/// </summary>
public void InitWeb()
{
string floader= System.Environment.CurrentDirectory + "\\.local-chromium";
if (System.IO.Directory.Exists(floader))
{
return;
}
IsInitLoding = true;
InitText = "检测到必要文件丢失,开始下载。。。";
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;
webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
webClient.DownloadFileTaskAsync("https://qymds.oss-cn-hangzhou.aliyuncs.com/chromium/.local-chromium.zip", System.Environment.CurrentDirectory+"\\tempZip.zip").Wait();
}
private void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Application.Current.Dispatcher.Invoke(() => {
InitText = $"正在下载必要文件,进度:{e.BytesReceived}/{e.TotalBytesToReceive}";
});
}
private void WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
//进行解压
IsInitLoding = false;
UnZip(System.Environment.CurrentDirectory + "\\tempZip.zip", System.Environment.CurrentDirectory);
}
private void UnZip(string fileToUnZip, string DstFile)
{
using (ZipFile zip = new ZipFile(fileToUnZip, Encoding.Default))
{
zip.ExtractAll(DstFile, ExtractExistingFileAction.OverwriteSilently);
}
}
public void LoadHYItems()
{

2
JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user

@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<History>True|2021-11-11T10:06:38.5161322Z;True|2021-11-11T17:53:13.2835443+08:00;True|2021-11-11T17:52:00.9170918+08:00;True|2021-11-11T17:51:37.4852682+08:00;True|2021-11-11T17:49:30.9386192+08:00;True|2021-11-11T17:44:28.5146341+08:00;True|2021-11-11T17:42:26.8480671+08:00;True|2021-11-11T17:37:14.4108790+08:00;True|2021-11-11T17:30:25.4460722+08:00;</History>
<History>True|2021-11-12T07:27:50.0418057Z;True|2021-11-12T15:06:23.1220477+08:00;True|2021-11-11T18:06:38.5161322+08:00;True|2021-11-11T17:53:13.2835443+08:00;True|2021-11-11T17:52:00.9170918+08:00;True|2021-11-11T17:51:37.4852682+08:00;True|2021-11-11T17:49:30.9386192+08:00;True|2021-11-11T17:44:28.5146341+08:00;True|2021-11-11T17:42:26.8480671+08:00;True|2021-11-11T17:37:14.4108790+08:00;True|2021-11-11T17:30:25.4460722+08:00;</History>
</PropertyGroup>
</Project>
Loading…
Cancel
Save