From 88f63ca665b78f4528f7319b628d1e4e8c904d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=C2=B7=C3=A6?= <279202647@qq.com> Date: Fri, 12 Nov 2021 15:46:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=86=85=E6=A0=B8=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JdShopListener/JdShopListener.csproj | 1 + .../JdShopListener/MainWindowViewModel.cs | 56 ++++++++++++++++++- .../PublishProfiles/FolderProfile.pubxml.user | 2 +- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/JdShopListener/JdShopListener/JdShopListener.csproj b/JdShopListener/JdShopListener/JdShopListener.csproj index 599d7d5..40e1505 100644 --- a/JdShopListener/JdShopListener/JdShopListener.csproj +++ b/JdShopListener/JdShopListener/JdShopListener.csproj @@ -18,6 +18,7 @@ + all diff --git a/JdShopListener/JdShopListener/MainWindowViewModel.cs b/JdShopListener/JdShopListener/MainWindowViewModel.cs index a80b9db..658b6c3 100644 --- a/JdShopListener/JdShopListener/MainWindowViewModel.cs +++ b/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() { 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); } } + /// + /// 初始化内核 + /// + 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() { diff --git a/JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user b/JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user index 0a4153d..4266d66 100644 --- a/JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - 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; + 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; \ No newline at end of file