Пример #1
0
        /// <summary>
        /// Unpack a PBP file, avoiding to consume too much memory
        /// (i.e. not reading each section completely in memory).
        /// </summary>
        /// <param name="vFile">        the PBP file </param>
        /// <exception cref="IOException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void unpackPBP(pspsharp.HLE.VFS.IVirtualFile vFile) throws java.io.IOException
        public static void unpackPBP(IVirtualFile vFile)
        {
            vFile.ioLseek(0L);
            PBP pbp = new PBP();

            pbp.size_pbp = (int)vFile.Length();
            pbp.p_magic  = read32(vFile);
            if (!pbp.Valid)
            {
                return;
            }
            pbp.p_version = read32(vFile);
            pbp.p_offsets = new int[] { read32(vFile), read32(vFile), read32(vFile), read32(vFile), read32(vFile), read32(vFile), read32(vFile), read32(vFile), pbp.size_pbp };

            File dir = new File(PBP_UNPACK_PATH_PREFIX);

            deleteDir(dir);             //delete all files and directory
            dir.mkdir();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override byte[] buffer = new byte[10 * 1024];
            sbyte[] buffer = new sbyte[10 * 1024];
            for (int index = 0; index < TOTAL_FILES; index++)
            {
                int size = pbp.getSize(index);
                if (size > 0)
                {
                    long offset = pbp.getOffset(index) & 0xFFFFFFFFL;
                    if (vFile.ioLseek(offset) == offset)
                    {
                        System.IO.Stream os = new System.IO.FileStream(PBP_UNPACK_PATH_PREFIX + pbp.getName(index), System.IO.FileMode.Create, System.IO.FileAccess.Write);
                        while (size > 0)
                        {
                            int Length     = System.Math.Min(size, buffer.Length);
                            int readLength = vFile.ioRead(buffer, 0, Length);
                            if (readLength > 0)
                            {
                                os.Write(buffer, 0, readLength);
                                size -= readLength;
                            }
                            if (readLength != Length)
                            {
                                break;
                            }
                        }
                        os.Close();
                    }
                }
            }
        }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void unpackPBP(ByteBuffer f) throws java.io.IOException
        public static void unpackPBP(ByteBuffer f)
        {
            f.position(0);             //seek to 0
            PBP pbp = new PBP(f);

            if (!pbp.Valid)
            {
                return;
            }
            File dir = new File(PBP_UNPACK_PATH_PREFIX);

            deleteDir(dir);             //delete all files and directory
            dir.mkdir();

            for (int index = 0; index < TOTAL_FILES; index++)
            {
                sbyte[] bytes = pbp.getBytes(f, index);
                if (bytes != null && bytes.Length > 0)
                {
                    FileUtil.writeBytes(new File(PBP_UNPACK_PATH_PREFIX + pbp.getName(index)), bytes);
                }
            }
        }