Beispiel #1
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            Config.bUseExternalDeLess = false;
            if (checkBox.IsChecked.Value == true)
            {
                Config.bUseExternalDeLess = true;
            }
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title    = "Select FHD file";
            openFileDialog.Filter   = "FHD file|*.FHD";
            openFileDialog.FileName = string.Empty;
            if (openFileDialog.ShowDialog().Value)
            {
                string filename = openFileDialog.FileName;
                FatalFrame.GetFHDInfo(filename);
            }
            MessageBox.Show("Operation completed");
        }
Beispiel #2
0
        public static bool PatchIMG(string FHD_name)
        {
            string directoryName   = Path.GetDirectoryName(FHD_name);//Get FHD file directory
            string patchFolderName = String.Format("{0}\\Patch", directoryName);

            if (!File.Exists(patchFolderName))
            //If the Patch folder does not exist,Create Patch folder
            {
                Directory.CreateDirectory(String.Format("{0}\\Patch", directoryName));
            }
            FatalFrame.FHD2INI(FHD_name);//Export ini table from currently selected FHD file
            List <FHDInfo> list = new List <FHDInfo>();

            GetIndexInfo(String.Format("{0}\\zero.ini", directoryName), list);//Get struct list

            fileInfo     m_fileInfo;
            FileStream   fStream    = new FileStream(FHD_name, FileMode.Open, FileAccess.ReadWrite);//Open FHD file stream
            BinaryReader fp         = new BinaryReader(fStream);
            BinaryWriter fhd_writer = new BinaryWriter(fStream);

            fp.BaseStream.Seek(0, SeekOrigin.Begin);
            fhd_writer.BaseStream.Seek(0, SeekOrigin.Begin);

            string       IMG_NAME   = String.Format("{0}\\IMG_BD.bin", directoryName);//Open the IMG_BD file stream
            FileStream   IMG_Stream = new FileStream(IMG_NAME, FileMode.Open, FileAccess.ReadWrite);
            BinaryWriter img        = new BinaryWriter(IMG_Stream);


            uint sig = fp.ReadUInt32();

            if (sig != 0x46484400)
            {
                Base.WriteLogging(String.Format("Error: Not a FHD file:{0}", FHD_name));
                MessageBox.Show("Error: Not a FHD file");
                fp.Close();
                fStream.Close();
                return(false);
            }
            else
            {
                fp.BaseStream.Seek(8, SeekOrigin.Begin);
                m_fileInfo.baseName      = FHD_name;
                m_fileInfo.baseSize      = fp.ReadInt32();
                m_fileInfo.baseNums      = fp.ReadInt32();
                m_fileInfo.BLOCK0_OFFSET = fp.ReadInt32();                      // Decompressed BLOCK
                m_fileInfo.BLOCK1_OFFSET = fp.ReadInt32();                      // TYPE BLOCK
                m_fileInfo.BLOCK2_OFFSET = fp.ReadInt32();                      // SIZE BLOCK
                m_fileInfo.BLOCK3_OFFSET = fp.ReadInt32();                      // NAME BLOCK
                m_fileInfo.BLOCK4_OFFSET = fp.ReadInt32();                      // LBA BLOCK
                fp.BaseStream.Seek(m_fileInfo.BLOCK0_OFFSET, SeekOrigin.Begin); // goto Block 0
                Base.WriteLogging(String.Format("{0} files need to patch", list.Count));
                for (int i = 0; i < list.Count; i++)
                {
                    FHDInfo m_FHDInfo = list[i];
                    //Get the FHD pointer address according to the current ID
                    long   LBA_POS  = m_fileInfo.BLOCK4_OFFSET + m_FHDInfo.FHD_ID * 4;
                    long   SIZE_POS = m_fileInfo.BLOCK2_OFFSET + m_FHDInfo.FHD_ID * 4;
                    long   NAME_POS = m_fileInfo.BLOCK3_OFFSET + m_FHDInfo.FHD_ID * 8;
                    long   DEC_POS  = m_fileInfo.BLOCK0_OFFSET + m_FHDInfo.FHD_ID * 4;
                    string pfName   = String.Format("{0}\\Patch\\{1}{2}", directoryName,
                                                    m_FHDInfo.FolderName.Replace("..", ""),
                                                    m_FHDInfo.FileName);
                    FileStream   pfStream = new FileStream(pfName, FileMode.Open, FileAccess.ReadWrite);//Open patch file file stream
                    BinaryReader pfReader = new BinaryReader(pfStream);
                    pfReader.BaseStream.Seek(0, SeekOrigin.Begin);
                    if (m_FHDInfo.LBA_OFFSET == -1)//The file is appended to the end of IMG_BD
                    {
                        img.BaseStream.Seek(0, SeekOrigin.End);
                        long currentPosition = img.BaseStream.Position;
                        long tmp_offset      = Convert.ToUInt32(currentPosition);
                        m_FHDInfo.LBA_OFFSET = tmp_offset;
                        Base.WriteLogging(String.Format("Writing {0} to the end of img --->{1}", pfName, m_FHDInfo.LBA_OFFSET));
                        byte[] data = pfReader.ReadBytes(Convert.ToInt32(pfStream.Length));
                        img.Write(data);
                        if (Convert.ToInt32(pfStream.Length) % 0x800 != 0)
                        {
                            img.Write(Base.FillByteArray(0x800 - Convert.ToInt32(pfStream.Length) % 0x800));
                        }
                        img.Flush();
                    }
                    else
                    {
                        long tmp_offset = m_FHDInfo.LBA_OFFSET;
                        img.BaseStream.Seek(tmp_offset, SeekOrigin.Begin);

                        byte[] data = pfReader.ReadBytes(Convert.ToInt32(pfStream.Length));
                        img.Write(data);
                        img.Flush();
                    }
                    fStream.Position = LBA_POS;
                    fStream.Write(System.BitConverter.GetBytes(m_FHDInfo.LBA_OFFSET / 0x800), 0, 4);
                    fStream.Position = SIZE_POS;
                    fStream.Write(System.BitConverter.GetBytes(m_FHDInfo.CompressedSize << 1), 0, 4);
                    fStream.Position = DEC_POS;
                    fStream.Write(System.BitConverter.GetBytes(m_FHDInfo.DecompressedSize), 0, 4);
                    pfReader.Close();
                    pfStream.Close();
                }
                fp.Close();
                fStream.Close();
                IMG_Stream.Close();
                img.Close();



                return(true);
            }
        }