📄 customemotionmanager.cs
字号:
using (HttpWebResponse response = ((HttpWebResponse) request.GetResponse()))
{
if (response.StatusCode == HttpStatusCode.OK)
{
string path = this.GetReceivedCustomEmotionImagePath(context.Id);
if (File.Exists(path))
{
Thread.Sleep(500);
}
else
{
using (Stream stream = response.GetResponseStream())
{
using (FileStream stream2 = new FileStream(path, FileMode.Create))
{
int count;
byte[] buffer = new byte[0x2800];
for (int i = 0; (count = stream.Read(buffer, 0, buffer.Length)) > 0; i += count)
{
stream2.Position = i;
stream2.Write(buffer, 0, count);
}
}
}
}
this.FireEventAfterDownLoadEmotion(context.Id, true);
}
response.Close();
}
}
catch (IOException exception)
{
if (!File.Exists(this.GetReceivedCustomEmotionImagePath(context.Id)))
{
throw exception;
}
this.FireEventAfterDownLoadEmotion(context.Id, true);
}
catch (WebException exception2)
{
HttpWebResponse response2 = exception2.Response as HttpWebResponse;
int num4 = (response2 == null) ? ((int) ((HttpStatusCode) 0x1aa)) : ((int) response2.StatusCode);
if ((num4 != 0x1aa) && (num4 != 520))
{
throw exception2;
}
if (num > 5)
{
ClientLogger.WriteGeneral(string.Format("自定义表情下载{0}此后失败!", num), exception2.ToString());
throw exception2;
}
Thread.Sleep(0xbb8);
num++;
goto Label_0070;
}
catch (Exception exception3)
{
throw exception3;
}
}
catch (Exception exception4)
{
ClientLogger.WriteGeneral("自定义表情下载失败", exception4.ToString());
this.FireEventAfterDownLoadEmotion(context.Id, false);
}
}
public bool ExistEmotionImage(string id)
{
return (File.Exists(this.GetOwnerEmotionImagePath(id)) || File.Exists(this.GetReceivedCustomEmotionImagePath(id)));
}
public bool ExistSameStartShortCut(string shortCut)
{
return this.ExistSameStartShortCut(shortCut, "");
}
public bool ExistSameStartShortCut(string shortCut, string ceID)
{
if (!string.IsNullOrEmpty(shortCut))
{
List<Imps.Client.Core.CustomEmotion.CustomEmotion>.Enumerator enumerator = this.OwnerEmotions.LstEmoitons.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
Imps.Client.Core.CustomEmotion.CustomEmotion emotion = enumerator.get_Current();
string text = emotion.ShortCut;
if ((((text != null) && !text.Trim().Equals(string.Empty)) && !emotion.Id.Equals(ceID)) && (text.StartsWith(shortCut) || shortCut.StartsWith(text)))
{
return true;
}
}
}
finally
{
enumerator.Dispose();
}
}
return false;
}
public bool ExistSameStartShortCutInSystemEmotions(string shortCut)
{
<>c__DisplayClass1 class2;
if (string.IsNullOrEmpty(shortCut))
{
return false;
}
return Array.Exists<string>(ImpsEmoticons.Instance.SortedKeys, new Predicate<string>(class2, (IntPtr) this.<ExistSameStartShortCutInSystemEmotions>b__0));
}
private void FireEventAfterDownLoadEmotion(string id, bool success)
{
lock (this._syncDownloadingObject)
{
if (this._downloadingEmotions.ContainsKey(id))
{
try
{
List<AsyncBizOperation>.Enumerator enumerator = this._downloadingEmotions.get_Item(id).GetEnumerator();
try
{
while (enumerator.MoveNext())
{
AsyncBizOperation operation = enumerator.get_Current();
if (success)
{
operation.FireSuccessedInUiThread(EventArgs.Empty);
}
else
{
operation.FireImpsErrorInUiThread(new ImpsErrorEventArgs(string.Empty));
}
}
}
finally
{
enumerator.Dispose();
}
}
finally
{
this._downloadingEmotions.Remove(id);
}
}
}
}
public Image GetEmotionImageById(string id)
{
string path = string.Empty;
string text2 = string.Format("{0}.{1}", id, "fce");
path = Path.Combine(this._customEmotionSavePath, text2);
if (!File.Exists(path))
{
path = Path.Combine(this._customEmotionRecivedPath, text2);
if (!File.Exists(path))
{
return null;
}
}
Image image = null;
try
{
image = Image.FromFile(path);
}
catch (Exception exception)
{
ClientLogger.WriteGeneral("读取自定义表情图片出错", exception.ToString());
}
return image;
}
public string GetOwnerEmotionImagePath(string id)
{
return Path.Combine(this._customEmotionSavePath, string.Format("{0}.{1}", id, "fce"));
}
public string GetReceivedCustomEmotionImagePath(string id)
{
return Path.Combine(this._customEmotionRecivedPath, string.Format("{0}.{1}", id, "fce"));
}
internal static string GetShortCutDictionaryKey(string shortCut)
{
if (string.IsNullOrEmpty(shortCut))
{
return string.Empty;
}
return shortCut;
}
public Image GetThumbnailEmotionImage(Imps.Client.Core.CustomEmotion.CustomEmotion emotion)
{
if (!this.OwnerEmotions.ContainsKey(emotion.Id))
{
return null;
}
if (this.EmotionthumbImages.ContainsKey(emotion))
{
return this.EmotionthumbImages.get_Item(emotion);
}
string filename = Path.Combine(this._customEmotionSavePath, string.Format("{0}.{1}", emotion.Id, "thumb"));
try
{
Image image = Image.FromFile(filename);
this.ManageThumbImages(emotion, image);
return image;
}
catch (Exception exception)
{
ClientLogger.WriteGeneral("读取自定义表情缩略图出错", exception.ToString());
return null;
}
}
private void Init()
{
this._customEmotionSavePath = Path.Combine(ImpsPathInfo.ApplicationDataDir, this._currentUser.Sid.ToString() + @"\CustomEmotion");
this._customEmotionRecivedPath = Path.Combine(this._customEmotionSavePath, "Received");
this._customEmotionConfigPath = Path.Combine(this._customEmotionSavePath, "map.dat");
if (!Directory.Exists(this._customEmotionSavePath))
{
Directory.CreateDirectory(this._customEmotionSavePath);
}
if (!Directory.Exists(this._customEmotionRecivedPath))
{
Directory.CreateDirectory(this._customEmotionRecivedPath);
}
}
private XmlDocument LoadEmotionConfigXmlDocument()
{
XmlDocument document = new XmlDocument();
if (!File.Exists(this._customEmotionConfigPath))
{
this.CreateNewEmotionConfig();
}
try
{
document.Load(this._customEmotionConfigPath);
}
catch (Exception exception)
{
ClientLogger.WriteGeneral("自定义表情配置读取异常", exception.ToString());
this.CreateNewEmotionConfig();
document.Load(this._customEmotionConfigPath);
}
return document;
}
private void LoadLocalCustomEmotions()
{
XmlDocument doc = this.LoadEmotionConfigXmlDocument();
for (int i = 0; i < doc.DocumentElement.ChildNodes.Count; i++)
{
XmlNode oldChild = doc.DocumentElement.ChildNodes[i];
if ((oldChild is XmlElement) && oldChild.Name.Equals("object"))
{
Imps.Client.Core.CustomEmotion.CustomEmotion emotion = Imps.Client.Core.CustomEmotion.CustomEmotion.FromXml(oldChild.OuterXml);
string path = Path.Combine(this._customEmotionSavePath, string.Format("{0}.{1}", emotion.Id, "fce"));
string text2 = Path.Combine(this._customEmotionRecivedPath, string.Format("{0}.{1}", emotion.Id, "fce"));
string text3 = Path.Combine(this._customEmotionSavePath, string.Format("{0}.{1}", emotion.Id, "thumb"));
if ((!File.Exists(path) && !File.Exists(text2)) || !File.Exists(text3))
{
doc.DocumentElement.RemoveChild(oldChild);
i--;
}
else
{
if (this.ExistSameStartShortCutInSystemEmotions(emotion.ShortCut))
{
emotion.ShortCut = "";
if (oldChild.Attributes["shortcut"] != null)
{
oldChild.Attributes["shortcut"].Value = "";
}
}
if ((emotion != null) && !string.IsNullOrEmpty(emotion.Id.Trim()))
{
this.AddOwnerEmotionToMemory(emotion, false);
}
}
}
}
this.SaveEmotionConfigXmlDocument(doc);
if (this.OwnerEmotions.Count > 0)
{
this.OwnerEmotions.Sort();
this.OwnerEmotions.SortShortCuts();
}
}
private void ManageThumbImages(Imps.Client.Core.CustomEmotion.CustomEmotion emotion, Image image)
{
for (int i = 0; i < this.ShowCountEveryPage; i++)
{
if (this.OwnerEmotions.LstEmoitons.get_Item(i) == emotion)
{
if (!this.EmotionthumbImages.ContainsKey(emotion))
{
this.EmotionthumbImages.Add(emotion, image);
return;
}
break;
}
}
}
private void RemoveEmotionConfig(Imps.Client.Core.CustomEmotion.CustomEmotion emotion)
{
XmlDocument doc = this.LoadEmotionConfigXmlDocument();
foreach (XmlNode node in doc.SelectNodes(string.Format("//object[@id='{0}']", emotion.Id)))
{
if (node != null)
{
doc.DocumentElement.RemoveChild(node);
}
}
this.SaveEmotionConfigXmlDocument(doc);
}
private void SaveEmotionConfigXmlDocument(XmlDocument doc)
{
doc.Save(this._customEmotionConfigPath);
}
private void UpdateEmotionConfig(Imps.Client.Core.CustomEmotion.CustomEmotion emotion)
{
XmlDocument doc = this.LoadEmotionConfigXmlDocument();
foreach (XmlNode node in doc.SelectNodes(string.Format("//object[@id='{0}']", emotion.Id)))
{
if (node == null)
{
continue;
}
if (node.Attributes["name"] != null)
{
node.Attributes["name"].Value = emotion.Name;
}
if (node.Attributes["clicks"] != null)
{
node.Attributes["clicks"].Value = emotion.Clicks.ToString();
}
if (node.Attributes["shortcut"] != null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -