private void OnOpen(object sender, EventArgs e) { if (this.openFileDialog.ShowDialog() != DialogResult.OK) { return; } string indexName = this.openFileDialog.FileName; if (indexName.EndsWith("_dir.vpk") == false) { MessageBox.Show(String.Format("{0} does not end in _dir.vpk.", Path.GetFileName(indexName)), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.savePathDialog.SelectedPath = Path.GetDirectoryName(indexName); if (this.savePathDialog.ShowDialog() != DialogResult.OK) { return; } string basePath = indexName.Substring(0, indexName.Length - 8); string savePath = this.savePathDialog.SelectedPath; PackageFile package = new PackageFile(); Stream indexStream = File.OpenRead(indexName); package.Deserialize(indexStream); indexStream.Close(); this.progressBar.Minimum = 0; this.progressBar.Maximum = package.Entries.Count; this.progressBar.Value = 0; ExtractThreadInfo info = new ExtractThreadInfo(); info.BasePath = basePath; info.SavePath = savePath; info.Package = package; this.ExtractThread = new Thread(new ParameterizedThreadStart(ExtractFiles)); this.ExtractThread.Start(info); this.EnableButtons(false); }
private void OnOpen(object sender, EventArgs e) { if (this.openFileDialog.ShowDialog() != DialogResult.OK) { return; } string path = this.openFileDialog.FileName; string save = Path.GetDirectoryName(path); save = Path.Combine(Path.Combine(Path.Combine(save, "modding"), "extracted"), Path.GetFileNameWithoutExtension(path)); Directory.CreateDirectory(save); this.savePathDialog.SelectedPath = save; if (this.savePathDialog.ShowDialog() != DialogResult.OK) { return; } save = this.savePathDialog.SelectedPath; PackageFile package = new PackageFile(); Stream stream = File.OpenRead(path); package.Read(stream); stream.Close(); this.progressBar.Minimum = 0; this.progressBar.Maximum = package.Entries.Count; this.progressBar.Value = 0; ExtractThreadInfo info = new ExtractThreadInfo(); info.Save = save; info.Path = path; info.Package = package; this.ExtractThread = new Thread(new ParameterizedThreadStart(ExtractFiles)); this.ExtractThread.Start(info); this.EnableButtons(false); }
public void ExtractFiles(object oinfo) { long succeeded, failed, current; ExtractThreadInfo info = (ExtractThreadInfo)oinfo; FileStream inputfs = new FileStream(info.Path, FileMode.Open, FileAccess.Read, FileShare.Read); Stream input = inputfs as Stream; succeeded = failed = current = 0; this.Log(String.Format("{0} files in package.", info.Package.Entries.Count)); foreach (PackageEntry entry in info.Package.Entries) { this.SetProgress(++current); input.Seek(entry.Offset, SeekOrigin.Begin); string outputName = entry.Name + "." + entry.Extension; this.Log(outputName); FileStream outputfs = new FileStream(Path.Combine(info.Save, outputName), FileMode.Create, FileAccess.Write, FileShare.None); Stream output = outputfs as Stream; if (entry.CompressedSize == -1) { long left = entry.UncompressedSize; byte[] data = new byte[4096]; while (left > 0) { int block = (int)(Math.Min(left, 4096)); input.Read(data, 0, block); output.Write(data, 0, block); left -= block; } } else { ICSharpCode.SharpZipLib.Zip.Compression.Inflater inflater = new ICSharpCode.SharpZipLib.Zip.Compression.Inflater(); // compressed using zlib long left = entry.CompressedSize; byte[] compressedData = new byte[4096]; byte[] data = new byte[4096]; while (inflater.TotalOut < entry.UncompressedSize) { if (inflater.IsNeedingInput == true) { if (left == 0) { throw new Exception(); } int block = (int)(Math.Min(left, 4096)); input.Read(compressedData, 0, block); inflater.SetInput(compressedData, 0, block); left -= block; } int inflated = inflater.Inflate(data); output.Write(data, 0, inflated); } } output.Close(); succeeded++; } input.Close(); this.Log(String.Format("Done, {0} succeeded, {1} failed, {2} total.", succeeded, failed, info.Package.Entries.Count)); this.EnableButtons(true); }
public void ExtractFiles(object oinfo) { long succeeded, failed, current; ExtractThreadInfo info = (ExtractThreadInfo)oinfo; Dictionary <string, Stream> archiveStreams = new Dictionary <string, Stream>(); succeeded = failed = current = 0; this.Log(String.Format("{0} files in package.", info.Package.Entries.Count)); foreach (PackageEntry entry in info.Package.Entries) { this.SetProgress(++current); if (entry.Size == 0 && entry.SmallData.Length > 0) { Directory.CreateDirectory(Path.Combine(info.SavePath, entry.DirectoryName)); string smallDataName = Path.Combine(entry.DirectoryName, Path.ChangeExtension(entry.FileName, entry.TypeName)); this.Log(smallDataName); Stream smallDataStream = File.OpenWrite(Path.Combine(info.SavePath, smallDataName)); smallDataStream.Write(entry.SmallData, 0, entry.SmallData.Length); smallDataStream.Close(); succeeded++; } else { string archiveName = string.Format("{0}_{1:D3}.vpk", info.BasePath, entry.ArchiveIndex); Stream archiveStream; if (archiveStreams.ContainsKey(archiveName) == true) { if (archiveStreams[archiveName] == null) { failed++; continue; } archiveStream = archiveStreams[archiveName]; } else { if (File.Exists(archiveName) == false) { this.Log(String.Format("Missing package {0}", Path.GetFileName(archiveName))); archiveStreams[archiveName] = null; failed++; continue; } archiveStream = File.OpenRead(archiveName); archiveStreams[archiveName] = archiveStream; } archiveStream.Seek(entry.Offset, SeekOrigin.Begin); string outputName = Path.Combine(entry.DirectoryName, Path.ChangeExtension(entry.FileName, entry.TypeName)); this.Log(outputName); Directory.CreateDirectory(Path.Combine(info.SavePath, entry.DirectoryName)); Stream outputStream = File.OpenWrite(Path.Combine(info.SavePath, outputName)); long left = entry.Size; byte[] data = new byte[4096]; while (left > 0) { int block = (int)(Math.Min(left, 4096)); archiveStream.Read(data, 0, block); outputStream.Write(data, 0, block); left -= block; } outputStream.Close(); if (entry.SmallData.Length > 0) { string smallDataName = Path.Combine(info.SavePath, Path.ChangeExtension(outputName, entry.TypeName + ".smalldata")); Stream smallDataStream = File.OpenWrite(smallDataName); smallDataStream.Write(entry.SmallData, 0, entry.SmallData.Length); smallDataStream.Close(); } succeeded++; } } foreach (Stream stream in archiveStreams.Values) { stream.Close(); } this.Log(String.Format("Done, {0} succeeded, {1} failed, {2} total.", succeeded, failed, info.Package.Entries.Count)); this.EnableButtons(true); }
public void ExtractFiles(object oinfo) { byte[] buffer = new byte[4096]; int succeeded, failed, current; ExtractThreadInfo info = (ExtractThreadInfo)oinfo; succeeded = failed = current = 0; foreach (var wstream in info.Streams) { current++; this.SetProgress(current); if (info.Containers.ContainsKey(wstream.Container) == false) { failed++; continue; } string savePath = Path.Combine(info.SavePath, wstream.Container); string riffPath = Path.Combine(savePath, Path.ChangeExtension(wstream.Name, ".riff")); string oggPath = Path.Combine(savePath, Path.ChangeExtension(wstream.Name, ".ogg")); Directory.CreateDirectory(savePath); Stream input = info.Containers[wstream.Container]; if (info.Validate == true) { input.Seek(wstream.Offset, SeekOrigin.Begin); uint checksum = 0; int left = (int)wstream.Size; while (left > 0) { int read = input.Read(buffer, 0, (int)Math.Min(left, buffer.Length)); if (read == 0) { break; } checksum = CRC32.Compute(buffer, 0, read, checksum); left -= read; } if (checksum != wstream.CRC) { failed++; this.LogError( "CRC mismatch for \"{0}.{1}\"! ({2:X} vs {3:X})", wstream.Container, wstream.Name, wstream.CRC, checksum); continue; } } Stream output = File.Create(riffPath); { input.Seek(wstream.Offset, SeekOrigin.Begin); int left = (int)wstream.Size; while (left > 0) { int read = input.Read(buffer, 0, (int)Math.Min(left, buffer.Length)); if (read == 0) { break; } output.Write(buffer, 0, buffer.Length); left -= read; } } output.Close(); if (info.Convert == true) { Process ogger = new Process(); ogger.StartInfo.UseShellExecute = false; ogger.StartInfo.CreateNoWindow = true; ogger.StartInfo.RedirectStandardOutput = true; ogger.StartInfo.FileName = info.Converter; ogger.StartInfo.Arguments = string.Format( "-o \"{0}\" --full-setup \"{1}\"", oggPath, riffPath); ogger.Start(); ogger.WaitForExit(); if (ogger.ExitCode != 0) { string stdout = ogger.StandardOutput.ReadToEnd(); this.LogError("Failed to convert \"{0}.{1}\"!", wstream.Container, wstream.Name); this.LogMessage(stdout); File.Delete(oggPath); failed++; continue; } File.Delete(riffPath); } succeeded++; } info.CloseStreams(); this.LogSuccess("Done, {0} succeeded, {1} failed, {2} total.", succeeded, failed, succeeded + failed); this.ToggleControls(false); }
private void OnStart(object sender, EventArgs e) { ExtractThreadInfo info = new ExtractThreadInfo(); info.Convert = this.ConverterPath != null ? this.convertCheckBox.Checked : false; info.Converter = this.ConverterPath; info.Validate = this.validateCheckBox.Checked; foreach (var wcontainer in this.WwiseContainers) { info.Streams.AddRange(wcontainer.Streams.Where(w => w.WillExtract == true)); } if (info.Streams.Count == 0) { this.LogError("No files selected."); return; } this.progressBar.Minimum = 0; this.progressBar.Maximum = info.Streams.Count; this.progressBar.Value = 0; if (this.savePathDialog.ShowDialog() != DialogResult.OK) { return; } info.SavePath = this.savePathDialog.SelectedPath; if (Directory.GetFiles(info.SavePath).Length > 0 || Directory.GetDirectories(info.SavePath).Length > 0) { if (MessageBox.Show( this, "Folder is not empty, continue anyway?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } string basePath = PackagePath; foreach (var container in info.Streams .Select(w => w.Container) .Distinct()) { string fileName = Path.ChangeExtension(container, ".afc"); string filePath = Path.Combine(basePath, fileName); if (File.Exists(filePath) == false) { this.openContainerDialog.Title = "Open " + fileName; this.openContainerDialog.Filter = fileName + "|" + fileName; if (this.openContainerDialog.ShowDialog() != DialogResult.OK) { this.LogError("Could not find \"{0}\"!", fileName); continue; } filePath = this.openContainerDialog.FileName; basePath = Path.GetDirectoryName(filePath); } info.Containers.Add(container, File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)); this.LogSuccess("Opening \"{0}\"...", fileName); } this.ToggleControls(true); this.ExtractThread = new Thread(new ParameterizedThreadStart(ExtractFiles)); this.ExtractThread.Start(info); }
private void OnOpen(object sender, EventArgs e) { if (this.openFileDialog.ShowDialog() != DialogResult.OK) { return; } string indexName = this.openFileDialog.FileName; if (indexName.EndsWith("_dir.vpk") == false) { MessageBox.Show(String.Format("{0} does not end in _dir.vpk.", Path.GetFileName(indexName)), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.savePathDialog.SelectedPath = Path.GetDirectoryName(indexName); if (this.savePathDialog.ShowDialog() != DialogResult.OK) { return; } string basePath = indexName.Substring(0, indexName.Length - 8); string savePath = this.savePathDialog.SelectedPath; PackageFile package = new PackageFile(); Stream indexStream = File.OpenRead(indexName); package.Deserialize(indexStream); indexStream.Close(); this.progressBar.Minimum = 0; this.progressBar.Maximum = package.Entries.Count; this.progressBar.Value = 0; ExtractThreadInfo info = new ExtractThreadInfo(); info.BasePath = basePath; info.SavePath = savePath; info.Package = package; this.ExtractThread = new Thread(new ParameterizedThreadStart(ExtractFiles)); this.ExtractThread.Start(info); this.EnableButtons(false); }