/// <summary> /// Exports a file of a given type. /// Formats available to export will depend on the type of the data. /// </summary> /// <param name="type">Type of the data to be exported</param> /// <param name="data">The data</param> /// <param name="arguments">Optional arguments to be used by the exporter</param> public static void export(fileType type, object data, params int[] arguments) { string fileName = null; switch (type) { case fileType.container: foreach (OContainer.fileEntry file in ((OContainer)data).content) { Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\" + ((OContainer)data).name); fileName = Path.Combine(System.Environment.CurrentDirectory + "\\" + ((OContainer)data).name, file.name); string dir = Path.GetDirectoryName(fileName); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } byte[] buffer; if (file.loadFromDisk) { buffer = new byte[file.fileLength]; ((OContainer)data).data.Seek(file.fileOffset, SeekOrigin.Begin); ((OContainer)data).data.Read(buffer, 0, buffer.Length); } else { buffer = file.data; } if (file.doDecompression) { buffer = LZSS_Ninty.decompress(buffer); } File.WriteAllBytes(fileName, buffer); Console.WriteLine("Extracted file: " + fileName); } break; case fileType.model: for (int i = 0; i < ((RenderBase.OModelGroup)data).model.Count; i++) { fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OModelGroup)data).model[i].name); switch (arguments[0]) { case 0: DAE.export(((RenderBase.OModelGroup)data), fileName + ".dae", i); break; case 1: SMD.export(((RenderBase.OModelGroup)data), fileName + ".smd", i); break; case 2: OBJ.export(((RenderBase.OModelGroup)data), fileName + ".obj", i); break; case 3: CMDL.export(((RenderBase.OModelGroup)data), fileName + ".cmdl", i); break; } Console.WriteLine("Extracted file: " + fileName); } break; case fileType.texture: if (data.GetType().Equals(typeof(RenderBase.OModelGroup))) //if extracting textures from a model { Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\" + ((RenderBase.OModelGroup)data).model[0].name + "_tex"); foreach (RenderBase.OTexture tex in ((RenderBase.OModelGroup)data).texture) { fileName = Path.Combine(System.Environment.CurrentDirectory + "\\" + ((RenderBase.OModelGroup)data).model[0].name + "_tex", tex.name + ".png"); tex.texture.Save(fileName); Console.WriteLine("Extracted file: " + fileName); } } else // not a model { fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OTexture)data).name + ".png"); ((RenderBase.OTexture)data).texture.Save(fileName); Console.WriteLine("Extracted file: " + fileName); } break; case fileType.skeletalAnimation: fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OModelGroup)data).model[0].name); SMD.export((RenderBase.OModelGroup)data, fileName, arguments[0], arguments[1]); Console.WriteLine("Extracted file: " + fileName); break; } Console.WriteLine("Extracting files completed!"); }
private void ok() { if (!Directory.Exists(TxtOutFolder.Text)) { MessageBox.Show("Invalid output directory!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } Settings.Default.meOutFolder = TxtOutFolder.Text; int format = 0; if (RadioSMD.Checked) { format = 1; } else if (RadioOBJ.Checked) { format = 2; } else if (RadioCMDL.Checked) { format = 3; } Settings.Default.meFormat = format; Settings.Default.meExportAllMdls = ChkExportAllModels.Checked; Settings.Default.meExportAllAnms = ChkExportAllAnimations.Checked; Settings.Default.Save(); if (ChkExportAllModels.Checked && !ChkExportAllAnimations.Checked) { for (int i = 0; i < mdls.model.Count; i++) { string fileName = Path.Combine(TxtOutFolder.Text, mdls.model[i].name); switch (format) { case 0: DAE.export(mdls, fileName + ".dae", i); break; case 1: SMD.export(mdls, fileName + ".smd", i); break; case 2: OBJ.export(mdls, fileName + ".obj", i); break; case 3: CMDL.export(mdls, fileName + ".cmdl", i); break; } } } else if (mdlIndex > -1) { string fileName = Path.Combine(TxtOutFolder.Text, TxtModelName.Text); switch (format) { case 0: DAE.export(mdls, fileName + ".dae", mdlIndex); break; case 1: SMD.export(mdls, fileName + ".smd", mdlIndex); if (ChkExportAllAnimations.Checked) { for (int i = 0; i < mdls.skeletalAnimation.list.Count; i++) { string name = mdls.skeletalAnimation.list[i].name + ".smd"; SMD.export(mdls, Path.Combine(TxtOutFolder.Text, name), mdlIndex, i); } } break; case 2: OBJ.export(mdls, fileName + ".obj", mdlIndex); break; case 3: CMDL.export(mdls, fileName + ".cmdl", mdlIndex); break; } } Close(); }