Ejemplo n.º 1
0
        public static void ExplodeCommonPic(string commonPicArc, string outDir, SplitCommonPicArgs opFlags)
        {
            string     idxFileName     = Path.ChangeExtension(commonPicArc, ".idx");
            string     pictureDir      = null;
            RefCounter completionCount = new RefCounter();

            if ((opFlags & SplitCommonPicArgs.OutputPngPicture) != 0)
            {
                pictureDir = Path.Combine(outDir, "pictures");
                Directory.CreateDirectory(pictureDir);
            }
            int numIdxEntries;

            using (FileStream packFile = File.OpenRead(commonPicArc))
                using (FileStream idxFile = File.OpenRead(idxFileName))
                    using (BinaryReader idxFileRead = new BinaryReader(idxFile))
                    {
                        long packFileSize = packFile.Length;
                        numIdxEntries = idxFileRead.ReadInt32();
                        int           startPoint  = idxFileRead.ReadInt32();
                        StringBuilder outFileName = new StringBuilder(outDir);
                        outFileName.Append(Path.DirectorySeparatorChar);
                        int fileNameStart = outFileName.Length;
                        for (int i = 0; i < numIdxEntries; ++i)
                        {
                            int    endPoint = idxFileRead.ReadInt32();
                            int    len      = endPoint - startPoint;
                            byte[] buffer   = new byte[len];
                            packFile.Position = startPoint;
                            packFile.Read(buffer, 0, len);
                            outFileName.Length = fileNameStart;
                            outFileName.Append(i.ToString() + ".gtmp");
                            AsyncWriteState aws     = new AsyncWriteState();
                            FileStream      outFile = new FileStream(outFileName.ToString(), FileMode.Create, FileAccess.ReadWrite, FileShare.None, UInt16.MaxValue, true);
                            aws.file            = outFile;
                            aws.data            = buffer;
                            aws.ops             = opFlags;
                            aws.completionCount = completionCount;
                            if ((opFlags & SplitCommonPicArgs.OutputPngPicture) != 0)
                            {
                                aws.picFileName = Path.Combine(pictureDir, i.ToString() + ".gtmp.png");
                            }
                            outFile.BeginWrite(buffer, 0, len, new AsyncCallback(WriteComplete), aws);
                            startPoint = endPoint;
                        }
                    }
            while (!completionCount.HasReached(numIdxEntries))
            {
                System.Threading.Thread.Sleep(100);
            }
        }
Ejemplo n.º 2
0
        private static void DumpImage(object o)
        {
            AsyncWriteState aws = (AsyncWriteState)o;

            using (FileStream fs = aws.file)
                using (Bitmap bm = Parse(fs))
                {
                    if (bm != null)
                    {
                        bm.Save(aws.picFileName, ImageFormat.Png);
                    }
                }
            aws.completionCount.Increment();
        }
Ejemplo n.º 3
0
        private static void WriteComplete(IAsyncResult res)
        {
            AsyncWriteState aws = (AsyncWriteState)res.AsyncState;
            FileStream      fs  = aws.file;

            fs.EndWrite(res);
            if ((aws.ops & SplitCommonPicArgs.OutputPngPicture) != 0)
            {
                fs.Position = 0;
                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(DumpImage), aws);
            }
            else
            {
                fs.Dispose();
                aws.completionCount.Increment();
            }
        }