Exemplo n.º 1
0
        private void GetFilDirInfo(sio.DirectoryInfo pDir, ref int itemNum, ref int filePos)
        {
            sio.DirectoryInfo   di;
            sio.DirectoryInfo[] dirs;
            sio.FileInfo[]      fils;
            TOCItemFil          tif;
            int tocDirIdx = itemNum - 1;

            dirs = pDir.GetDirectories();
            //IEnumerable<sio.DirectoryInfo> query = dirs.Where(dir => dir.Name.ToLower() == "&&systemdata");
            for (int cnt = 0; cnt < dirs.Length; cnt++)
            {
                if (dirs[cnt].Name.ToLower() == "&&systemdata")
                {
                    di        = dirs[0];
                    dirs[0]   = dirs[cnt];
                    dirs[cnt] = di;
                    break;
                }
            }

            for (int cnt = 0; cnt < dirs.Length; cnt++)
            {
                tif = new TOCItemFil(itemNum, tocDirIdx, tocDirIdx, 0, true,
                                     dirs[cnt].Name, dirs[cnt].FullName.Replace(resPath, ""), dirs[cnt].FullName);
                toc.fils.Add(tif);
                itemNum      += 1;
                toc.dirCount += 1;
                GetFilDirInfo(dirs[cnt], ref itemNum, ref filePos);
            }

            fils = pDir.GetFiles();
            for (int cnt = 0; cnt < fils.Length; cnt++)
            {
                tif = new TOCItemFil(itemNum, tocDirIdx, filePos, (int)fils[cnt].Length, false,
                                     fils[cnt].Name, fils[cnt].FullName.Replace(resPath, ""), fils[cnt].FullName);
                toc.fils.Add(tif);
                toc.fils[0].len = toc.fils.Count;
                filePos        += 2;
                itemNum        += 1;
                toc.filCount   += 1;
            }

            toc.fils[tocDirIdx].len = itemNum;
        }
Exemplo n.º 2
0
        private bool ReadTOC()
        {
            TOCItemFil tif;

            sio.FileStream   fsr;
            sio.BinaryReader brr;
            long             prevPos, newPos;
            string           tocName = "game.toc";

            sio.DirectoryInfo di;
            sio.FileInfo      fi;

            int    namesTableEntryCount;
            int    namesTableStart;
            int    itemNamePtr;
            bool   itemIsDir = false;
            int    itemPos;
            int    itemLen;
            string itemName;
            string itemGamePath = "";
            string itemPath;

            int itemNum;
            int shift;

            //int dirIdx = 0;
            //int endIdx = 999999;
            int[] dirEntry      = new int[512];
            int   dirEntryCount = 0;

            dirEntry[1] = 99999999;

            int    mod = 1;
            bool   error = false;
            string errorText = "";
            int    i, j;

            toc     = new TOCClass(resPath);
            itemNum = toc.fils.Count;
            shift   = toc.fils.Count - 1;

            for (i = 2; i < 6; i++)
            {
                fi = new sio.FileInfo(toc.fils[i].path);
                if (!fi.Exists)
                {
                    errorText = string.Format("File '{0}' not found", toc.fils[i].path);
                    error     = true;
                }
                else
                {
                    toc.fils[i].len = (int)fi.Length;
                    toc.totalLen   += toc.fils[i].len;
                }
            }
            toc.dataStart = toc.totalLen;

            if (!error)
            {
                fsr = new sio.FileStream(toc.fils[2].path, sio.FileMode.Open, sio.FileAccess.Read);
                brr = new sio.BinaryReader(fsr, ste.Default);

                fsr.Position = 0x1c;
                if (brr.ReadInt32() != 0x3d9f33c2)
                {
                    errorText = "Not a GameCube image";
                    error     = true;
                }

                fsr.Position    = 0x0400;
                toc.fils[2].pos = 0x0;
                toc.fils[3].pos = 0x2440;
                brr.ReadInt32BE();
                fsr.Position   += 0x1c;
                toc.fils[4].pos = brr.ReadInt32BE();
                toc.fils[5].pos = brr.ReadInt32BE();
                brr.ReadInt32BE();
                fsr.Position += 0x08;
                toc.dataStart = brr.ReadInt32BE();

                brr.Close();
                fsr.Close();
            }

            if (!error)
            {
                fsr = new sio.FileStream(resPath + "&&systemdata\\" + tocName, sio.FileMode.Open, sio.FileAccess.Read);
                brr = new sio.BinaryReader(fsr, ste.Default);

                i = brr.ReadInt32();
                if (i != 1)
                {
                    error     = true;
                    errorText = "Multiple FST image?\r\nPlease mail me info about this image";
                }

                i = brr.ReadInt32();
                if (i != 0)
                {
                    error     = true;
                    errorText = "Multiple FST image?\r\nPlease mail me info about this image";
                }

                namesTableEntryCount = brr.ReadInt32BE() - 1;
                namesTableStart      = (namesTableEntryCount * 12) + 12;

                if (retrieveFilesInfo)
                {
                    sspbProgress.Minimum = 0;
                    sspbProgress.Maximum = 100;
                    sspbProgress.Step    = 1;
                    sspbProgress.Value   = 0;
                    mod = (int)Math.Floor((float)(namesTableEntryCount + itemNum) / sspbProgress.Maximum);
                    if (mod == 0)
                    {
                        sspbProgress.Maximum = namesTableEntryCount + itemNum;
                        mod = 1;
                    }
                }

                for (int cnt = 0; cnt < namesTableEntryCount; cnt++)
                {
                    itemNamePtr = brr.ReadInt32BE();
                    if (itemNamePtr >> 0x18 == 1)
                    {
                        itemIsDir = true;
                    }
                    itemNamePtr &= 0x00ffffff;
                    itemPos      = brr.ReadInt32BE();
                    itemLen      = brr.ReadInt32BE();
                    prevPos      = fsr.Position;
                    newPos       = namesTableStart + itemNamePtr;
                    fsr.Position = newPos;
                    itemName     = brr.ReadStringNT();
                    fsr.Position = prevPos;

                    while (dirEntry[dirEntryCount + 1] <= itemNum)
                    {
                        dirEntryCount -= 2;
                    }

                    if (itemIsDir)
                    {
                        dirEntryCount          += 2;
                        dirEntry[dirEntryCount] = (itemPos > 0) ? itemPos + shift : itemPos;
                        itemPos += shift;
                        itemLen += shift;
                        dirEntry[dirEntryCount + 1] = itemLen;
                        toc.dirCount += 1;
                    }
                    else
                    {
                        toc.filCount += 1;
                    }

                    itemPath = itemName;
                    j        = dirEntry[dirEntryCount];
                    for (i = 0; i < 256; i++)
                    {
                        if (j == 0)
                        {
                            itemGamePath = itemPath;
                            itemPath     = resPath + itemPath;
                            break;
                        }
                        else
                        {
                            itemPath = itemPath.Insert(0, toc.fils[j].name + '\\');
                            j        = toc.fils[j].dirIdx;
                        }
                    }
                    if (itemIsDir)
                    {
                        itemPath += '\\';
                    }

                    if (retrieveFilesInfo)
                    {
                        if (itemIsDir)
                        {
                            di = new sio.DirectoryInfo(itemPath);
                            if (!di.Exists)
                            {
                                errorText = string.Format("Directory '{0}' not found", itemPath);
                                error     = true;
                            }
                        }
                        else
                        {
                            fi = new sio.FileInfo(itemPath);
                            if (!fi.Exists)
                            {
                                errorText = string.Format("File '{0}' not found", itemPath);
                                error     = true;
                            }
                            else
                            {
                                itemLen       = (int)fi.Length;
                                toc.totalLen += itemLen;
                            }
                        }
                        if (error)
                        {
                            break;
                        }

                        if (itemNum % mod == 0)
                        {
                            if (sspbProgress.Value < sspbProgress.Maximum)
                            {
                                sspbProgress.Value += 1;
                            }
                            //sslblAction.Text = string.Format("Check: '{0}'…", itemPath.Replace(resPath, ""));
                        }
                    }

                    tif = new TOCItemFil(itemNum, dirEntry[dirEntryCount], itemPos, itemLen, itemIsDir, itemName, itemGamePath, itemPath);
                    toc.fils.Add(tif);
                    toc.fils[0].len = toc.fils.Count;

                    if (itemIsDir)
                    {
                        dirEntry[dirEntryCount] = itemNum;
                        itemIsDir = false;
                    }

                    itemNum += 1;
                }
                brr.Close();
                fsr.Close();
            }

            if (retrieveFilesInfo)
            {
                sspbProgress.Value = 0;
            }

            if (error)
            {
                MessageBox.Show(errorText, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //sslblAction.Text = "Ready";
                return(false);;
            }

            CalcNextFileIds();

            //sslblAction.Text = "Building Structure…";
            error = GenerateTreeView(fileNameSort);
            //sslblAction.Text = "Ready";

            rootOpened = true;
            LoadInfo(!rootOpened);

            return(error);
        }