📄 customemotionaddform.cs
字号:
namespace Imps.Client.Pc
{
using Imps.Client.Core;
using Imps.Client.Core.CustomEmotion;
using Imps.Client.Pc.BizControls;
using Imps.Client.Pc.Controls;
using Imps.Client.Pc.CustomEmotionUI;
using Imps.Client.Resource;
using Imps.Client.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
public class CustomEmotionAddForm : XIMDialog
{
private CustomEmotionAddOperate _ceAdd;
private CustomEmotionBatchResultForm _ceResultForm;
private Imps.Client.Core.CustomEmotion.CustomEmotion _editCustomEmotion;
private IList<string[]> _errList;
private string[] _fileNames;
private IFrameworkWindow _frameworkWin;
private ICustomEmotionManager _iceManager;
private OperateTypeEnum _operateType;
private int _successCount;
private XButton btnBrowse;
private XButton btnCancel;
private XButton btnOk;
private BackgroundWorker bwBatchAdd;
private BackgroundWorker bwImport;
private CheckBox cbAssignName;
private CheckBox cbAssignShotCut;
private IContainer components;
private Label lItem1;
private Label lItem2;
private Label lItem3;
private Label lItem4;
private Label lTitle;
private OpenFileDialog opdBrowse;
private Panel panel1;
private Panel pBatchAdd;
private ProgressBar pbState;
private Panel pSingleAdd;
private XTextBox tbFileNames;
private XTextBox tbName;
private XTextBox tbShotCut;
private UPanel upPicture;
public event EventHandler<CustomEmotionEventArgs> AddCE;
public event EventHandler<CustomEmotionEventArgs> RefreshList;
public CustomEmotionAddForm(OperateTypeEnum ot, IFrameworkWindow frameworkWin)
{
this.InitializeComponent();
this._frameworkWin = frameworkWin;
this._operateType = ot;
this._iceManager = frameworkWin.AccountManager.CurrentUser.CustomEmotionManager;
this._ceAdd = new CustomEmotionAddOperate(this.AddCustomEmotion);
this.ResetForm();
}
private void AddCustomEmotion(string shortCut, string name, string filepath)
{
try
{
CustomEmotionStatus status;
Imps.Client.Core.CustomEmotion.CustomEmotion ce = this._iceManager.AddOwnerEmotion(shortCut, name, filepath, out status);
if (status == CustomEmotionStatus.OK)
{
if (ce != null)
{
this._successCount++;
if (this.AddCE != null)
{
FuncDispatcher.InvokeEventHandlerInUiThread<CustomEmotionEventArgs>(this, this.AddCE, new CustomEmotionEventArgs(ce));
}
}
}
else
{
if (this._operateType == OperateTypeEnum.Import)
{
filepath = this.TransToImportPath(filepath, this._fileNames[0]);
}
this._errList.Add(new string[] { filepath, CustomEmotionUtils.GetCustomEmotionStatusDesc(status, this._frameworkWin.AccountManager.CurrentUser) });
}
}
catch (Exception exception)
{
this._errList.Add(new string[] { filepath, "系统异常错误" });
ClientLogger.WriteException("自定义表情 -> 添加", exception);
}
}
private void BatchAdd()
{
if (!this.bwBatchAdd.get_IsBusy())
{
this.bwBatchAdd.RunWorkerAsync();
}
}
private void BatchAddPerCustomEmotion(string shortCut, string name, string filePath, int index, int count)
{
if (!base.IsDisposed)
{
this.AddCustomEmotion(shortCut, name, filePath);
double num = ((double) index) / ((double) count);
this.bwBatchAdd.ReportProgress((int) (num * 100));
Thread.Sleep(50);
}
}
private void btnBrowse_Click(object sender, EventArgs e)
{
if (this.opdBrowse.ShowDialog() != DialogResult.OK)
{
if (this._operateType == OperateTypeEnum.Edit)
{
this._fileNames = new string[] { this.EditCustomEmotion.Name };
this.tbFileNames.Text = this.EditCustomEmotion.Name;
}
}
else
{
this._fileNames = this.opdBrowse.FileNames;
this.SetFileNames();
this.SetShotCutAndName();
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.bwBatchAdd.CancelAsync();
this.bwImport.CancelAsync();
base.Close();
}
private void btnOk_Click(object sender, EventArgs e)
{
this._successCount = 0;
this._errList = new List<string[]>();
this.ChangeControlEnabled(false);
switch (this._operateType)
{
case OperateTypeEnum.Add:
if (this._fileNames.Length != 1)
{
this.BatchAdd();
return;
}
this.SingleAdd();
return;
case OperateTypeEnum.Edit:
this.SingleEdit();
return;
case OperateTypeEnum.Import:
this.ImportAdd();
return;
}
}
private void bwBatchAdd_DoWork(object sender, DoWorkEventArgs e)
{
string shortCut = string.Empty;
string name = string.Empty;
string filePath = string.Empty;
try
{
if (this.cbAssignShotCut.Checked && this.cbAssignName.Checked)
{
for (int i = 0; i < this._fileNames.Length; i++)
{
if (this.bwBatchAdd.get_CancellationPending())
{
return;
}
filePath = this._fileNames[i];
shortCut = this.MakeShortCut("");
name = this.GetShortCut(this.GetFileName(filePath));
this.BatchAddPerCustomEmotion(shortCut, name, filePath, i + 1, this._fileNames.Length);
}
}
else if (this.cbAssignShotCut.Checked && !this.cbAssignName.Checked)
{
for (int j = 0; j < this._fileNames.Length; j++)
{
if (this.bwBatchAdd.get_CancellationPending())
{
return;
}
filePath = this._fileNames[j];
shortCut = this.MakeShortCut("");
name = "";
this.BatchAddPerCustomEmotion(shortCut, name, filePath, j + 1, this._fileNames.Length);
}
}
else if (!this.cbAssignShotCut.Checked && !this.cbAssignName.Checked)
{
for (int k = 0; k < this._fileNames.Length; k++)
{
if (this.bwBatchAdd.get_CancellationPending())
{
return;
}
filePath = this._fileNames[k];
shortCut = "";
name = "";
this.BatchAddPerCustomEmotion(shortCut, name, filePath, k + 1, this._fileNames.Length);
}
}
else if (!this.cbAssignShotCut.Checked && this.cbAssignName.Checked)
{
for (int m = 0; m < this._fileNames.Length; m++)
{
if (this.bwBatchAdd.get_CancellationPending())
{
return;
}
filePath = this._fileNames[m];
shortCut = "";
name = this.GetShortCut(this.GetFileName(filePath));
this.BatchAddPerCustomEmotion(shortCut, name, filePath, m + 1, this._fileNames.Length);
}
}
}
catch (Exception exception)
{
ClientLogger.WriteException("自定义表情 -> 批量添加", exception);
}
}
private void bwBatchAdd_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.pbState.Value = e.get_ProgressPercentage();
}
private void bwBatchAdd_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (this._errList.get_Count() == 0)
{
if ((this != null) && !base.IsDisposed)
{
this._frameworkWin.UnifiedMessageBox.ShowInfo(this, string.Format("成功添加{0}个表情!", this._successCount));
base.Close();
}
else
{
this._frameworkWin.UnifiedMessageBox.ShowInfo(string.Format("成功添加{0}个表情!", this._successCount));
}
}
else
{
this.ShowResult();
}
}
private void bwImport_DoWork(object sender, DoWorkEventArgs e)
{
string shortCut = string.Empty;
string name = string.Empty;
string filePath = string.Empty;
string text4 = (string) e.get_Argument();
string path = Path.Combine(text4, "list.xml");
try
{
if (!File.Exists(path))
{
e.set_Result(false);
}
else
{
e.set_Result(true);
XmlDocument document = new XmlDocument();
document.Load(path);
if (this.cbAssignShotCut.Checked)
{
for (int i = 0; i < document.DocumentElement.ChildNodes.Count; i++)
{
if (this.bwBatchAdd.get_CancellationPending())
{
return;
}
XmlNode node = document.DocumentElement.ChildNodes[i];
shortCut = this.MakeShortCut(node.Attributes["ShortCut"].Value);
name = node.Attributes["Name"].Value;
filePath = Path.Combine(text4, node.Attributes["FileName"].Value);
this.ImportAddPerCustomEmotion(shortCut, name, filePath, i + 1, document.DocumentElement.ChildNodes.Count);
}
}
else
{
for (int j = 0; j < document.DocumentElement.ChildNodes.Count; j++)
{
if (this.bwBatchAdd.get_CancellationPending())
{
return;
}
XmlNode node2 = document.DocumentElement.ChildNodes[j];
shortCut = node2.Attributes["ShortCut"].Value;
name = node2.Attributes["Name"].Value;
filePath = Path.Combine(text4, node2.Attributes["FileName"].Value);
if (this.ExistShortCut(shortCut, ""))
{
shortCut = "";
}
this.ImportAddPerCustomEmotion(shortCut, name, filePath, j + 1, document.DocumentElement.ChildNodes.Count);
}
}
}
}
catch (Exception exception)
{
ClientLogger.WriteException("自定义表情 -> 导入", exception);
}
finally
{
try
{
Directory.Delete(text4, true);
}
catch (Exception exception2)
{
string message = exception2.Message;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -