static void DoConvert() { Dictionary <string, int> errors = new Dictionary <string, int>(); int okCount = 0; string[] files; string dir = "C:\\my\\proj\\mods\\spore\\SporeMaster\\SporeMaster\\bin\\Release\\spore.unpacked\\part_models~\\"; //string dir = "C:\\my\\proj\\mods\\spore\\SporeMaster\\SporeMaster\\bin\\Release\\mod_eye.package.unpacked\\part_models~\\"; Dictionary <string, List <string> > name_files = new Dictionary <string, List <string> >(); files = Directory.GetFiles(dir, "raw.rw4", SearchOption.AllDirectories); foreach (var f in files) { //var outdir = "c:\\my\\proj\\mods\\spore\\rw4test\\" + Path.GetFileNameWithoutExtension(f) + ".rw4"; var outdir = Path.GetDirectoryName(f); try { //Console.Write(f.Substring(dir.Length) + ": "); var fn = Path.GetDirectoryName(f.Substring(dir.Length)); Console.WriteLine(" " + fn); //if (fn != "ce_details_hair_01.rw4") continue; //if (fn != "ce_details_wing_04.rw4") continue; ModelUnpack up; using (var stream = File.OpenRead(f)) { Directory.CreateDirectory(outdir); up = new ModelUnpack(stream, outdir); } if (up.Model.FileType == RW4Model.FileTypes.Model) { ReadAnim(up.Model, outdir + "\\anim.xml", outdir + "\\model.skeleton.xml"); var anims = (from anim in up.Model.GetObjects(Anim.type_code) select(Anim) anim).ToArray(); foreach (var a in anims) { var n = SporeMaster.NameRegistry.Files.toName(a.hash_name); if (a.is_handle) { n += " (H)"; } if (!name_files.ContainsKey(n)) { name_files.Add(n, new List <string>()); } name_files[n].Add(fn); Console.WriteLine(" " + n); } } okCount++; //Console.WriteLine(up.Type); } catch (SporeMaster.RenderWare4.ModelFormatException e) { System.Console.WriteLine(" " + e.Message); if (errors.ContainsKey(e.exception_type)) { errors[e.exception_type]++; } else { errors[e.exception_type] = 1; } /*try { Directory.Delete(outdir); } * catch (System.IO.IOException) { }*/ } catch (Exception e) { System.Console.WriteLine(" " + e.Message); if (errors.ContainsKey(e.Message)) { errors[e.Message]++; } else { errors[e.Message] = 1; } /*try { Directory.Delete(outdir); } * catch (System.IO.IOException) { }*/ } } System.Console.WriteLine(String.Format("Converted {0}/{1} files.", okCount, files.Length)); if (errors.Count() != 0) { System.Console.WriteLine("Errors:"); foreach (var e in errors) { System.Console.WriteLine(String.Format(" {0}: {1}", e.Key, e.Value)); } } System.Console.WriteLine("Handles:"); foreach (var n in name_files) { if (!n.Key.EndsWith("(H)")) { continue; } System.Console.WriteLine(" " + n.Key); foreach (var f in n.Value) { System.Console.WriteLine(" " + f); } } System.Console.WriteLine("Animations:"); foreach (var n in name_files) { if (n.Key.EndsWith("(H)")) { continue; } System.Console.WriteLine(" " + n.Key); foreach (var f in n.Value) { System.Console.WriteLine(" " + f); } } }
static void DoConvert() { Dictionary<string, int> errors = new Dictionary<string, int>(); int okCount = 0; string[] files; string dir = "C:\\my\\proj\\mods\\spore\\SporeMaster\\SporeMaster\\bin\\Release\\spore.unpacked\\part_models~\\"; //string dir = "C:\\my\\proj\\mods\\spore\\SporeMaster\\SporeMaster\\bin\\Release\\mod_eye.package.unpacked\\part_models~\\"; Dictionary<string, List<string>> name_files = new Dictionary<string, List<string>>(); files = Directory.GetFiles(dir, "raw.rw4", SearchOption.AllDirectories); foreach (var f in files) { //var outdir = "c:\\my\\proj\\mods\\spore\\rw4test\\" + Path.GetFileNameWithoutExtension(f) + ".rw4"; var outdir = Path.GetDirectoryName(f); try { //Console.Write(f.Substring(dir.Length) + ": "); var fn = Path.GetDirectoryName(f.Substring(dir.Length)); Console.WriteLine(" " + fn); //if (fn != "ce_details_hair_01.rw4") continue; //if (fn != "ce_details_wing_04.rw4") continue; ModelUnpack up; using (var stream = File.OpenRead(f)) { Directory.CreateDirectory(outdir); up = new ModelUnpack(stream, outdir); } if (up.Model.FileType == RW4Model.FileTypes.Model) { ReadAnim(up.Model, outdir + "\\anim.xml", outdir + "\\model.skeleton.xml"); var anims = (from anim in up.Model.GetObjects(Anim.type_code) select (Anim)anim).ToArray(); foreach (var a in anims) { var n = SporeMaster.NameRegistry.Files.toName(a.hash_name); if (a.is_handle) n += " (H)"; if (!name_files.ContainsKey(n)) name_files.Add(n, new List<string>()); name_files[n].Add(fn); Console.WriteLine(" " + n); } } okCount++; //Console.WriteLine(up.Type); } catch (SporeMaster.RenderWare4.ModelFormatException e) { System.Console.WriteLine(" " + e.Message); if (errors.ContainsKey(e.exception_type)) errors[e.exception_type]++; else errors[e.exception_type] = 1; /*try { Directory.Delete(outdir); } catch (System.IO.IOException) { }*/ } catch (Exception e) { System.Console.WriteLine(" " + e.Message); if (errors.ContainsKey(e.Message)) errors[e.Message]++; else errors[e.Message] = 1; /*try { Directory.Delete(outdir); } catch (System.IO.IOException) { }*/ } } System.Console.WriteLine(String.Format("Converted {0}/{1} files.", okCount, files.Length)); if (errors.Count() != 0) { System.Console.WriteLine("Errors:"); foreach (var e in errors) System.Console.WriteLine(String.Format(" {0}: {1}", e.Key, e.Value)); } System.Console.WriteLine("Handles:"); foreach (var n in name_files) { if (!n.Key.EndsWith("(H)")) continue; System.Console.WriteLine(" " + n.Key); foreach (var f in n.Value) System.Console.WriteLine(" " + f); } System.Console.WriteLine("Animations:"); foreach (var n in name_files) { if (n.Key.EndsWith("(H)")) continue; System.Console.WriteLine(" " + n.Key); foreach (var f in n.Value) System.Console.WriteLine(" " + f); } }