Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.exampleBLP != null)
                {
                    this.exampleBLP.Close();
                    this.exampleBLP = null;
                }

                var dlg = openFileDialog.ShowDialog();
                if (dlg != DialogResult.OK)
                    return;
                FileStream file = new FileStream(openFileDialog.FileName, FileMode.Open);
                this.exampleBLP = new SereniaBLPLib.BlpFile(file);
                //MessageBox.Show("Mipmap count: "+exampleBLP.MipMapCount);

                // loading bitmap level 0
                bmp = this.exampleBLP.GetBitmap(0);

                g.DrawImage(bmp, 0, 0);

                button3.Enabled = true;                
            }
            catch (FileNotFoundException fe)
            {
                MessageBox.Show("The 'example.blp' was not found!");
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.exampleBLP != null)
                {
                    this.exampleBLP.Close();
                    this.exampleBLP = null;
                }

                var dlg = openFileDialog.ShowDialog();
                if (dlg != DialogResult.OK)
                {
                    return;
                }
                FileStream file = new FileStream(openFileDialog.FileName, FileMode.Open);
                this.exampleBLP = new SereniaBLPLib.BlpFile(file);
                //MessageBox.Show("Mipmap count: "+exampleBLP.MipMapCount);

                // loading bitmap level 0
                bmp = this.exampleBLP.GetBitmap(0);

                g.DrawImage(bmp, 0, 0);

                button3.Enabled = true;
            }
            catch (FileNotFoundException fe)
            {
                MessageBox.Show("The 'example.blp' was not found!");
            }
        }
        public async Task <FileContentResult> GetByContentHash(string buildConfig, string cdnConfig, string contenthash, string filename)
        {
            Console.WriteLine("[" + DateTime.Now + "] Serving preview of \"" + filename + "\" (" + contenthash + ") for build " + buildConfig + " and cdn " + cdnConfig);

            System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
            {
                FileName = "preview",
                Inline   = true
            };

            Response.Headers[HeaderNames.ContentDisposition] = cd.ToString();

            var fileBytes = await CASC.GetFile(buildConfig, cdnConfig, contenthash);

            var ext  = Path.GetExtension(filename);
            var mime = GetMimeTypeByExt(ext);

            if (ext == ".blp")
            {
                using (var stream = new MemoryStream(fileBytes))
                    using (var outStream = new MemoryStream())
                    {
                        var blpReader = new SereniaBLPLib.BlpFile(stream);
                        var blp       = blpReader.GetBitmap(0);
                        blp.Save(outStream, ImageFormat.Png);
                        fileBytes = outStream.ToArray();
                    }

                mime = "image/png";
            }

            return(new FileContentResult(fileBytes, mime));
        }
        public FileContentResult GetByFileDataID(string buildConfig, string cdnConfig, uint filedataid, string filename)
        {
            Logger.WriteLine("Serving preview of \"" + filename + "\" for build " + buildConfig + " and cdn " + cdnConfig);

            System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
            {
                FileName = "preview",
                Inline   = true
            };

            Response.Headers[HeaderNames.ContentDisposition] = cd.ToString();

            var fileBytes = CASC.GetFile(buildConfig, cdnConfig, filedataid);
            var ext       = Path.GetExtension(filename);

            var mime = GetMimeTypeByExt(ext);

            if (ext == ".blp")
            {
                using (var stream = new MemoryStream(fileBytes))
                    using (var outStream = new MemoryStream())
                    {
                        var blpReader = new SereniaBLPLib.BlpFile(stream);
                        var blp       = blpReader.GetBitmap(0);
                        blp.Save(outStream, ImageFormat.Png);
                        fileBytes = outStream.ToArray();
                    }

                mime = "image/png";
            }

            return(new FileContentResult(fileBytes, mime));
        }
Exemple #5
0
        public ImageSource GetImageSourceFromBlpPath(string filePath)
        {
            ImageSource source;
            var         exists = _ImageMap.TryGetValue(filePath, out source);

            if (exists)
            {
                return(source);
            }
            try
            {
                using (var fileStream = new FileStream(filePath, FileMode.Open))
                {
                    using (var blpImage = new SereniaBLPLib.BlpFile(fileStream))
                    {
                        using (var bit = blpImage.getBitmap(0))
                        {
                            var handle = bit.GetHbitmap();
                            try
                            {
                                source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                                    handle, IntPtr.Zero, Int32Rect.Empty,
                                    BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
                                // Freeze so that it can be accessed on any thread
                                source.Freeze();
                                _ImageMap.TryAdd(filePath, source);
                                return(source);
                            }
                            finally
                            {
                                DeleteObject(handle);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Logging full exception is quite costly here
                Console.WriteLine($"[BlpManager] WARNING Unable to load image: {filePath} - {e.Message}");
                // Making the choice here to not try to load the resource again until the program is restarted
                _ImageMap.TryAdd(filePath, null);
            }
            return(null);
        }
        public async Task <FileContentResult> GetByFileDataID(string buildConfig, string cdnConfig, uint filedataid, string filename, byte mipmap = 0)
        {
            Logger.WriteLine("Serving preview of \"" + filename + "\" for build " + buildConfig + " and cdn " + cdnConfig);

            System.Net.Mime.ContentDisposition cd = new()
            {
                FileName = "preview",
                Inline   = true
            };

            Response.Headers[HeaderNames.ContentDisposition] = cd.ToString();
            var fileBytes = await CASC.GetFile(buildConfig, cdnConfig, filedataid);

            var ext = Path.GetExtension(filename);

            var mime = GetMimeTypeByExt(ext);

            if (ext == ".blp")
            {
                using (var stream = new MemoryStream(fileBytes))
                    using (var outStream = new MemoryStream())
                    {
                        var blpReader = new SereniaBLPLib.BlpFile(stream);
                        var blp       = blpReader.GetBitmap(mipmap);
                        blp.Save(outStream, ImageFormat.Png);
                        fileBytes = outStream.ToArray();
                        Response.Headers["X-WoWTools-Res-Width"]        = blp.Width.ToString();
                        Response.Headers["X-WoWTools-Res-Height"]       = blp.Height.ToString();
                        Response.Headers["X-WoWTools-AvailableMipMaps"] = blpReader.MipMapCount.ToString();
                    }

                mime = "image/png";
            }

            return(new FileContentResult(fileBytes, mime));
        }
        public async void UpdateMainWindowIcons(double margin)
        {
			if (adapter == null || main.selectedID == 0) { // adapter.query below caused unhandled exception with main.selectedID as 0.
                return;
            }

            DataRow res;
            try
            {
				res = adapter.query(string.Format("SELECT `SpellIconID`,`ActiveIconID` FROM `{0}` WHERE `ID` = '{1}'", adapter.Table, main.selectedID)).Rows[0];
            }
            catch (Exception)
            {
                return;
            }
            UInt32 iconInt = UInt32.Parse(res[0].ToString());
            UInt32 iconActiveInt = UInt32.Parse(res[1].ToString());
            UInt32 selectedRecord = UInt32.MaxValue;

            for (UInt32 i = 0; i < header.RecordCount; ++i)
            {
                if (body.records[i].ID == iconInt)
                {
                    selectedRecord = i;

                    break;
                }

                if (body.records[i].ID == iconActiveInt)
                {
                    selectedRecord = i;

                    break;
                }
            }

            string icon = "";

            int offset = 0;

            try
            {
                if (selectedRecord == UInt32.MaxValue) { throw new Exception("The icon for this spell does not exist in the SpellIcon.dbc"); }

                offset = (int)body.records[selectedRecord].Name;

                while (body.StringBlock[offset] != '\0') { icon += body.StringBlock[offset++]; }

                if (!File.Exists(icon + ".blp")) { throw new Exception("File could not be found: " + "Icons\\" + icon + ".blp"); }
            }

            catch (Exception ex)
            {
				main.Dispatcher.Invoke(new Action(()=>main.HandleErrorMessage(ex.Message)));

                return;
            }

            FileStream fileStream = new FileStream(icon + ".blp", FileMode.Open);

            SereniaBLPLib.BlpFile image;

            image = new SereniaBLPLib.BlpFile(fileStream);

            Bitmap bit = image.getBitmap(0);

            await Task.Factory.StartNew(() =>
            {
                main.CurrentIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bit.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
            }, CancellationToken.None, TaskCreationOptions.None, main.UIScheduler);

            image.close();
            fileStream.Close();

            if (!loadedAllIcons)
            {
                loadedAllIcons = true;

                int currentOffset = 1;

                string[] icons = body.StringBlock.Split('\0');

                int iconIndex = 0;
                int columnsUsed = icons.Length / 11;
                int rowsToDo = columnsUsed / 2;

                for (int j = -rowsToDo; j <= rowsToDo; ++j)
                {
                    for (int i = -5; i < 6; ++i)
                    {
                        ++iconIndex;
                        if (iconIndex >= icons.Length - 1) { break; }
                        int this_icons_offset = currentOffset;

                        currentOffset += icons[iconIndex].Length + 1;

                        if (!File.Exists(icons[iconIndex] + ".blp"))
                        {
                            Console.WriteLine("Warning: Icon not found: " + icons[iconIndex] + ".blp");

                            continue;
                        }

                        fileStream = new FileStream(icons[iconIndex] + ".blp", FileMode.Open);
                        image = new SereniaBLPLib.BlpFile(fileStream);
                        bit = image.getBitmap(0);

                        await Task.Factory.StartNew(() =>
                        {
                            System.Windows.Controls.Image temp = new System.Windows.Controls.Image();

                            temp.Width = 32;
                            temp.Height = 32;
                            temp.Margin = new System.Windows.Thickness(margin, 0, 0, 0);
                            temp.VerticalAlignment = VerticalAlignment.Top;
                            temp.HorizontalAlignment = HorizontalAlignment.Left;
                            temp.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bit.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
                            temp.Name = "Index_" + this_icons_offset;
                            temp.MouseDown += this.ImageDown;

                            main.IconGrid.Children.Add(temp);
                        }, CancellationToken.None, TaskCreationOptions.None, main.UIScheduler);

                        image.close();
                        fileStream.Close();
                    }
                }
            }
        }
        public async void updateMainWindowIcons()
        {
            if (spell == null)
                return;
            UInt32 iconInt = spell.body.records[main.selectedID].record.SpellIconID;
            UInt32 selectedRecord = UInt32.MaxValue;
            for (UInt32 i = 0; i < header.record_count; ++i)
            {
                if (body.records[i].ID == iconInt)
                {
                    selectedRecord = i;
                    break;
                }
            }

            string icon = "";
            int offset = 0;

            try
            {
                if (selectedRecord == UInt32.MaxValue)
                    throw new Exception("The icon for this spell does not exist in the SpellIcon.dbc");

                offset = (int)body.records[selectedRecord].name;
                while (body.StringBlock[offset] != '\0')
                {
                    icon += body.StringBlock[offset++];
                }

                if (!File.Exists(icon + ".blp"))
                    throw new Exception("File could not be found: " + "Icons\\" + icon + ".blp");
            }
            catch (Exception ex)
            {
                main.ERROR_STR = ex.Message;
                return;
            }

            FileStream file = new FileStream(icon + ".blp", FileMode.Open);

            SereniaBLPLib.BlpFile image;
            image = new SereniaBLPLib.BlpFile(file);

            Bitmap bit = image.getBitmap(0);

            await Task.Factory.StartNew(() =>
            {
                main.CurrentIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                   bit.GetHbitmap(),
                   IntPtr.Zero,
                   System.Windows.Int32Rect.Empty,
                   BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
            }, CancellationToken.None, TaskCreationOptions.None, main.uiScheduler);

            image.close();
            file.Close();

            if (!loadedAllIcons)
            {
                loadedAllIcons = true;

                int currentOffset = 1;

                string[] icons = body.StringBlock.Split('\0');
                int iconIndex = 0;

                int columnsUsed = icons.Length / 11;
                int rowsToDo = columnsUsed / 2;

                for (int j = -rowsToDo; j <= rowsToDo; ++j) // Rows
                {
                    for (int i = -5; i < 6; ++i) // Columns
                    {
                        ++iconIndex;
                        if (iconIndex >= icons.Length - 1)
                            break;
                        int thisIconsOffset = currentOffset;
                        currentOffset += icons[iconIndex].Length + 1;
                        if (!File.Exists(icons[iconIndex] + ".blp"))
                        {
                            Console.WriteLine("Warning: Icon not found: " + icons[iconIndex] + ".blp");
                            continue;
                        }
                        file = new FileStream(icons[iconIndex] + ".blp", FileMode.Open);
                    
                        image = new SereniaBLPLib.BlpFile(file);
                        bit = image.getBitmap(0);

                        await Task.Factory.StartNew(() =>
                        {
                            System.Windows.Controls.Image temp = new System.Windows.Controls.Image();
                            temp.Width = 64;
                            temp.Height = 64;
                            temp.Margin = new System.Windows.Thickness(139 * i, 139 * j, 0, 0);
                            temp.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                               bit.GetHbitmap(),
                               IntPtr.Zero,
                               System.Windows.Int32Rect.Empty,
                               BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
                            temp.Name = "Index_" + thisIconsOffset;
                            temp.MouseDown += this.imageDown;
                            main.IconGrid.Children.Add(temp);
                        }, CancellationToken.None, TaskCreationOptions.None, main.uiScheduler);
                        image.close();
                        file.Close();
                    }
                }
            }
        }
        public async void UpdateMainWindowIcons()
        {
            if (mySQL == null) { return; }

            var res = mySQL.query(String.Format("SELECT `SpellIconID`,`ActiveIconID` FROM `{0}` WHERE `ID` = '{1}'", mySQL.Table, main.selectedID)).Rows[0];
            UInt32 iconInt = UInt32.Parse(res[0].ToString());
            UInt32 iconActiveInt = UInt32.Parse(res[1].ToString());
            UInt32 selectedRecord = UInt32.MaxValue;

            for (UInt32 i = 0; i < header.RecordCount; ++i)
            {
                if (body.records[i].ID == iconInt)
                {
                    selectedRecord = i;

                    break;
                }

                if (body.records[i].ID == iconActiveInt)
                {
                    selectedRecord = i;

                    break;
                }
            }

            string icon = "";

            int offset = 0;

            try
            {
                if (selectedRecord == UInt32.MaxValue) { throw new Exception("The icon for this spell does not exist in the SpellIcon.dbc"); }

                offset = (int)body.records[selectedRecord].Name;

                while (body.StringBlock[offset] != '\0') { icon += body.StringBlock[offset++]; }

                if (!File.Exists(icon + ".blp")) { throw new Exception("File could not be found: " + "Icons\\" + icon + ".blp"); }
            }

            catch (Exception ex)
            {
                main.HandleErrorMessage(ex.Message);

                return;
            }

            FileStream fileStream = new FileStream(icon + ".blp", FileMode.Open);

            SereniaBLPLib.BlpFile image;

            image = new SereniaBLPLib.BlpFile(fileStream);

            Bitmap bit = image.getBitmap(0);

            await Task.Factory.StartNew(() =>
            {
                main.CurrentIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bit.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
            }, CancellationToken.None, TaskCreationOptions.None, main.UIScheduler);

            image.close();
            fileStream.Close();

            if (!loadedAllIcons)
            {
                loadedAllIcons = true;

                int currentOffset = 1;

                string[] icons = body.StringBlock.Split('\0');

                int iconIndex = 0;
                int columnsUsed = icons.Length / 11;
                int rowsToDo = columnsUsed / 2;

                for (int j = -rowsToDo; j <= rowsToDo; ++j)
                {
                    for (int i = -5; i < 6; ++i)
                    {
                        ++iconIndex;

                        if (iconIndex >= icons.Length - 1) { break; }

                        int this_icons_offset = currentOffset;

                        currentOffset += icons[iconIndex].Length + 1;

                        if (!File.Exists(icons[iconIndex] + ".blp"))
                        {
                            Console.WriteLine("Warning: Icon not found: " + icons[iconIndex] + ".blp");

                            continue;
                        }

                        fileStream = new FileStream(icons[iconIndex] + ".blp", FileMode.Open);
                        image = new SereniaBLPLib.BlpFile(fileStream);
                        bit = image.getBitmap(0);

                        await Task.Factory.StartNew(() =>
                        {
                            System.Windows.Controls.Image temp = new System.Windows.Controls.Image();

                            temp.Width = 64;
                            temp.Height = 64;
                            temp.Margin = new System.Windows.Thickness(139 * i, 139 * j, 0, 0);
                            temp.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bit.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bit.Width, bit.Height));
                            temp.Name = "Index_" + this_icons_offset;
                            temp.MouseDown += this.ImageDown;

                            main.IconGrid.Children.Add(temp);
                        }, CancellationToken.None, TaskCreationOptions.None, main.UIScheduler);

                        image.close();
                        fileStream.Close();
                    }
                }
            }
        }