Пример #1
0
        public static CriUtfTocFileInfo GetUtfItocFileInfo(CriUtfTable dataUtf, int rowIndex)
        {
            CriUtfTocFileInfo fileInfo = new CriUtfTocFileInfo();
            object            temp;

            temp = CriUtfTable.GetUtfFieldForRow(dataUtf, rowIndex, "ID");
            fileInfo.FileName = temp != null ? ((ushort)temp).ToString("D5") : null;

            temp = CriUtfTable.GetUtfFieldForRow(dataUtf, rowIndex, "FileSize");
            fileInfo.FileSize = temp != null?Convert.ToUInt32(temp) : uint.MaxValue;

            temp = CriUtfTable.GetUtfFieldForRow(dataUtf, rowIndex, "ExtractSize");
            fileInfo.ExtractSize = temp != null?Convert.ToUInt32(temp) : uint.MaxValue;

            return(fileInfo);
        }
Пример #2
0
        public static CriUtfTocFileInfo GetUtfTocFileInfo(CriUtfTable tocUtf, int rowIndex)
        {
            CriUtfTocFileInfo fileInfo = new CriUtfTocFileInfo();
            object            temp;

            temp             = CriUtfTable.GetUtfFieldForRow(tocUtf, rowIndex, "DirName");
            fileInfo.DirName = temp != null ? (string)temp : null;
            fileInfo.DirName = fileInfo.DirName.Equals(CriCpkArchive.NULL_FILENAME) ? String.Empty : fileInfo.DirName;

            temp = CriUtfTable.GetUtfFieldForRow(tocUtf, rowIndex, "FileName");
            fileInfo.FileName = temp != null ? (string)temp : null;
            fileInfo.FileName = fileInfo.FileName.Equals(CriCpkArchive.NULL_FILENAME) ? String.Format("{0}.bin", rowIndex.ToString("D5")) : fileInfo.FileName;

            temp = CriUtfTable.GetUtfFieldForRow(tocUtf, rowIndex, "FileOffset");
            fileInfo.FileOffset = temp != null ? (ulong)temp : ulong.MaxValue;

            temp = CriUtfTable.GetUtfFieldForRow(tocUtf, rowIndex, "FileSize");
            fileInfo.FileSize = temp != null ? (uint)temp : uint.MaxValue;

            temp = CriUtfTable.GetUtfFieldForRow(tocUtf, rowIndex, "ExtractSize");
            fileInfo.ExtractSize = temp != null ? (uint)temp : uint.MaxValue;

            return(fileInfo);
        }
Пример #3
0
        public CriCpkDirectory GetDirectoryForItoc(FileStream fs, CriUtfTable cpkUtf, string BaseDirectoryName, long volumeBaseOffset)
        {
            ulong             currentOffset = 0;
            CriUtfTocFileInfo fileInfo      = new CriUtfTocFileInfo();
            CriAfs2File       afs2File      = new CriAfs2File();

            // get content offset and align
            ulong  contentOffset = (ulong)CriUtfTable.GetUtfFieldForRow(cpkUtf, 0, "ContentOffset");
            ushort align         = (ushort)CriUtfTable.GetUtfFieldForRow(cpkUtf, 0, "Align");

            // build direcory path
            CriCpkDirectory baseDirectory = new CriCpkDirectory(this.SourceFileName, BaseDirectoryName, String.Empty);
            CriCpkFile      tempFile;

            // read file groups
            uint   filesH    = 0;
            uint   filesL    = 0;
            object filesHObj = CriUtfTable.GetUtfFieldForRow(this.ItocUtf, 0, "FilesH"); //count of files in DataH
            object filesLObj = CriUtfTable.GetUtfFieldForRow(this.ItocUtf, 0, "FilesL"); // count of files in DataL

            if (filesHObj != null)
            {
                filesH = (uint)filesHObj;
            }

            if (filesHObj != null)
            {
                filesL = (uint)filesLObj;
            }

            if ((filesH > 0) || (filesL > 0))
            {
                Dictionary <string, CriUtfTocFileInfo> fileList = new Dictionary <string, CriUtfTocFileInfo>();

                if (filesH > 0)
                {
                    // read DataH group
                    CriUtfTable dataH = new CriUtfTable();
                    dataH.Initialize(fs, (long)CriUtfTable.GetOffsetForUtfFieldForRow(this.ItocUtf, 0, "DataH"));

                    for (int i = 0; i < dataH.Rows.GetLength(0); i++)
                    {
                        fileInfo = GetUtfItocFileInfo(dataH, i);
                        fileList.Add(fileInfo.FileName, fileInfo);
                    }
                }

                if (filesL > 0)
                {
                    // read DataL group
                    CriUtfTable dataL = new CriUtfTable();
                    dataL.Initialize(fs, (long)CriUtfTable.GetOffsetForUtfFieldForRow(this.ItocUtf, 0, "DataL"));

                    for (int i = 0; i < dataL.Rows.GetLength(0); i++)
                    {
                        fileInfo = GetUtfItocFileInfo(dataL, i);
                        fileList.Add(fileInfo.FileName, fileInfo);
                    }
                }

                // initialize current offset
                currentOffset = contentOffset;

                // populate offsets for files
                var keys = fileList.Keys.ToList();
                keys.Sort();

                foreach (string key in keys)
                {
                    // afs2 file for ACB extraction
                    afs2File               = new CriAfs2File();
                    afs2File.CueId         = Convert.ToUInt16(fileList[key].FileName); // ??? @TODO maybe key is enough?  need to check.
                    afs2File.FileOffsetRaw = volumeBaseOffset + (long)currentOffset;

                    // align offset
                    if (currentOffset % align != 0)
                    {
                        currentOffset = MathUtil.RoundUpToByteAlignment(currentOffset, align);
                    }

                    // update file info
                    fileList[key].FileOffset = (ulong)volumeBaseOffset + currentOffset;
                    fileList[key].FileName  += ".bin";

                    // afs2 file for ACB extraction
                    afs2File.FileOffsetByteAligned = (long)fileList[key].FileOffset;
                    afs2File.FileLength            = fileList[key].FileSize;

                    // increment current offset
                    currentOffset += fileList[key].FileSize;

                    // create file and add to base directory
                    tempFile = new CriCpkFile(BaseDirectoryName, this.SourceFileName, fileList[key].FileName,
                                              (long)fileList[key].FileOffset, this.VolumeBaseOffset, (long)fileList[key].FileOffset,
                                              fileList[key].FileSize, fileList[key].ExtractSize);

                    baseDirectory.FileArray.Add(tempFile);

                    // add afs2 file to ItocFiles for ACB extraction
                    this.ItocFiles.Add(afs2File.CueId, afs2File);
                } // foreach (string key in keys)
            }     // if ((filesH > 0) || (filesL > 0))


            return(baseDirectory);
        }
Пример #4
0
        public CriCpkDirectory GetDirectoryForToc(FileStream fs, CriUtfTable cpkUtf, string BaseDirectoryName, long volumeBaseOffset)
        {
            CriUtfTocFileInfo fileInfo = new CriUtfTocFileInfo();

            long   trueTocBaseOffset;
            ulong  contentOffset = (ulong)CriUtfTable.GetUtfFieldForRow(cpkUtf, 0, "ContentOffset");
            ushort align         = (ushort)CriUtfTable.GetUtfFieldForRow(cpkUtf, 0, "Align");

            char[]    separators     = new char[] { '/', '\\' };
            ArrayList allDirectories = new ArrayList();

            CriCpkDirectory baseDirectory = new CriCpkDirectory(this.SourceFileName, BaseDirectoryName, String.Empty);
            CriCpkDirectory newDirectory;
            CriCpkDirectory currentDirectory;
            int             indexOfNewDirectory;

            CriCpkFile tempFile;
            Dictionary <string, ArrayList> fileListDictionary = new Dictionary <string, ArrayList>();
            string parentName;

            // loop over files to get unique dirs
            for (int i = 0; i < this.TocUtf.Rows.GetLength(0); i++)
            {
                fileInfo = GetUtfTocFileInfo(this.TocUtf, i);

                if (fileInfo.FileName != null)
                {
                    //---------------
                    // get directory
                    //---------------
                    if (!fileListDictionary.ContainsKey(fileInfo.DirName))
                    {
                        fileListDictionary.Add(fileInfo.DirName, new ArrayList());
                    }

                    //--------------
                    // create file
                    //--------------
                    // set true base offset, since UTF header starts at 0x10 of a container type
                    trueTocBaseOffset = this.TocUtf.BaseOffset - 0x10;

                    // get absolute offset
                    if (contentOffset < (ulong)trueTocBaseOffset)
                    {
                        fileInfo.FileOffset += contentOffset;
                    }
                    else
                    {
                        fileInfo.FileOffset += (ulong)trueTocBaseOffset;
                    }

                    if (fileInfo.FileOffset % align != 0)
                    {
                        fileInfo.FileOffset = MathUtil.RoundUpToByteAlignment(fileInfo.FileOffset, align);
                    }

                    parentName = BaseDirectoryName + Path.DirectorySeparatorChar + fileInfo.DirName;
                    parentName = parentName.Replace('/', Path.DirectorySeparatorChar);

                    tempFile = new CriCpkFile(parentName, this.SourceFileName, fileInfo.FileName, (long)fileInfo.FileOffset, this.VolumeBaseOffset,
                                              (long)fileInfo.FileOffset, fileInfo.FileSize, fileInfo.ExtractSize);

                    // add to Dictionary
                    fileListDictionary[fileInfo.DirName].Add(tempFile);
                }
            }

            foreach (var path in fileListDictionary.Keys)
            {
                currentDirectory = baseDirectory;
                var pathItems = path.Split(separators);

                parentName = BaseDirectoryName;

                for (int i = 0; i < pathItems.Count(); i++)
                {
                    var item = pathItems[i];

                    var tmp = currentDirectory.SubDirectoryArray.Cast <CriCpkDirectory>().Where(x => x.DirectoryName.Equals(item));

                    if (tmp.Count() > 0)
                    {
                        currentDirectory = tmp.Single();
                    }
                    else
                    {
                        newDirectory        = new CriCpkDirectory(this.SourceFileName, item, parentName);
                        indexOfNewDirectory = currentDirectory.SubDirectoryArray.Add(newDirectory);
                        currentDirectory    = (CriCpkDirectory)currentDirectory.SubDirectoryArray[indexOfNewDirectory];
                    }

                    if (i == pathItems.GetUpperBound(0))
                    {
                        foreach (CriCpkFile f in fileListDictionary[path])
                        {
                            currentDirectory.FileArray.Add(f);
                        }
                    }

                    parentName += Path.DirectorySeparatorChar + item;
                }
            }

            return(baseDirectory);
        }