public static void SaveSpecies(string destinationPath, Dictionary <MonsterID, byte[]> spriteData) { if (spriteData.Count == 0) { DiagManager.Instance.LogInfo("Skipped data for " + Path.GetFullPath(destinationPath)); return; } //generate formtree CharaIndexNode guide = new CharaIndexNode(); Dictionary <MonsterID, long> spritePositions = new Dictionary <MonsterID, long>(); long currentPosition = 0; foreach (MonsterID key in spriteData.Keys) { spritePositions[key] = currentPosition; currentPosition += spriteData[key].LongLength; } foreach (MonsterID key in spritePositions.Keys) { guide.AddSubValue(0, key.Form, key.Skin, (int)key.Gender); } using (FileStream stream = new FileStream(destinationPath, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { using (BinaryWriter writer = new BinaryWriter(stream)) { //save the guide guide.Save(writer); //update how much space it takes foreach (MonsterID key in spritePositions.Keys) { guide.AddSubValue(spritePositions[key] + writer.BaseStream.Position, key.Form, key.Skin, (int)key.Gender); } //save it again writer.Seek(0, SeekOrigin.Begin); guide.Save(writer); //save data foreach (byte[] formData in spriteData.Values) { writer.Write(formData); } } } DiagManager.Instance.LogInfo("Wrote data to " + Path.GetFullPath(destinationPath)); }
public static void BuildCharIndex(string cachePattern) { CharaIndexNode fullGuide = new CharaIndexNode(); string search = Path.GetDirectoryName(String.Format(cachePattern, '*')); string pattern = Path.GetFileName(String.Format(cachePattern, '*')); try { foreach (string dir in Directory.GetFiles(search, pattern)) { string file = Path.GetFileNameWithoutExtension(dir); int num = Convert.ToInt32(file.Split('-')[1]); using (FileStream stream = File.OpenRead(dir)) { using (BinaryReader reader = new BinaryReader(stream)) { CharaIndexNode speciesGuide = CharaIndexNode.Load(reader); fullGuide.Nodes[num] = speciesGuide; } } } using (FileStream stream = new FileStream(search + "/index.idx", FileMode.Create, FileAccess.Write)) { using (BinaryWriter writer = new BinaryWriter(stream)) fullGuide.Save(writer); } } catch (Exception ex) { DiagManager.Instance.LogError(new Exception("Error importing index at " + search + "\n", ex)); } }