private void LoadOriginAndTargetIconPic(PictureBox picture, JObject elementData, bool async = false) { var cachePath = BstManager.GetIconPicTmpPath(elementData); if (async) { MethodInvoker picUpdate = delegate { if (File.Exists(cachePath)) { picture.ImageLocation = cachePath; } else { picture.ImageLocation = BstManager.GetIconPicUrl(elementData); } picture.Load(); }; picture.BeginInvoke(picUpdate); } else { if (File.Exists(cachePath)) { picture.ImageLocation = cachePath; } else { picture.ImageLocation = BstManager.GetIconPicUrl(elementData); } picture.Load(); } }
private void DownloadAllImageResources() { var finishedCount = 0; var types = BstManager.Instance.Types; foreach (var type in types) { JObject data = null; switch (Array.IndexOf(types, type)) { case BstManager.TypeAttach: data = BstManager.Instance.DataAttach; break; case BstManager.TypeCostume: data = BstManager.Instance.DataCostume; break; case BstManager.TypeWeapon: data = BstManager.Instance.DataWeapon; break; } foreach (var element in data.Properties()) { var elementData = (JObject)element.Value; var iconUrl = BstManager.GetIconPicUrl(elementData); var iconTmpPath = BstManager.GetIconPicTmpPath(elementData); var itemPicUrl = BstManager.GetItemPicUrl(Array.IndexOf(types, type), elementData); var itemPicTmpPath = BstManager.GetItemPicTmpPath(Array.IndexOf(types, type), elementData); if (File.Exists(iconTmpPath)) { // 无需下载 BstManager.ShowMsgInTextBox(this.textBoxOut, string.Format(this._i18N.LoadI18NValue("BstIconLoader", "iconDownloadSucceed"), iconUrl)); } else { var icon = BstManager.DownloadImageFile(iconUrl, iconTmpPath); if (icon == null) { // 下载失败 BstManager.ShowMsgInTextBox(this.textBoxOut, string.Format(this._i18N.LoadI18NValue("BstIconLoader", "iconDownloadFailed"), iconUrl)); } else { // 下载成功 BstManager.ShowMsgInTextBox(this.textBoxOut, string.Format(this._i18N.LoadI18NValue("BstIconLoader", "iconDownloadSucceed"), iconUrl)); } } if (File.Exists(itemPicTmpPath)) { // 无需下载 BstManager.ShowMsgInTextBox(this.textBoxOut, string.Format(this._i18N.LoadI18NValue("BstPicLoader", "picDownloadSucceed"), itemPicUrl)); } else { var pic = BstManager.DownloadImageFile(itemPicUrl, itemPicTmpPath); if (pic == null) { // 下载失败 BstManager.ShowMsgInTextBox(this.textBoxOut, string.Format(this._i18N.LoadI18NValue("BstPicLoader", "picDownloadFailed"), itemPicUrl)); } else { // 下载成功 BstManager.ShowMsgInTextBox(this.textBoxOut, string.Format(this._i18N.LoadI18NValue("BstPicLoader", "picDownloadSucceed"), itemPicUrl)); } } finishedCount += 2; if (finishedCount >= this.progBarDownloadAll.Maximum) { this.UpdateDownloadProgressBar(0); BstManager.ShowMsgInTextBox(this.textBoxOut, this._i18N.LoadI18NValue("GuiUtil", "downloadAllDone")); } else { this.UpdateDownloadProgressBar(finishedCount); } } } }