コード例 #1
0
        // Read tileset represented by Outpost 2 specific format into memory
        // After Reading into memory, reformats into standard 8 bit indexed bitmap before returning results
        public static BitmapFile ReadCustomTileset(Stream streamToRead)
        {
            using (BinaryReader reader = new BinaryReader(streamToRead, System.Text.Encoding.UTF8, true))
            {
                SectionHeader fileSignature = new SectionHeader(reader);
                ValidateFileSignatureHeader(fileSignature);

                TilesetHeader tilesetHeader = new TilesetHeader(reader);
                tilesetHeader.Validate();

                PpalHeader ppalHeader = new PpalHeader(reader);
                ppalHeader.Validate();

                SectionHeader paletteHeader = new SectionHeader(reader);
                ValidatePaletteHeader(paletteHeader);

                BitmapFile bitmapFile = new BitmapFile((ushort)tilesetHeader.bitDepth, tilesetHeader.pixelWidth, (int)tilesetHeader.pixelHeight * -1);
                for (int i = 0; i < bitmapFile.palette.Length; ++i)
                {
                    bitmapFile.palette[i] = new Color(reader);
                }

                SectionHeader pixelHeader = new SectionHeader(reader);
                ValidatePixelHeader(pixelHeader, tilesetHeader.pixelHeight);

                reader.Read(bitmapFile.pixels, 0, bitmapFile.pixels.Length);
                // Tilesets store red and blue Color values swapped from standard Bitmap file format
                bitmapFile.SwapRedAndBlue();

                ValidateTileset(bitmapFile);

                return(bitmapFile);
            }
        }
コード例 #2
0
ファイル: BitmapLoader.cs プロジェクト: destrofer/IGE.Data
        public override void Process()
        {
            if (Attributes["path"].Value == null)
            {
                throw new UserFriendlyException("Bitmap source must be set");
            }
            if (((string)Attributes["path"].Value).Equals(""))
            {
                throw new UserFriendlyException("Bitmap source must not be empty");
            }

            BitmapFile file = GameFile.LoadFile <BitmapFile>((string)Attributes["path"].Value);

            if (file == null)
            {
                throw new UserFriendlyException("Could not find a source bitmap file or the file format is not supported");
            }

            Outputs["bitmap"].Value = file.Bitmap;
            if (file.Bitmap != null)
            {
                Outputs["width"].Value  = (ushort)file.Bitmap.Width;
                Outputs["height"].Value = (ushort)file.Bitmap.Height;
            }
            else
            {
                Outputs["width"].Value  = null;
                Outputs["height"].Value = null;
            }
        }
コード例 #3
0
        public void SwapRedAndBlue()
        {
            BitmapFile bitmapFile = new BitmapFile(8, 2, 2, new Color[] { DiscreteColor.Red });

            bitmapFile.SwapRedAndBlue();
            Assert.AreEqual(DiscreteColor.Blue, bitmapFile.palette[0]);
        }
コード例 #4
0
        public void InvertScanLines()
        {
            byte[] pixels = new byte[]
            {
                1, 1, 1, 1, 1, 1, 1, 1,
                0, 0, 0, 0, 0, 0, 0, 0
            };

            byte[] invertedPixels = new byte[]
            {
                0, 0, 0, 0, 0, 0, 0, 0,
                1, 1, 1, 1, 1, 1, 1, 1
            };

            BitmapFile bitmap = new BitmapFile(8, 8, 2, new Color[] { /* Empty Palette */ }, pixels);

            bitmap.InvertScanLines();

            Assert.AreEqual(ScanLineOrientation.TopDown, bitmap.GetScanLineOrientation());
            CollectionAssert.AreEqual(invertedPixels, bitmap.pixels);

            bitmap.InvertScanLines();

            Assert.AreEqual(ScanLineOrientation.BottomUp, bitmap.GetScanLineOrientation());
            CollectionAssert.AreEqual(pixels, bitmap.pixels);
        }
コード例 #5
0
        public void WriteCustomTilesetError()
        {
            MemoryStream writer = new MemoryStream();

            // Use incorrect pixel width - Ensure error is thrown
            BitmapFile tileset = new BitmapFile(8, 20, 32, new Color[] { DiscreteColor.Red });

            Assert.ThrowsException <Exception>(() => TilesetLoader.WriteCustomTileset(writer, tileset));
        }
コード例 #6
0
        private Bitmap ReadBitmap2(BinaryReader br)
        {
            BitmapFile BF = new BitmapFile();

            BF.bmpHeader = ReadBitmapFileHeader(br);
            br.BaseStream.Seek(-14, SeekOrigin.Current);
            byte[] bitmapData = br.ReadBytes((int)BF.bmpHeader.size);

            return(new Bitmap(new MemoryStream(bitmapData)));
        }
コード例 #7
0
 public void AbsoluteHeight()
 {
     {             // Test Positive Height
         BitmapFile bitmap = new BitmapFile(1, 32, 32);
         Assert.AreEqual(32, bitmap.AbsoluteHeight());
     }
     {             // Test Negative Height
         BitmapFile bitmap = new BitmapFile(1, 32, -32);
         Assert.AreEqual(32, bitmap.AbsoluteHeight());
     }
 }
コード例 #8
0
 public void TestScanLineOrientation()
 {
     {             // Test Negative Height
         BitmapFile bitmap = new BitmapFile(1, 32, -32);
         Assert.AreEqual(ScanLineOrientation.TopDown, bitmap.GetScanLineOrientation());
     }
     {             // Test Positive Height
         BitmapFile bitmap = new BitmapFile(1, 32, 32);
         Assert.AreEqual(ScanLineOrientation.BottomUp, bitmap.GetScanLineOrientation());
     }
 }
コード例 #9
0
 private void FillSplitSegments()
 {
     foreach (DataGridViewRow rows in segmentsGridView.Rows)
     {
         string     segmentName     = (rows.Cells[SEGMENT_NAME_ROW].Value == null) ? "-" : rows.Cells[SEGMENT_NAME_ROW].Value.ToString();
         double     splitTime       = (rows.Cells[SEGMENT_SPLIT_TIME_ROW].Value == null) ? 0.0 : FaceSplitUtils.TimeParse(rows.Cells[SEGMENT_SPLIT_TIME_ROW].Value.ToString());
         double     segmentTime     = (rows.Cells[SEGMENT_TIME_ROW].Value == null) ? 0.0 : FaceSplitUtils.TimeParse(rows.Cells[SEGMENT_TIME_ROW].Value.ToString());
         double     bestSegmentTime = (rows.Cells[SEGMENT_BEST_TIME_ROW].Value == null) ? 0.0 : FaceSplitUtils.TimeParse(rows.Cells[SEGMENT_BEST_TIME_ROW].Value.ToString());
         BitmapFile icon            = icons.ElementAt(rows.Index);
         split.Segments.Add(new Segment(segmentName, splitTime, segmentTime, bestSegmentTime, icon));
     }
 }
コード例 #10
0
        public void Equality()
        {
            BitmapFile bitmapFile1 = BitmapFile.CreateDefaultIndexed(1, 1, 1);
            BitmapFile bitmapFile2 = BitmapFile.CreateDefaultIndexed(1, 1, 1);

            Assert.IsTrue(bitmapFile1 == bitmapFile2);
            Assert.IsFalse(bitmapFile1 != bitmapFile2);

            bitmapFile1.pixels[0] = 1;
            Assert.IsFalse(bitmapFile1 == bitmapFile2);
            Assert.IsTrue(bitmapFile1 != bitmapFile2);
        }
コード例 #11
0
        public void VerifyPixelSizeMatchesImageDimensionsWithPitch()
        {
            BitmapFile.VerifyPixelSizeMatchesImageDimensionsWithPitch(1, 1, 1, 4);
            Assert.ThrowsException <Exception>(() => BitmapFile.VerifyPixelSizeMatchesImageDimensionsWithPitch(1, 1, 1, 1));

            // Test non-static version of function
            BitmapFile bitmapFile = BitmapFile.CreateDefaultIndexed(1, 1, 1);;

            bitmapFile.VerifyPixelSizeMatchesImageDimensionsWithPitch();
            bitmapFile.pixels = new byte[1];
            Assert.ThrowsException <Exception>(() => bitmapFile.VerifyPixelSizeMatchesImageDimensionsWithPitch());
        }
コード例 #12
0
        public void VerifyIndexedPaletteSizeDoesNotExceedBitCount()
        {
            BitmapFile.VerifyIndexedPaletteSizeDoesNotExceedBitCount(1, 1);
            BitmapFile.VerifyIndexedPaletteSizeDoesNotExceedBitCount(1, 2);
            Assert.ThrowsException <Exception>(() => BitmapFile.VerifyIndexedPaletteSizeDoesNotExceedBitCount(1, 3));

            // Test non-static version of function
            BitmapFile bitmapFile = BitmapFile.CreateDefaultIndexed(1, 1, 1);

            bitmapFile.VerifyIndexedPaletteSizeDoesNotExceedBitCount();
            bitmapFile.palette = new Color[3];
            Assert.ThrowsException <Exception>(() => bitmapFile.VerifyIndexedPaletteSizeDoesNotExceedBitCount());
        }
コード例 #13
0
        public void WriteCustomTileset()
        {
            MemoryStream writer = new MemoryStream();

            BitmapFile tileset1 = new BitmapFile(8, 32, -32, new Color[] { DiscreteColor.Red });

            TilesetLoader.WriteCustomTileset(writer, tileset1);
            writer.Position = 0;

            // Read just written tileset to ensure it was well formed
            BitmapFile tileset2 = TilesetLoader.ReadTileset(writer);

            Assert.AreEqual(tileset1, tileset2);
        }
コード例 #14
0
        void RoundTripSub(ushort bitCount, uint width, int height)
        {
            const string filename = "BitmapTest.bmp";

            BitmapFile bitmapFile = BitmapFile.CreateDefaultIndexed(bitCount, width, height);
            BitmapFile bitmapFile2;

            bitmapFile.Serialize(filename);
            bitmapFile2 = BitmapFile.ReadIndexed(filename);

            Assert.AreEqual(bitmapFile, bitmapFile2);

            File.Delete(filename);
        }
コード例 #15
0
 public void PeekIsBitmapFile()
 {
     {
         MemoryStream writer = new MemoryStream();
         new BitmapFile(1, 1, 1).Serialize(writer);
         writer.Position = 0;
         Assert.IsTrue(BitmapFile.PeekIsBitmap(writer));
     }
     {
         MemoryStream ms     = new MemoryStream();
         BinaryWriter writer = new BinaryWriter(ms);
         writer.Write("test");
         Assert.IsFalse(BitmapFile.PeekIsBitmap(ms));
     }
 }
コード例 #16
0
        public void CreateWithPalette()
        {
            BitmapFile bitmapFile = new BitmapFile(8, 2, 2, new Color[] { DiscreteColor.Green });

            Assert.AreEqual(DiscreteColor.Green, bitmapFile.palette[0]);

            // Ensure all pixels are set to palette index 0 (so they register as the initial color)
            foreach (byte pixel in bitmapFile.pixels)
            {
                Assert.AreEqual(0u, pixel);
            }

            // Proivde palette with more indices than bit count supports
            Color[] palette = new Color[] { DiscreteColor.Green, DiscreteColor.Red, DiscreteColor.Blue };
            Assert.ThrowsException <Exception>(() => new BitmapFile(1, 2, 2, palette));
        }
コード例 #17
0
        public void TestReplaceBitmapResource()
        {
            Uri    uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            string bitmapsdirectory = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Bitmaps");

            foreach (string bitmapfilename in Directory.GetFiles(bitmapsdirectory))
            {
                if (!bitmapfilename.EndsWith(".bmp"))
                {
                    continue;
                }

                Image imageFile = Bitmap.FromFile(bitmapfilename);
                Console.WriteLine("{0}: {1}x{2}", Path.GetFileName(bitmapfilename), imageFile.Width, imageFile.Height);

                string filename = Path.Combine(Environment.SystemDirectory, "msftedit.dll");
                Assert.IsTrue(File.Exists(filename));
                string targetFilename = Path.Combine(Path.GetTempPath(), "testLoadAndSaveBitmapResource.exe");
                File.Copy(filename, targetFilename, true);
                Console.WriteLine(targetFilename);

                BitmapResource bitmapResource = new BitmapResource();
                using (ResourceInfo targetFilenameResources = new ResourceInfo())
                {
                    targetFilenameResources.Load(targetFilename);
                    Resource existingBitmapResource = targetFilenameResources[Kernel32.ResourceTypes.RT_BITMAP][0];
                    bitmapResource.Name     = existingBitmapResource.Name;
                    bitmapResource.Language = existingBitmapResource.Language;
                    Console.WriteLine("Replacing {0}", bitmapResource.Name);
                }

                BitmapFile bitmapFile = new BitmapFile(bitmapfilename);
                bitmapResource.Bitmap = bitmapFile.Bitmap;
                Console.WriteLine("DIB: {0}x{1}", bitmapResource.Bitmap.Image.Width, bitmapResource.Bitmap.Image.Height);
                bitmapResource.SaveTo(targetFilename);

                Console.WriteLine("Written BitmapResource:");
                BitmapResource newBitmapResource = new BitmapResource();
                newBitmapResource.Name = bitmapResource.Name;
                newBitmapResource.LoadFrom(targetFilename);
                DumpResource.Dump(newBitmapResource);

                Image newBitmapResourceImage = newBitmapResource.Bitmap.Image;
                Assert.AreEqual(imageFile.Width, newBitmapResourceImage.Width);
                Assert.AreEqual(imageFile.Height, newBitmapResourceImage.Height);
            }
        }
コード例 #18
0
        // Read either custom tileset format or standard bitmap format tileset into memory
        // After reading into memory, if needed, reformats into standard 8 bit indexed bitmap before returning
        public static BitmapFile ReadTileset(Stream reader)
        {
            if (PeekIsCustomTileset(reader))
            {
                return(ReadCustomTileset(reader));
            }

            try
            {
                BitmapFile tileset = BitmapFile.ReadIndexed(reader);
                ValidateTileset(tileset);
                return(tileset);
            }
            catch (System.Exception e)
            {
                throw new System.Exception("Unable to read tileset represented as standard bitmap. " + e.ToString());
            }
        }
コード例 #19
0
        public void ReadTileset()
        {
            // Well formed standard bitmap
            BitmapFile   tileset = new BitmapFile(8, 32, 32, new Color[] { DiscreteColor.Red });
            MemoryStream writer  = new MemoryStream();

            tileset.Serialize(writer);

            writer.Position = 0;
            BitmapFile newTileset = TilesetLoader.ReadTileset(writer);

            Assert.AreEqual(tileset, newTileset);

            // Well formed standard bitmap - Wrong width for a tileset
            tileset = new BitmapFile(8, 20, 32, new Color[] { DiscreteColor.Red });
            tileset.Serialize(writer);
            Assert.ThrowsException <Exception>(() => TilesetLoader.ReadTileset(writer));
        }
コード例 #20
0
ファイル: BitmapSaver.cs プロジェクト: destrofer/IGE.Data
        public override void Process()
        {
            if (Attributes["path"].Value == null)
            {
                throw new UserFriendlyException("Bitmap destination must be set");
            }
            if (((string)Attributes["path"].Value).Equals(""))
            {
                throw new UserFriendlyException("Bitmap destination must not be empty");
            }
            if (Inputs["bitmap"].Value == null)
            {
                throw new UserFriendlyException("Bitmap saver requires a bitmap on input");
            }

            BitmapFile file = new BitmapFile();

            file.Bitmap = (Bitmap)Inputs["bitmap"].Value;
            file.Save((string)Attributes["path"].Value);
        }
コード例 #21
0
        public void TestLoadAndSaveBitmapResource()
        {
            Uri    uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            string bitmapsdirectory = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Bitmaps");

            foreach (string bitmapfilename in Directory.GetFiles(bitmapsdirectory))
            {
                if (!bitmapfilename.EndsWith(".bmp"))
                {
                    continue;
                }

                Assert.IsTrue(File.Exists(bitmapfilename));
                Image imageFile = Bitmap.FromFile(bitmapfilename);
                Console.WriteLine("{0}: {1}x{2}", Path.GetFileName(bitmapfilename), imageFile.Width, imageFile.Height);

                string filename = HttpUtility.UrlDecode(uri.AbsolutePath);
                Assert.IsTrue(File.Exists(filename));
                string targetFilename = Path.Combine(Path.GetTempPath(), "testLoadAndSaveBitmapResource.exe");
                File.Copy(filename, targetFilename, true);
                Console.WriteLine(targetFilename);

                BitmapResource bitmapResource = new BitmapResource();
                bitmapResource.Name = new ResourceId("RESOURCELIB");
                BitmapFile bitmapFile = new BitmapFile(bitmapfilename);
                bitmapResource.Bitmap = bitmapFile.Bitmap;
                Console.WriteLine("DIB: {0}x{1}", bitmapResource.Bitmap.Image.Width, bitmapResource.Bitmap.Image.Height);
                bitmapResource.SaveTo(targetFilename);

                Console.WriteLine("Written BitmapResource:");
                BitmapResource newBitmapResource = new BitmapResource();
                newBitmapResource.Name = new ResourceId("RESOURCELIB");
                newBitmapResource.LoadFrom(targetFilename);
                DumpResource.Dump(newBitmapResource);

                Image newBitmapResourceImage = newBitmapResource.Bitmap.Image;
                Assert.AreEqual(imageFile.Width, newBitmapResourceImage.Width);
                Assert.AreEqual(imageFile.Height, newBitmapResourceImage.Height);
            }
        }
コード例 #22
0
        // Throw runtime error if provided bitmap does not meet specific tileset requirements
        // Assumes provided tileset is already properly formed to standard bitmap file format
        public static void ValidateTileset(BitmapFile tileset)
        {
            int    DefaultPixelWidth          = 32;
            int    DefaultPixelHeightMultiple = DefaultPixelWidth;
            ushort DefaultBitCount            = 8;

            if (tileset.imageHeader.bitCount != DefaultBitCount)
            {
                TilesetCommon.throwReadError("Bit Depth", tileset.imageHeader.bitCount, DefaultBitCount);
            }

            if (tileset.imageHeader.width != DefaultPixelWidth)
            {
                TilesetCommon.throwReadError("Pixel Width", tileset.imageHeader.width, DefaultPixelWidth);
            }

            if (tileset.imageHeader.height % DefaultPixelHeightMultiple != 0)
            {
                throw new System.Exception("Tileset property Pixel Height reads " + tileset.imageHeader.height +
                                           ". Expected value must be a multiple of " + DefaultPixelHeightMultiple + " pixels");
            }
        }
コード例 #23
0
        private void OnExtractFileSavePathSelected(ArchiveFile archive, string fileName, string destPath)
        {
            interactable = true;
            try
            {
                if (Path.GetExtension(fileName).ToLowerInvariant() == ".bmp")
                {
                    // Special processing to convert tileset to a standard bmp format
                    BitmapFile bitmapFile = TilesetLoader.ReadTileset(archive.ExtractFileToMemory(fileName));
                    bitmapFile.Serialize(destPath);
                }
                else
                {
                    archive.ExtractFile(fileName, destPath);
                }
            }
            finally
            {
                archive.Dispose();
            }

            Debug.Log(Path.GetFileName(destPath) + " extracted successfully.");
        }
コード例 #24
0
        // Write tileset in Outpost 2's custom bitmap format.
        // To write tileset in standard bitmap format, use BitmapFile::WriteIndexed
        public static void WriteCustomTileset(Stream streamToWrite, BitmapFile tileset)
        {
            tileset = tileset.Clone();

            ValidateTileset(tileset);

            // OP2 Custom Tileset assumes a positive height and TopDown Scan Line (Contradicts Windows Bitmap File Format)
            if (tileset.GetScanLineOrientation() == ScanLineOrientation.BottomUp)
            {
                tileset.InvertScanLines();
            }
            uint absoluteHeight = (uint)tileset.AbsoluteHeight();

            SectionHeader fileSignature = new SectionHeader(TagFileSignature, CalculatePbmpSectionSize(absoluteHeight));
            TilesetHeader tilesetHeader = TilesetHeader.Create(absoluteHeight / TilesetHeader.DefaultPixelHeightMultiple);
            PpalHeader    ppalHeader    = PpalHeader.Create();

            SectionHeader paletteHeader = new SectionHeader(TilesetCommon.DefaultTagData, TilesetCommon.DefaultPaletteHeaderSize);

            SwapPaletteRedAndBlue(tileset.palette);

            SectionHeader pixelHeader = new SectionHeader(TilesetCommon.DefaultTagData, CalculatePixelHeaderLength(absoluteHeight));

            using (BinaryWriter writer = new BinaryWriter(streamToWrite, System.Text.Encoding.UTF8, true))
            {
                fileSignature.Serialize(writer);
                tilesetHeader.Serialize(writer);
                ppalHeader.Serialize(writer);
                paletteHeader.Serialize(writer);
                for (int i = 0; i < tileset.palette.Length; ++i)
                {
                    tileset.palette[i].Serialize(writer);
                }
                pixelHeader.Serialize(writer);
                writer.Write(tileset.pixels);
            }
        }
コード例 #25
0
        private void WriteToStream(Stream destination, int index)
        {
            BitmapFile bmpFile = GetImage(index);

            bmpFile.Serialize(destination);
        }
コード例 #26
0
        private Bitmap ReadBitmap(BinaryReader br)
        {
            BitmapFile BF = new BitmapFile();

            BF.bmpHeader = ReadBitmapFileHeader(br);
            BF.bmpInfo   = ReadBitmapInfo(br);

            int Height = BF.bmpInfo.bih.biHeight;
            int Width  = BF.bmpInfo.bih.biWidth;


            uint bitmapSize;

            if (BF.bmpInfo.bih.biSizeImage == 0)
            {
                bitmapSize = BF.bmpHeader.size - BF.bmpHeader.offBits;
            }
            else
            {
                bitmapSize = BF.bmpInfo.bih.biSizeImage;
            }


            int[]  newbmp  = new int[bitmapSize];
            byte[] bmpData = new byte[bitmapSize];
            bmpData = br.ReadBytes((int)(bitmapSize));

            int stride = Width * (BF.bmpInfo.bih.biBitCount / 8);

            if (stride % 4 != 0)
            {
                stride += (4 - stride % 4); //Rounds up to nearest 4;
            }
            Bitmap ret = new Bitmap(Width, Height, PixelFormat.Format32bppRgb);

            if (BF.bmpInfo.bmiColours != null)
            {
                Color[] cols = new Color[BF.bmpInfo.bmiColours.Length];
                for (int ind = 0; ind < cols.Length; ind++)
                {
                    cols[ind] = Color.FromArgb(BF.bmpInfo.bmiColours[ind]);
                }


                for (int m = 0; m < Height; m++)//Copy, inverse, translate from 8bpp indexed to 32bpp
                {
                    for (int k = 0; k < Width; k++)
                    {
                        ret.SetPixel(k, Height - m - 1, cols[bmpData[(m * stride) + k]]);
                    }
                }
            }
            else
            {
                BitmapData bmd = ret.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
                System.Runtime.InteropServices.Marshal.Copy(bmpData, 0, bmd.Scan0, (int)bitmapSize);
                ret.UnlockBits(bmd);
                ret.RotateFlip(RotateFlipType.RotateNoneFlipY);
            }

            return(ret);
        }
コード例 #27
0
        private void updateResource()
        {
            string filenameDownloader = WorkingDir + DownloaderFileName;
            string filenameDownloaderSatelliteResource = WorkingDir + constDownloaderSatelliteResource;

            // Look up the satellite resource
            ResourceInfo rcInfo = new ResourceInfo();

            rcInfo.Load(filenameDownloader);
            rcInfo.Unload(); // Release the module so its can be saved

            // Chinese Satellite Resource
            msResIdToFind = 1000;
            if (AppResource.Culture.Name == "en-US")
            {
                // English Satellite Resource
                msResIdToFind = 1002;
            }

            GenericResource satelliteRC = (GenericResource)rcInfo.Resources[new ResourceId(1001)].Find(FindRes);

            byte[]       temp         = satelliteRC.WriteAndGetBytes();
            MemoryStream memSatellite = new MemoryStream(1024 * 10);

            memSatellite.Write(temp, 0, temp.Length);
            memSatellite.Position = 0;
            //Create the decompressed file.
            using (FileStream fileSatellite = File.Create(filenameDownloaderSatelliteResource))
            {
                using (GZipStream Decompress = new GZipStream(memSatellite, CompressionMode.Decompress))
                {
                    readWriteStream(Decompress, fileSatellite);
                }
            }
            // Load the satellite resource
            rcInfo = new ResourceInfo();
            rcInfo.Load(filenameDownloaderSatelliteResource);
            rcInfo.Unload(); // Release the module so its can be saved
            // Begin the batch update to the designated module to speed up the process
            ResourceInfo.BeginBatchUpdate(filenameDownloaderSatelliteResource);
            try
            {
                // ==========================
                // Modify the Banner
                // ==========================
                // Look up the bitmap resource
                if (BannerBitmapFullPath.Trim() != "")
                {
                    msResIdToFind = 207;
                    BitmapResource bmpRC = (BitmapResource)rcInfo[Kernel32.ResourceTypes.RT_BITMAP].Find(FindRes);
                    if (bmpRC == null)
                    {
                        throw new ApplicationException(
                                  AppResource.ResBitmap207NotFound);
                    }

                    BitmapFile bmpFile = new BitmapFile(BannerBitmapFullPath.Trim());
                    bmpRC.Bitmap = bmpFile.Bitmap;
                    bmpRC.SaveTo(filenameDownloaderSatelliteResource);
                }
                // ==========================
                // Modify the Icon
                // ==========================
                // Look up the ICON resource
                if (IconFullPath.Trim() != "")
                {
                    msResIdToFind = 128;
                    IconDirectoryResource icoRC = (IconDirectoryResource)rcInfo[Kernel32.ResourceTypes.RT_GROUP_ICON].Find(FindRes);
                    if (icoRC == null)
                    {
                        throw new ApplicationException(AppResource.ResIcon128NotFound);
                    }

                    IconFile icoFile = new IconFile(IconFullPath.Trim());
                    uint     j       = 1;
                    icoRC.Icons.RemoveRange(0, icoRC.Icons.Count);
                    icoRC.SaveTo(filenameDownloaderSatelliteResource);
                    foreach (IconFileIcon icoFileIcon in icoFile.Icons)
                    {
                        IconResource icoRes = new IconResource(icoFileIcon, new ResourceId(j), 1033);
                        icoRes.Name = new ResourceId(j++);
                        icoRC.Icons.Add(icoRes);
                    }
                    icoRC.SaveTo(filenameDownloaderSatelliteResource);
                }
                // ==========================
                // Modify the main dialog box
                // ==========================
                // Look up the dialog resource
                msResIdToFind = 201;
                DialogResource dlgRC = (DialogResource)rcInfo[Kernel32.ResourceTypes.RT_DIALOG].Find(FindRes);
                if (dlgRC == null)
                {
                    throw new ApplicationException(AppResource.ResDialog201NotFound);
                }

                // Find the designated label control
                msCtrlIdToFind = 1010;
                DialogTemplateControlBase ctrl = dlgRC.Template.Controls.Find(FindDlgControl);
                ctrl.CaptionId.Name = string.Format(ctrl.CaptionId.Name, DownloaderDisplayName);
                // Find the designated link control
                msCtrlIdToFind      = 1006;
                ctrl                = dlgRC.Template.Controls.Find(FindDlgControl);
                ctrl.CaptionId.Name = string.Format(ctrl.CaptionId.Name, DownloaderHomeUrl);
                dlgRC.SaveTo(filenameDownloaderSatelliteResource);
                // ===================================================
                // Embed the specified .Torrent file into the resource
                // ===================================================
                // Look up the torrent resource
                msResIdToFind = 1021;
                GenericResource torrentRC = (GenericResource)rcInfo.Resources[new ResourceId(1022)].Find(FindRes);
                if (torrentRC == null)
                {
                    throw new ApplicationException(AppResource.ResTorrentSlot2011NotFound);
                }

                FileStream fs = new FileStream(MetafileFullPath, FileMode.Open);
                temp = new byte[fs.Length];
                fs.Read(temp, 0, temp.Length);
                fs.Close();
                torrentRC.Data = temp;
                torrentRC.SaveTo(filenameDownloaderSatelliteResource);
                // ===================================================
                // Embed the specified disclaimer file into the resource
                // ===================================================
                // Look up the disclaimer resource
                if (DisclaimerFullPath.Trim() != "")
                {
                    msResIdToFind = 40111;
                    GenericResource disclaimerRC = (GenericResource)rcInfo.Resources[new ResourceId(40112)].Find(FindRes);
                    if (disclaimerRC == null)
                    {
                        throw new ApplicationException(AppResource.ResDisclaimerSlot40112NotFound);
                    }

                    fs   = new FileStream(DisclaimerFullPath.Trim(), FileMode.Open);
                    temp = new byte[fs.Length];
                    fs.Read(temp, 0, temp.Length);
                    fs.Close();
                    disclaimerRC.Data = temp;
                    disclaimerRC.SaveTo(filenameDownloaderSatelliteResource);
                }
                // ==================================
                // Modify the strings in the resource
                // ==================================
                // Display Name
                StringResource stringRC = null;
                int[]          stringID = new int[] { 1112, 13015, 13016, 13017, 13018, 13019, 13027 };
                for (int i = 0; i < stringID.Length; i++)
                {
                    int sID = stringID[i];
                    // Check if the string resource has been loaded in the last string block or not.
                    if (stringRC == null || !stringRC.Strings.ContainsKey((ushort)sID))
                    {
                        msResIdToFind = StringResource.GetBlockId(sID);
                        stringRC      = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes);
                        if (stringRC == null)
                        {
                            throw new ApplicationException(
                                      string.Format(AppResource.ResStringTemplateNotFound, sID));
                        }
                    }
                    stringRC.Strings[(ushort)sID] = string.Format(stringRC.Strings[(ushort)sID], DownloaderDisplayName);
                    // Leave the modified string resource unsaved until all the strings in the string block are done.
                    if (stringID.Length == (i + 1) || !stringRC.Strings.ContainsKey((ushort)stringID[i + 1]))
                    {
                        stringRC.SaveTo(filenameDownloaderSatelliteResource);
                    }
                }
                // Google Analytics Profile ID
                msResIdToFind = StringResource.GetBlockId(1113);
                stringRC      = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes);
                if (stringRC == null)
                {
                    throw new ApplicationException(
                              string.Format(AppResource.ResStringTemplateNotFound, 1113));
                }

                stringRC.Strings[1113] = string.Format(stringRC.Strings[1113], GoogleAnalyticsProfileID);
                stringRC.SaveTo(filenameDownloaderSatelliteResource);
                // Downloader GUID
                msResIdToFind = StringResource.GetBlockId(40401);
                stringRC      = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes);
                if (stringRC == null)
                {
                    throw new ApplicationException(
                              string.Format(AppResource.ResStringTemplateNotFound, 40401));
                }

                stringRC.Strings[40401] = string.Format(stringRC.Strings[40401], DownloaderGuid);
                stringRC.SaveTo(filenameDownloaderSatelliteResource);
                // Online FAQ URL
                if (OnlineFaqUrl.Trim() != "")
                {
                    msResIdToFind = StringResource.GetBlockId(13020);
                    stringRC      = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes);
                    if (stringRC == null)
                    {
                        throw new ApplicationException(
                                  string.Format(AppResource.ResStringTemplateNotFound, 13020));
                    }

                    stringRC.Strings[13020] = OnlineFaqUrl;
                    stringRC.SaveTo(filenameDownloaderSatelliteResource);
                }
                // Event ID
                if (PromotionEventID.Trim() != "")
                {
                    msResIdToFind = StringResource.GetBlockId(1104);
                    stringRC      = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes);
                    if (stringRC == null)
                    {
                        throw new ApplicationException(
                                  string.Format(AppResource.ResStringTemplateNotFound, 1104));
                    }

                    stringRC.Strings[1104] = string.Format(stringRC.Strings[1104], PromotionEventID);
                    stringRC.SaveTo(filenameDownloaderSatelliteResource);
                }
                // Event Server URL
                if (PromotionEventID.Trim() != "")
                {
                    msResIdToFind = StringResource.GetBlockId(1101);
                    stringRC      = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes);
                    if (stringRC == null)
                    {
                        throw new ApplicationException(
                                  string.Format(AppResource.ResStringTemplateNotFound, 1101));
                    }

                    // Conver the URL to base64 encoded string
                    stringRC.Strings[1101] = Convert.ToBase64String(Encoding.ASCII.GetBytes(PromotionEventServerUrl));
                    stringRC.SaveTo(filenameDownloaderSatelliteResource);
                }
            }
            catch (Exception oEx)
            {
                throw oEx;
            }
            finally
            {
                // Commit the batch updates to the module
                ResourceInfo.EndBatchUpdate();
            }
        }