private void PraseList() { SetProgress(1); SetStatus("Working..."); string html = Curl.GetHtmlAsync(currentUrl); if (null == html) { SetProgress(100); SetStatus(null); MessageBox.Show("获取远程内容失败,请重试!"); return; } SetProgress(50); InitPage(html); SetProgress(60); if (!treeInited) { InitTree(html); } SetProgress(70); try { var lis = Curse.PraseList(html); if (null == lis) { SetStatus("No Result!"); } else { int i = 0; foreach (var li in lis) { ListItem ad = new ListItem(li, i); ad.SetOnClickListener(onListItemClickListener); AddListItem(ad); i++; } } }catch (Exception e) { Settings.LogException(e); } SetStatus(null); SetProgress(100); }
private void PraseDetail() { CleanToolstrip(toolStripDetail); UpdateDetailHeader(currentItem); string html = Curl.GetHtmlAsync(baseHref + currentItem.href); SetProgress(50); if (null != html) { try { CurseDetail cd = Curse.PraseDetail(html); currentDetail = cd; ShowDetailContent(cd); }catch (Exception e) { Settings.LogException(e); } } else { SetStatus("Error!"); SetProgress(0); } try { foreach (var li in flowLayoutPanel1.Controls) { var cli = (ListItem)li; cli.Invoke(new EventHandler(delegate { cli.SetClickEnable(true); cli.Refresh(); })); } }catch (Exception e) { Settings.LogException(e); } SetStatus(null); SetProgress(100); }
private void DetailPage_click(object sender, EventArgs e) { try { var t = ((ToolStripButton)sender).Name; foreach (var p in currentDetail.pages) { if (p.title.ToLower().Equals(t.ToLower())) { string html = Curl.GetHtmlAsync(baseHref + p.href); if (null != html) { CurseDetail cd = Curse.PraseDetail(html); richTextBoxContent.Text = cd.content; } } } }catch (Exception ex) { Settings.LogException(ex); } }
public WorkerResult Update() { var h = Curl.GetHtmlAsync(Settings.baseHref + addon.href); if (null == h) { Settings.LogException(GenMsg("抓取远程内容失败!插件更新退出")); return(result); } var cdl = Curse.PraseDownload(h); if (null == cdl || string.IsNullOrEmpty(cdl.version) || string.IsNullOrEmpty(cdl.href)) { Settings.LogException(new Exception(GenMsg("无法获取插件最新版本,可能解析错误!插件更新退出"))); return(result); } if (!string.IsNullOrEmpty(addon.local_version) && cdl.version.Equals(addon.local_version)) { Settings.Log(GenMsg("插件已经最新,插件更新退出")); return(result); } string cachePath; try { cachePath = Path.Combine(Settings.sc.cachePath, addon.addon_id); if (!Directory.Exists(cachePath)) { Directory.CreateDirectory(cachePath); } } catch (Exception e) { Settings.LogException(e); return(result); } string localFile = string.Format(@"{0}\{1}\{2}", Settings.sc.cachePath, addon.addon_id, cdl.version); string tmp = localFile + ".tmp"; string tar = localFile + ".zip"; if (File.Exists(tar)) { Settings.Log(GenMsg("该插件已有本地缓存跳过下载")); } else { if (Curl.Download(Settings.baseHref + cdl.href, tmp)) { Settings.Log(GenMsg("插件包下载成功")); File.Move(tmp, tar); } else { Settings.LogException(new Exception(GenMsg("下载最新版本失败!插件更新退出"))); return(result); } } string addonPath = ""; try { addonPath = Path.Combine(Settings.sc.game_path, Settings.addonPath); if (!Directory.Exists(addonPath)) { Directory.CreateDirectory(addonPath); Settings.Log(GenMsg("游戏插件目录不存在,创建成功")); } } catch { Settings.LogException(new Exception(GenMsg("创建游戏插件目录失败!插件更新退出:" + addonPath))); return(result); } try { //安装结果是顶级路径,便于卸载时删除,返回null说明安装失败 var installResult = SharpZip.DecomparessFile(tar, addonPath); if (null != installResult) { addon.local_version = cdl.version; addon.update_time = DateTime.Now.ToString(); addon.file_paths = installResult; Settings.db.UpdateAddon(addon); Settings.Xlog.Add(GenMsg(" 插件更新成功,最新版本[" + cdl.version + "]"), "插件更新", XLog.AsyncLogLevel.INFO); result.success = true; return(result); } else { Settings.LogException(new Exception(GenMsg("插件安装失败,尝试接解压到插件目录出错;" + addonPath))); return(result); } }catch (Exception e) { Settings.LogException(e); GenMsg("插件安装失败!"); return(result); } }