public static void Save(TextBox author, string interfaceVersion, TextBox addonName) { AddonAuthor = author.Text.Replace("\n", "").Replace("\r", ""); InterfaceVersion = interfaceVersion; try { string fullRotationText = ""; bool encrypted = (FullRotationFilePath.EndsWith(".enc")); using (var sr = new StreamReader(FullRotationFilePath)) { bool readLines = true; string fileContents = sr.ReadToEnd(); if (encrypted) { fileContents = Encryption.Decrypt(fileContents); } foreach (string line in fileContents.Split('\n')) { if (line.Contains("AddonDetails.db")) { readLines = false; } if (readLines) { if (line.StartsWith("/*")) { fullRotationText += line.Replace("\r", "").Replace("\n", ""); } else { fullRotationText += line.Replace("\r", "").Replace("\n", "") + Environment.NewLine; } } } sr.Close(); } string updatedRotationText = fullRotationText + Environment.NewLine; updatedRotationText += "[AddonDetails.db]" + Environment.NewLine; updatedRotationText += $"AddonAuthor={AddonAuthor}" + Environment.NewLine; updatedRotationText += $"AddonName={AddonName}" + Environment.NewLine; updatedRotationText += $"WoWVersion={InterfaceVersion}" + Environment.NewLine; updatedRotationText += "[SpellBook.db]" + Environment.NewLine; foreach (var spell in Spells) { updatedRotationText += $"Spell,{spell.SpellId},{spell.SpellName},{spell.KeyBind}" + Environment.NewLine; } foreach (var aura in Auras) { updatedRotationText += $"Aura,{aura.AuraId},{aura.AuraName}" + Environment.NewLine; } updatedRotationText += "*/"; using (var sw = new StreamWriter(FullRotationFilePath, false)) { if (encrypted) { updatedRotationText = Encryption.Encrypt(updatedRotationText); sw.WriteLine(updatedRotationText); } else { sw.WriteLine(updatedRotationText); } sw.Close(); } GenerateLUAFile(); MessageBox.Show("Spell Book Saved.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static bool Load() { using (var sr = new StreamReader(FullRotationFilePath)) { string fileContents = sr.ReadToEnd(); bool encrypted = (FullRotationFilePath.EndsWith(".enc")); if (encrypted) { fileContents = Encryption.Decrypt(fileContents); } RotationFileContents = fileContents; bool addonLines = false; bool readLines = false; foreach (string line in fileContents.Split('\n')) { if (line.Contains("AddonDetails.db")) { addonLines = true; } if (line.Contains("SpellBook.db")) { readLines = true; } if (addonLines) { if (line.Contains("AddonLines.db")) { continue; } var split = line.Split('='); if (split[0] == "AddonAuthor") { AddonAuthor = split[1]; } if (split[0] == "WoWVersion") { InterfaceVersion = split[1]; } } if (readLines) { if (line.Contains("SpellBook.db")) { continue; } var split = line.Split(','); if (split[0] == "Spell") { AddSpell(int.Parse(split[1]), split[2], split[3]); } if (split[0] == "Aura") { AddAura(int.Parse(split[1]), split[2]); } } } sr.Close(); if (addonLines && readLines) // If the word "AddonDetails.db" and "SpellBook.db" exists in the rotation.cs file { RenumberSpells(); Log.Write($"Found {Spells.Count} spells defined", Color.Gray); Log.Write($"Found {Auras.Count} auras defined", Color.Gray); Log.Write("SpellBook loaded."); if (!File.Exists(AddonPath + "\\" + AddonName + "\\" + AddonName + ".toc")) { return(GenerateLUAFile()); } } else { Log.Write("Failed to load addon details or spellbook from rotation file, please ensure that it is not missing.", Color.Red); Log.Write("you can see the file: " + Application.StartupPath + "\\Rotations\\Warrior\\Warrior.cs for reference", Color.Red); return(false); } } return(false); }