void checkModReady() { FilesEditor.SetPath(1, null, null); if (RightPath != null) { FullTextIndex.ResetPath(RightPath); } if (ModPath.Text != "") { RightPath = buildRightPath(ModPath.Text); Unpack_Mod.IsEnabled = File.Exists(ModPath.Text); if (Directory.Exists(RightPath)) { FilesEditor.SetPath(1, RightPath, null); TabFilesEditor.IsEnabled = true; Pack_Mod.IsEnabled = true; Unpack_Mod_Doc.Text = "You have unpacked this mod. Edit it in the Files tab."; Pack_Mod_Doc.Text = "You must pack the mod to see changes in Spore."; } else { TabFilesEditor.IsEnabled = false; Pack_Mod.IsEnabled = false; Unpack_Mod_Doc.Text = "You must unpack this mod before editing it."; Pack_Mod_Doc.Text = ""; } } else { Unpack_Mod.IsEnabled = false; Pack_Mod.IsEnabled = false; Unpack_Mod_Doc.Text = ""; Pack_Mod_Doc.Text = ""; RightPath = null; } }
public PackageUnpack(Stream[] packageFiles, string destinationFolder, PleaseWait progress) { double e = 0.0; FullTextIndex.ResetPath(destinationFolder); if (Directory.Exists(destinationFolder)) { if (progress != null) { progress.beginTask(e = 0.25, 1.0); } Directory.Delete(destinationFolder, true); if (progress != null) { progress.endTask(); } } Directory.CreateDirectory(destinationFolder); double totalSize = 0; for (int i = 0; i < packageFiles.Length; i++) { totalSize += packageFiles[i].Length; } if (progress != null) { progress.beginTask(1.0 - e, totalSize); } foreach (var filestream in packageFiles) { DatabasePackedFile db = new DatabasePackedFile(); db.Read(filestream); var DatabaseFiles = db.Indices.ToArray(); var group_sporemaster = "sporemaster".FNV(); var instance_names = "names".FNV(); foreach (var dbf in DatabaseFiles) { if (dbf.GroupId == group_sporemaster && dbf.InstanceId == instance_names) { byte[] data = unpack(filestream, dbf); readNamesFile(data); } } var locale_type = NameRegistry.Types.toHash("locale"); var prop_type = NameRegistry.Types.toHash("prop"); var rw4_type = NameRegistry.Types.toHash("rw4"); foreach (var dbf in DatabaseFiles) { // skip over automatically generated locale files if (!(dbf.TypeId == locale_type && ( NameRegistry.Groups.toName(dbf.InstanceId).StartsWith("auto_") || NameRegistry.Groups.toName(dbf.InstanceId).EndsWith("_auto")))) { var fn = Path.Combine(destinationFolder, NameRegistry.getFileName(dbf.GroupId, dbf.InstanceId, dbf.TypeId)); Directory.CreateDirectory(Path.GetDirectoryName(fn)); byte[] data = unpack(filestream, dbf); if (dbf.TypeId == prop_type) { writePropFile(data, fn); } else if (dbf.TypeId == rw4_type) { writeRW4File(data, fn); } else { writeBinaryFile(data, fn); } } if (progress != null) { progress.addProgress(dbf.CompressedSize); } } filestream.Close(); } if (progress != null) { progress.endTask(); } }