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(); } }
private void write( FullTextIndex fti ) { if (writer == null) { writer = new BinaryWriter(File.Create(filename)); } writer.Write(Path.GetFileName(fti.fullpath)); writer.Write((Int32)fti.data.Length); writer.Write(fti.lastModified.ToFileTimeUtc()); writer.Write(fti.data, 0, fti.data.Length); for (int i = 0; i < fti.data.Length; i++) writer.Write(fti.suffix_array[i]); }
public void read(string filename) { this.filename = filename; if (!File.Exists(filename)) return; try { using (var file = File.OpenRead(filename)) { var reader = new BinaryReader(file); int fileLength = (int)reader.BaseStream.Length; int pos = 0; while (pos < fileLength) { var name = reader.ReadString(); pos += name.Length >= 128 * 128 ? 3 : name.Length >= 128 ? 2 : 1; pos += name.Length; var len = reader.ReadInt32(); if (len<0 || (ulong)pos + (ulong)12 + (ulong)len * (ulong)5 > (ulong)fileLength) throw new Exception("Bad length in index file."); pos += 4; DateTime lastModified = DateTime.FromFileTimeUtc(reader.ReadInt64()); pos += 8; var data = new byte[len]; reader.Read(data, 0, len); pos += len; var suffix_array = new int[len]; for (int i = 0; i < len; i++) { suffix_array[i] = reader.ReadInt32(); if (suffix_array[i] < 0 || suffix_array[i] >= len) throw new Exception("Out of bounds data in suffix array."); } pos += len * 4; cache[name] = new FullTextIndex { data = data, suffix_array = suffix_array, lastModified = lastModified }; totalsize += cache[name].data.Length; } } } catch (Exception) { File.Delete(filename); this.storedsize = 0; cache = new Dictionary<string, FullTextIndex>(); totalsize = 0; } }
public void Add(FullTextIndex fti) { var fname = Path.GetFileName( fti.fullpath ); if (cache.ContainsKey(fname)) this.totalsize -= cache[fname].data.Length; cache[fname] = fti; var oldtotalsize = this.totalsize; this.totalsize += fti.data.Length; this.storedsize += fti.data.Length; if (this.storedsize > this.totalsize * 2 && this.storedsize > this.totalsize + 16384) { this.storedsize = totalsize; writer.Close(); writer = null; File.Delete(filename); foreach (var i in cache.Values) write(i); writer.Flush(); } else { write(fti); if (this.totalsize / 1000000 > oldtotalsize / 1000000) writer.Flush(); } }