⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 portraitform.cs

📁 飞信的收发使用csharp进行开发
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Imps.Client.Pc.Options
{
    using Imps.Client;
    using Imps.Client.Core;
    using Imps.Client.Pc;
    using Imps.Client.Pc.BizControls;
    using Imps.Client.Pc.Controls;
    using Imps.Client.Resource;
    using Imps.Client.Utils;
    using Imps.Utils;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Windows.Forms;

    public class PortraitForm : XIMDialog
    {
        private List<headicon> _addPortrait;
        private List<headicon> _delPortrait;
        private IFrameworkWindow _iFrameworkWnd;
        private string _initDir;
        private Imps.Client.Core.User _user;
        private XButton buttonAdd;
        private XButton buttonCancel;
        private XButton buttonDel;
        private XButton buttonOK;
        private IContainer components;
        private XLabel label1;
        private listbox_widget_t<headicon> lbPortrait;
        private headiconlist_drawer m_headiconlist_drawer = new headiconlist_drawer();
        private vscroll_widget m_headiconlist_vscroll = scroll_maker.instance.vscroll();
        private int m_index_of_customicon;
        private int m_index_of_sysicon;
        private Panel m_pane;
        protected OpenFileDialog OpenFileDialogPic;
        private DisplayPortrait pbMyPortrait;

        public PortraitForm(IFrameworkWindow wnd)
        {
            this.m_headiconlist_drawer.item_height = 0x24;
            this.lbPortrait = new listbox_widget_t<headicon>();
            this.InitializeComponent();
            this.lbPortrait.FormattingEnabled = true;
            this.lbPortrait.Location = new Point(12, this.buttonAdd.Location.Y);
            this.lbPortrait.Name = "lbPortrait";
            this.lbPortrait.Size = new Size((this.buttonAdd.Location.X - 10) - 12, (this.buttonOK.Location.Y - 10) - this.buttonAdd.Location.Y);
            this.lbPortrait.TabIndex = 1;
            this.lbPortrait.BorderStyle = BorderStyle.FixedSingle;
            this.lbPortrait.compare_func = new listbox_widget.compare_func_type(this.compare_func);
            this._iFrameworkWnd = wnd;
            this._user = wnd.AccountManager.CurrentUser;
            this._addPortrait = new List<headicon>();
            this._delPortrait = new List<headicon>();
            this._initDir = ImpsPathInfo.StartupPath;
            if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)))
            {
                this._initDir = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            }
            else if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Personal)))
            {
                this._initDir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            }
            this.lbPortrait.SelectedIndexChanged += new EventHandler(this.lbPortrait_SelectedIndexChanged);
            this.lbPortrait.drawer = this.m_headiconlist_drawer;
            this.OpenFileDialogPic = new OpenFileDialog();
            this.OpenFileDialogPic.Multiselect = false;
            this.OpenFileDialogPic.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*";
            this.OpenFileDialogPic.InitialDirectory = this._initDir;
            this.m_pane.Controls.Add(this.lbPortrait);
            this.m_headiconlist_vscroll.host = this.lbPortrait;
            this.m_pane.Controls.Add(this.m_headiconlist_vscroll);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.OpenFileDialogPic.ShowDialog(this) == DialogResult.OK)
                {
                    string fileName = this.OpenFileDialogPic.FileName;
                    string text = fileName.Substring(fileName.LastIndexOf(@"\") + 1, (fileName.LastIndexOf(".") - fileName.LastIndexOf(@"\")) - 1);
                    Image icon = ImageHelper.TryGetSquareThumbnailImage(fileName, 0x60);
                    if (icon == null)
                    {
                        this._iFrameworkWnd.UnifiedMessageBox.ShowInfo("未能成功添加头像:头像文件格式错误");
                    }
                    else
                    {
                        int num = 0;
                        foreach (object obj2 in this.lbPortrait.Items)
                        {
                            if (obj2 is headicon)
                            {
                                headicon headicon = (headicon) obj2;
                                if (headicon.iconpath.ToLower().CompareTo(fileName.ToLower()) == 0)
                                {
                                    this.lbPortrait.SelectedIndex = num;
                                    this._iFrameworkWnd.UnifiedMessageBox.ShowInfo("已经存在和当前路径相同的文件");
                                    return;
                                }
                            }
                            num++;
                        }
                        headicon headicon2 = new headicon(icon, text);
                        headicon2.iconpath = fileName.ToLower();
                        this.lbPortrait.Sorted = false;
                        int num2 = this.lbPortrait.add(headicon2);
                        this.lbPortrait.SelectedIndex = num2;
                        this._addPortrait.Add(headicon2);
                    }
                }
            }
            catch (ArgumentException)
            {
                this._iFrameworkWnd.UnifiedMessageBox.ShowError("无效的图片文件或者文件已损坏,请重新选择!");
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            try
            {
                base.Close();
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
        }

        private void buttonDel_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.lbPortrait.SelectedIndex != -1)
                {
                    headicon item = this.lbPortrait.get_selected_item();
                    if (item != null)
                    {
                        this._delPortrait.Add(item);
                        int num = this.lbPortrait.get_selected_index();
                        if (num < this.m_index_of_customicon)
                        {
                            this.m_index_of_customicon--;
                        }
                        this.lbPortrait.Items.Remove(item);
                        if (num < this.lbPortrait.Items.Count)
                        {
                            this.lbPortrait.SelectedIndex = num;
                        }
                        else if (0 < num)
                        {
                            this.lbPortrait.SelectedIndex = num - 1;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (this._delPortrait.Count > 0)
                {
                    foreach (headicon headicon in this._delPortrait)
                    {
                        string path = this._user.PersistentManager.BaseDirForMyUsedPortrait + headicon.text + ".dat";
                        if (File.Exists(path))
                        {
                            headicon.icon.Dispose();
                            File.Delete(path);
                        }
                    }
                }
                if (this._user.Configuration.UserSetting.SaveMyInfo && (this._addPortrait.Count > 0))
                {
                    if (!Directory.Exists(this._user.PersistentManager.BaseDirForMyUsedPortrait))
                    {
                        Directory.CreateDirectory(this._user.PersistentManager.BaseDirForMyUsedPortrait);
                    }
                    foreach (headicon headicon2 in this._addPortrait)
                    {
                        string str2 = this._user.PersistentManager.BaseDirForMyUsedPortrait + headicon2.text + ".dat";
                        if (File.Exists(str2))
                        {
                            int num = 1;
                            while (true)
                            {
                                str2 = (this._user.PersistentManager.BaseDirForMyUsedPortrait + headicon2.text) + num.ToString() + ".dat";
                                if (!File.Exists(str2))
                                {
                                    break;
                                }
                                num++;
                            }
                        }
                        int width = 0x60;
                        using (Bitmap bitmap = new Bitmap(width, width))
                        {
                            using (Graphics graphics = Graphics.FromImage(bitmap))
                            {
                                graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, width);
                                graphics.DrawImage(headicon2.icon, 0, 0);
                                bitmap.Save(str2, ImageHelper.GetImageCodecInfo(ImageFormat.Jpeg), ImageHelper.JpegParms());
                            }
                        }
                        headicon2.iconpath = str2;
                    }
                }
                headicon headicon3 = this.lbPortrait.get_selected_item();
                Image newPortrait = new Bitmap(headicon3.icon);
                headicon3.icon.Dispose();
                AsyncBizOperation op = new AsyncBizOperation(new object[] { this._iFrameworkWnd, base.Owner });
                op.ImpsError += new EventHandler<ImpsErrorEventArgs>(PortraitForm.uploadPortrait_ImpsError);
                this._user.PortraitDownloader.AsyncUploadPortrait(newPortrait, op);
                if (!string.IsNullOrEmpty(headicon3.iconpath))
                {
                    this._user.Configuration.UserSetting.ConversationSetting.CurrentPortraitFileInfo = string.Format("{0},{1}", 1, headicon3.iconpath);
                }
                base.Close();
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
                base.Close();
            }
        }

        private bool compare_func(object headicon1, object headicon2)
        {
            if (!(headicon1 is headicon) || !(headicon2 is headicon))
            {
                return false;
            }
            headicon headicon = (headicon) headicon1;
            headicon headicon3 = (headicon) headicon2;
            return (0 > headicon.text.CompareTo(headicon3.text));
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -