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

📄 portraitform.cs

📁 破解的飞信源代码
💻 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.InitializeComponent();
            this.lbPortrait = new listbox_widget_t<headicon>();
            this.lbPortrait.set_FormattingEnabled(true);
            this.lbPortrait.Location = new System.Drawing.Point(10, this.buttonAdd.Top);
            this.lbPortrait.Name = "lbPortrait";
            this.lbPortrait.Size = new Size(this.label1.Left - 20, this.m_pane.Height - 0x12);
            this.lbPortrait.TabIndex = 0;
            this.lbPortrait.BorderStyle = BorderStyle.FixedSingle;
            this.m_pane.Controls.Add(this.lbPortrait);
            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.compare_func = new listbox_widget.compare_func_type(this.compare_func);
            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_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 path = this.OpenFileDialogPic.FileName;
                    string text = path.Substring(path.LastIndexOf(@"\") + 1, (path.LastIndexOf(".") - path.LastIndexOf(@"\")) - 1);
                    Image icon = ImageHelper.TryGetSquareThumbnailImage(path, 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(path.ToLower()) == 0)
                                {
                                    this.lbPortrait.SelectedIndex = num;
                                    this._iFrameworkWnd.UnifiedMessageBox.ShowInfo("已经存在和当前路径相同的文件");
                                    return;
                                }
                            }
                            num++;
                        }
                        headicon headicon2 = new headicon(icon, text);
                        headicon2.iconpath = path.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 headicon = this.lbPortrait.get_selected_item();
                    if (headicon != null)
                    {
                        this._delPortrait.Add(headicon);
                        int num = this.lbPortrait.get_selected_index();
                        if (num < this.m_index_of_customicon)
                        {
                            this.m_index_of_customicon--;
                        }
                        this.lbPortrait.Items.Remove(headicon);
                        int num2 = num;
                        do
                        {
                            if (num2 < 0)
                            {
                                break;
                            }
                            num2--;
                        }
                        while (!(this.lbPortrait.Items[num2] is headicon));
                        this.lbPortrait.SelectedIndex = num2;
                    }
                }
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (this._delPortrait.get_Count() > 0)
                {
                    List<headicon>.Enumerator enumerator = this._delPortrait.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            headicon headicon = enumerator.get_Current();
                            string path = this._user.PersistentManager.BaseDirForMyUsedPortrait + headicon.text + ".dat";
                            if (File.Exists(path))
                            {
                                headicon.icon.Dispose();
                                File.Delete(path);
                            }
                        }
                    }
                    finally
                    {
                        enumerator.Dispose();
                    }
                }
                if (this._user.Configuration.UserSetting.SaveMyInfo && (this._addPortrait.get_Count() > 0))
                {
                    if (!Directory.Exists(this._user.PersistentManager.BaseDirForMyUsedPortrait))
                    {
                        Directory.CreateDirectory(this._user.PersistentManager.BaseDirForMyUsedPortrait);
                    }
                    List<headicon>.Enumerator enumerator2 = this._addPortrait.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            headicon headicon2 = enumerator2.get_Current();
                            string text2 = this._user.PersistentManager.BaseDirForMyUsedPortrait + headicon2.text + ".dat";
                            if (File.Exists(text2))
                            {
                                int num = 1;
                                while (true)
                                {
                                    text2 = (this._user.PersistentManager.BaseDirForMyUsedPortrait + headicon2.text) + num.ToString() + ".dat";
                                    if (!File.Exists(text2))
                                    {
                                        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(text2, ImageHelper.GetImageCodecInfo(ImageFormat.Jpeg), ImageHelper.JpegParms());
                                }
                            }
                            headicon2.iconpath = text2;
                        }
                    }
                    finally
                    {
                        enumerator2.Dispose();
                    }
                }
                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>(null, (IntPtr) 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))
            {

⌨️ 快捷键说明

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