|
|
@ -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 |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
{ |
|
|
|