private void PreviewResourcePack([NotNull] ResourcePack resourcePack)
        {
            if (resourcePack == null)
            {
                throw new ArgumentNullException("resourcePack");
            }
            if (resourcePack.Images == null || resourcePack.Images.Count == 0)
            {
                return;
            }

            var originalImageIndices = new List <int>();
            var importedImages       = new List <bool[, ]>();

            foreach (var exportedImage in resourcePack.Images)
            {
                originalImageIndices.Add(exportedImage.Index);
                importedImages.Add(exportedImage.Data);
            }

            using (var importWindow = new PreviewResourcePackWindow(m_firmware, originalImageIndices, importedImages, true))
            {
                importWindow.Text             = Consts.ApplicationTitleWoVersion + @" - Resource Pack Preview";
                importWindow.ImportButtonText = "Import";
                if (importWindow.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                ImportResourcePack(originalImageIndices, importedImages);
            }
        }
        private void ImportImages([NotNull] IList <int> originalImageIndices, [NotNull] IList <bool[, ]> importedImages)
        {
            if (importedImages == null)
            {
                throw new ArgumentNullException("importedImages");
            }
            if (originalImageIndices == null)
            {
                throw new ArgumentNullException("originalImageIndices");
            }
            if (importedImages.Count == 0)
            {
                return;
            }

            var minimumImagesCount = Math.Min(originalImageIndices.Count, importedImages.Count);

            originalImageIndices = originalImageIndices.Take(minimumImagesCount).ToList();
            importedImages       = importedImages.Take(minimumImagesCount).ToList();

            ImageImportMode importMode;
            bool            allowResizeOriginalImages;

            using (var importWindow = new PreviewResourcePackWindow(m_firmware, originalImageIndices, importedImages, false, m_currentBlock))
            {
                importWindow.Text             = Consts.ApplicationTitleWoVersion + @" - Paste image(s)";
                importWindow.ImportButtonText = "Paste";
                if (importWindow.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                importMode = importWindow.GetImportMode();
                allowResizeOriginalImages = importWindow.AllowResizeOriginalImages;
            }

            for (var i = 0; i < minimumImagesCount; i++)
            {
                var index = i;
                var originalImageIndex = originalImageIndices[index];
                var importedImage      = importedImages[index];
                if (importMode == ImageImportMode.Block1)
                {
                    var block1ImageMetadata = m_firmware.Block1Images.First(x => x.Index == originalImageIndex);
                    if (allowResizeOriginalImages)
                    {
                        ProcessImage(x => importedImage, block1ImageMetadata);
                    }
                    else
                    {
                        ProcessImage(x => FirmwareImageProcessor.PasteImage(block1ImageMetadata.CreateImage(), importedImage), block1ImageMetadata);
                    }
                }
                else if (importMode == ImageImportMode.Block2)
                {
                    var block2ImageMetadata = m_firmware.Block2Images.First(x => x.Index == originalImageIndex);
                    if (allowResizeOriginalImages)
                    {
                        ProcessImage(x => importedImage, block2ImageMetadata);
                    }
                    else
                    {
                        ProcessImage(x => FirmwareImageProcessor.PasteImage(block2ImageMetadata.CreateImage(), importedImage), block2ImageMetadata);
                    }
                }
                else
                {
                    var block1ImageMetadata = m_firmware.Block1Images.First(x => x.Index == originalImageIndex);
                    var block2ImageMetadata = m_firmware.Block2Images.First(x => x.Index == originalImageIndex);

                    if (allowResizeOriginalImages)
                    {
                        ProcessImage(x => importedImage, block1ImageMetadata);
                        ProcessImage(x => importedImage, block2ImageMetadata);
                    }
                    else
                    {
                        ProcessImage(x => FirmwareImageProcessor.PasteImage(block1ImageMetadata.CreateImage(), importedImage), block1ImageMetadata);
                        ProcessImage(x => FirmwareImageProcessor.PasteImage(block2ImageMetadata.CreateImage(), importedImage), block2ImageMetadata);
                    }
                }
            }

            ImageCacheManager.RebuildImageCache(m_firmware);
            ImageListBox.Invalidate();
            ImageListBox_SelectedValueChanged(ImageListBox, EventArgs.Empty);
        }
        private void ImportImages([NotNull] IList<int> originalImageIndices, [NotNull] IList<bool[,]> importedImages)
        {
            if (importedImages == null) throw new ArgumentNullException("importedImages");
            if (originalImageIndices == null) throw new ArgumentNullException("originalImageIndices");
            if (importedImages.Count == 0) return;

            var minimumImagesCount = Math.Min(originalImageIndices.Count, importedImages.Count);

            originalImageIndices = originalImageIndices.Take(minimumImagesCount).ToList();
            importedImages = importedImages.Take(minimumImagesCount).ToList();

            ImageImportMode importMode;
            bool allowResizeOriginalImages;

            using (var importWindow = new PreviewResourcePackWindow(m_firmware, originalImageIndices, importedImages, false, m_currentBlock))
            {
                importWindow.Text = Consts.ApplicationTitleWoVersion + @" - Paste image(s)";
                importWindow.ImportButtonText = "Paste";
                if (importWindow.ShowDialog() != DialogResult.OK) return;

                importMode = importWindow.GetImportMode();
                allowResizeOriginalImages = importWindow.AllowResizeOriginalImages;
            }

            for (var i = 0; i < minimumImagesCount; i++)
            {
                var index = i;
                var originalImageIndex = originalImageIndices[index];
                var importedImage = importedImages[index];

                if (importMode == ImageImportMode.Block1)
                {
                    ImportBlockImage(m_firmware.Block1Images, originalImageIndex, importedImage, allowResizeOriginalImages);
                }
                else if (importMode == ImageImportMode.Block2)
                {
                    ImportBlockImage(m_firmware.Block2Images, originalImageIndex, importedImage, allowResizeOriginalImages);
                }
                else
                {
                    ImportBlockImage(m_firmware.Block1Images, originalImageIndex, importedImage, allowResizeOriginalImages);
                    ImportBlockImage(m_firmware.Block2Images, originalImageIndex, importedImage, allowResizeOriginalImages);
                }
            }

            ImageCacheManager.RebuildCache(m_firmware);
            ImageListBox.Invalidate();
            ImageListBox_SelectedValueChanged(ImageListBox, EventArgs.Empty);
        }
        private void PreviewResourcePack([NotNull] ResourcePack resourcePack)
        {
            if (resourcePack == null) throw new ArgumentNullException("resourcePack");
            if (resourcePack.Images == null || resourcePack.Images.Count == 0) return;

            var originalImageIndices = new List<int>();
            var importedImages = new List<bool[,]>();

            foreach (var exportedImage in resourcePack.Images)
            {
                originalImageIndices.Add(exportedImage.Index);
                importedImages.Add(exportedImage.Data);
            }

            using (var importWindow = new PreviewResourcePackWindow(m_firmware, originalImageIndices, importedImages, true))
            {
                importWindow.Text = Consts.ApplicationTitleWoVersion + @" - Resource Pack Preview";
                importWindow.ImportButtonText = "Import";
                if (importWindow.ShowDialog() != DialogResult.OK) return;

                ImportResourcePack(originalImageIndices, importedImages);
            }
        }