public object Clone() { TOCClass res; res = new TOCClass(this.fils[0].path); res.fils.Clear(); res.dirCount = this.dirCount; res.filCount = this.filCount; for (int i = 0; i < this.fils.Count; i++) { res.fils.Add((TOCItemFil)this.fils[i].Clone()); } return(res); }
private bool GenerateTOC() { int itemNum = 0; int filePosDef = 1000000; int filePos = filePosDef; TOCItemFil tif; toc = new TOCClass(resPath); toc.fils.RemoveRange(1, 5); itemNum = toc.fils.Count; GetFilDirInfo(new sio.DirectoryInfo(resPath), ref itemNum, ref filePos); filePos = filePosDef; toc.fils[0].len -= 5; toc.fils[1].len -= 5; tif = toc.fils[2]; toc.fils[2] = toc.fils[4]; toc.fils[4] = tif; toc.fils[2].TOCIdx = 2; toc.fils[2].pos = filePos; tif = toc.fils[3]; toc.fils[3] = toc.fils[4]; toc.fils[4] = tif; toc.fils[3].TOCIdx = 3; toc.fils[3].pos = filePos + 2; tif = toc.fils[4]; toc.fils[4] = toc.fils[5]; toc.fils[5] = tif; toc.fils[4].TOCIdx = 4; toc.fils[4].pos = filePos + 4; toc.fils[5].TOCIdx = 5; toc.fils[5].pos = filePos + 6; CalcNextFileIds(); toc.fils[2].pos = filePos; GenerateTreeView(fileNameSort); rootOpened = true; LoadInfo(!rootOpened); return(true); }
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); }