예제 #1
0
        public void ExportDirectory(FileSystem.DirectoryEntry entry, string path, BackgroundWorker bw)
        {
            if (bw != null)
                bw.ReportProgress(0, String.Empty);

            FileSystem.Traversal traversal = new FileSystem.Traversal(entry);
            int currentFileIndex = 0;
            int totalFiles = traversal.TotalFiles();

            FileSystem.FileEntry file;
            while ((file = traversal.Next()) != null)
            {
                string outputPath = Path.Combine(path, file.Directory.LocalPath);

                if (!Directory.Exists(outputPath))
                    Directory.CreateDirectory(outputPath);

                if (bw != null)
                    bw.ReportProgress((int)((float)currentFileIndex / totalFiles * 100), Path.Combine(file.Directory.LocalPath, file.Name));

                ExportFile(file, outputPath);

                currentFileIndex++;
            }
        }
예제 #2
0
        public bool Rebuild(string path, bool quick, BackgroundWorker bw)
        {
            if (bw != null)
                bw.ReportProgress(0, String.Empty);

            // Create a buffer when we are doing a full rebuild so it can go quicker
            byte[] nullBuffer = null;
            if (!quick)
                nullBuffer = new byte[4096];

            // The first thing we want to do is make sure all the files exist.
            // So, let's loop through the file system.
            FileSystem.Traversal traversal;
            FileSystem.FileEntry file;

            traversal = new FileSystem.Traversal(FileSystem.Root);
            while ((file = traversal.Next()) != null)
            {
                if (!File.Exists(Path.Combine(path, Path.Combine(file.Directory.LocalPath, file.Name))))
                    return false;
            }

            // All the files exist, let's gather all the new offsets and lengths for the files and add them to the ISO
            uint offset = 0;

            traversal = new FileSystem.Traversal(FileSystem.Root);
            int currentFileIndex = 0;
            int totalFiles = traversal.TotalFiles();

            while ((file = traversal.Next()) != null)
            {
                if (bw != null)
                    bw.ReportProgress((int)((float)currentFileIndex / totalFiles * 100), Path.Combine(file.Directory.LocalPath, file.Name));

                using (FileStream input = File.OpenRead(Path.Combine(path, Path.Combine(file.Directory.LocalPath, file.Name))))
                {
                    // Update the entries and re-add back to the raw file system
                    file.Offset = (uint)offset;
                    file.Length = (uint)input.Length;

                    gameISO.Seek(ExeOffset + FileOffsets + (file.EntryId * 16) + 8, SeekOrigin.Begin);
                    Extensions.WriteUInt32(gameISO, (uint)(file.Offset) >> 11);
                    Extensions.WriteUInt32(gameISO, file.Length);

                    // Now copy the data
                    gameISO.Seek(DataBinOffset + file.Offset, SeekOrigin.Begin);
                    Extensions.CopyStream(input, gameISO);
                }

                // If we're doing a full rebuild, null out any old data
                if (!quick)
                    gameISO.Write(nullBuffer, 0, 2048 - ((int)file.Length % 2048));

                offset += Extensions.RoundUpTo(file.Length, 2048);

                currentFileIndex++;
            }

            // If we're doing a full rebuild, null out any old data
            if (!quick)
            {
                if (bw != null)
                    bw.ReportProgress(0, String.Empty);

                Thread t = new Thread(new ThreadStart(delegate()
                    {
                        while (true)
                        {
                            if (bw != null)
                                bw.ReportProgress((int)((float)(gameISO.Position - DataBinOffset - offset) / (DataBinLength - offset) * 100), (gameISO.Position - DataBinOffset).ToString("N0") + " of " + DataBinLength.ToString("N0") + " bytes written");

                            Thread.Sleep(500);
                        }
                    }
                ));
                t.Start();

                while ((gameISO.Position - DataBinOffset) < DataBinLength)
                {
                    if ((gameISO.Position - DataBinOffset) + nullBuffer.Length > DataBinLength)
                        gameISO.Write(nullBuffer, 0, (int)(DataBinLength - (gameISO.Position - DataBinOffset)));
                    else
                        gameISO.Write(nullBuffer, 0, nullBuffer.Length);
                }

                t.Abort();
            }

            return true;
        }