private static void OpenAndSaveFieldSceneBatchTest() { if (!Directory.Exists("unique_f1")) { FindUniqueFiles("unique_f1", @"D:\Modding\DDS3", ".F1"); } if (!Directory.Exists("unique_lb")) { FindUniqueFiles("unique_lb", @"D:\Modding\DDS3", ".LB"); } if (!Directory.Exists("unique_lb_extracted")) { Directory.CreateDirectory("unique_lb_extracted"); var checksums = new HashSet <string>(); Parallel.ForEach(Directory.EnumerateFiles("unique_lb"), (path) => { var fileName = Path.GetFileNameWithoutExtension(path); var outPath = $"unique_lb_extracted\\"; Directory.CreateDirectory(outPath); using (var lb = new AtlusFileSystemLibrary.FileSystems.LB.LBFileSystem()) { lb.Load(path); foreach (var file in lb.EnumerateFiles()) { var info = lb.GetInfo(file); using (var stream = lb.OpenFile(file)) { var checksum = GetChecksum(stream); stream.Position = 0; var extract = false; lock ( checksums ) { if (!checksums.Contains(checksum)) { checksums.Add(checksum); extract = true; } } if (extract) { var nameParts = Path.GetFileNameWithoutExtension(path).Split(new[] { '_' }); Array.Resize(ref nameParts, nameParts.Length - 1); using (var fileStream = File.Create(Path.Combine(outPath, string.Concat(nameParts) + "_" + file + "_" + checksum + "." + info.Extension) )) { Console.WriteLine($"Extracting: {fileName} #{file} ({info.UserId:D2}, {info.Extension})"); stream.CopyTo(fileStream); } } } } } }); } //FindUniqueFiles( "unique_f1", "unique_lb_extracted", ".F1" ); var uniqueValues = new HashSet <MeshFlags>(); var frequencyMap = new ConcurrentDictionary <MeshFlags, int>(); var paths = Directory.EnumerateFiles("unique_f1", "*.F1", SearchOption.AllDirectories).ToList(); var done = 0; Parallel.ForEach(paths, new ParallelOptions() { MaxDegreeOfParallelism = 16 }, (path) => { if (path != "unique_f1\\f500_001_9E6A1BA4D63DD8AA05144CEF3768A380EEAFD2E6D620C24CE85DC173533B5992.F1") { Console.WriteLine(Path.GetFileName(path)); var field = new FieldScene(path); //ExportObj( field, Path.GetFileNameWithoutExtension( path ) + ".obj" ); new FieldScene(field.Save()); //field.Save( path + ".out" ); //new FieldScene( path + ".out" ); //File.Delete( path + ".out" ); } }); foreach (var kvp in frequencyMap.OrderBy(x => x.Value)) { Console.WriteLine(kvp.Value + " " + kvp.Key); } }
private static void OpenAndSaveModelPackBatchTest() { if (!Directory.Exists("unique_models")) { FindUniqueFiles("unique_models", @"D:\Modding\DDS3", ".PB"); } if (!Directory.Exists("unique_lb")) { FindUniqueFiles("unique_lb", @"D:\Modding\DDS3", ".LB"); } if (!Directory.Exists("unique_lb_extracted")) { Directory.CreateDirectory("unique_lb_extracted"); var checksums = new HashSet <string>(); Parallel.ForEach(Directory.EnumerateFiles("unique_lb"), (path) => { var fileName = Path.GetFileNameWithoutExtension(path); var outPath = $"unique_lb_extracted\\"; Directory.CreateDirectory(outPath); using (var lb = new AtlusFileSystemLibrary.FileSystems.LB.LBFileSystem()) { lb.Load(path); foreach (var file in lb.EnumerateFiles()) { var info = lb.GetInfo(file); using (var stream = lb.OpenFile(file)) { var checksum = GetChecksum(stream); stream.Position = 0; var extract = false; lock ( checksums ) { if (!checksums.Contains(checksum)) { checksums.Add(checksum); extract = true; } } if (extract) { var nameParts = Path.GetFileNameWithoutExtension(path).Split(new[] { '_' }); Array.Resize(ref nameParts, nameParts.Length - 1); using (var fileStream = File.Create(Path.Combine(outPath, string.Concat(nameParts) + "_" + file + "_" + checksum + "." + info.Extension) )) { Console.WriteLine($"Extracting: {fileName} #{file} ({info.UserId:D2}, {info.Extension})"); stream.CopyTo(fileStream); } } } } } }); } var uniqueValues = new HashSet <MeshFlags>(); var frequencyMap = new ConcurrentDictionary <MeshFlags, int>(); var paths = Directory.EnumerateFiles("unique_models", "*.PB", SearchOption.AllDirectories).ToList(); var done = 0; //foreach ( var path in paths ) Parallel.ForEach(paths, new ParallelOptions() { MaxDegreeOfParallelism = 16 }, (path) => { Console.WriteLine(Path.GetFileName(path)); var modelPack = new ModelPack(path); new ModelPack(modelPack.Save()); //modelPack.Save( path + ".out" ); //new ModelPack( path + ".out" ); //ExportObj( modelPack, Path.GetFileNameWithoutExtension( path ) + ".obj" ); } ); //var modelPack = new ModelPack( @"D:\Programming\Repos\DDS3-Model-Studio\Source\DDS3ModelLibraryCLI\bin\Debug\unique_models\tiaki_DF1D93D2EC3ED36D63239A1A2B27ED1745DA9991F231884EA7BC5FAF291F74AA.PB" ); //modelPack.Save( @"D:\Programming\Repos\DDS3-Model-Studio\Source\DDS3ModelLibraryCLI\bin\Debug\unique_models\tiaki_DF1D93D2EC3ED36D63239A1A2B27ED1745DA9991F231884EA7BC5FAF291F74AA.PB" + ".out" ); //foreach ( var kvp in frequencyMap.OrderBy( x => x.Value ) ) //{ // Console.WriteLine( kvp.Value + " " + kvp.Key ); //} //var paths = Directory.EnumerateFiles( "unique_models", "*.PB", SearchOption.AllDirectories ).ToList(); //var done = 0; //Parallel.ForEach( paths, new ParallelOptions() { MaxDegreeOfParallelism = 8 }, ( path ) => //{ // //Console.WriteLine( Path.GetFileName( path ) ); // var modelPack = new ModelPack( path ); // //modelPack.Save( path + ".out" ); // //File.Delete( path + ".out" ); // //modelPack.Save(); //} ); //var done = 0; //Parallel.ForEach( paths, new ParallelOptions() { MaxDegreeOfParallelism = 8 }, ( path ) => //{ // Console.WriteLine( Path.GetFileName( path ) ); // var outPath = "unique_models\\" + Path.GetFileName( path ) + ".PB"; // if ( Path.GetExtension( path ) == ".PAC" ) // { // using ( var reader = new EndianBinaryReader( path, Endianness.Little ) ) // { // reader.Position = 0x24; // var size = reader.ReadInt32(); // reader.Position += 4; // var offset = reader.ReadInt32(); // using ( var fileStream = File.Create( outPath ) ) // new StreamView( reader.BaseStream, offset, size ).CopyTo( fileStream ); // } // } // else // { // File.Copy( path, outPath, true ); // } //} ); }