Ejemplo n.º 1
0
        public static void AddCustomFace(string imageFilePath)
        {
            string name = Path.GetFileName(imageFilePath);

            if (m_item_names.ContainsKey(name))
            {
                return;
            }

            m_item_names.Add(name, name);

            Bitmap       icon = GenerateIconImageBytes(imageFilePath);
            MemoryStream ms   = new MemoryStream();

            icon.Save(ms, ImageFormat.Png);

            using (FileStream fs = new FileStream(GetCustomFaceCfgPath(), FileMode.Append, FileAccess.Write))
            {
                byte[] bytes  = null;
                byte[] length = null;

                bytes = Helper.GetBytes(MagicNumber);
                fs.Write(bytes, 0, 4);

                bytes  = Helper.GetBytes(name);
                length = Helper.GetBytes(bytes.Length);

                fs.Write(length, 0, 4);
                fs.Write(bytes, 0, bytes.Length);

                bytes  = ms.ToArray();
                length = Helper.GetBytes(bytes.Length);

                fs.Write(length, 0, 4);
                fs.Write(bytes, 0, bytes.Length);

                fs.Flush();
            }

            CustomFaceItem item = new CustomFaceItem();

            item.Filename = name;
            item.Icon     = icon;
            item.ID       = m_items.Count;
            m_items.Add(item);
        }
Ejemplo n.º 2
0
        static CustomFaceManager()
        {
            string path = GetCustomFaceCfgPath();

            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read))
            {
                int length    = (int)fs.Length;
                int byteCount = 0;

                while (byteCount < length)
                {
                    CustomFaceItem item = new CustomFaceItem();

                    byte[] bytes = new byte[4];
                    fs.Read(bytes, 0, 4);
                    int magic = Helper.GetInt(bytes);
                    if (magic != MagicNumber)
                    {
                        return;
                    }

                    fs.Read(bytes, 0, 4);
                    int    strlen    = Helper.GetInt(bytes);
                    byte[] fileBytes = new byte[strlen];
                    fs.Read(fileBytes, 0, fileBytes.Length);
                    item.Filename = Helper.GetString(fileBytes);

                    fs.Read(bytes, 0, 4);
                    int    imglen   = Helper.GetInt(bytes);
                    byte[] imgBytes = new byte[imglen];
                    fs.Read(imgBytes, 0, imgBytes.Length);
                    item.Icon = new Bitmap(new MemoryStream(imgBytes));

                    item.ID = m_items.Count;

                    if (!m_item_names.ContainsKey(item.Filename))
                    {
                        m_item_names.Add(item.Filename, item.Filename);
                        m_items.Add(item);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        static CustomFaceManager()
        {
            string path = GetCustomFaceCfgPath();
            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read))
            {
                int length = (int)fs.Length;
                int byteCount = 0;

                while (byteCount < length)
                {
                    CustomFaceItem item = new CustomFaceItem();

                    byte[] bytes = new byte[4];
                    fs.Read(bytes, 0, 4);
                    int magic = Helper.GetInt(bytes);
                    if (magic != MagicNumber)
                        return;

                    fs.Read(bytes, 0, 4);
                    int strlen = Helper.GetInt(bytes);
                    byte[] fileBytes = new byte[strlen];
                    fs.Read(fileBytes, 0, fileBytes.Length);
                    item.Filename = Helper.GetString(fileBytes);

                    fs.Read(bytes, 0, 4);
                    int imglen = Helper.GetInt(bytes);
                    byte[] imgBytes = new byte[imglen];
                    fs.Read(imgBytes, 0, imgBytes.Length);
                    item.Icon = new Bitmap(new MemoryStream(imgBytes));

                    item.ID = m_items.Count;

                    if (!m_item_names.ContainsKey(item.Filename))
                    {
                        m_item_names.Add(item.Filename, item.Filename);
                        m_items.Add(item);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static void AddCustomFace(string imageFilePath)
        {
            string name = Path.GetFileName(imageFilePath);
            if (m_item_names.ContainsKey(name))
                return;

            m_item_names.Add(name, name);

            Bitmap icon = GenerateIconImageBytes(imageFilePath);
            MemoryStream ms = new MemoryStream();
            icon.Save(ms, ImageFormat.Png);

            using (FileStream fs = new FileStream(GetCustomFaceCfgPath(), FileMode.Append, FileAccess.Write))
            {
                byte[] bytes = null;
                byte[] length = null;

                bytes = Helper.GetBytes(MagicNumber);
                fs.Write(bytes, 0, 4);

                bytes = Helper.GetBytes(name);
                length = Helper.GetBytes(bytes.Length);

                fs.Write(length, 0, 4);
                fs.Write(bytes, 0, bytes.Length);

                bytes = ms.ToArray();
                length = Helper.GetBytes(bytes.Length);

                fs.Write(length, 0, 4);
                fs.Write(bytes, 0, bytes.Length);

                fs.Flush();
            }

            CustomFaceItem item = new CustomFaceItem();
            item.Filename = name;
            item.Icon = icon;
            item.ID = m_items.Count;
            m_items.Add(item);
        }