www.pudn.com > Fetion.rar > 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 _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 AddCE; 
 
        public event EventHandler 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(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.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.0)); 
                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(); 
            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.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.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.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.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.ProgressPercentage; 
        } 
 
        private void bwBatchAdd_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 
        { 
            if (this._errList.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 argument = (string) e.Argument; 
            string path = Path.Combine(argument, "list.xml"); 
            try 
            { 
                if (!File.Exists(path)) 
                { 
                    e.Result = false; 
                } 
                else 
                { 
                    e.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.CancellationPending) 
                            { 
                                return; 
                            } 
                            XmlNode node = document.DocumentElement.ChildNodes[i]; 
                            shortCut = this.MakeShortCut(node.Attributes["ShortCut"].Value); 
                            name = node.Attributes["Name"].Value; 
                            filePath = Path.Combine(argument, 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.CancellationPending) 
                            { 
                                return; 
                            } 
                            XmlNode node2 = document.DocumentElement.ChildNodes[j]; 
                            shortCut = node2.Attributes["ShortCut"].Value; 
                            name = node2.Attributes["Name"].Value; 
                            filePath = Path.Combine(argument, 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(argument, true); 
                } 
                catch (Exception exception2) 
                { 
                    string message = exception2.Message; 
                } 
            } 
        } 
 
        private void bwImport_ProgressChanged(object sender, ProgressChangedEventArgs e) 
        { 
            this.pbState.Value = e.ProgressPercentage; 
        } 
 
        private void bwImport_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 
        { 
            if (!Convert.ToBoolean(e.Result)) 
            { 
                if ((this != null) && !base.IsDisposed) 
                { 
                    this._frameworkWin.UnifiedMessageBox.ShowInfo(this, "请使用飞信的表情库文件。"); 
                } 
                else 
                { 
                    this._frameworkWin.UnifiedMessageBox.ShowInfo("请使用飞信的表情库文件。"); 
                } 
                this.ChangeControlEnabled(true); 
            } 
            else if (this._errList.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 ChangeControlEnabled(bool enabled) 
        { 
            if (this._operateType == OperateTypeEnum.Edit) 
            { 
                this.btnBrowse.Enabled = false; 
            } 
            else 
            { 
                this.btnBrowse.Enabled = enabled; 
            } 
            this.cbAssignName.Enabled = enabled; 
            this.cbAssignShotCut.Enabled = enabled; 
            this.btnOk.Enabled = enabled; 
        } 
 
        private void CustomEmotionAddForm_FormClosed(object sender, FormClosedEventArgs e) 
        { 
            this.bwBatchAdd.CancelAsync(); 
            this.bwImport.CancelAsync(); 
            if ((this._ceResultForm != null) && !this._ceResultForm.IsDisposed) 
            { 
                this._ceResultForm.Dispose(); 
            } 
        } 
 
        private void CustomEmotionAddForm_Load(object sender, EventArgs e) 
        { 
            this.btnBrowse.Focus(); 
        } 
 
        protected override void Dispose(bool disposing) 
        { 
            if (disposing && (this.components != null)) 
            { 
                this.components.Dispose(); 
            } 
            base.Dispose(disposing); 
        } 
 
        private bool ExistShortCut(string shortCut, string id) 
        { 
            if (ImpsEmoticons.Instance.ContainsKey(shortCut)) 
            { 
                return true; 
            } 
            Imps.Client.Core.CustomEmotion.CustomEmotion emotionByShortCut = this._iceManager.OwnerEmotions.GetEmotionByShortCut(shortCut); 
            return (((emotionByShortCut != null) && !emotionByShortCut.Id.Equals(id)) || (this._iceManager.ExistSameStartShortCutInSystemEmotions(shortCut) || this._iceManager.ExistSameStartShortCut(shortCut, id))); 
        } 
 
        private string GetFileName(int index) 
        { 
            return this.GetFileName(this._fileNames[index]); 
        } 
 
        private string GetFileName(string filePath) 
        { 
            int startIndex = filePath.LastIndexOf('\\') + 1; 
            int num2 = filePath.LastIndexOf('.'); 
            return filePath.Substring(startIndex, num2 - startIndex); 
        } 
 
        private string GetShortCut(string fileName) 
        { 
            if (fileName.Length <= 8) 
            { 
                return fileName; 
            } 
            return fileName.Substring(0, 8); 
        } 
 
        private void ImportAdd() 
        { 
            string fileName = this.GetFileName(0); 
            string dirPath = Path.Combine(ImpsPathInfo.ApplicationDataDir, string.Format(@"temp\{0}\", fileName)); 
            bool flag = false; 
            try 
            { 
                GZipCompressXml.DeCompress(this._fileNames[0], dirPath); 
                flag = true; 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException("自定义表情 -> 解压表情文件", exception); 
            } 
            if (!flag) 
            { 
                this._frameworkWin.UnifiedMessageBox.ShowError(this, "文件读取失败,请选择正确的表情文件。"); 
                this.ChangeControlEnabled(true); 
            } 
            else if (!this.bwImport.IsBusy) 
            { 
                this.bwImport.RunWorkerAsync(dirPath); 
            } 
        } 
 
        private void ImportAddPerCustomEmotion(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.bwImport.ReportProgress((int) (num * 100.0)); 
                Thread.Sleep(50); 
            } 
        } 
 
        private void InitializeComponent() 
        { 
            ComponentResourceManager manager = new ComponentResourceManager(typeof(CustomEmotionAddForm)); 
            this.lTitle = new Label(); 
            this.tbFileNames = new XTextBox(); 
            this.btnBrowse = new XButton(); 
            this.lItem1 = new Label(); 
            this.lItem2 = new Label(); 
            this.tbShotCut = new XTextBox(); 
            this.lItem3 = new Label(); 
            this.tbName = new XTextBox(); 
            this.lItem4 = new Label(); 
            this.btnCancel = new XButton(); 
            this.btnOk = new XButton(); 
            this.opdBrowse = new OpenFileDialog(); 
            this.pBatchAdd = new Panel(); 
            this.upPicture = new UPanel(); 
            this.pbState = new ProgressBar(); 
            this.cbAssignName = new CheckBox(); 
            this.cbAssignShotCut = new CheckBox(); 
            this.pSingleAdd = new Panel(); 
            this.bwBatchAdd = new BackgroundWorker(); 
            this.bwImport = new BackgroundWorker(); 
            this.panel1 = new Panel(); 
            this.pBatchAdd.SuspendLayout(); 
            this.upPicture.SuspendLayout(); 
            this.pSingleAdd.SuspendLayout(); 
            this.panel1.SuspendLayout(); 
            base.SuspendLayout(); 
            this.lTitle.AutoSize = true; 
            this.lTitle.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0); 
            this.lTitle.Location = new System.Drawing.Point(9, 12); 
            this.lTitle.Name = "lTitle"; 
            this.lTitle.Size = new Size(0xa3, 13); 
            this.lTitle.TabIndex = 0; 
            this.lTitle.Text = "请按提示设置您的自定义表情"; 
            this.tbFileNames.BackColor = Color.FromArgb(240, 240, 240); 
            this.tbFileNames.BorderStyle = BorderStyle.FixedSingle; 
            this.tbFileNames.EmptyTextTip = ""; 
            this.tbFileNames.EmptyTextTipColor = Color.DarkGray; 
            this.tbFileNames.Location = new System.Drawing.Point(14, 0x4c); 
            this.tbFileNames.Name = "tbFileNames"; 
            this.tbFileNames.ReadOnly = true; 
            this.tbFileNames.Size = new Size(0xef, 20); 
            this.tbFileNames.TabIndex = 2; 
            this.tbFileNames.TabStop = false; 
            this.tbFileNames.TextChanged += new EventHandler(this.tbFileNames_TextChanged); 
            this.btnBrowse.AutoArrangementX = true; 
            this.btnBrowse.AutoSizeToImage = false; 
            this.btnBrowse.BackColor = Color.Transparent; 
            this.btnBrowse.BackgroundImage = (Image) manager.GetObject("btnBrowse.BackgroundImage"); 
            this.btnBrowse.BackgroundImageDisable = (Image) manager.GetObject("btnBrowse.BackgroundImageDisable"); 
            this.btnBrowse.BackgroundImageDown = (Image) manager.GetObject("btnBrowse.BackgroundImageDown"); 
            this.btnBrowse.BackgroundImageHover = (Image) manager.GetObject("btnBrowse.BackgroundImageHover"); 
            this.btnBrowse.ChangeSkin = false; 
            this.btnBrowse.Location = new System.Drawing.Point(0x106, 0x4c); 
            this.btnBrowse.Name = "btnBrowse"; 
            this.btnBrowse.Size = new Size(0x3d, 0x15); 
            this.btnBrowse.TabIndex = 0; 
            this.btnBrowse.Text = "浏览..."; 
            this.btnBrowse.UseVisualStyleBackColor = false; 
            this.btnBrowse.Click += new EventHandler(this.btnBrowse_Click); 
            this.lItem1.AutoSize = true; 
            this.lItem1.Location = new System.Drawing.Point(12, 0x2a); 
            this.lItem1.Name = "lItem1"; 
            this.lItem1.Size = new Size(0xf8, 0x1a); 
            this.lItem1.TabIndex = 4; 
            this.lItem1.Text = "1、请选择表情图片位置(文件不要超过50K)\r\n   支持jpg,gif,png,bmp格式"; 
            this.lItem2.AutoSize = true; 
            this.lItem2.Location = new System.Drawing.Point(3, 11); 
            this.lItem2.Name = "lItem2"; 
            this.lItem2.Size = new Size(0xeb, 0x1a); 
            this.lItem2.TabIndex = 6; 
            this.lItem2.Text = "2、设置表情键盘输入快捷键,8个字符以内\r\n   例如:prz"; 
            this.tbShotCut.BackColor = Color.White; 
            this.tbShotCut.BorderStyle = BorderStyle.FixedSingle; 
            this.tbShotCut.EmptyTextTip = ""; 
            this.tbShotCut.EmptyTextTipColor = Color.DarkGray; 
            this.tbShotCut.Location = new System.Drawing.Point(5, 0x2d); 
            this.tbShotCut.MaxLength = 8; 
            this.tbShotCut.Name = "tbShotCut"; 
            this.tbShotCut.Size = new Size(0xef, 20); 
            this.tbShotCut.TabIndex = 0; 
            this.tbShotCut.TextChanged += new EventHandler(this.tbShotCut_TextChanged); 
            this.tbShotCut.KeyDown += new KeyEventHandler(this.tbShotCut_KeyDown); 
            this.lItem3.AutoSize = true; 
            this.lItem3.Location = new System.Drawing.Point(3, 0x4c); 
            this.lItem3.Name = "lItem3"; 
            this.lItem3.Size = new Size(0x91, 13); 
            this.lItem3.TabIndex = 8; 
            this.lItem3.Text = "3、设置表情名称(可选)"; 
            this.tbName.BackColor = Color.White; 
            this.tbName.BorderStyle = BorderStyle.FixedSingle; 
            this.tbName.EmptyTextTip = ""; 
            this.tbName.EmptyTextTipColor = Color.DarkGray; 
            this.tbName.Location = new System.Drawing.Point(5, 0x62); 
            this.tbName.MaxLength = 8; 
            this.tbName.Name = "tbName"; 
            this.tbName.Size = new Size(0xef, 20); 
            this.tbName.TabIndex = 1; 
            this.tbName.KeyDown += new KeyEventHandler(this.tbName_KeyDown); 
            this.lItem4.AutoSize = true; 
            this.lItem4.Location = new System.Drawing.Point(3, 11); 
            this.lItem4.Name = "lItem4"; 
            this.lItem4.Size = new Size(0xaf, 13); 
            this.lItem4.TabIndex = 9; 
            this.lItem4.Text = "您批量添加自定义表情,飞信将"; 
            this.btnCancel.AutoArrangementX = true; 
            this.btnCancel.AutoSizeToImage = false; 
            this.btnCancel.BackColor = Color.Transparent; 
            this.btnCancel.BackgroundImageDisable = null; 
            this.btnCancel.BackgroundImageDown = null; 
            this.btnCancel.BackgroundImageHover = null; 
            this.btnCancel.ChangeSkin = true; 
            this.btnCancel.DialogResult = DialogResult.Cancel; 
            this.btnCancel.Location = new System.Drawing.Point(0x10d, 0x110); 
            this.btnCancel.Name = "btnCancel"; 
            this.btnCancel.Size = new Size(0x4b, 0x17); 
            this.btnCancel.TabIndex = 2; 
            this.btnCancel.Text = "取消"; 
            this.btnCancel.UseVisualStyleBackColor = false; 
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click); 
            this.btnOk.AutoArrangementX = true; 
            this.btnOk.AutoSizeToImage = false; 
            this.btnOk.BackColor = Color.Transparent; 
            this.btnOk.BackgroundImageDisable = null; 
            this.btnOk.BackgroundImageDown = null; 
            this.btnOk.BackgroundImageHover = null; 
            this.btnOk.ChangeSkin = true; 
            this.btnOk.Enabled = false; 
            this.btnOk.Location = new System.Drawing.Point(0xb8, 0x110); 
            this.btnOk.Name = "btnOk"; 
            this.btnOk.Size = new Size(0x4b, 0x17); 
            this.btnOk.TabIndex = 1; 
            this.btnOk.Text = "确定"; 
            this.btnOk.UseVisualStyleBackColor = false; 
            this.btnOk.Click += new EventHandler(this.btnOk_Click); 
            this.opdBrowse.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*"; 
            this.opdBrowse.Multiselect = true; 
            this.opdBrowse.Title = "选择表情"; 
            this.pBatchAdd.Controls.Add(this.upPicture); 
            this.pBatchAdd.Controls.Add(this.cbAssignName); 
            this.pBatchAdd.Controls.Add(this.cbAssignShotCut); 
            this.pBatchAdd.Controls.Add(this.lItem4); 
            this.pBatchAdd.Location = new System.Drawing.Point(9, 0xf8); 
            this.pBatchAdd.Name = "pBatchAdd"; 
            this.pBatchAdd.Size = new Size(0x148, 0x7a); 
            this.pBatchAdd.TabIndex = 2; 
            this.pBatchAdd.Visible = false; 
            this.upPicture.BorderColor = Color.FromArgb(0xcb, 0xd4, 0xde); 
            this.upPicture.BorderInsideColor = Color.White; 
            this.upPicture.BorderInsideWidth = 1; 
            this.upPicture.BorderWidth = 1; 
            this.upPicture.Controls.Add(this.pbState); 
            this.upPicture.Location = new System.Drawing.Point(5, 0x53); 
            this.upPicture.Name = "upPicture"; 
            this.upPicture.Padding = new Padding(3); 
            this.upPicture.Size = new Size(0x135, 0x17); 
            this.upPicture.TabIndex = 14; 
            this.pbState.Location = new System.Drawing.Point(0, 0); 
            this.pbState.Name = "pbState"; 
            this.pbState.Size = new Size(0x134, 0x16); 
            this.pbState.TabIndex = 12; 
            this.cbAssignName.AutoSize = true; 
            this.cbAssignName.Checked = true; 
            this.cbAssignName.CheckState = CheckState.Checked; 
            this.cbAssignName.Location = new System.Drawing.Point(5, 0x39); 
            this.cbAssignName.Name = "cbAssignName"; 
            this.cbAssignName.Size = new Size(0x92, 0x11); 
            this.cbAssignName.TabIndex = 1; 
            this.cbAssignName.Text = "使用文件名做表情名称"; 
            this.cbAssignName.UseVisualStyleBackColor = true; 
            this.cbAssignShotCut.AutoSize = true; 
            this.cbAssignShotCut.Checked = true; 
            this.cbAssignShotCut.CheckState = CheckState.Checked; 
            this.cbAssignShotCut.Location = new System.Drawing.Point(5, 0x20); 
            this.cbAssignShotCut.Name = "cbAssignShotCut"; 
            this.cbAssignShotCut.Size = new Size(0x9e, 0x11); 
            this.cbAssignShotCut.TabIndex = 0; 
            this.cbAssignShotCut.Text = "系统分配键盘输入快捷键"; 
            this.cbAssignShotCut.UseVisualStyleBackColor = true; 
            this.pSingleAdd.Controls.Add(this.tbName); 
            this.pSingleAdd.Controls.Add(this.tbShotCut); 
            this.pSingleAdd.Controls.Add(this.lItem2); 
            this.pSingleAdd.Controls.Add(this.lItem3); 
            this.pSingleAdd.Location = new System.Drawing.Point(9, 0x68); 
            this.pSingleAdd.Name = "pSingleAdd"; 
            this.pSingleAdd.Size = new Size(0xfd, 0x88); 
            this.pSingleAdd.TabIndex = 1; 
            this.bwBatchAdd.WorkerReportsProgress = true; 
            this.bwBatchAdd.WorkerSupportsCancellation = true; 
            this.bwBatchAdd.DoWork += new DoWorkEventHandler(this.bwBatchAdd_DoWork); 
            this.bwBatchAdd.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.bwBatchAdd_RunWorkerCompleted); 
            this.bwBatchAdd.ProgressChanged += new ProgressChangedEventHandler(this.bwBatchAdd_ProgressChanged); 
            this.bwImport.WorkerReportsProgress = true; 
            this.bwImport.WorkerSupportsCancellation = true; 
            this.bwImport.DoWork += new DoWorkEventHandler(this.bwImport_DoWork); 
            this.bwImport.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.bwImport_RunWorkerCompleted); 
            this.bwImport.ProgressChanged += new ProgressChangedEventHandler(this.bwImport_ProgressChanged); 
            this.panel1.Controls.Add(this.lTitle); 
            this.panel1.Controls.Add(this.pSingleAdd); 
            this.panel1.Controls.Add(this.pBatchAdd); 
            this.panel1.Controls.Add(this.tbFileNames); 
            this.panel1.Controls.Add(this.btnBrowse); 
            this.panel1.Controls.Add(this.lItem1); 
            this.panel1.Location = new System.Drawing.Point(2, 12); 
            this.panel1.Name = "panel1"; 
            this.panel1.Size = new Size(0x15b, 0xfe); 
            this.panel1.TabIndex = 0; 
            base.AutoScaleDimensions = new SizeF(6f, 13f); 
            this.BackColor = Color.White; 
            base.BaseHeight = 0x1d2; 
            base.BaseWidth = 0x15f; 
            base.CancelButton = this.btnCancel; 
            base.ClientSize = new Size(0x15f, 0x1d2); 
            base.Controls.Add(this.panel1); 
            base.Controls.Add(this.btnOk); 
            base.Controls.Add(this.btnCancel); 
            base.DisplayLocation = new System.Drawing.Point(15, 15); 
            base.DisplaySize = new Size(0x15f, 0x1d2); 
            base.FormBorderStyle = FormBorderStyle.FixedSingle; 
            base.MinimizeBox = false; 
            base.Name = "CustomEmotionAddForm"; 
            base.Padding = new Padding(4, 0, 4, 0x2b); 
            base.StartPosition = FormStartPosition.Manual; 
            base.Text = "Fetion 2008"; 
            base.FormClosed += new FormClosedEventHandler(this.CustomEmotionAddForm_FormClosed); 
            base.Load += new EventHandler(this.CustomEmotionAddForm_Load); 
            this.pBatchAdd.ResumeLayout(false); 
            this.pBatchAdd.PerformLayout(); 
            this.upPicture.ResumeLayout(false); 
            this.pSingleAdd.ResumeLayout(false); 
            this.pSingleAdd.PerformLayout(); 
            this.panel1.ResumeLayout(false); 
            this.panel1.PerformLayout(); 
            base.ResumeLayout(false); 
        } 
 
        private string MakeShortCut(string shortCut) 
        { 
            if ((shortCut == null) || (shortCut == string.Empty)) 
            { 
                shortCut = StringHelper.RandomString(8); 
            } 
            for (int i = 0; this.ExistShortCut(shortCut, ""); i++) 
            { 
                if (i > 0x7a) 
                { 
                    shortCut = ""; 
                    return shortCut; 
                } 
                shortCut = StringHelper.RandomString(8); 
            } 
            return shortCut; 
        } 
 
        private void ResetForm() 
        { 
            this.pBatchAdd.Top = this.pSingleAdd.Top; 
            switch (this._operateType) 
            { 
                case OperateTypeEnum.Add: 
                    this.lItem1.Text = string.Format("1、请选择表情图片位置(文件不要超过{0}K)支持jpg,gif,\r\npng,bmp格式", CustomEmotionUtils.GetMaxEmotionPicSize(this._frameworkWin.AccountManager.CurrentUser)); 
                    return; 
 
                case OperateTypeEnum.Edit: 
                    this.lItem1.Text = string.Format("1、请选择表情图片位置(文件不要超过{0}K)支持jpg,gif,\r\npng,bmp格式", CustomEmotionUtils.GetMaxEmotionPicSize(this._frameworkWin.AccountManager.CurrentUser)); 
                    this.opdBrowse.Multiselect = false; 
                    return; 
 
                case OperateTypeEnum.Import: 
                    this.btnOk.Text = "导入"; 
                    this.lItem1.Text = "请选择飞信表情库文件(*.ffl)"; 
                    this.lItem4.Text = "您导入表情库里自定义表情,飞信将"; 
                    this.cbAssignShotCut.Text = "系统分配重复的键盘输入快捷键"; 
                    this.opdBrowse.Multiselect = false; 
                    this.opdBrowse.Filter = "飞信表情文件(*.ffl)|*.ffl"; 
                    this.pSingleAdd.Visible = false; 
                    this.pBatchAdd.Visible = true; 
                    this.cbAssignName.Visible = false; 
                    return; 
            } 
        } 
 
        private void SetControlText() 
        { 
            this.lTitle.Text = StringTable.CustomEmotions.CustomEmotionAdd.Title; 
            this.lItem1.Text = StringTable.CustomEmotions.CustomEmotionAdd.Item1; 
            this.lItem2.Text = StringTable.CustomEmotions.CustomEmotionAdd.Item2; 
            this.lItem3.Text = StringTable.CustomEmotions.CustomEmotionAdd.Item3; 
            this.lItem4.Text = StringTable.CustomEmotions.CustomEmotionAdd.Item4; 
            this.btnBrowse.Text = StringTable.CustomEmotions.CustomEmotionAdd.Browse; 
            this.btnCancel.Text = StringTable.CustomEmotions.CustomEmotionAdd.Cancel; 
        } 
 
        private void SetFileNames() 
        { 
            if (this._fileNames.Length >= 1) 
            { 
                this.tbFileNames.Text = this._fileNames[0]; 
                for (int i = 1; i < this._fileNames.Length; i++) 
                { 
                    this.tbFileNames.Text = this.tbFileNames.Text + ";" + Path.GetFileName(this._fileNames[i]); 
                } 
            } 
        } 
 
        private void SetShotCutAndName() 
        { 
            if (this._operateType != OperateTypeEnum.Add) 
            { 
                this.btnOk.Focus(); 
            } 
            else 
            { 
                int length = this._fileNames.Length; 
                this.pSingleAdd.Visible = length == 1; 
                this.pBatchAdd.Visible = length > 1; 
                if (length > 1) 
                { 
                    this.lItem4.Text = string.Format("您批量添加了{0}个自定义表情,飞信将", this._fileNames.Length); 
                    this.btnOk.Focus(); 
                } 
                else 
                { 
                    string fileName = this.GetFileName(0); 
                    string shortCut = this.GetShortCut(fileName); 
                    this.tbShotCut.Text = shortCut; 
                    this.tbName.Text = shortCut; 
                    this.tbShotCut.Focus(); 
                } 
            } 
        } 
 
        private void ShowResult() 
        { 
            if ((this._ceResultForm != null) && !this._ceResultForm.IsDisposed) 
            { 
                this._ceResultForm.Close(); 
                this._ceResultForm.Dispose(); 
            } 
            this._ceResultForm = new CustomEmotionBatchResultForm(this._successCount, this._errList, this); 
            ControlHelper.ShowFormCenterOnParent(this._ceResultForm, this); 
            this._ceResultForm.Focus(); 
        } 
 
        private void SingleAdd() 
        { 
            string filepath = this._fileNames[0]; 
            string shortCut = this.tbShotCut.Text.Trim(); 
            string name = this.tbName.Text.Trim(); 
            try 
            { 
                Imps.Client.Core.CustomEmotion.CustomEmotion emotionByShortCut = this._iceManager.OwnerEmotions.GetEmotionByShortCut(shortCut); 
                if (emotionByShortCut != null) 
                { 
                    if (this._frameworkWin.UnifiedMessageBox.ShowConfirmation(this, "与其他表情的输入快捷键重复\r\n点击“是”将删除原表情\r\n“否”将重新设置快捷键") != DialogResult.Yes) 
                    { 
                        return; 
                    } 
                    this._iceManager.DeleteOwnerEmotion(emotionByShortCut); 
                    if (this.RefreshList != null) 
                    { 
                        this.RefreshList(this, new CustomEmotionEventArgs(emotionByShortCut)); 
                    } 
                    this.AddCustomEmotion(shortCut, name, filepath); 
                } 
                else 
                { 
                    this.AddCustomEmotion(shortCut, name, filepath); 
                } 
                if (this._errList.Count > 0) 
                { 
                    this._frameworkWin.UnifiedMessageBox.ShowError(this, "自定义表情添加失败:" + this._errList[0][1] + "。"); 
                } 
                else 
                { 
                    base.Close(); 
                } 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException("自定义表情 -> 添加", exception); 
            } 
            finally 
            { 
                this.ChangeControlEnabled(true); 
                this.tbShotCut.Focus(); 
            } 
        } 
 
        private void SingleEdit() 
        { 
            string str = this._fileNames[0]; 
            string shortCut = this.tbShotCut.Text.Trim(); 
            string name = this.tbName.Text.Trim(); 
            try 
            { 
                Imps.Client.Core.CustomEmotion.CustomEmotion emotionByShortCut = this._iceManager.OwnerEmotions.GetEmotionByShortCut(shortCut); 
                if ((emotionByShortCut != null) && (emotionByShortCut.Id != this.EditCustomEmotion.Id)) 
                { 
                    if (this._frameworkWin.UnifiedMessageBox.ShowConfirmation(this, "与其他表情的输入快捷键重复\r\n点击“是”将删除原表情\r\n“否”将重新设置快捷键") != DialogResult.Yes) 
                    { 
                        return; 
                    } 
                    this._iceManager.DeleteOwnerEmotion(emotionByShortCut); 
                    if (this.RefreshList != null) 
                    { 
                        FuncDispatcher.InvokeEventHandlerInUiThread(this, this.RefreshList, new CustomEmotionEventArgs(emotionByShortCut)); 
                    } 
                } 
                if (this.EditCustomEmotion.Name.Equals(str)) 
                { 
                    CustomEmotionStatus ceStatus = this._iceManager.UpdateOwnerEmotion(this.EditCustomEmotion, shortCut, name); 
                    if (ceStatus != CustomEmotionStatus.OK) 
                    { 
                        this._errList.Add(new string[] { str, CustomEmotionUtils.GetCustomEmotionStatusDesc(ceStatus, this._frameworkWin.AccountManager.CurrentUser) }); 
                    } 
                    else if (this.RefreshList != null) 
                    { 
                        FuncDispatcher.InvokeEventHandlerInUiThread(this, this.RefreshList, new CustomEmotionEventArgs(this.EditCustomEmotion)); 
                    } 
                } 
                else 
                { 
                    this._iceManager.DeleteOwnerEmotion(this.EditCustomEmotion); 
                    if (this.RefreshList != null) 
                    { 
                        FuncDispatcher.InvokeEventHandlerInUiThread(this, this.RefreshList, new CustomEmotionEventArgs(this.EditCustomEmotion)); 
                    } 
                    this.AddCustomEmotion(shortCut, name, str); 
                } 
                if (this._errList.Count > 0) 
                { 
                    this._frameworkWin.UnifiedMessageBox.ShowError(this, "自定义表情编辑失败:" + this._errList[0][1] + "。"); 
                } 
                else 
                { 
                    base.Close(); 
                } 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException("自定义表情 -> 修改", exception); 
            } 
            finally 
            { 
                this.ChangeControlEnabled(true); 
                this.tbShotCut.Focus(); 
            } 
        } 
 
        private void tbFileNames_TextChanged(object sender, EventArgs e) 
        { 
            this.btnOk.Enabled = !this.tbFileNames.Text.Trim().Equals(""); 
        } 
 
        private void tbName_KeyDown(object sender, KeyEventArgs e) 
        { 
            if ((e.KeyCode == Keys.Return) || (e.KeyCode == Keys.Tab)) 
            { 
                this.btnOk.Focus(); 
            } 
        } 
 
        private void tbShotCut_KeyDown(object sender, KeyEventArgs e) 
        { 
            if ((e.KeyCode == Keys.Return) || (e.KeyCode == Keys.Tab)) 
            { 
                this.tbName.Focus(); 
            } 
        } 
 
        private void tbShotCut_TextChanged(object sender, EventArgs e) 
        { 
            string str = this.tbShotCut.Text.Replace(" ", ""); 
            this.tbShotCut.Text = str; 
        } 
 
        private string TransToImportPath(string fileName, string packageName) 
        { 
            fileName = Path.GetFileName(fileName); 
            packageName = Path.GetFileName(packageName); 
            return ("$" + packageName + "/" + fileName); 
        } 
 
        public Imps.Client.Core.CustomEmotion.CustomEmotion EditCustomEmotion 
        { 
            get 
            { 
                return this._editCustomEmotion; 
            } 
            set 
            { 
                this._editCustomEmotion = value; 
                this.tbName.Text = this._editCustomEmotion.Name; 
                this.tbShotCut.Text = this._editCustomEmotion.ShortCut; 
                this.tbFileNames.Text = this._editCustomEmotion.Name; 
                this.btnBrowse.Enabled = false; 
                this.btnOk.Enabled = true; 
                this._fileNames = new string[] { this._editCustomEmotion.Name }; 
            } 
        } 
 
        public OperateTypeEnum OperateType 
        { 
            get 
            { 
                return this._operateType; 
            } 
        } 
 
        private delegate void CustomEmotionAddOperate(string shortCut, string name, string filepath); 
 
        public enum OperateTypeEnum 
        { 
            Add, 
            Edit, 
            Import 
        } 
    } 
}